A platform for community discussion. Free, open, simple.
FIX: Make sure staff group is selected on UC page load when localized (#38140)
Martin Brennan899a483d74c6
diff --git a/app/services/upcoming_changes/list.rb b/app/services/upcoming_changes/list.rbindex d0b68ed6616..b342a2af26e 100644--- a/app/services/upcoming_changes/list.rb+++ b/app/services/upcoming_changes/list.rb@@ -60,26 +60,18 @@ class UpcomingChanges::List.flatten.compact.uniq-groups = Group.where(id: group_ids).pluck(:id, :name).to_hupcoming_changes.each do |setting|- group_ids_for_setting = SiteSetting.site_setting_group_ids[setting[:setting]]- setting[:groups] = groups.values_at(*group_ids_for_setting).join(- ",",- ) if group_ids_for_setting.present?+ enabled_for, setting_groups =+ UpcomingChanges.enabled_for_with_groups(+ setting[:setting],+ setting[:value],+ groups,+ ).values_at(:enabled_for, :setting_groups)- setting[:upcoming_change][:enabled_for] = if !setting[:value]- "no_one"- elsif setting[:groups].blank?- "everyone"- else- if group_ids_for_setting == [Group::AUTO_GROUPS[:staff]]- "staff"- else- "groups"- end- end+ setting[:upcoming_change][:enabled_for] = enabled_for+ setting[:groups] = setting_groupsendenddiff --git a/lib/upcoming_changes.rb b/lib/upcoming_changes.rbindex aebc1af7062..ebf71fa9985 100644--- a/lib/upcoming_changes.rb+++ b/lib/upcoming_changes.rb@@ -181,4 +181,28 @@ module UpcomingChanges}endend++ def self.enabled_for_with_groups(setting_name, setting_value, upcoming_change_selected_groups)+ group_ids_for_setting = SiteSetting.site_setting_group_ids[setting_name]+ setting_groups =+ upcoming_change_selected_groups.values_at(*group_ids_for_setting).join(+ ",",+ ) if group_ids_for_setting.present?++ enabled_for =+ if !setting_value+ "no_one"+ elsif setting_groups.blank?+ "everyone"+ else+ if group_ids_for_setting == [Group::AUTO_GROUPS[:staff]]+ # Have to do this because the staff auto group name is localized+ upcoming_change_selected_groups[Group::AUTO_GROUPS[:staff]]+ else+ "groups"+ end+ end++ { enabled_for:, setting_groups: }+ endenddiff --git a/spec/services/upcoming_changes/list_spec.rb b/spec/services/upcoming_changes/list_spec.rbindex 4b782eedd46..a91dd3ca215 100644--- a/spec/services/upcoming_changes/list_spec.rb+++ b/spec/services/upcoming_changes/list_spec.rb@@ -129,6 +129,29 @@ RSpec.describe UpcomingChanges::List doexpect(mock_setting[:upcoming_change][:enabled_for]).to eq("groups")end++ context "when the staff group has been localized" do+ before do+ SiteSetting.default_locale = "de"+ Group.refresh_automatic_group!(:staff)+ end++ it "sets enabled_for to the localized staff group name when setting value is true and group is staff" do+ SiteSetting.enable_upload_debug_mode = true+ SiteSettingGroup.create!(+ name: "enable_upload_debug_mode",+ group_ids: Group::AUTO_GROUPS[:staff].to_s,+ )+ SiteSetting.refresh_site_setting_group_ids!+ SiteSetting.notify_changed!++ results = result.upcoming_changes+ setting = results.find { |change| change[:setting] == :enable_upload_debug_mode }+ expect(setting[:upcoming_change][:enabled_for]).to eq(+ Group.find(Group::AUTO_GROUPS[:staff]).name,+ )+ end+ endendit "updates the user's last_visited_upcoming_changes_at custom field" dodiff --git a/spec/system/admin_upcoming_changes_spec.rb b/spec/system/admin_upcoming_changes_spec.rbindex d6b44204bec..1d1ce0168ff 100644--- a/spec/system/admin_upcoming_changes_spec.rb+++ b/spec/system/admin_upcoming_changes_spec.rb@@ -284,6 +284,11 @@ describe "Admin upcoming changes", type: :system doexpect(SiteSettingGroup.find_by(name: "enable_upload_debug_mode").group_ids).to include(Group::AUTO_GROUPS[:staff].to_s,)++ upcoming_changes_page.visit+ expect(upcoming_changes_page.change_item(:enable_upload_debug_mode).enabled_for).to eq(+ Group.find(Group::AUTO_GROUPS[:staff]).name,+ )endendend