From 46f1c209be71d0c0d8c8a0be1ce4d3236d872807 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Fri, 19 Jan 2024 11:10:28 +0800 Subject: [PATCH] FIX: Account for moderators in group to TL mapping (#25326) If configuring only moderators in a group based access setting, the mapping to the old setting wouldn't work correctly, because the case was unaccounted for. This PR accounts for moderators group when doing the mapping. --- config/site_settings.yml | 1 + lib/site_settings/deprecated_settings.rb | 7 +++++-- spec/lib/site_settings/deprecated_settings_spec.rb | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/site_settings.yml b/config/site_settings.yml index 14bbfc787ab..33e41c33799 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -3029,6 +3029,7 @@ tags: client: true min_trust_to_create_tag: default: "3" + type: enum enum: "TrustLevelAndStaffSetting" hidden: true create_tag_allowed_groups: diff --git a/lib/site_settings/deprecated_settings.rb b/lib/site_settings/deprecated_settings.rb index 97df85f0530..e4b13808bb6 100644 --- a/lib/site_settings/deprecated_settings.rb +++ b/lib/site_settings/deprecated_settings.rb @@ -77,13 +77,16 @@ module SiteSettings::DeprecatedSettings if tl_and_staff valid_auto_groups_excluding_staff_and_admins = - valid_auto_groups - [Group::AUTO_GROUPS[:staff], Group::AUTO_GROUPS[:admins]] + valid_auto_groups - + [Group::AUTO_GROUPS[:staff], Group::AUTO_GROUPS[:admins], Group::AUTO_GROUPS[:moderators]] if valid_auto_groups_excluding_staff_and_admins.any? return valid_auto_groups_excluding_staff_and_admins.min - Group::AUTO_GROUPS[:trust_level_0] end - if valid_auto_groups.include?(Group::AUTO_GROUPS[:staff]) + if valid_auto_groups.include?(Group::AUTO_GROUPS[:moderators]) + "moderator" + elsif valid_auto_groups.include?(Group::AUTO_GROUPS[:staff]) "staff" elsif valid_auto_groups.include?(Group::AUTO_GROUPS[:admins]) "admin" diff --git a/spec/lib/site_settings/deprecated_settings_spec.rb b/spec/lib/site_settings/deprecated_settings_spec.rb index c76075fdde1..ad51513842c 100644 --- a/spec/lib/site_settings/deprecated_settings_spec.rb +++ b/spec/lib/site_settings/deprecated_settings_spec.rb @@ -152,6 +152,11 @@ RSpec.xdescribe SiteSettings::DeprecatedSettings do ) end + it "returns moderator if there is only the moderators auto group in the new group setting" do + SiteSetting.invite_allowed_groups = "#{Group::AUTO_GROUPS[:moderators]}" + expect(SiteSetting.min_trust_level_to_allow_invite_tl_and_staff).to eq("moderator") + end + it "returns staff if there are staff and admin auto groups in the new group setting" do SiteSetting.invite_allowed_groups = "#{Group::AUTO_GROUPS[:admins]}|#{Group::AUTO_GROUPS[:staff]}"