mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
dd5ca6cc4c
commit
a764ab5b54
@ -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
|
||||
|
@ -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(
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user