- Injected auth collection with roles: admins manage all accounts, others only themselves (Payload's default let any account edit or delete any other) - 2FA defaults to the resolved auth collection instead of 'users' - SiteSettings, CookieSettings, Notifications, Forms: write needs editor+; form Emails tab readable by editor+ only Co-Authored-By: Claude Opus 5.5 <[email protected]>
77 lines
2.6 KiB
TypeScript
77 lines
2.6 KiB
TypeScript
import type { Field, GlobalConfig } from 'payload'
|
|
|
|
import { adminOrEditor } from '../../modules/access/index.js'
|
|
import { generalFields } from './fields/general.js'
|
|
import { themeFields } from './fields/theme.js'
|
|
|
|
type BuildSiteSettingsArgs = {
|
|
/** Extra fields injected by the client project */
|
|
additionalFields?: Field[]
|
|
/** "Under construction" tab (developer tool) — given when the pages module is on. */
|
|
constructionFields?: Field[]
|
|
/** "Emails" tab — given with `forms: { emailLayout: true }`. */
|
|
emailFields?: Field[]
|
|
/**
|
|
* Fields for the "System Pages" tab — page assignments by role (homepage,
|
|
* privacy policy, collection archives). Assembled by the caller, which is the
|
|
* only place that knows which modules are enabled. The tab is omitted when
|
|
* this is empty.
|
|
*/
|
|
systemPageFields?: Field[]
|
|
}
|
|
|
|
/**
|
|
* Builds the SiteSettings global.
|
|
*
|
|
* Composes tabs out of field groups; it deliberately doesn't know where those
|
|
* groups come from. Earlier it imported the pages and content modules directly,
|
|
* which meant a global — a presentation-layer concern — had an opinion about
|
|
* blogs. Now the plugin's composition root passes fields in, and adding a new
|
|
* kind of page assignment needs no change here.
|
|
*
|
|
* Uses unnamed tabs — data stays flat (siteSettings.siteName, not
|
|
* siteSettings.general.siteName). Client-provided fields land in their own
|
|
* "Custom" tab so core data paths never shift.
|
|
*/
|
|
export function buildSiteSettings({
|
|
additionalFields,
|
|
constructionFields,
|
|
emailFields,
|
|
systemPageFields,
|
|
}: BuildSiteSettingsArgs = {}): GlobalConfig {
|
|
return {
|
|
slug: 'site-settings',
|
|
access: {
|
|
read: () => true,
|
|
// Editors and admins only — a plain 'user' account (open sign-up) must
|
|
// not rewrite the brand, homepage or construction mode.
|
|
update: adminOrEditor,
|
|
},
|
|
admin: {
|
|
group: 'Settings',
|
|
},
|
|
fields: [
|
|
{
|
|
type: 'tabs',
|
|
tabs: [
|
|
{
|
|
fields: generalFields,
|
|
label: 'General',
|
|
},
|
|
{
|
|
fields: themeFields,
|
|
label: 'Theme',
|
|
},
|
|
...(systemPageFields?.length
|
|
? [{ fields: systemPageFields, label: 'System Pages' }]
|
|
: []),
|
|
...(emailFields?.length ? [{ fields: emailFields, label: 'Emails' }] : []),
|
|
...(constructionFields?.length ? [{ fields: constructionFields, label: 'Under construction' }] : []),
|
|
...(additionalFields?.length ? [{ fields: additionalFields, label: 'Custom' }] : []),
|
|
],
|
|
},
|
|
],
|
|
label: 'Site Settings',
|
|
}
|
|
}
|