Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AllCops:
TargetRubyVersion: 3.1
Exclude:
- 'config/**/*'
- 'db/**/*'
- 'db/schema.rb'
- 'scripts/**/*'
- 'bin/**/*'
- 'lib/namespaced_env_cache.rb'
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/site_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $(() => {
const settingEditFields = {
'array': $(`<select class="form-element js-setting-edit" multiple></select>`),
'string': $(`<input type="text" class="form-element js-setting-edit" />`),
'uri_path': $(`<input type="text" class="form-element js-setting-edit" />`),
'integer': $('<input type="number" class="form-element js-setting-edit" />'),
'float': $('<input type="number" step="0.0001" class="form-element js-setting-edit" />'),
'boolean': $(`<select class="form-element js-setting-edit">
Expand Down
20 changes: 20 additions & 0 deletions app/helpers/seeds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,24 @@ def self.prioritize(types, files)
(priority.index(a.second) || 999) <=> (priority.index(b.second) || 999)
end.to_h
end

Stats = Struct.new('Stats', :created, :updated, :errored, :skipped) do |struct|
struct.members.each do |member|
define_method "add_#{member}" do |num|
self[member] += num
end
end

def <<(other)
members.each do |member|
send("add_#{member}", other[member])
end
end

def print
members.map { |m| self[m]&.positive? ? "#{m} #{self[m]}" : nil }
.compact
.join(', ')
end
end
end
2 changes: 1 addition & 1 deletion app/models/site_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def global?
end

# Defines predicates for each value type
[:array, :boolean, :float, :integer, :string, :text].each do |method|
[:array, :boolean, :float, :integer, :string, :text, :uri_path].each do |method|
define_method "#{method}?" do
value_type.downcase.to_sym == method
end
Expand Down
15 changes: 12 additions & 3 deletions app/views/layouts/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
<%= page_title %>
</title>

<% icon_path = SiteSetting['IconPath'] %>
<%
css_path = SiteSetting['CSSPath']
icon_path = SiteSetting['IconPath']
js_path = SiteSetting['JSPath']
%>

<link rel="icon" href="<%= icon_path.present? ? icon_path : '/assets/favicon.ico' %>" />
<link rel="search"
type="application/opensearchdescription+xml"
Expand All @@ -23,7 +28,9 @@
<%= stylesheet_link_tag "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/all.min.css" %>
<%= stylesheet_link_tag "https://cdn.jsdelivr.net/npm/@codidact/co-design@latest/dist/codidact.css" %>
<%= stylesheet_link_tag "https://cdn.jsdelivr.net/npm/select2@4.0.12/dist/css/select2.min.css" %>
<%= stylesheet_link_tag "/assets/community/#{@community.host.split('.')[0]}.css" %>
<% if css_path.present? %>
<%= stylesheet_link_tag css_path %>
<% end %>
<%= stylesheet_link_tag 'application', media: 'all' %>

<%= javascript_include_tag "https://cdn.jsdelivr.net/npm/jquery@2.2.2/dist/jquery.min.js" %>
Expand All @@ -33,7 +40,9 @@
<%= javascript_include_tag "https://js.stripe.com/v3/" %>
<% end %>
<%= javascript_include_tag "https://cdn.jsdelivr.net/npm/dompurify@2.5.8/dist/purify.min.js" %>
<%= javascript_include_tag "/assets/community/#{@community.host.split('.')[0]}.js" %>
<% if js_path.present? %>
<%= javascript_include_tag js_path %>
<% end %>
<%= javascript_include_tag 'application' %>
<script src="https://cdn.jsdelivr.net/npm/@codidact/co-design@latest/js/co-design.js" defer></script>

Expand Down
4 changes: 0 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,4 @@
scope 'network' do
root to: 'fake_community#communities', as: :fc_communities
end

# Communities can have custom js or css defined (placed in public/assets/community).
# If these are not defined for a community, respond with 204 (ok but empty)
get '/assets/community/*path', to: ->(env) { [204, {}, ['']] }
end
5 changes: 2 additions & 3 deletions db/migrate/20160424111225_devise_create_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.string :email, null: false, default: ''
t.string :encrypted_password, null: false, default: ''

## Recoverable
t.string :reset_password_token
Expand All @@ -30,7 +30,6 @@ def change
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at


t.timestamps null: false
end

Expand Down
1 change: 0 additions & 1 deletion db/migrate/20160501095155_create_comments.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|

t.timestamps null: false
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def change
t.string :checksum, null: false
t.datetime :created_at, null: false

t.index [ :key ], unique: true
t.index [:key], unique: true
end

create_table :active_storage_attachments do |t|
Expand All @@ -20,7 +20,9 @@ def change

t.datetime :created_at, null: false

t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
t.index [:record_type, :record_id, :name, :blob_id],
name: 'index_active_storage_attachments_uniqueness',
unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
Expand Down
12 changes: 6 additions & 6 deletions db/migrate/20191225135200_add_category_to_site_settings.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AddCategoryToSiteSettings < ActiveRecord::Migration[5.2]
def change
add_column :site_settings, :category, :string
add_index :site_settings, :category
end
end
class AddCategoryToSiteSettings < ActiveRecord::Migration[5.2]
def change
add_column :site_settings, :category, :string
add_index :site_settings, :category
end
end
74 changes: 37 additions & 37 deletions db/migrate/20191225141700_add_setting_categories.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
class AddSettingCategories < ActiveRecord::Migration[5.2]
def change
# This migration only needs to run if there are already existing settings without a category.
# That's not the case in test, because they get seeded as necessary, so we don't need to run this.
return if Rails.env.test?
categories = {
site_name: :site_details,
site_logo_path: :site_details,
question_up_vote_rep: :reputation_and_voting,
question_down_vote_rep: :reputation_and_voting,
answer_up_vote_rep: :reputation_and_voting,
answer_down_vote_rep: :reputation_and_voting,
allow_self_votes: :reputation_and_voting,
asking_guidance: :help_and_guidance,
answering_guidance: :help_and_guidance,
administrator_contact_email: :site_details,
hot_questions_count: :display,
admin_badge_character: :display,
mod_badge_character: :display,
soft_delete_transfer_user: :advanced_settings,
new_user_initial_rep: :reputation_and_voting,
se_api_client_id: :integrations,
se_api_client_secret: :integrations,
se_api_key: :integrations,
content_license_name: :site_details,
content_license_link: :site_details,
max_tag_length: :site_details,
max_upload_size: :advanced_settings
}
categories.each do |name, category|
puts "#{name.to_s.camelize}: #{category.to_s.camelize}"
SiteSetting.find_by(name: name.to_s.camelize).update(category: category.to_s.camelize)
end
end
end
class AddSettingCategories < ActiveRecord::Migration[5.2]
def change
# This migration only needs to run if there are already existing settings without a category.
# That's not the case in test, because they get seeded as necessary, so we don't need to run this.
return if Rails.env.test?

categories = {
site_name: :site_details,
site_logo_path: :site_details,
question_up_vote_rep: :reputation_and_voting,
question_down_vote_rep: :reputation_and_voting,
answer_up_vote_rep: :reputation_and_voting,
answer_down_vote_rep: :reputation_and_voting,
allow_self_votes: :reputation_and_voting,
asking_guidance: :help_and_guidance,
answering_guidance: :help_and_guidance,
administrator_contact_email: :site_details,
hot_questions_count: :display,
admin_badge_character: :display,
mod_badge_character: :display,
soft_delete_transfer_user: :advanced_settings,
new_user_initial_rep: :reputation_and_voting,
se_api_client_id: :integrations,
se_api_client_secret: :integrations,
se_api_key: :integrations,
content_license_name: :site_details,
content_license_link: :site_details,
max_tag_length: :site_details,
max_upload_size: :advanced_settings
}

categories.each do |name, category|
puts "#{name.to_s.camelize}: #{category.to_s.camelize}"
SiteSetting.find_by(name: name.to_s.camelize).update(category: category.to_s.camelize)
end
end
end
9 changes: 4 additions & 5 deletions db/migrate/20200202052500_create_communities_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def change
dir.up do
@community = Community.create(name: 'Sample', host: 'sample.qpixel.com')
community_users = MigrationSafeUser.pluck(:id, :reputation).map do |user_id, reputation|
{community_id: @community.id, user_id: user_id, reputation: reputation}
{ community_id: @community.id, user_id: user_id, reputation: reputation }
end
CommunityUser.create(community_users)
change_table :users do |t|
Expand All @@ -38,15 +38,14 @@ def change
t.integer :reputation, after: 'is_admin'
end
@community = Community.first
CommunityUser.where(community_id: @community.id).pluck(:user_id,:reputation).map do |user_id, reputation|
CommunityUser.where(community_id: @community.id).pluck(:user_id, :reputation).map do |user_id, reputation|
MigrationSafeUser.find(user_id).update(reputation: reputation)
end
end
end

%i(posts comments flags post_histories votes
notifications privileges site_settings subscriptions tags
).each do |table|
%i[posts comments flags post_histories votes
notifications privileges site_settings subscriptions tags].each do |table|
change_table table do |t|
t.references :community
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20200317173232_close_reasons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ def change
t.boolean :requires_other_post
end
add_reference :posts, :close_reasons, foreign_key: true, null: true
add_reference :posts, :duplicate_post, foreign_key: {to_table: :posts}, null: true
add_reference :posts, :duplicate_post, foreign_key: { to_table: :posts }, null: true
end
end
7 changes: 4 additions & 3 deletions db/migrate/20200321135945_add_tag_set_reference_to_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ def change
RequestContext.community = community
main_set = TagSet.find_or_create_by(community: community, name: 'Main')
meta_set = TagSet.find_or_create_by(community: community, name: 'Meta')
sql = "select tag_id from posts_tags where post_id in (select id from posts where community_id = #{community.id} and category = '$cat')"
in_sql = "(select id from posts where community_id = #{community.id} and category = '$cat')"
sql = "select tag_id from posts_tags where post_id in #{in_sql}"
Comment on lines +8 to +9
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a manual line length fix

main_sql = sql.gsub('$cat', 'Main')
meta_sql = sql.gsub('$cat', 'Meta')
update_sql = "update tags set tag_set_id = $tsid where id in ($sql);"
update_sql = 'update tags set tag_set_id = $tsid where id in ($sql);'
ActiveRecord::Base.connection.execute update_sql.gsub('$tsid', main_set.id.to_s).gsub('$sql', main_sql)
ActiveRecord::Base.connection.execute update_sql.gsub('$tsid', meta_set.id.to_s).gsub('$sql', meta_sql)
end
ActiveRecord::Base.connection.execute "delete from tags where tag_set_id is null;"
ActiveRecord::Base.connection.execute 'delete from tags where tag_set_id is null;'
change_column_null :tags, :tag_set_id, false
end
end
3 changes: 1 addition & 2 deletions db/migrate/20200512115318_create_suggested_edits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ def change
t.string :tags_cache, null: true
t.text :body_markdown, null: true


t.string :comment, null: true

t.boolean :active
t.boolean :accepted
t.datetime :decided_at
t.references :decided_by, foreign_key: {to_table: :users}, null: true
t.references :decided_by, foreign_key: { to_table: :users }, null: true
t.string :rejected_comment

t.timestamps
Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20200618094826_add_suspensions_and_warnings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ class AddSuspensionsAndWarnings < ActiveRecord::Migration[5.2]
def change
create_table :warnings do |t|
t.references :community_user, foreign_key: true

t.text :body, null: true
t.boolean :is_suspension
t.datetime :suspension_end
t.datetime :suspension_end
t.boolean :active
t.references :author, foreign_key: {to_table: :users}, null: true

t.references :author, foreign_key: { to_table: :users }, null: true

t.timestamps
end
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20200618124645_add_warning_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ class AddWarningTemplates < ActiveRecord::Migration[5.2]
def change
create_table :warning_templates do |t|
t.references :community, foreign_key: true

t.string :name
t.text :body
t.boolean :active

t.timestamps
end
end
Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20201231124614_create_comment_threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ def change
t.references :post

t.boolean :locked
t.references :locked_by, foreign_key: {to_table: :users}, null: true
t.references :locked_by, foreign_key: { to_table: :users }, null: true
t.timestamp :locked_until, null: true

t.boolean :archived
t.references :archived_by, foreign_key: {to_table: :users}, null: true
t.references :archived_by, foreign_key: { to_table: :users }, null: true
t.timestamp :archived_until, null: true
t.boolean :ever_archived_before

t.boolean :deleted
t.references :deleted_by, foreign_key: {to_table: :users}, null: true
t.references :deleted_by, foreign_key: { to_table: :users }, null: true

t.timestamps
end
Expand All @@ -24,6 +24,6 @@ def change

add_column :comments, :has_reference, :boolean
add_column :comments, :reference_text, :text, null: true
add_reference :comments, :references_comment, foreign_key: {to_table: :comments}, null: true
add_reference :comments, :references_comment, foreign_key: { to_table: :comments }, null: true
end
end
6 changes: 3 additions & 3 deletions db/migrate/20210710203352_create_reaction_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ def change

t.string :icon
t.string :color

t.boolean :requires_comment

t.references :community
t.integer :position

t.timestamps
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ class ChangeNotificationsContentFieldType < ActiveRecord::Migration[5.2]
def change
change_column :notifications, :content, :text
end
end
end
2 changes: 1 addition & 1 deletion db/migrate/20220811131155_create_sso_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ def change
t.references :user, null: false, foreign_key: true
end
end
end
end
Loading