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

* DEV: Update min trust level to tag topics migration to groups

- Update the existing migration to include staff and admin
- Update default values
- Added migration to include staff and admin cases
This commit is contained in:
Blake Erickson 2024-02-05 09:49:54 -07:00 committed by GitHub
parent dd5ca6cc4c
commit a764ab5b54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 56 additions and 2 deletions

View File

@ -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

View File

@ -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(

View File

@ -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