DEV: Correct some tl to group site setting changes (#25550)

- Created a new migration for here_mention
- Updated existing migration for here_mention
- Updated site settings for here_mention, create_tag, and
  send_email_messages
This commit is contained in:
Blake Erickson 2024-02-05 09:50:46 -07:00 committed by GitHub
parent a764ab5b54
commit 3159522546
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 13 deletions

View File

@ -1744,7 +1744,7 @@ trust:
enum: "TrustLevelAndStaffSetting"
hidden: true
send_email_messages_allowed_groups:
default: "3|14" # auto group staff and trust_level_4
default: "1|3|14" # auto group admin, staff, and trust_level_4
type: group_list
allow_any: false
refresh: true
@ -3059,7 +3059,7 @@ tags:
enum: "TrustLevelAndStaffSetting"
hidden: true
create_tag_allowed_groups:
default: "3|13" # auto group staff and trust_level_3
default: "1|3|13" # auto group admin, staff, and trust_level_3
type: group_list
allow_any: false
refresh: true

View File

@ -15,17 +15,10 @@ class MigrateMinTrustLevelForHereMentionToGroup < ActiveRecord::Migration[7.0]
when "admin"
"1"
when "staff"
"3"
when "0"
"10"
when "1"
"11"
when "2"
"12"
when "3"
"13"
when "4"
"14"
"1|3"
# Matches Group::AUTO_GROUPS to the trust levels.
else
"1|3|1#{min_trust_level_for_here_mention_raw}"
end
# Data_type 20 is group_list.

View File

@ -0,0 +1,36 @@
# frozen_string_literal: true
class FixHereMentionAllowedGroupsSetting < ActiveRecord::Migration[7.0]
def up
configured_trust_level =
DB.query_single(
"SELECT value FROM site_settings WHERE name = 'min_trust_level_for_here_mention' LIMIT 1",
).first
configured_groups =
DB.query_single(
"SELECT value FROM site_settings WHERE name = 'here_mention_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
if corresponding_group
DB.exec(
"UPDATE site_settings SET value = :setting, updated_at = NOW() WHERE name = 'here_mention_allowed_groups'",
setting: corresponding_group,
)
end
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end