Skip to content

A platform for community discussion. Free, open, simple.

DEV: Update min trust level to tag topics migration to groups (#25527)

Blake Ericksona764ab5b54d9
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 85b9d02eb4f..6b75ad43171 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -3070,7 +3070,7 @@ tags:
client: true
hidden: true
tag_topic_allowed_groups:
- default: "3|10" # auto group staff and trust_level_0
+ default: "1|3|10" # auto group admin, staff, and trust_level_0
type: group_list
allow_any: false
refresh: true
diff --git a/db/migrate/20240112073149_fill_tag_topic_allowed_groups_based_on_deprecated_settings.rb b/db/migrate/20240112073149_fill_tag_topic_allowed_groups_based_on_deprecated_settings.rb
index 1c6d6b50590..4ba4dbe4b71 100644
--- a/db/migrate/20240112073149_fill_tag_topic_allowed_groups_based_on_deprecated_settings.rb
+++ b/db/migrate/20240112073149_fill_tag_topic_allowed_groups_based_on_deprecated_settings.rb
@@ -10,7 +10,16 @@ class FillTagTopicAllowedGroupsBasedOnDeprecatedSettings < ActiveRecord::Migrati
# Default for old setting is TL0, we only need to do anything if it's been changed in the DB.
if configured_trust_level.present?
# Matches Group::AUTO_GROUPS to the trust levels.
- corresponding_group = "1#{configured_trust_level}"
+ corresponding_group =
+ case configured_trust_level
+ when "admin"
+ "1"
+ when "staff"
+ "1|3"
+ # Matches Group::AUTO_GROUPS to the trust levels.
+ else
+ "1|3|1#{configured_trust_level}"
+ end
# Data_type 20 is group_list.
DB.exec(
diff --git a/db/migrate/20240201170412_fix_tag_topic_allowed_groups_setting.rb b/db/migrate/20240201170412_fix_tag_topic_allowed_groups_setting.rb
new file mode 100644
index 00000000000..3c92c64c062
--- /dev/null
+++ b/db/migrate/20240201170412_fix_tag_topic_allowed_groups_setting.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class FixTagTopicAllowedGroupsSetting < ActiveRecord::Migration[7.0]
+ def up
+ configured_trust_level =
+ DB.query_single(
+ "SELECT value FROM site_settings WHERE name = 'min_trust_level_to_tag_topics' LIMIT 1",
+ ).first
+
+ configured_groups =
+ DB.query_single(
+ "SELECT value FROM site_settings WHERE name = 'tag_topic_allowed_groups' LIMIT 1",
+ ).first
+
+ # We only need to do anything if it's been changed in the DB.
+ if configured_trust_level.present? && configured_groups.present?
+ # The previous migration for this, changed it to only
+ # `"1#{configured_trust_level}"`, so if it has been
+ # changed we need to add back in admin & staff if they match.
+ if "1#{configured_trust_level}" == configured_groups
+ corresponding_group = "1|3|1#{configured_trust_level}"
+ end
+
+ # Just in case this happend in the previous migration.
+ corresponding_group =
+ case configured_groups
+ when "1admin"
+ "1"
+ when "1staff"
+ "1|3"
+ end
+
+ if corresponding_group
+ DB.exec(
+ "UPDATE site_settings SET value = :setting, updated_at = NOW() WHERE name = 'tag_topic_allowed_groups'",
+ setting: corresponding_group,
+ )
+ end
+ end
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end