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:
co-authored by
Claude Fable 5.2
parent
5d35b2c3f4
commit
0b4c4e8295
@@ -2,6 +2,7 @@ import type { Payload } from 'payload'
|
||||
|
||||
import type { CookieScanLabels } from '../labels.js'
|
||||
|
||||
import { userMeetsRole } from '../../../access/predicates.js'
|
||||
import { COOKIE_APPROVAL_VIEW_PATH, countPendingCookies } from '../approval.js'
|
||||
import { COOKIE_REVIEW_SLUG } from '../collection.js'
|
||||
import { COOKIE_SCAN_LABELS, labelFor } from '../labels.js'
|
||||
@@ -11,12 +12,19 @@ type Props = {
|
||||
adminRoute?: string
|
||||
/** Cookie approval is on: remind while cookies wait, link to the approval view. Default true. */
|
||||
approval?: boolean
|
||||
/**
|
||||
* Who sees the alert: `'editor'` (default — the role that may read the crawl result and the
|
||||
* cookie review) or `'all'` (everyone who opens the dashboard, as before).
|
||||
*/
|
||||
audience?: 'all' | 'editor'
|
||||
/** The browser crawl is on: report violations and failed crawls. Default true. */
|
||||
crawl?: boolean
|
||||
/** Injected by Payload into admin server components. */
|
||||
i18n?: { language?: string }
|
||||
labels?: Record<string, CookieScanLabels>
|
||||
payload?: Payload
|
||||
/** Injected by Payload into admin server components — the account looking at the dashboard. */
|
||||
user?: null | Record<string, unknown>
|
||||
}
|
||||
|
||||
type CrawlDoc = { error?: null | string; status?: null | string; summary?: { newUnknown?: null | number; violations?: null | number } | null }
|
||||
@@ -29,8 +37,11 @@ const fill = (template: string, values: Record<string, number | string>) =>
|
||||
* link to the approval view), and — with the crawl — violations or a failed
|
||||
* crawl. Renders nothing when nothing needs attention, and never throws.
|
||||
*/
|
||||
export async function CookieCrawlAlert({ adminRoute = '/admin', approval = true, crawl = true, i18n, labels = COOKIE_SCAN_LABELS, payload }: Props) {
|
||||
export async function CookieCrawlAlert({ adminRoute = '/admin', approval = true, audience = 'editor', crawl = true, i18n, labels = COOKIE_SCAN_LABELS, payload, user }: Props) {
|
||||
if (!payload) {return null}
|
||||
// The crawl result and the review list are for editors and above; the widget reads them with
|
||||
// access control off, so it asks the same question itself (the second factor included).
|
||||
if (audience !== 'all' && !(user && userMeetsRole({ payload, user }, 'editor'))) {return null}
|
||||
let doc: CrawlDoc = {}
|
||||
if (crawl) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user