FEATURE: new admin sidebar for moderators (#26795)

Enable a new sidebar for moderators with limited links.
This commit is contained in:
Krzysztof Kotlarek 2024-04-29 11:32:47 +10:00 committed by GitHub
parent 6c9f04a56c
commit da329d54af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 44 additions and 4 deletions

View File

@ -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,
},
],
},

View File

@ -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(

View File

@ -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?

View File

@ -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:

View File

@ -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