M1 (9): dashboard alerts by role

IntegrationAlerts reads the admin-only Site integrations global with access
control off and showed its error texts to everyone who opened the dashboard.
Now: an admin sees what is failing and the link, an editor a neutral "an
integration needs attention — ask an administrator", anyone else nothing.
CookieCrawlAlert is shown to editors and above (the role that may read the crawl
result). Both use userMeetsRole, so a session that still owes its second factor
sees neither. dashboardAlerts: { integrations: 'admin' | 'editor' | 'all',
cookies: 'editor' | 'all' } loosens it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 00:39:12 +01:00
co-authored by Claude Fable 5.2
parent 5d35b2c3f4
commit 0b4c4e8295
7 changed files with 173 additions and 13 deletions
+4 -4
View File
@@ -139,7 +139,7 @@ describe('cookie crawl — panel button → service → results', () => {
expect(crawl.violations.map((v: { name: string }) => v.name).sort()).toEqual(['_fbp', 'tracker.invalid'])
expect(sendEmail).toHaveBeenCalledWith(expect.objectContaining({ subject: expect.stringContaining('2'), to: ['[email protected]'] }))
expect(await CookieCrawlAlert({ payload })).not.toBeNull()
expect(await CookieCrawlAlert({ audience: 'all', payload })).not.toBeNull()
sendEmail.mockRestore()
}, 60_000)
@@ -158,8 +158,8 @@ describe('cookie crawl — panel button → service → results', () => {
const crawl = (await payload.findGlobal({ slug: 'cookie-crawl' as never })) as unknown as CrawlDoc
expect(crawl.summary.violations).toBe(0)
// No crawl problem left; only the approval reminder remains (drafts from the first crawl wait).
expect(await CookieCrawlAlert({ approval: false, payload })).toBeNull()
expect(await CookieCrawlAlert({ crawl: false, payload })).not.toBeNull()
expect(await CookieCrawlAlert({ approval: false, audience: 'all', payload })).toBeNull()
expect(await CookieCrawlAlert({ audience: 'all', crawl: false, payload })).not.toBeNull()
})
test('a failed crawl is reported and the next one may start', async () => {
@@ -168,6 +168,6 @@ describe('cookie crawl — panel button → service → results', () => {
expect((await call(2, { body: { error: 'site down', jobId, ok: false }, token: TOKEN })).status).toBe(200)
const status = (await (await call(0, { user: editor })).json()) as Record<string, unknown>
expect(status).toMatchObject({ error: 'site down', status: 'failed' })
expect(await CookieCrawlAlert({ payload })).not.toBeNull()
expect(await CookieCrawlAlert({ audience: 'all', payload })).not.toBeNull()
})
})