From 31595225460b94b4d7996546fc37a367b7411788 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Mon, 5 Feb 2024 09:50:46 -0700 Subject: [PATCH] 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 --- config/site_settings.yml | 4 +-- ...n_trust_level_for_here_mention_to_group.rb | 15 +++----- ...fix_here_mention_allowed_groups_setting.rb | 36 +++++++++++++++++++ 3 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20240202204030_fix_here_mention_allowed_groups_setting.rb diff --git a/config/site_settings.yml b/config/site_settings.yml index 6b75ad43171..83ea3c6eae4 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -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 diff --git a/db/migrate/20231107055903_migrate_min_trust_level_for_here_mention_to_group.rb b/db/migrate/20231107055903_migrate_min_trust_level_for_here_mention_to_group.rb index a76de48a53e..ff7cafac689 100644 --- a/db/migrate/20231107055903_migrate_min_trust_level_for_here_mention_to_group.rb +++ b/db/migrate/20231107055903_migrate_min_trust_level_for_here_mention_to_group.rb @@ -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. diff --git a/db/migrate/20240202204030_fix_here_mention_allowed_groups_setting.rb b/db/migrate/20240202204030_fix_here_mention_allowed_groups_setting.rb new file mode 100644 index 00000000000..3ab3e6705d0 --- /dev/null +++ b/db/migrate/20240202204030_fix_here_mention_allowed_groups_setting.rb @@ -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