From 009e5969533f695cad8981edafeaadb2978e0103 Mon Sep 17 00:00:00 2001 From: Ferdinand99 Date: Mon, 16 Nov 2026 00:48:47 +0100 Subject: [PATCH 1/7] feat(web): focused moderator view for Inbox-level access An Inbox-level person lands on the inbox and sees only the moderation tools in the sidebar and the command palette. A quiet "Show everything" link in the sidebar footer brings back the full, still locked, navigation and is remembered in the browser. View and Edit keep the full dashboard. Adds the moderator-view feature string to /api/mobile/info. --- docs/mobile-app.md | 3 +- docs/self-hosting.md | 7 +- src/web/routes/mobile.js | 3 + test/mobileInfo.test.js | 1 + web-v2/src/App.jsx | 4 +- web-v2/src/__tests__/moderatorView.test.jsx | 240 ++++++++++++++++++++ web-v2/src/access.jsx | 46 +++- web-v2/src/components/CommandPalette.jsx | 6 +- web-v2/src/components/Sidebar.jsx | 27 ++- web-v2/src/main.jsx | 1 + web-v2/src/overviewModel.js | 22 +- web-v2/src/pages/GuildHome.jsx | 15 ++ web-v2/src/paletteModel.js | 9 +- web-v2/src/styles/p1.css | 24 ++ web-v2/src/util.js | 21 ++ 15 files changed, 408 insertions(+), 21 deletions(-) create mode 100644 web-v2/src/__tests__/moderatorView.test.jsx create mode 100644 web-v2/src/pages/GuildHome.jsx create mode 100644 web-v2/src/styles/p1.css diff --git a/docs/mobile-app.md b/docs/mobile-app.md index d03cd0c3..2ab149db 100644 --- a/docs/mobile-app.md +++ b/docs/mobile-app.md @@ -317,7 +317,7 @@ in there: | `login` | Whether sign-in is available (false in open mode) | | `loginProviders` | The configured logins, for example `["discord", "fluxer"]`; empty when `login` is false | | `platforms` | The platforms the bot runs on, for example `["discord"]` | -| `features` | What this version's app API supports, so the app can hide what an older Sylo lacks. Today: `app-login`, `live-access`, `changelog`, `collectibles`, `welcome-trigger`, `member-search`, `access-levels`, `health`, `app-connect`, `setup-wizard`, `config-history`, `inbox-search`, `config-import`, `duplicate`, `message-templates` and `message-move`, plus `push` and `push-pigeon` when this instance can send notifications. See the list below | +| `features` | What this version's app API supports, so the app can hide what an older Sylo lacks. Today: `app-login`, `live-access`, `changelog`, `collectibles`, `welcome-trigger`, `member-search`, `access-levels`, `health`, `app-connect`, `setup-wizard`, `config-history`, `inbox-search`, `config-import`, `duplicate`, `message-templates`, `message-move` and `moderator-view`, plus `push` and `push-pigeon` when this instance can send notifications. See the list below | The feature strings: @@ -338,6 +338,7 @@ The feature strings: - `duplicate`: the `duplicate` routes for reminders, embed messages, reaction-role sets, custom commands and shop items. - `message-templates`: the built-in message templates and the raw message JSON import and export. - `message-move`: when the channel of a posted **embed message**, the **Welcome channel** message or a **role panel** changes and is published, the server posts a fresh message in the new channel, stores it and then deletes the old one, so the app must not unpublish first. Other bot posts (verification, honeypot traps, applications and so on) are not covered. A publish that loses a race with another publish of the same embed message answers `409` with the current record. +- `moderator-view`: the web dashboard gives a person whose level in a server is `inbox` a focused view: the server opens on the inbox, and the navigation lists only the moderation tools (Tickets, Appeals, Applications, Suggestions, Moderation, Member data, Audit log), with a "Show everything" switch for the full, still locked, navigation. Nothing changes on the server side: the level is the `access` of each `GET /api/v2/guilds` entry (and `level` of `GET /api/v2/guilds/:id/access`). The app can follow the same rules for that level and keeps the full read-only app for `view`. - `app-connect`: [adding the other login](#adding-the-other-login). Only where sign-in is on and both Discord and Fluxer logins are set up. - `push`, `push-pigeon`: this instance can send notifications to signed-in apps. diff --git a/docs/self-hosting.md b/docs/self-hosting.md index 8e70e1b2..417953d0 100644 --- a/docs/self-hosting.md +++ b/docs/self-hosting.md @@ -176,7 +176,12 @@ require **Manage Server** (or Administrator / owner) in that server, or one of t roles set under *Dashboard access* on that server's *Settings* page: **Edit** (the bot-master roles: everything), **Inbox** (tickets, ban appeals, applications and suggestions, and reading the rest) or **View** (the pages and settings, read -only, without what the inboxes contain). Only the owner or someone with Manage +only, without what the inboxes contain). A person with Inbox access gets a focused +dashboard: the server opens on the inbox, and the sidebar lists only the moderation +tools (Tickets, Appeals, Applications, Suggestions, Moderation, Member data, Audit +log); a "Show everything" link at the foot of the sidebar brings back the full, still +locked, navigation and is remembered in that browser. View and Edit see the full +dashboard. Only the owner or someone with Manage Server can change the Edit roles; anyone with Edit can change the Inbox and View roles and save the rest of that page. With `INTENT_GUILD_MEMBERS=false` Sylo fetches a member from Discord before their role decides access (on every change, diff --git a/src/web/routes/mobile.js b/src/web/routes/mobile.js index 1d5575c4..ba3781eb 100644 --- a/src/web/routes/mobile.js +++ b/src/web/routes/mobile.js @@ -312,6 +312,8 @@ export const mobileApiRouter = Router(); // sign-in is on and both Discord and Fluxer logins are set up. `access-levels`: View / Inbox / Edit // dashboard access, with `access` on each GET /api/v2/guilds entry and GET/POST // /api/v2/guilds/:id/access. `message-move`: a posted message moves to its new channel on publish. +// `moderator-view`: the web dashboard's focused view for Inbox-level access (landing on the inbox, only the +// moderation tools); the app can follow it with `access` from GET /api/v2/guilds. const FEATURES = Object.freeze([ 'app-login', 'live-access', @@ -328,6 +330,7 @@ const FEATURES = Object.freeze([ 'duplicate', 'message-templates', 'message-move', + 'moderator-view', ]); // Public and ahead of the open-mode guard: the app calls it before anyone signs in, and an open-mode diff --git a/test/mobileInfo.test.js b/test/mobileInfo.test.js index efba5685..e7d23ee3 100644 --- a/test/mobileInfo.test.js +++ b/test/mobileInfo.test.js @@ -51,6 +51,7 @@ test('GET /api/mobile/info describes a server with login on, without a cookie or assert.ok(info.features.includes(f), f); } assert.ok(info.features.includes('message-move'), 'a posted message moves when its channel changes'); + assert.ok(info.features.includes('moderator-view'), 'the focused moderator view for Inbox access'); assert.ok(info.features.every((f) => typeof f === 'string')); }); diff --git a/web-v2/src/App.jsx b/web-v2/src/App.jsx index e824fb23..02bcefb2 100644 --- a/web-v2/src/App.jsx +++ b/web-v2/src/App.jsx @@ -12,7 +12,7 @@ import MemberShell from './components/MemberShell.jsx'; import RouteError from './components/RouteError.jsx'; import NotFound from './components/NotFound.jsx'; import GuildPicker from './pages/GuildPicker.jsx'; -import Overview from './pages/Overview.jsx'; +import GuildHome from './pages/GuildHome.jsx'; const Leaderboard = lazy(() => import('./pages/Leaderboard.jsx')); const Settings = lazy(() => import('./pages/Settings.jsx')); const Personalizer = lazy(() => import('./pages/Personalizer.jsx')); @@ -63,7 +63,7 @@ const router = createBrowserRouter( } errorElement={}> }> } /> - } /> + } /> } /> } /> } /> diff --git a/web-v2/src/__tests__/moderatorView.test.jsx b/web-v2/src/__tests__/moderatorView.test.jsx new file mode 100644 index 00000000..003fa5d9 --- /dev/null +++ b/web-v2/src/__tests__/moderatorView.test.jsx @@ -0,0 +1,240 @@ +import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react'; +import { RouterProvider, createMemoryRouter } from 'react-router-dom'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import Shell from '../components/Shell.jsx'; +import GuildHome from '../pages/GuildHome.jsx'; +import { navModel } from '../overviewModel.js'; +import { paletteItems } from '../paletteModel.js'; + +const G = '123456789012345678'; +const H = '223456789012345678'; + +vi.mock('../pages/Overview.jsx', () => ({ default: () =>

overview page

})); +vi.mock('../api.js', async (importOriginal) => ({ + ...(await importOriginal()), + getGuilds: vi.fn(), + getGuildAccess: vi.fn(), + getOverview: vi.fn(), + getAnnouncement: vi.fn().mockResolvedValue(null), + getAccount: vi.fn(), + getInvites: vi.fn().mockResolvedValue([]), + getCsrfToken: vi.fn().mockResolvedValue('t'), + searchMembers: vi.fn().mockResolvedValue({ members: [] }), + searchInbox: vi.fn().mockResolvedValue({ items: [] }), +})); +const api = await import('../api.js'); +const { resetOperatorCache } = await import('../useOperator.js'); + +const overview = { + openTickets: 2, + openAppeals: 0, + attention: { waiting: { tickets: 2, appeals: 0, applications: 0, suggestions: 0 }, problems: [] }, + groups: [ + { + title: 'Engagement', + cards: [ + { id: 'welcome', name: 'Welcome', hasToggle: true, enabled: true, beta: false, lines: [] }, + { id: 'leveling', name: 'Leveling', hasToggle: true, enabled: true, beta: false, lines: [] }, + ], + }, + ], +}; + +const MOD_TOOLS = [ + 'Tickets', + 'Appeals', + 'Applications', + 'Suggestions', + 'Moderation hub', + 'Member data', + 'Audit log', +]; +const SETUP_PAGES = ['Overview', 'Server settings', 'Commands', 'Leaderboard', 'Welcome', 'Leveling', 'Roadmap']; + +function setLevel(level) { + api.getGuildAccess.mockImplementation((id) => Promise.resolve({ level: id === G ? level : 'edit' })); +} + +async function open(path = `/guilds/${G}`) { + const router = createMemoryRouter( + [ + { + element: , + children: [ + { path: '/guilds/:guildId', element: }, + { path: '/guilds/:guildId/tickets', element:

tickets page

}, + ], + }, + ], + { initialEntries: [path] } + ); + await act(async () => { + render(); + }); + return router; +} + +const hasLink = (name) => screen.queryByRole('link', { name: new RegExp(`^${name}`) }) !== null; + +beforeEach(() => { + vi.clearAllMocks(); + resetOperatorCache(); + localStorage.clear(); + window.scrollTo = vi.fn(); + Element.prototype.scrollIntoView = vi.fn(); + window.matchMedia = vi.fn().mockReturnValue({ + matches: false, + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + }); + api.getGuilds.mockResolvedValue([ + { id: G, name: 'Home', icon: null, platform: 'discord', access: 'inbox' }, + { id: H, name: 'Other', icon: null, platform: 'discord', access: 'edit' }, + ]); + api.getOverview.mockResolvedValue(overview); + api.getAccount.mockResolvedValue({ open: false, operator: false, platforms: [], devices: [] }); +}); +afterEach(() => { + cleanup(); + vi.restoreAllMocks(); +}); + +describe('the focused moderator view', () => { + it('opens an Inbox person on the inbox, with only the moderation tools in the sidebar', async () => { + setLevel('inbox'); + const router = await open(); + expect(router.state.location.pathname).toBe(`/guilds/${G}/tickets`); + expect(screen.getByText('tickets page')).toBeTruthy(); + const nav = screen.getByRole('navigation', { name: 'Dashboard' }); + for (const name of MOD_TOOLS) { + expect(within(nav).getByRole('link', { name: new RegExp(`^${name}`) })).toBeTruthy(); + } + for (const name of SETUP_PAGES) expect(hasLink(name), name).toBe(false); + expect(within(nav).queryByText('Modules')).toBeNull(); + expect(within(nav).queryByRole('group', { name: 'Server' })).toBeNull(); + expect(within(nav).getByRole('button', { name: 'Show everything' })).toBeTruthy(); + }); + + it('shows the full navigation after "Show everything", keeps the choice and can undo it', async () => { + setLevel('inbox'); + const router = await open(); + await act(async () => { + fireEvent.click(screen.getByRole('button', { name: 'Show everything' })); + }); + for (const name of [...MOD_TOOLS, ...SETUP_PAGES]) expect(hasLink(name), name).toBe(true); + expect(localStorage.getItem('sylo:v2:showEverything')).toBe('1'); + expect(screen.getByRole('button', { name: 'Show only moderation' })).toBeTruthy(); + // The overview link now stays on the overview. + await act(async () => { + fireEvent.click(screen.getByRole('link', { name: 'Overview' })); + }); + expect(router.state.location.pathname).toBe(`/guilds/${G}`); + expect(screen.getByText('overview page')).toBeTruthy(); + + // A new visit (a reload) keeps the choice. + cleanup(); + const again = await open(); + expect(again.state.location.pathname).toBe(`/guilds/${G}`); + expect(screen.getByText('overview page')).toBeTruthy(); + expect(hasLink('Server settings')).toBe(true); + + await act(async () => { + fireEvent.click(screen.getByRole('button', { name: 'Show only moderation' })); + }); + expect(hasLink('Server settings')).toBe(false); + expect(localStorage.getItem('sylo:v2:showEverything')).toBeNull(); + }); + + it('still switches when the browser has no usable storage', async () => { + setLevel('inbox'); + const blocked = () => { + throw new Error('blocked'); + }; + vi.spyOn(Storage.prototype, 'getItem').mockImplementation(blocked); + vi.spyOn(Storage.prototype, 'setItem').mockImplementation(blocked); + vi.spyOn(Storage.prototype, 'removeItem').mockImplementation(blocked); + await open(); + await act(async () => { + fireEvent.click(screen.getByRole('button', { name: 'Show everything' })); + }); + expect(hasLink('Server settings')).toBe(true); + }); + + it.each(['view', 'edit'])('%s keeps the overview and the full navigation, with no switch', async (level) => { + setLevel(level); + const router = await open(); + expect(router.state.location.pathname).toBe(`/guilds/${G}`); + expect(screen.getByText('overview page')).toBeTruthy(); + for (const name of [...MOD_TOOLS, ...SETUP_PAGES]) expect(hasLink(name), name).toBe(true); + expect(screen.queryByRole('button', { name: /Show everything|Show only moderation/ })).toBeNull(); + }); + + it("opens another server on its own level, not the previous server's", async () => { + // Inbox in G, Edit in H. + setLevel('inbox'); + const router = await open(`/guilds/${H}`); + expect(router.state.location.pathname).toBe(`/guilds/${H}`); + expect(screen.getByText('overview page')).toBeTruthy(); + expect(hasLink('Server settings')).toBe(true); + }); + + it('keeps the bot pages of an operator', async () => { + setLevel('inbox'); + api.getAccount.mockResolvedValue({ open: false, operator: true, platforms: [], devices: [] }); + await open(); + expect(hasLink('Health')).toBe(true); + expect(hasLink('Server settings')).toBe(false); + }); + + it('lists only what the focused view can open in the command palette', async () => { + setLevel('inbox'); + await open(); + fireEvent.click(screen.getByRole('button', { name: 'Search the dashboard' })); + const labels = () => screen.getAllByRole('option').map((o) => o.textContent); + for (const name of MOD_TOOLS) expect(labels().some((l) => l.startsWith(name)), name).toBe(true); + for (const name of SETUP_PAGES) expect(labels().some((l) => l.startsWith(name)), name).toBe(false); + // A typed text finds no module or settings page either. + fireEvent.change(screen.getByRole('combobox'), { target: { value: 'welcome' } }); + expect(screen.queryAllByRole('option').filter((o) => /Welcome/.test(o.textContent))).toHaveLength(0); + fireEvent.change(screen.getByRole('combobox'), { target: { value: 'settings' } }); + expect(screen.queryAllByRole('option').filter((o) => /settings/i.test(o.textContent))).toHaveLength(0); + }); + + it('lists the modules in the palette for Edit', async () => { + setLevel('edit'); + await open(); + fireEvent.click(screen.getByRole('button', { name: 'Search the dashboard' })); + fireEvent.change(screen.getByRole('combobox'), { target: { value: 'welcome' } }); + expect(screen.getAllByRole('option').some((o) => /Welcome/.test(o.textContent))).toBe(true); + }); +}); + +describe('the models of the focused view', () => { + const nav = (focused) => navModel({ guildId: G, data: overview, operator: false, focused }); + + it('keeps the inboxes and three moderation tools, and drops the rest', () => { + const n = nav(true); + expect(n.top).toEqual([]); + expect(n.inbox.map((i) => i.key)).toEqual(['tickets', 'appeals', 'applications', 'suggestions']); + expect(n.people.map((i) => i.key)).toEqual(['moderation', 'member-data', 'audit']); + expect(n.modules).toEqual([]); + expect(n.server).toEqual([]); + expect(n.more).toEqual([]); + }); + + it('is unchanged when not focused', () => { + const n = nav(false); + expect(n.top).toHaveLength(1); + expect(n.people).toHaveLength(4); + expect(n.modules.length).toBeGreaterThan(0); + expect(n.server).toHaveLength(2); + }); + + it('gives the palette no module pages and no setup pages', () => { + const keys = paletteItems({ guildId: G, data: overview, operator: false, focused: true }).map((i) => i.key); + expect(keys.some((k) => k.startsWith('module:'))).toBe(false); + expect(keys).not.toContain('page:settings'); + expect(keys).not.toContain('page:overview'); + expect(keys).toContain('page:tickets'); + }); +}); diff --git a/web-v2/src/access.jsx b/web-v2/src/access.jsx index c3bb8e0c..1e841b23 100644 --- a/web-v2/src/access.jsx +++ b/web-v2/src/access.jsx @@ -1,5 +1,6 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'react'; import { getGuildAccess } from './api.js'; +import { readShowEverything, writeShowEverything } from './util.js'; // The signed-in person's dashboard access level in the selected server (src/web/middleware/access.js // on the server): 'view' reads only, 'inbox' may also act on tickets, appeals, applications and @@ -12,12 +13,26 @@ const RANK = { view: 1, inbox: 2, edit: 3 }; export const LEVEL_LABEL = { view: 'View only', inbox: 'Inbox only' }; -const AccessContext = createContext({ level: 'edit', guildId: null, reload: () => {} }); +// `ready` is false while the level of the selected server is still being read. `showEverything` is the +// Inbox person's choice to see the full navigation instead of the focused view (see useAccess). +const AccessContext = createContext({ + level: 'edit', + guildId: null, + reload: () => {}, + ready: true, + showEverything: false, + setShowEverything: () => {}, +}); export function AccessProvider({ guildId, children }) { const [state, setState] = useState({ guildId: null, level: 'edit' }); const [tick, setTick] = useState(0); const reload = useCallback(() => setTick((t) => t + 1), []); + const [showEverything, setShow] = useState(readShowEverything); + const setShowEverything = useCallback((on) => { + setShow(Boolean(on)); + writeShowEverything(Boolean(on)); + }, []); useEffect(() => { if (!guildId) return undefined; @@ -37,8 +52,15 @@ export function AccessProvider({ guildId, children }) { }, [guildId, tick]); // The level of another server (the previous one, while the new one loads) is not used. - const level = state.guildId === guildId ? state.level : 'edit'; - return {children}; + const known = state.guildId === guildId; + const level = known ? state.level : 'edit'; + // Without a server there is nothing to wait for. + const ready = !guildId || known; + return ( + + {children} + + ); } /** @@ -46,8 +68,22 @@ export function AccessProvider({ guildId, children }) { * const { can } = useAccess(); */ export function useAccess() { - const { level, guildId, reload } = useContext(AccessContext); - return { level, guildId, reload, can: (need) => (RANK[level] ?? 0) >= RANK[need] }; + const { level, guildId, reload, ready, showEverything, setShowEverything } = useContext(AccessContext); + return { + level, + guildId, + reload, + ready, + can: (need) => (RANK[level] ?? 0) >= RANK[need], + // The focused moderator view: a person whose level here is exactly Inbox gets the moderation tools + // instead of the whole dashboard, unless they chose "Show everything". View keeps the full read-only + // dashboard (observers need the whole picture) and Edit is unchanged. `canFocus` is whether the choice + // is theirs to make at all. + canFocus: level === 'inbox', + focused: level === 'inbox' && !showEverything, + showEverything, + setShowEverything, + }; } /** diff --git a/web-v2/src/components/CommandPalette.jsx b/web-v2/src/components/CommandPalette.jsx index a0b646eb..39fc9750 100644 --- a/web-v2/src/components/CommandPalette.jsx +++ b/web-v2/src/components/CommandPalette.jsx @@ -1,6 +1,7 @@ import { useEffect, useId, useMemo, useRef, useState } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; import { searchInbox, searchMembers } from '../api.js'; +import { useAccess } from '../access.jsx'; import { useOverview } from '../OverviewContext.jsx'; import { useOperator } from '../useOperator.js'; import { groupItems, paletteItems, rankItems, readRecent, rememberRecent } from '../paletteModel.js'; @@ -105,6 +106,7 @@ function PaletteDialog({ onClose, guildId, guilds }) { const { data: shared, dataGuildId } = useOverview(); const data = dataGuildId === guildId ? shared : null; const operator = useOperator(); + const { focused } = useAccess(); const dialogRef = useRef(null); const settled = useRef(false); const closeTimer = useRef(null); @@ -116,8 +118,8 @@ function PaletteDialog({ onClose, guildId, guilds }) { const [recent] = useState(readRecent); const items = useMemo( - () => paletteItems({ guildId, data, operator, guilds }), - [guildId, data, operator, guilds] + () => paletteItems({ guildId, data, operator, guilds, focused }), + [guildId, data, operator, guilds, focused] ); const found = useServerMatches(guildId, text); // A pasted member id (or a mention) is a place to open without asking the server. diff --git a/web-v2/src/components/Sidebar.jsx b/web-v2/src/components/Sidebar.jsx index 2d478697..62b69e7f 100644 --- a/web-v2/src/components/Sidebar.jsx +++ b/web-v2/src/components/Sidebar.jsx @@ -1,5 +1,6 @@ import { useEffect, useRef, useSyncExternalStore } from 'react'; import { Link, useLocation } from 'react-router-dom'; +import { useAccess } from '../access.jsx'; import { useOverview } from '../OverviewContext.jsx'; import { useOperator } from '../useOperator.js'; import { navModel } from '../overviewModel.js'; @@ -109,7 +110,10 @@ export default function Sidebar({ activeGuildId, open, onClose, returnFocusRef } // Guild-scoped links need a selected server. Without one (a fresh visit to the picker) their groups // are left out. const operator = useOperator(); - const nav = navModel({ guildId: activeGuildId, data, operator }); + // An Inbox-level person gets the moderation tools only (access.jsx); a quiet link at the foot of the + // sidebar switches to the full, still locked, navigation and back. + const { focused, canFocus, showEverything, setShowEverything } = useAccess(); + const nav = navModel({ guildId: activeGuildId, data, operator, focused: Boolean(activeGuildId) && focused }); return ( <> @@ -129,14 +133,16 @@ export default function Sidebar({ activeGuildId, open, onClose, returnFocusRef } aria-label="Dashboard" inert={isDrawer && !open} > - + {nav.top.length ? : null} {/* The groups that belong to a server only exist once one is chosen: before that they would be a long column of greyed-out links. */} {activeGuildId ? ( <> - + {nav.server.length ? ( + + ) : null} ) : null} @@ -167,10 +173,23 @@ export default function Sidebar({ activeGuildId, open, onClose, returnFocusRef } ) : null} - + {nav.more.length ? ( + + ) : null} {nav.bot.length ? ( ) : null} + {activeGuildId && canFocus ? ( +
+ +
+ ) : null} ); diff --git a/web-v2/src/main.jsx b/web-v2/src/main.jsx index e97b7ce7..5d419b73 100644 --- a/web-v2/src/main.jsx +++ b/web-v2/src/main.jsx @@ -22,6 +22,7 @@ import './styles/setup-wizard.css'; import './styles/access.css'; import './styles/history.css'; import './styles/health.css'; +import './styles/p1.css'; createRoot(document.getElementById('root')).render( diff --git a/web-v2/src/overviewModel.js b/web-v2/src/overviewModel.js index 4069a3fc..23b571e3 100644 --- a/web-v2/src/overviewModel.js +++ b/web-v2/src/overviewModel.js @@ -195,12 +195,17 @@ const INBOX_SAME_PAGE = new Set(['applications', 'suggestions']); // Inbox entries whose queue is another page than the module's settings: the settings keep an entry. const SETTINGS_SUFFIX = new Set(['tickets', 'appeals']); +// What the focused moderator view keeps of "Members & moderation": every page here only needs View to +// read, and its actions are guarded by the server; the leaderboard is not a moderation tool. +const FOCUSED_PEOPLE = new Set(['moderation', 'member-data', 'audit']); + /** * The sidebar as groups. `guildId` is null before a server is picked (links are then null and shown * disabled). `operator` is whether the server marks the viewer as the bot owner (OWNER_IDS): the bot - * pages (Bot personalizer, Health, Roadmap admin, Stats cache) only exist for them. + * pages (Bot personalizer, Health, Roadmap admin, Stats cache) only exist for them. `focused` is the + * moderator view for an Inbox-level person (see useAccess in access.jsx). */ -export function navModel({ guildId, data, operator }) { +export function navModel({ guildId, data, operator, focused = false }) { const g = (path) => (guildId ? `/guilds/${guildId}${path}` : null); const waiting = data?.attention?.waiting ?? {}; const count = (n) => (Number(n) > 0 ? Number(n) : 0); @@ -281,5 +286,18 @@ export function navModel({ guildId, data, operator }) { { key: 'stats', label: 'Game stats cache', icon: 'chart', href: '/stats' }, ] : []; + if (focused) { + // The focused moderator view (an Inbox-level person): the inboxes and the moderation tools, nothing + // about setting the server up. Operators keep their bot pages. + return { + top: [], + inbox, + people: people.filter((it) => FOCUSED_PEOPLE.has(it.key)), + modules: [], + server: [], + more: [], + bot, + }; + } return { top, inbox, people, modules, server, more, bot }; } diff --git a/web-v2/src/pages/GuildHome.jsx b/web-v2/src/pages/GuildHome.jsx new file mode 100644 index 00000000..fd36a9ae --- /dev/null +++ b/web-v2/src/pages/GuildHome.jsx @@ -0,0 +1,15 @@ +import { Navigate, useParams } from 'react-router-dom'; +import { useAccess } from '../access.jsx'; +import Overview from './Overview.jsx'; + +// Where a server opens. Most people land on the overview; an Inbox-level person lands on the inbox, because +// that is what they are here for (the focused moderator view, access.jsx). Their "Show everything" choice +// brings the overview back. There is no combined inbox page, so this is the tickets, the first of the inboxes. +export default function GuildHome() { + const { guildId } = useParams(); + const { ready, focused, guildId: accessGuildId } = useAccess(); + // Not before the level of this server is known: the previous server's level must not decide. + if (!ready || (accessGuildId && accessGuildId !== guildId)) return

Loading…

; + if (focused) return ; + return ; +} diff --git a/web-v2/src/paletteModel.js b/web-v2/src/paletteModel.js index f75536a1..da2f848f 100644 --- a/web-v2/src/paletteModel.js +++ b/web-v2/src/paletteModel.js @@ -70,10 +70,11 @@ const ALIASES = { tickets: 'modmail' }; * Every place the palette can open for the picked server: the pages of the sidebar, every module page (also a * module that is switched off: the person may be looking for where to switch it on), and the other servers. * An item is `{ key, group, label, hint, href, icon, keywords }`; `href` is relative to the dashboard base. - * @param {{ guildId: string|null, data: object|null, operator: boolean, guilds?: Array<{id: string, name: string}> }} src + * In the focused moderator view (`focused`) it lists only what that view's sidebar shows, and no module pages. + * @param {{ guildId: string|null, data: object|null, operator: boolean, focused?: boolean, guilds?: Array<{id: string, name: string}> }} src */ -export function paletteItems({ guildId, data, operator, guilds = [] }) { - const nav = navModel({ guildId, data, operator }); +export function paletteItems({ guildId, data, operator, guilds = [], focused = false }) { + const nav = navModel({ guildId, data, operator, focused }); const items = []; const seen = new Set(); const add = (item) => { @@ -97,7 +98,7 @@ export function paletteItems({ guildId, data, operator, guilds = [] }) { } const problems = new Set((data?.attention?.problems ?? []).map((p) => p.id)); - for (const grp of data?.groups ?? []) { + for (const grp of focused ? [] : (data?.groups ?? [])) { for (const card of grp.cards ?? []) { const href = guildId ? v2Href(card, guildId) : null; const tone = cardTone(card, problems); diff --git a/web-v2/src/styles/p1.css b/web-v2/src/styles/p1.css new file mode 100644 index 00000000..821591b6 --- /dev/null +++ b/web-v2/src/styles/p1.css @@ -0,0 +1,24 @@ +/* The focused moderator view (Sidebar.jsx): the quiet switch at the foot of the sidebar. */ +.v2-sidebar-foot { + margin-top: auto; + padding: 16px 12px 0; +} +.v2-sidebar-focus-toggle { + padding: 0; + border: 0; + background: none; + color: var(--text-muted); + font: inherit; + font-size: var(--fs-xs); + text-decoration: underline; + text-underline-offset: 3px; + cursor: pointer; +} +.v2-sidebar-focus-toggle:hover { + color: var(--text); +} +.v2-sidebar-focus-toggle:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + border-radius: 4px; +} diff --git a/web-v2/src/util.js b/web-v2/src/util.js index bf6d012a..a6b7777a 100644 --- a/web-v2/src/util.js +++ b/web-v2/src/util.js @@ -24,6 +24,27 @@ export function writeLastGuildId(guildId) { } } +// An Inbox person's choice to see the whole dashboard instead of the focused moderator view. One choice +// for this browser, which belongs to one person. +const SHOW_EVERYTHING_KEY = 'sylo:v2:showEverything'; + +export function readShowEverything() { + try { + return localStorage.getItem(SHOW_EVERYTHING_KEY) === '1'; + } catch { + return false; + } +} + +export function writeShowEverything(on) { + try { + if (on) localStorage.setItem(SHOW_EVERYTHING_KEY, '1'); + else localStorage.removeItem(SHOW_EVERYTHING_KEY); + } catch { + // ignore — this is just a convenience + } +} + const THEME_KEY = 'sylo:v2:theme'; /** 'light' or 'dark' — null means "no explicit choice yet", so the default applies. */ From b68421175b74cee062ff3610e735a71e0a46c7c3 Mon Sep 17 00:00:00 2001 From: Ferdinand99 Date: Mon, 16 Nov 2026 00:50:42 +0100 Subject: [PATCH 2/7] style(web): format the moderator view files --- web-v2/src/__tests__/moderatorView.test.jsx | 45 +++++++++++++++------ web-v2/src/components/Sidebar.jsx | 7 +++- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/web-v2/src/__tests__/moderatorView.test.jsx b/web-v2/src/__tests__/moderatorView.test.jsx index 003fa5d9..3ba8345c 100644 --- a/web-v2/src/__tests__/moderatorView.test.jsx +++ b/web-v2/src/__tests__/moderatorView.test.jsx @@ -49,7 +49,15 @@ const MOD_TOOLS = [ 'Member data', 'Audit log', ]; -const SETUP_PAGES = ['Overview', 'Server settings', 'Commands', 'Leaderboard', 'Welcome', 'Leveling', 'Roadmap']; +const SETUP_PAGES = [ + 'Overview', + 'Server settings', + 'Commands', + 'Leaderboard', + 'Welcome', + 'Leveling', + 'Roadmap', +]; function setLevel(level) { api.getGuildAccess.mockImplementation((id) => Promise.resolve({ level: id === G ? level : 'edit' })); @@ -160,14 +168,17 @@ describe('the focused moderator view', () => { expect(hasLink('Server settings')).toBe(true); }); - it.each(['view', 'edit'])('%s keeps the overview and the full navigation, with no switch', async (level) => { - setLevel(level); - const router = await open(); - expect(router.state.location.pathname).toBe(`/guilds/${G}`); - expect(screen.getByText('overview page')).toBeTruthy(); - for (const name of [...MOD_TOOLS, ...SETUP_PAGES]) expect(hasLink(name), name).toBe(true); - expect(screen.queryByRole('button', { name: /Show everything|Show only moderation/ })).toBeNull(); - }); + it.each(['view', 'edit'])( + '%s keeps the overview and the full navigation, with no switch', + async (level) => { + setLevel(level); + const router = await open(); + expect(router.state.location.pathname).toBe(`/guilds/${G}`); + expect(screen.getByText('overview page')).toBeTruthy(); + for (const name of [...MOD_TOOLS, ...SETUP_PAGES]) expect(hasLink(name), name).toBe(true); + expect(screen.queryByRole('button', { name: /Show everything|Show only moderation/ })).toBeNull(); + } + ); it("opens another server on its own level, not the previous server's", async () => { // Inbox in G, Edit in H. @@ -191,8 +202,16 @@ describe('the focused moderator view', () => { await open(); fireEvent.click(screen.getByRole('button', { name: 'Search the dashboard' })); const labels = () => screen.getAllByRole('option').map((o) => o.textContent); - for (const name of MOD_TOOLS) expect(labels().some((l) => l.startsWith(name)), name).toBe(true); - for (const name of SETUP_PAGES) expect(labels().some((l) => l.startsWith(name)), name).toBe(false); + for (const name of MOD_TOOLS) + expect( + labels().some((l) => l.startsWith(name)), + name + ).toBe(true); + for (const name of SETUP_PAGES) + expect( + labels().some((l) => l.startsWith(name)), + name + ).toBe(false); // A typed text finds no module or settings page either. fireEvent.change(screen.getByRole('combobox'), { target: { value: 'welcome' } }); expect(screen.queryAllByRole('option').filter((o) => /Welcome/.test(o.textContent))).toHaveLength(0); @@ -231,7 +250,9 @@ describe('the models of the focused view', () => { }); it('gives the palette no module pages and no setup pages', () => { - const keys = paletteItems({ guildId: G, data: overview, operator: false, focused: true }).map((i) => i.key); + const keys = paletteItems({ guildId: G, data: overview, operator: false, focused: true }).map( + (i) => i.key + ); expect(keys.some((k) => k.startsWith('module:'))).toBe(false); expect(keys).not.toContain('page:settings'); expect(keys).not.toContain('page:overview'); diff --git a/web-v2/src/components/Sidebar.jsx b/web-v2/src/components/Sidebar.jsx index 62b69e7f..35c63969 100644 --- a/web-v2/src/components/Sidebar.jsx +++ b/web-v2/src/components/Sidebar.jsx @@ -113,7 +113,12 @@ export default function Sidebar({ activeGuildId, open, onClose, returnFocusRef } // An Inbox-level person gets the moderation tools only (access.jsx); a quiet link at the foot of the // sidebar switches to the full, still locked, navigation and back. const { focused, canFocus, showEverything, setShowEverything } = useAccess(); - const nav = navModel({ guildId: activeGuildId, data, operator, focused: Boolean(activeGuildId) && focused }); + const nav = navModel({ + guildId: activeGuildId, + data, + operator, + focused: Boolean(activeGuildId) && focused, + }); return ( <> From c75386fa73137e23dc0001171bfa5d3d7a53afed Mon Sep 17 00:00:00 2001 From: Ferdinand99 Date: Mon, 16 Nov 2026 01:10:49 +0100 Subject: [PATCH 3/7] fix(web): moderator view landing, no nav flash, switcher and review fixes --- docs/mobile-app.md | 2 +- docs/self-hosting.md | 6 +- web-v2/src/__tests__/moderatorView.test.jsx | 141 +++++++++++++++++- web-v2/src/access.jsx | 17 ++- web-v2/src/components/CommandPalette.jsx | 5 +- web-v2/src/components/ServerSwitcher.jsx | 10 +- web-v2/src/components/Shell.jsx | 2 +- web-v2/src/components/Sidebar.jsx | 16 +- web-v2/src/main.jsx | 2 +- web-v2/src/overviewModel.js | 37 ++++- web-v2/src/pages/GuildHome.jsx | 27 +++- web-v2/src/paletteModel.js | 1 + .../src/styles/{p1.css => moderator-view.css} | 11 +- 13 files changed, 241 insertions(+), 36 deletions(-) rename web-v2/src/styles/{p1.css => moderator-view.css} (69%) diff --git a/docs/mobile-app.md b/docs/mobile-app.md index 2ab149db..5e9ad6ff 100644 --- a/docs/mobile-app.md +++ b/docs/mobile-app.md @@ -338,7 +338,7 @@ The feature strings: - `duplicate`: the `duplicate` routes for reminders, embed messages, reaction-role sets, custom commands and shop items. - `message-templates`: the built-in message templates and the raw message JSON import and export. - `message-move`: when the channel of a posted **embed message**, the **Welcome channel** message or a **role panel** changes and is published, the server posts a fresh message in the new channel, stores it and then deletes the old one, so the app must not unpublish first. Other bot posts (verification, honeypot traps, applications and so on) are not covered. A publish that loses a race with another publish of the same embed message answers `409` with the current record. -- `moderator-view`: the web dashboard gives a person whose level in a server is `inbox` a focused view: the server opens on the inbox, and the navigation lists only the moderation tools (Tickets, Appeals, Applications, Suggestions, Moderation, Member data, Audit log), with a "Show everything" switch for the full, still locked, navigation. Nothing changes on the server side: the level is the `access` of each `GET /api/v2/guilds` entry (and `level` of `GET /api/v2/guilds/:id/access`). The app can follow the same rules for that level and keeps the full read-only app for `view`. +- `moderator-view`: the web dashboard gives a person whose level in a server is `inbox` a focused view: the server opens on the inbox, and the navigation lists only the moderation tools (Tickets, Appeals, Applications, Suggestions, Moderation hub, Member data; only the inboxes that are switched on), with a "Show everything" switch for the full, still locked, navigation. Nothing changes on the server side: the level is the `access` of each `GET /api/v2/guilds` entry (and `level` of `GET /api/v2/guilds/:id/access`). The app can follow the same rules for that level and keeps the full read-only app for `view`. - `app-connect`: [adding the other login](#adding-the-other-login). Only where sign-in is on and both Discord and Fluxer logins are set up. - `push`, `push-pigeon`: this instance can send notifications to signed-in apps. diff --git a/docs/self-hosting.md b/docs/self-hosting.md index 417953d0..614d69c2 100644 --- a/docs/self-hosting.md +++ b/docs/self-hosting.md @@ -177,9 +177,9 @@ roles set under *Dashboard access* on that server's *Settings* page: **Edit** (the bot-master roles: everything), **Inbox** (tickets, ban appeals, applications and suggestions, and reading the rest) or **View** (the pages and settings, read only, without what the inboxes contain). A person with Inbox access gets a focused -dashboard: the server opens on the inbox, and the sidebar lists only the moderation -tools (Tickets, Appeals, Applications, Suggestions, Moderation, Member data, Audit -log); a "Show everything" link at the foot of the sidebar brings back the full, still +dashboard: the server opens on the first inbox that is switched on, and the sidebar lists only the moderation +tools (the inboxes that are switched on: Tickets, Appeals, Applications, +Suggestions; and the Moderation hub and Member data); a "Show everything" link at the foot of the sidebar brings back the full, still locked, navigation and is remembered in that browser. View and Edit see the full dashboard. Only the owner or someone with Manage Server can change the Edit roles; anyone with Edit can change the Inbox and View diff --git a/web-v2/src/__tests__/moderatorView.test.jsx b/web-v2/src/__tests__/moderatorView.test.jsx index 3ba8345c..d1d2aa09 100644 --- a/web-v2/src/__tests__/moderatorView.test.jsx +++ b/web-v2/src/__tests__/moderatorView.test.jsx @@ -3,7 +3,7 @@ import { RouterProvider, createMemoryRouter } from 'react-router-dom'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import Shell from '../components/Shell.jsx'; import GuildHome from '../pages/GuildHome.jsx'; -import { navModel } from '../overviewModel.js'; +import { focusedLanding, navModel, switchSubpath } from '../overviewModel.js'; import { paletteItems } from '../paletteModel.js'; const G = '123456789012345678'; @@ -25,11 +25,25 @@ vi.mock('../api.js', async (importOriginal) => ({ const api = await import('../api.js'); const { resetOperatorCache } = await import('../useOperator.js'); -const overview = { +const INBOX_CARDS = ['tickets', 'appeals', 'applications', 'suggestions']; + +/** The overview of a server; `off` lists the inbox modules that are switched off. */ +const overviewOf = (off = []) => ({ openTickets: 2, openAppeals: 0, attention: { waiting: { tickets: 2, appeals: 0, applications: 0, suggestions: 0 }, problems: [] }, groups: [ + { + title: 'Inbox modules', + cards: INBOX_CARDS.map((id) => ({ + id, + name: id, + hasToggle: true, + enabled: !off.includes(id), + beta: false, + lines: [], + })), + }, { title: 'Engagement', cards: [ @@ -38,7 +52,8 @@ const overview = { ], }, ], -}; +}); +const overview = overviewOf(); const MOD_TOOLS = [ 'Tickets', @@ -47,10 +62,10 @@ const MOD_TOOLS = [ 'Suggestions', 'Moderation hub', 'Member data', - 'Audit log', ]; const SETUP_PAGES = [ 'Overview', + 'Audit log', 'Server settings', 'Commands', 'Leaderboard', @@ -71,6 +86,9 @@ async function open(path = `/guilds/${G}`) { children: [ { path: '/guilds/:guildId', element: }, { path: '/guilds/:guildId/tickets', element:

tickets page

}, + { path: '/guilds/:guildId/appeals', element:

appeals page

}, + { path: '/guilds/:guildId/moderation', element:

moderation page

}, + { path: '/guilds/:guildId/settings', element:

settings page

}, ], }, ], @@ -228,6 +246,97 @@ describe('the focused moderator view', () => { }); }); +describe('landing, flash and server switching', () => { + it('lands on the first inbox that is on: appeals when tickets are off, and the sidebar leaves tickets out', async () => { + setLevel('inbox'); + api.getOverview.mockResolvedValue(overviewOf(['tickets'])); + const router = await open(); + expect(router.state.location.pathname).toBe(`/guilds/${G}/appeals`); + expect(screen.getByText('appeals page')).toBeTruthy(); + expect(hasLink('Tickets')).toBe(false); + expect(hasLink('Appeals')).toBe(true); + }); + + it('lands on the Moderation hub when no inbox is on', async () => { + setLevel('inbox'); + api.getOverview.mockResolvedValue(overviewOf(INBOX_CARDS)); + const router = await open(); + expect(router.state.location.pathname).toBe(`/guilds/${G}/moderation`); + const nav = screen.getByRole('navigation', { name: 'Dashboard' }); + expect(within(nav).queryByRole('group', { name: 'Inbox' })).toBeNull(); + expect(hasLink('Moderation hub')).toBe(true); + }); + + it('falls back to the tickets when the overview does not load', async () => { + setLevel('inbox'); + api.getOverview.mockRejectedValue(new Error('down')); + const router = await open(); + expect(router.state.location.pathname).toBe(`/guilds/${G}/tickets`); + }); + + it('does not show the full navigation while the level is still being read, when the list says Inbox', async () => { + api.getGuildAccess.mockReturnValue(new Promise(() => {})); + await open(); + expect(hasLink('Tickets')).toBe(true); + for (const name of SETUP_PAGES) expect(hasLink(name), name).toBe(false); + expect(screen.queryByText('overview page')).toBeNull(); + }); + + it('holds the setup groups back while neither the list nor the server has given the level', async () => { + api.getGuildAccess.mockReturnValue(new Promise(() => {})); + api.getGuilds.mockReturnValue(new Promise(() => {})); + await open(); + for (const name of SETUP_PAGES) expect(hasLink(name), name).toBe(false); + }); + + it('opens the overview at once for Edit when the list gives the level, before the access call answers', async () => { + api.getGuildAccess.mockReturnValue(new Promise(() => {})); + api.getGuilds.mockResolvedValue([{ id: G, name: 'Home', icon: null, platform: 'discord', access: 'edit' }]); + await open(); + expect(screen.getByText('overview page')).toBeTruthy(); + expect(hasLink('Server settings')).toBe(true); + }); + + it('switching from an Inbox server to an Edit server in the session shows the overview, and back lands on the inbox', async () => { + setLevel('inbox'); + const router = await open(); + expect(router.state.location.pathname).toBe(`/guilds/${G}/tickets`); + await act(async () => { + await router.navigate(`/guilds/${H}`); + }); + expect(router.state.location.pathname).toBe(`/guilds/${H}`); + expect(screen.getByText('overview page')).toBeTruthy(); + expect(hasLink('Server settings')).toBe(true); + await act(async () => { + await router.navigate(`/guilds/${G}`); + }); + expect(router.state.location.pathname).toBe(`/guilds/${G}/tickets`); + expect(hasLink('Server settings')).toBe(false); + }); + + it('the server switcher does not carry a page the focused view hides into an Inbox server', async () => { + setLevel('inbox'); + const router = await open(`/guilds/${H}/settings`); + expect(screen.getByText('settings page')).toBeTruthy(); + await act(async () => { + fireEvent.click(screen.getByRole('link', { name: /Home/ })); + }); + expect(router.state.location.pathname).toBe(`/guilds/${G}/tickets`); + }); + + it('the switcher keeps a page the focused view lists, and every page for the other levels', () => { + expect(switchSubpath('/appeals', { access: 'inbox' })).toBe('/appeals'); + expect(switchSubpath('/m/applications', { access: 'inbox' })).toBe('/m/applications'); + expect(switchSubpath('/applications/12', { access: 'inbox' })).toBe('/applications/12'); + expect(switchSubpath('/settings', { access: 'inbox' })).toBe(''); + expect(switchSubpath('/m/welcome', { access: 'inbox' })).toBe(''); + expect(switchSubpath('/settings', { access: 'inbox', showEverything: true })).toBe('/settings'); + expect(switchSubpath('/settings', { access: 'edit' })).toBe('/settings'); + expect(switchSubpath('/settings', { access: 'view' })).toBe('/settings'); + expect(switchSubpath('', { access: 'inbox' })).toBe(''); + }); +}); + describe('the models of the focused view', () => { const nav = (focused) => navModel({ guildId: G, data: overview, operator: false, focused }); @@ -235,12 +344,34 @@ describe('the models of the focused view', () => { const n = nav(true); expect(n.top).toEqual([]); expect(n.inbox.map((i) => i.key)).toEqual(['tickets', 'appeals', 'applications', 'suggestions']); - expect(n.people.map((i) => i.key)).toEqual(['moderation', 'member-data', 'audit']); + expect(n.people.map((i) => i.key)).toEqual(['moderation', 'member-data']); expect(n.modules).toEqual([]); expect(n.server).toEqual([]); expect(n.more).toEqual([]); }); + it('lists only the inboxes whose module is on, keeping the Moderation hub', () => { + const d = overviewOf(['suggestions', 'appeals']); + const n = navModel({ guildId: G, data: d, operator: false, focused: true }); + expect(n.inbox.map((i) => i.key)).toEqual(['tickets', 'applications']); + expect(n.people.map((i) => i.key)).toContain('moderation'); + // The full view still lists them all, so an admin can find where to switch them on. + expect(navModel({ guildId: G, data: d, operator: false }).inbox).toHaveLength(4); + // A card the overview does not list counts as on. + expect(navModel({ guildId: G, data: { groups: [] }, operator: false, focused: true }).inbox).toHaveLength(4); + }); + + it('picks the landing from the modules that are on', () => { + expect(focusedLanding(G, overviewOf())).toBe(`/guilds/${G}/tickets`); + expect(focusedLanding(G, overviewOf(['tickets']))).toBe(`/guilds/${G}/appeals`); + expect(focusedLanding(G, overviewOf(['tickets', 'appeals']))).toBe(`/guilds/${G}/m/applications`); + expect(focusedLanding(G, overviewOf(['tickets', 'appeals', 'applications']))).toBe( + `/guilds/${G}/m/suggestions` + ); + expect(focusedLanding(G, overviewOf(INBOX_CARDS))).toBe(`/guilds/${G}/moderation`); + expect(focusedLanding(G, null)).toBe(`/guilds/${G}/tickets`); + }); + it('is unchanged when not focused', () => { const n = nav(false); expect(n.top).toHaveLength(1); diff --git a/web-v2/src/access.jsx b/web-v2/src/access.jsx index 1e841b23..1c63515d 100644 --- a/web-v2/src/access.jsx +++ b/web-v2/src/access.jsx @@ -20,11 +20,15 @@ const AccessContext = createContext({ guildId: null, reload: () => {}, ready: true, + hintLevel: null, showEverything: false, setShowEverything: () => {}, }); -export function AccessProvider({ guildId, children }) { +// `hint` is the level the server list already gave for this server (`access` on each entry): it stands in +// until the server's own answer is in, so a person with Inbox access never sees the full navigation flash +// before it narrows. Only the answer itself sets `ready`. +export function AccessProvider({ guildId, hint, children }) { const [state, setState] = useState({ guildId: null, level: 'edit' }); const [tick, setTick] = useState(0); const reload = useCallback(() => setTick((t) => t + 1), []); @@ -53,11 +57,12 @@ export function AccessProvider({ guildId, children }) { // The level of another server (the previous one, while the new one loads) is not used. const known = state.guildId === guildId; - const level = known ? state.level : 'edit'; + const hintLevel = RANK[hint] ? hint : null; + const level = known ? state.level : (hintLevel ?? 'edit'); // Without a server there is nothing to wait for. const ready = !guildId || known; return ( - + {children} ); @@ -68,12 +73,16 @@ export function AccessProvider({ guildId, children }) { * const { can } = useAccess(); */ export function useAccess() { - const { level, guildId, reload, ready, showEverything, setShowEverything } = useContext(AccessContext); + const { level, guildId, reload, ready, hintLevel, showEverything, setShowEverything } = + useContext(AccessContext); return { level, guildId, reload, ready, + // The level is settled enough to draw the navigation: the answer is in, or the server list gave it. + levelKnown: ready || Boolean(hintLevel), + hintLevel, can: (need) => (RANK[level] ?? 0) >= RANK[need], // The focused moderator view: a person whose level here is exactly Inbox gets the moderation tools // instead of the whole dashboard, unless they chose "Show everything". View keeps the full read-only diff --git a/web-v2/src/components/CommandPalette.jsx b/web-v2/src/components/CommandPalette.jsx index 39fc9750..de742a91 100644 --- a/web-v2/src/components/CommandPalette.jsx +++ b/web-v2/src/components/CommandPalette.jsx @@ -4,6 +4,7 @@ import { searchInbox, searchMembers } from '../api.js'; import { useAccess } from '../access.jsx'; import { useOverview } from '../OverviewContext.jsx'; import { useOperator } from '../useOperator.js'; +import { switchSubpath } from '../overviewModel.js'; import { groupItems, paletteItems, rankItems, readRecent, rememberRecent } from '../paletteModel.js'; import { parseMemberIds } from './MemberPicker.jsx'; import { Icon } from './icons.jsx'; @@ -106,7 +107,7 @@ function PaletteDialog({ onClose, guildId, guilds }) { const { data: shared, dataGuildId } = useOverview(); const data = dataGuildId === guildId ? shared : null; const operator = useOperator(); - const { focused } = useAccess(); + const { focused, showEverything } = useAccess(); const dialogRef = useRef(null); const settled = useRef(false); const closeTimer = useRef(null); @@ -184,7 +185,7 @@ function PaletteDialog({ onClose, guildId, guilds }) { let href = item.href; if (item.key.startsWith('guild:')) { const m = pathname.match(GUILD_PAGE); - if (m) href = `${item.href}${m[1] ?? ''}`; + if (m) href = `${item.href}${switchSubpath(m[1], { access: item.access, showEverything })}`; } navigate(href); finish(); diff --git a/web-v2/src/components/ServerSwitcher.jsx b/web-v2/src/components/ServerSwitcher.jsx index c0be89b3..44bc6296 100644 --- a/web-v2/src/components/ServerSwitcher.jsx +++ b/web-v2/src/components/ServerSwitcher.jsx @@ -3,6 +3,8 @@ import { Link, useLocation } from 'react-router-dom'; import PlatformBadge from './PlatformBadge.jsx'; import { getInvites } from '../api.js'; import { useApiData } from '../useApiData.js'; +import { useAccess } from '../access.jsx'; +import { switchSubpath } from '../overviewModel.js'; import { initial } from '../util.js'; // Matches /guilds/:id or /guilds/:id/ — captures the subpath (or '' @@ -19,6 +21,7 @@ export default function ServerSwitcher({ guilds, activeGuildId, onSelectGuild }) const multiPlatform = new Set(guilds.map((g) => g.platform)).size > 1; const { data: invites } = useApiData(() => getInvites(), []); const addLinks = invites ?? []; + const { showEverything } = useAccess(); const detailsRef = useRef(null); const { pathname } = useLocation(); const guildPageMatch = pathname.match(GUILD_PAGE); @@ -83,7 +86,12 @@ export default function ServerSwitcher({ guilds, activeGuildId, onSelectGuild }) // picker) there's no guild-scoped page to jump to, so just update // the selection in place — no navigation. return subpath !== null ? ( - + {inner} ) : ( diff --git a/web-v2/src/components/Shell.jsx b/web-v2/src/components/Shell.jsx index e856c0f0..9305f3cf 100644 --- a/web-v2/src/components/Shell.jsx +++ b/web-v2/src/components/Shell.jsx @@ -94,7 +94,7 @@ function SignedInShell() { const { guilds, loading, error } = state; return ( - + g.id === lastGuildId)?.access}>
+
+ ) : null} {nav.top.length ? : null} {/* The groups that belong to a server only exist once one is chosen: before that they would be a long column of greyed-out links. */} @@ -189,17 +205,6 @@ export default function Sidebar({ activeGuildId, open, onClose, returnFocusRef } {nav.bot.length ? ( ) : null} - {activeGuildId && canFocus ? ( -
- -
- ) : null} ); diff --git a/web-v2/src/pages/AppealsReview.jsx b/web-v2/src/pages/AppealsReview.jsx index 9d3d399b..ec254c46 100644 --- a/web-v2/src/pages/AppealsReview.jsx +++ b/web-v2/src/pages/AppealsReview.jsx @@ -8,7 +8,7 @@ import LoadError from '../components/LoadError.jsx'; import Meta from '../components/Meta.jsx'; import { formatCount } from '../util.js'; import Time from '../components/Time.jsx'; -import { AccessLock, NeedsInbox } from '../access.jsx'; +import { AccessLock, NeedsInbox, useAccess } from '../access.jsx'; const STATUS_LABEL = { open: 'Open', accepted: 'Accepted', denied: 'Denied' }; @@ -100,6 +100,8 @@ function AppealCard({ appeal, onDecide }) { export default function AppealsReview() { const { guildId } = useParams(); const { data, error, setData } = useApiData(() => getAppealsReview(guildId), [guildId]); + // The settings page needs Edit access: an Inbox person is not sent to a page they cannot open. + const canEdit = useAccess().can('edit'); if (error) return ; if (!data) return

Loading…

; @@ -140,16 +142,24 @@ export default function AppealsReview() { <>

Appeals

- - Appeal settings → - + {canEdit ? ( + + Appeal settings → + + ) : null}
{data.contentHidden ? : null} {!data.moduleEnabled || !data.configured ? (

{!data.moduleEnabled ? 'The Appeals module is off. ' : ''} {!data.configured ? 'No appeal questions are set up yet. ' : ''} - Set it up under Appeal settings. + {canEdit ? ( + <> + Set it up under Appeal settings. + + ) : ( + 'Ask a server admin to set it up.' + )}

) : null} diff --git a/web-v2/src/pages/Overview.jsx b/web-v2/src/pages/Overview.jsx index e9689b6d..b24f4f10 100644 --- a/web-v2/src/pages/Overview.jsx +++ b/web-v2/src/pages/Overview.jsx @@ -56,7 +56,7 @@ function BetaTag() { // rows after it and the button on a wider screen). const PHONE_ROWS = 3; -function NeedsAttention({ items }) { +function NeedsAttention({ items, canFix = true }) { const [all, setAll] = useState(false); if (!items.length) { return ( @@ -115,7 +115,7 @@ function NeedsAttention({ items }) { )} - {item.href ? ( + {item.href && (canFix || item.kind === 'waiting') ? ( {item.kind === 'waiting' ? 'Open' : 'Fix'} + ) : item.href ? ( + // The page that fixes it is a settings page this person cannot open. + Ask a server admin ) : null} ))} @@ -386,7 +389,7 @@ export default function Overview() { {needsSetupOffer(groups, problemIds) ? : null} - +
getTickets(guildId), [guildId]); + // The settings page needs Edit access: an Inbox person is not sent to a page they cannot open. + const canEdit = useAccess().can('edit'); if (error) return ; if (!data) return

Loading…

; @@ -41,9 +43,11 @@ export default function TicketsInbox() {

Tickets

- - Ticket settings → - + {canEdit ? ( + + Ticket settings → + + ) : null}

Members open a ticket by sending the bot a DM. Replies you write here reach them as an anonymous diff --git a/web-v2/src/styles/moderator-view.css b/web-v2/src/styles/moderator-view.css index 89931007..82520142 100644 --- a/web-v2/src/styles/moderator-view.css +++ b/web-v2/src/styles/moderator-view.css @@ -1,18 +1,33 @@ -/* The focused moderator view (Sidebar.jsx): the quiet switch at the foot of the sidebar. */ -.v2-sidebar-foot { - margin-top: auto; - padding: 16px 12px 0; +/* The focused moderator view (Sidebar.jsx): the switch at the top of the sidebar, which says which view it is + and changes to the other one. It stays at the top so the way back is never below a long list of links. */ +.v2-sidebar-viewswitch { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 2px 8px; + margin: 0 0 12px; + padding: 8px 10px; + border: 1px solid var(--border-subtle); + border-radius: var(--radius-sm); + background: var(--bg-surface); +} +.v2-sidebar-viewswitch-label { + color: var(--text-muted); + font-size: var(--fs-xs); + font-weight: 600; } .v2-sidebar-focus-toggle { display: inline-flex; align-items: center; min-height: 24px; - padding: 6px 0; + padding: 2px 0; border: 0; background: none; - color: var(--text-muted); + color: var(--accent-text); font: inherit; - font-size: var(--fs-xs); + font-size: var(--fs-sm); + font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; @@ -31,3 +46,10 @@ outline-offset: 2px; border-radius: 4px; } + +/* The Overview's "Needs attention" for someone who cannot change settings: no Fix link to a locked page. */ +.v2-attention-ask { + flex: none; + color: var(--text-muted); + font-size: var(--fs-sm); +} From 07cfb1a1d7853bef3fea550f7c7af9e77cbdd66e Mon Sep 17 00:00:00 2001 From: Ferdinand99 Date: Tue, 17 Nov 2026 05:20:17 +0100 Subject: [PATCH 7/7] test(web): the unfocused server group is not counted --- web-v2/src/__tests__/moderatorView.test.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web-v2/src/__tests__/moderatorView.test.jsx b/web-v2/src/__tests__/moderatorView.test.jsx index f412e2dc..b502a0e6 100644 --- a/web-v2/src/__tests__/moderatorView.test.jsx +++ b/web-v2/src/__tests__/moderatorView.test.jsx @@ -387,7 +387,10 @@ describe('the models of the focused view', () => { expect(n.top).toHaveLength(1); expect(n.people).toHaveLength(4); expect(n.modules.length).toBeGreaterThan(0); - expect(n.server).toHaveLength(2); + // The server group is whatever the nav model lists (other changes add pages to it), so it is not counted: + // it keeps the pages the focused view hides. + expect(n.server.map((i) => i.key)).toEqual(expect.arrayContaining(['settings', 'commands'])); + expect(n.server).toEqual(navModel({ guildId: G, data: overview, operator: false }).server); }); it('gives the palette no module pages and no setup pages', () => {