A platform for community discussion. Free, open, simple.
FIX: move something else flag to the bottom (#27366)
Krzysztof Kotlarek4b1e01772284
diff --git a/db/fixtures/003_flags.rb b/db/fixtures/003_flags.rbindex 2b7e19f3659..b6c0d9670e6 100644--- a/db/fixtures/003_flags.rb+++ b/db/fixtures/003_flags.rb@@ -1,9 +1,16 @@# frozen_string_literal: true+Flag.seed do |s|+ s.id = 6+ s.name = "notify_user"+ s.notify_type = false+ s.auto_action_type = false+ s.custom_type = true+ s.applies_to = %w[Post Chat::Message]+endFlag.seed do |s|s.id = 3s.name = "off_topic"- s.position = 2s.notify_type = trues.auto_action_type = trues.custom_type = false@@ -12,7 +19,6 @@ endFlag.seed do |s|s.id = 4s.name = "inappropriate"- s.position = 3s.notify_type = trues.auto_action_type = trues.custom_type = false@@ -21,34 +27,22 @@ endFlag.seed do |s|s.id = 8s.name = "spam"- s.position = 4s.notify_type = trues.auto_action_type = trues.custom_type = falses.applies_to = %w[Post Topic Chat::Message]endFlag.seed do |s|- s.id = 6- s.name = "notify_user"- s.position = 0- s.notify_type = false- s.auto_action_type = false- s.custom_type = true- s.applies_to = %w[Post Chat::Message]-end-Flag.seed do |s|- s.id = 7- s.name = "notify_moderators"- s.position = 1+ s.id = 10+ s.name = "illegal"s.notify_type = trues.auto_action_type = falses.custom_type = trues.applies_to = %w[Post Topic Chat::Message]endFlag.seed do |s|- s.id = 10- s.name = "illegal"- s.position = 5+ s.id = 7+ s.name = "notify_moderators"s.notify_type = trues.auto_action_type = falses.custom_type = true@@ -57,7 +51,6 @@ endFlag.unscoped.seed do |s|s.id = 9s.name = "needs_approval"- s.position = 6s.notify_type = falses.auto_action_type = falses.custom_type = falsediff --git a/db/migrate/20240606003822_reorder_flags.rb b/db/migrate/20240606003822_reorder_flags.rbnew file mode 100644index 00000000000..769216aba21--- /dev/null+++ b/db/migrate/20240606003822_reorder_flags.rb@@ -0,0 +1,25 @@+# frozen_string_literal: true++class ReorderFlags < ActiveRecord::Migration[7.0]+ def up+ current_order = DB.query(<<~SQL)+ SELECT name FROM flags+ WHERE score_type IS FALSE+ ORDER BY position ASC+ SQL++ if current_order.map(&:name) ==+ %w[notify_user notify_moderators off_topic inappropriate spam illegal]+ execute "UPDATE flags SET position = 0 WHERE name = 'notify_user'"+ execute "UPDATE flags SET position = 1 WHERE name = 'off_topic'"+ execute "UPDATE flags SET position = 2 WHERE name = 'inappropriate'"+ execute "UPDATE flags SET position = 3 WHERE name = 'spam'"+ execute "UPDATE flags SET position = 4 WHERE name = 'illegal'"+ execute "UPDATE flags SET position = 5 WHERE name = 'notify_moderators'"+ end+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/spec/models/flag_spec.rb b/spec/models/flag_spec.rbindex 1f40c7d3e5e..884a3b13688 100644--- a/spec/models/flag_spec.rb+++ b/spec/models/flag_spec.rb@@ -31,32 +31,32 @@ RSpec.describe Flag, type: :model doit "updates post action types when created, modified or destroyed" doexpect(PostActionType.flag_types.keys).to eq(- %i[notify_user notify_moderators off_topic inappropriate spam illegal],+ %i[notify_user off_topic inappropriate spam illegal notify_moderators],)expect(ReviewableScore.types.keys).to eq(- %i[notify_user notify_moderators off_topic inappropriate spam illegal needs_approval],+ %i[notify_user off_topic inappropriate spam illegal notify_moderators needs_approval],)flag = Fabricate(:flag, name: "custom")expect(PostActionType.flag_types.keys).to eq(- %i[notify_user notify_moderators off_topic inappropriate spam illegal custom],+ %i[notify_user off_topic inappropriate spam illegal notify_moderators custom],)expect(ReviewableScore.types.keys).to eq(- %i[notify_user notify_moderators off_topic inappropriate spam illegal custom needs_approval],+ %i[notify_user off_topic inappropriate spam illegal notify_moderators custom needs_approval],)flag.update!(name: "edited_custom")expect(PostActionType.flag_types.keys).to eq(- %i[notify_user notify_moderators off_topic inappropriate spam illegal edited_custom],+ %i[notify_user off_topic inappropriate spam illegal notify_moderators edited_custom],)expect(ReviewableScore.types.keys).to eq(%i[notify_user- notify_moderatorsoff_topicinappropriatespamillegal+ notify_moderatorsedited_customneeds_approval],@@ -64,10 +64,10 @@ RSpec.describe Flag, type: :model doflag.destroy!expect(PostActionType.flag_types.keys).to eq(- %i[notify_user notify_moderators off_topic inappropriate spam illegal],+ %i[notify_user off_topic inappropriate spam illegal notify_moderators],)expect(ReviewableScore.types.keys).to eq(- %i[notify_user notify_moderators off_topic inappropriate spam illegal needs_approval],+ %i[notify_user off_topic inappropriate spam illegal notify_moderators needs_approval],)endenddiff --git a/spec/services/reorder_flag_spec.rb b/spec/services/reorder_flag_spec.rbindex 1c6c5e21fec..cc0e51b3c8b 100644--- a/spec/services/reorder_flag_spec.rb+++ b/spec/services/reorder_flag_spec.rb@@ -41,11 +41,11 @@ RSpec.describe(ReorderFlag) doit "moves the flag" doexpect(Flag.order(:position).map(&:name)).to eq(- %w[notify_user notify_moderators off_topic inappropriate spam illegal],+ %w[notify_user off_topic inappropriate spam illegal notify_moderators],)resultexpect(Flag.order(:position).map(&:name)).to eq(- %w[notify_user notify_moderators off_topic inappropriate illegal spam],+ %w[notify_user off_topic inappropriate spam notify_moderators illegal],)enddiff --git a/spec/system/admin_flags_spec.rb b/spec/system/admin_flags_spec.rbindex a525b2b8742..ec5ab7f6580 100644--- a/spec/system/admin_flags_spec.rb+++ b/spec/system/admin_flags_spec.rb@@ -14,7 +14,7 @@ describe "Admin Flags Page", type: :system dotopic_page.visit_topic(post.topic)topic_page.open_flag_topic_modalexpect(all(".flag-action-type-details strong").map(&:text)).to eq(- ["Something Else", "It's Inappropriate", "It's Spam", "It's Illegal"],+ ["It's Inappropriate", "It's Spam", "It's Illegal", "Something Else"],)visit "/admin/config/flags"@@ -23,7 +23,7 @@ describe "Admin Flags Page", type: :system dotopic_page.visit_topic(post.topic)topic_page.open_flag_topic_modalexpect(all(".flag-action-type-details strong").map(&:text)).to eq(- ["Something Else", "It's Inappropriate", "It's Illegal"],+ ["It's Inappropriate", "It's Illegal", "Something Else"],)Flag.system.where(name: "spam").update!(enabled: true)@@ -33,7 +33,7 @@ describe "Admin Flags Page", type: :system dotopic_page.visit_topic(post.topic)topic_page.open_flag_topic_modalexpect(all(".flag-action-type-details strong").map(&:text)).to eq(- ["Something Else", "It's Inappropriate", "It's Spam", "It's Illegal"],+ ["It's Inappropriate", "It's Spam", "It's Illegal", "Something Else"],)visit "/admin/config/flags"@@ -42,7 +42,7 @@ describe "Admin Flags Page", type: :system dotopic_page.visit_topic(post.topic)topic_page.open_flag_topic_modalexpect(all(".flag-action-type-details strong").map(&:text)).to eq(- ["Something Else", "It's Inappropriate", "It's Illegal", "It's Spam"],+ ["It's Inappropriate", "It's Illegal", "It's Spam", "Something Else"],)visit "/admin/config/flags"@@ -51,7 +51,7 @@ describe "Admin Flags Page", type: :system dotopic_page.visit_topic(post.topic)topic_page.open_flag_topic_modalexpect(all(".flag-action-type-details strong").map(&:text)).to eq(- ["Something Else", "It's Inappropriate", "It's Spam", "It's Illegal"],+ ["It's Inappropriate", "It's Spam", "It's Illegal", "Something Else"],)end@@ -62,13 +62,13 @@ describe "Admin Flags Page", type: :system doit "does not allow bottom flag to move down" dovisit "/admin/config/flags"- admin_flags_page.open_flag_menu("illegal")+ admin_flags_page.open_flag_menu("notify_moderators")expect(page).not_to have_css(".dropdown-menu__item .move-down")endit "does not allow top flag to move up" dovisit "/admin/config/flags"- admin_flags_page.open_flag_menu("notify_moderators")+ admin_flags_page.open_flag_menu("off_topic")expect(page).not_to have_css(".dropdown-menu__item .move-up")endend