mirror of
https://github.com/discourse/discourse.git
synced 2024-11-21 16:38:15 -06:00
FEATURE: Add setting to exclude groups from /about page (#28809)
This commit adds a new `about_page_hidden_groups` setting to exclude members of specific groups from the admin and moderator lists on the /about page. Internal topic: t/137717.
This commit is contained in:
parent
88e1690d86
commit
0a994a9221
@ -69,14 +69,17 @@ class About
|
||||
end
|
||||
|
||||
def moderators
|
||||
@moderators ||= User.where(moderator: true, admin: false).human_users.order("last_seen_at DESC")
|
||||
@moderators ||=
|
||||
apply_excluded_groups(
|
||||
User.where(moderator: true, admin: false).human_users.order(last_seen_at: :desc),
|
||||
)
|
||||
end
|
||||
|
||||
def admins
|
||||
@admins ||=
|
||||
DiscoursePluginRegistry.apply_modifier(
|
||||
:about_admins,
|
||||
User.where(admin: true).human_users.order("last_seen_at DESC"),
|
||||
apply_excluded_groups(User.where(admin: true).human_users.order(last_seen_at: :desc)),
|
||||
)
|
||||
end
|
||||
|
||||
@ -137,4 +140,18 @@ class About
|
||||
def category_mods_limit=(number)
|
||||
@category_mods_limit = number
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def apply_excluded_groups(query)
|
||||
group_ids = SiteSetting.about_page_hidden_groups_map
|
||||
return query if group_ids.blank?
|
||||
|
||||
query.joins(
|
||||
DB.sql_fragment(
|
||||
"LEFT JOIN group_users ON group_id IN (:group_ids) AND user_id = users.id",
|
||||
group_ids:,
|
||||
),
|
||||
).where("group_users.id": nil)
|
||||
end
|
||||
end
|
||||
|
@ -2709,6 +2709,7 @@ en:
|
||||
|
||||
page_loading_indicator: "Configure the loading indicator which appears during page navigations within Discourse. 'Spinner' is a full page indicator. 'Slider' shows a narrow bar at the top of the screen."
|
||||
show_user_menu_avatars: "Show user avatars in the user menu"
|
||||
about_page_hidden_groups: "Do not show members of specific groups on the /about page."
|
||||
view_raw_email_allowed_groups: "Groups which can view the raw email content of a post if it was created by an incoming email. This includes email headers and other technical information."
|
||||
experimental_flags_admin_page_enabled_groups: "EXPERIMENTAL: Remove the Moderation Flags link from the admin sidebar."
|
||||
|
||||
|
@ -410,6 +410,9 @@ basic:
|
||||
show_user_menu_avatars:
|
||||
client: true
|
||||
default: false
|
||||
about_page_hidden_groups:
|
||||
default: ""
|
||||
type: group_list
|
||||
extended_site_description:
|
||||
default: ""
|
||||
max: 10_000
|
||||
|
@ -132,6 +132,29 @@ RSpec.describe About do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#moderators" do
|
||||
fab!(:mod_1) { Fabricate(:moderator) }
|
||||
fab!(:mod_2) { Fabricate(:moderator) }
|
||||
fab!(:mod_3) { Fabricate(:moderator) }
|
||||
|
||||
context "with the about_page_hidden_groups setting" do
|
||||
fab!(:group_1) { Fabricate(:group, users: [mod_1, mod_3]) }
|
||||
fab!(:group_2) { Fabricate(:group, users: [mod_3]) }
|
||||
fab!(:group_3) { Fabricate(:group) }
|
||||
|
||||
before { SiteSetting.about_page_hidden_groups = [group_1.id, group_2.id].join("|") }
|
||||
|
||||
it "hides moderators that are in any of the specified groups" do
|
||||
expect(About.new.moderators).to contain_exactly(mod_2)
|
||||
end
|
||||
|
||||
it "doesn't hide any moderators if the setting is empty" do
|
||||
SiteSetting.about_page_hidden_groups = ""
|
||||
expect(About.new.moderators).to contain_exactly(mod_1, mod_2, mod_3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#admins" do
|
||||
fab!(:admin_mark) { Fabricate(:admin, name: "mark") }
|
||||
fab!(:admin_matt) { Fabricate(:admin, name: "matt") }
|
||||
@ -148,5 +171,22 @@ RSpec.describe About do
|
||||
DiscoursePluginRegistry.unregister_modifier(plugin_instance, :about_admins, &modifier_block)
|
||||
end
|
||||
end
|
||||
|
||||
context "with the about_page_hidden_groups setting" do
|
||||
fab!(:group_1) { Fabricate(:group, users: [admin_mark, admin_matt]) }
|
||||
fab!(:group_2) { Fabricate(:group, users: [admin_mark]) }
|
||||
fab!(:group_3) { Fabricate(:group, users: [admin_kate]) }
|
||||
|
||||
before { SiteSetting.about_page_hidden_groups = [group_1.id, group_2.id].join("|") }
|
||||
|
||||
it "hides admins that are in any of the specified groups" do
|
||||
expect(About.new.admins).to contain_exactly(admin_kate)
|
||||
end
|
||||
|
||||
it "doesn't hide any admins if the setting is empty" do
|
||||
SiteSetting.about_page_hidden_groups = ""
|
||||
expect(About.new.admins).to contain_exactly(admin_kate, admin_mark, admin_matt)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user