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
+27 -1
View File
@@ -2,6 +2,7 @@ import type { Payload } from 'payload'
import type { IntegrationStatus } from './status.js'
import { userMeetsRole } from '../access/predicates.js'
import { turnstileMissingKey } from '../turnstile/config.js'
import { type IntegrationLabel, resolveLabel, serverText, STATUS_CODE_TEXTS } from './texts.js'
@@ -10,10 +11,18 @@ type Props = {
adminRoute?: string
/** Status groups to check: field name → label (one string, or one per language). */
checks?: Record<string, IntegrationLabel>
/**
* Who sees WHAT is failing (the error text and the link to Site integrations): `'admin'`
* (default — the role that may read that global), `'editor'`, or `'all'` (everyone who opens
* the dashboard, as before). Below that, an editor sees a neutral line; anyone else nothing.
*/
details?: 'admin' | 'all' | 'editor'
/** Injected by Payload into admin server components. */
i18n?: { language?: string; t?: (key: never, vars?: Record<string, unknown>) => string }
/** Injected by Payload into admin server components. */
payload?: Payload
/** Injected by Payload into admin server components — the account looking at the dashboard. */
user?: null | Record<string, unknown>
}
const DEFAULT_CHECKS: Record<string, IntegrationLabel> = {
@@ -25,9 +34,16 @@ const DEFAULT_CHECKS: Record<string, IntegrationLabel> = {
* Dashboard alert (admin.components.beforeDashboard): lists integrations that
* are currently failing, with a link to Site integrations. Renders nothing when
* everything is fine — and never throws (DB not ready → nothing).
*
* The texts come from the Site integrations global, which only admins may read: the widget
* reads it with access control off, so it decides itself who gets them (`details`). A
* session that still owes its second factor gets nothing (`userMeetsRole` includes it).
*/
export async function IntegrationAlerts({ adminRoute = '/admin', checks = DEFAULT_CHECKS, i18n, payload }: Props) {
export async function IntegrationAlerts({ adminRoute = '/admin', checks = DEFAULT_CHECKS, details = 'admin', i18n, payload, user }: Props) {
if (!payload) {return null}
const sees = (role: 'admin' | 'editor') => Boolean(user) && userMeetsRole({ payload, user }, role)
const full = details === 'all' || sees(details)
if (!full && !sees('editor')) {return null}
let doc: Record<string, unknown>
try {
doc = (await payload.findGlobal({ slug: 'site-integrations' as never, depth: 0 })) as Record<string, unknown>
@@ -57,8 +73,18 @@ export async function IntegrationAlerts({ adminRoute = '/admin', checks = DEFAUL
}
if (!failing.length) {return null}
// Not allowed the detail: that something needs attention, and whom to ask — nothing of what or why.
if (!full) {
return (
<div data-ipal="integration-alerts" role="status" style={{ border: '1px solid var(--theme-elevation-200, #ddd)', borderRadius: 4, marginBottom: '1.5rem', padding: '1rem 1.25rem' }}>
<strong>{serverText(i18nLike, 'alertsHeading')}</strong> {serverText(i18nLike, 'alertsAskAdmin')}
</div>
)
}
return (
<div
data-ipal="integration-alerts"
role="alert"
style={{
background: 'var(--theme-error-50, rgba(229, 72, 77, 0.08))',