diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js index c9b3c18a2ea..a7cdb583228 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js @@ -85,6 +85,7 @@ export const ADMIN_NAV_MAP = [ route: "adminUsers", label: "admin.community.sidebar_link.users", icon: "users", + moderator: true, }, { name: "admin_user_fields", @@ -97,6 +98,7 @@ export const ADMIN_NAV_MAP = [ route: "adminWatchedWords", label: "admin.community.sidebar_link.watched_words", icon: "eye", + moderator: true, }, { name: "admin_legal", @@ -247,24 +249,28 @@ export const ADMIN_NAV_MAP = [ route: "adminLogs.screenedEmails", label: "admin.security.sidebar_link.screened_emails", icon: "envelope", + moderator: true, }, { name: "admin_logs_screened_ip_addresses", route: "adminLogs.screenedIpAddresses", label: "admin.security.sidebar_link.screened_ips", icon: "globe", + moderator: true, }, { name: "admin_logs_screened_urls", route: "adminLogs.screenedUrls", label: "admin.security.sidebar_link.screened_urls", icon: "globe", + moderator: true, }, { name: "admin_logs_search_logs", route: "adminSearchLogs", label: "admin.security.sidebar_link.search_logs", icon: "search", + moderator: true, }, { name: "admin_security", @@ -287,6 +293,7 @@ export const ADMIN_NAV_MAP = [ route: "adminLogs.staffActionLogs", label: "admin.security.sidebar_link.staff_action_logs", icon: "user-shield", + moderator: true, }, ], }, diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js index 148baa8dfcf..1af4038e18f 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js @@ -156,6 +156,7 @@ export function useAdminNavConfig(navMap) { route: "admin.dashboard.general", label: "admin.dashboard.title", icon: "home", + moderator: true, }, { name: "admin_all_site_settings", @@ -314,7 +315,14 @@ export default class AdminSidebarPanel extends BaseCustomSidebarPanel { }) ); - const navConfig = useAdminNavConfig(navMap); + let navConfig = useAdminNavConfig(navMap); + + if (!currentUser.admin && currentUser.moderator) { + navConfig.forEach((section) => { + section.links = section.links.filterBy("moderator"); + }); + navConfig = navConfig.filterBy("links.length"); + } return navConfig.map((adminNavSectionData) => { return defineAdminSection( diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index a5785828777..977dd60bafa 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -133,7 +133,7 @@ class CurrentUserSerializer < BasicUserSerializer end def use_admin_sidebar - object.admin? && object.in_any_groups?(SiteSetting.admin_sidebar_enabled_groups_map) + object.staff? && object.in_any_groups?(SiteSetting.admin_sidebar_enabled_groups_map) end def include_user_admin_sidebar? diff --git a/config/site_settings.yml b/config/site_settings.yml index cde6b4efc12..1a7ad450f56 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -2375,7 +2375,7 @@ developer: admin_sidebar_enabled_groups: type: group_list list_type: compact - default: "1" + default: "1|2" allow_any: false refresh: true lazy_load_categories_groups: diff --git a/spec/system/admin_sidebar_navigation_spec.rb b/spec/system/admin_sidebar_navigation_spec.rb index a733f5079e2..95f63948199 100644 --- a/spec/system/admin_sidebar_navigation_spec.rb +++ b/spec/system/admin_sidebar_navigation_spec.rb @@ -2,13 +2,17 @@ describe "Admin Revamp | Sidebar Navigation", type: :system do fab!(:admin) + fab!(:moderator) let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new } let(:sidebar_dropdown) { PageObjects::Components::SidebarHeaderDropdown.new } let(:filter) { PageObjects::Components::Filter.new } before do - SiteSetting.admin_sidebar_enabled_groups = Group::AUTO_GROUPS[:admins] + SiteSetting.admin_sidebar_enabled_groups = [ + Group::AUTO_GROUPS[:admins], + Group::AUTO_GROUPS[:moderators], + ] sign_in(admin) end @@ -184,4 +188,25 @@ describe "Admin Revamp | Sidebar Navigation", type: :system do visit("/admin") expect(sidebar).to have_no_add_section_button end + + it "displays limited links for moderator" do + sign_in(moderator) + visit("/admin") + + sidebar.toggle_all_sections + + links = page.all(".sidebar-section-link-content-text") + expect(links.map(&:text)).to eq( + [ + "Dashboard", + "Users", + "Watched Words", + "Screened Emails", + "Screened IPs", + "Screened URLs", + "Search Logs", + "Staff Action Logs", + ], + ) + end end