@bison-lab/payload-core 5.6.1 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/dist/{capability-DCwqbZ82.mjs → capability-B3Mk0KRh.mjs} +42 -28
- package/dist/capability-B3Mk0KRh.mjs.map +1 -0
- package/dist/index.d.mts +23 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +14 -25
- package/dist/index.mjs.map +1 -1
- package/dist/translate.d.mts.map +1 -1
- package/dist/translate.mjs +1 -1
- package/package.json +2 -2
- package/dist/capability-DCwqbZ82.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -645,9 +645,10 @@ wraps `@payloadcms/plugin-redirects` for `pages` only (permanent 308) and
|
|
|
645
645
|
collapses chains when a published slug changes. The plugin stores the
|
|
646
646
|
rows; the site still has to serve them. Pin the plugin to the same
|
|
647
647
|
version as `payload`, then `payload generate:importmap`,
|
|
648
|
-
`payload generate:types`, and `payload migrate:create`. Create
|
|
649
|
-
|
|
650
|
-
|
|
648
|
+
`payload generate:types`, and `payload migrate:create`. Create and update follow the Content tick;
|
|
649
|
+
only the Publish grant writes the live page (a publish, a save without
|
|
650
|
+
`?draft=true`, every version restore), held by the shared
|
|
651
|
+
`roles/publish-gate` hooks (#330). Users sit under Settings next to Roles,
|
|
651
652
|
take `secureCookies`, and offer whatever rows the Global (or the seed
|
|
652
653
|
plus the same `extras`) has. `users.roles` and `users.allowedFeatures`
|
|
653
654
|
set `saveToJWT: true`. The checklist labels are the editable names.
|
|
@@ -708,7 +709,9 @@ so an existing one-document row does not move. Footer is
|
|
|
708
709
|
Postgres's 63-character identifier cap the same way `nav` did. Both sit
|
|
709
710
|
in `admin.group: "Navigation"` until a Developer moves them from Admin
|
|
710
711
|
nav. One Features tick (`navigation`, passed as a `createFeatures`
|
|
711
|
-
extra).
|
|
712
|
+
extra; no seed role holds it). The tick saves drafts; a publish, a save
|
|
713
|
+
without `?draft=true` and every version restore need the Publish tick
|
|
714
|
+
(`roles/publish-gate`, #330). `getNavigation({ payload,
|
|
712
715
|
draft })` finds both and returns `{ header, footer, bar }`; a site with
|
|
713
716
|
more than one locale adds `locale` (and `fallbackLocale`) so the labels
|
|
714
717
|
read in it.
|
|
@@ -668,6 +668,45 @@ function hideUnlessFeature(slug) {
|
|
|
668
668
|
};
|
|
669
669
|
}
|
|
670
670
|
//#endregion
|
|
671
|
+
//#region src/roles/publish-gate.ts
|
|
672
|
+
/**
|
|
673
|
+
* Without Publish, an update must be a draft save (`draft: true`;
|
|
674
|
+
* `?draft=true` over REST, which the admin's Save draft and autosave send),
|
|
675
|
+
* and a version restore is refused outright: a restore writes the live row
|
|
676
|
+
* even with `draft: true` (Payload only marks it a draft first). Writes with
|
|
677
|
+
* no user or with `overrideAccess` are the server's own and pass.
|
|
678
|
+
*/
|
|
679
|
+
async function draftSavesOnly({ args, operation, req }) {
|
|
680
|
+
if (operation !== "update" && operation !== "restoreVersion") return args;
|
|
681
|
+
const write = args ?? {};
|
|
682
|
+
if (write.overrideAccess || !req.user) return args;
|
|
683
|
+
if (operation === "update" && write.draft === true && !write.publishAllLocales && !write.publishSpecificLocale && !write.unpublishAllLocales) return args;
|
|
684
|
+
if (await Promise.resolve(canPublish({ req }))) return args;
|
|
685
|
+
throw new Forbidden();
|
|
686
|
+
}
|
|
687
|
+
/** Publishing (`_status: 'published'`) needs the Publish grant. */
|
|
688
|
+
async function refusePublish({ data, req }) {
|
|
689
|
+
if (data?._status !== "published" || !req.user) return data;
|
|
690
|
+
if (await Promise.resolve(canPublish({ req }))) return data;
|
|
691
|
+
throw new Forbidden();
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Update access for a drafted document: `base` (the Content or feature
|
|
695
|
+
* tick), refused for data that publishes unless the login holds Publish.
|
|
696
|
+
* Enforcement is the two hooks; this is what hides the admin's Publish
|
|
697
|
+
* button, which Payload shows from `access.update` called with
|
|
698
|
+
* `_status: 'published'` (and draft editing from `_status: 'draft'`).
|
|
699
|
+
*/
|
|
700
|
+
function updateUnlessPublishing(base) {
|
|
701
|
+
return async (args) => {
|
|
702
|
+
if (!await Promise.resolve(base(args))) return false;
|
|
703
|
+
if (args.data?._status !== "published") return true;
|
|
704
|
+
return Boolean(await Promise.resolve(canPublish({ req: args.req })));
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
const draftSavesOnlyWithoutPublish = draftSavesOnly;
|
|
708
|
+
const refusePublishWithoutGrant = refusePublish;
|
|
709
|
+
//#endregion
|
|
671
710
|
//#region src/translate/fields.ts
|
|
672
711
|
const isDoc = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
673
712
|
const asRows = (value) => Array.isArray(value) ? value.filter(isDoc) : void 0;
|
|
@@ -3704,31 +3743,6 @@ function getMessages(payload, locale, options = {}) {
|
|
|
3704
3743
|
value.catch(() => byLocale.delete(locale));
|
|
3705
3744
|
return value;
|
|
3706
3745
|
}
|
|
3707
|
-
/** Publishing needs the Publish grant, as on Pages and the Header; Content alone saves drafts. */
|
|
3708
|
-
const refusePublishWithoutGrant = async ({ data, req }) => {
|
|
3709
|
-
if (data?._status !== "published" || !req.user) return data;
|
|
3710
|
-
if (await Promise.resolve(canPublish({ req }))) return data;
|
|
3711
|
-
throw new Forbidden();
|
|
3712
|
-
};
|
|
3713
|
-
/**
|
|
3714
|
-
* Without Publish, an update must be a draft save (`draft: true`;
|
|
3715
|
-
* `?draft=true` over REST, which the admin's Save draft sends), and a
|
|
3716
|
-
* version restore is refused outright. The gate above is not enough on its
|
|
3717
|
-
* own: Payload fills `_status` from the latest version, so once anyone has
|
|
3718
|
-
* saved a draft a plain update reads `'draft'`, passes it, and still writes
|
|
3719
|
-
* the live row that `getMessages` serves (#309). A restore writes that live
|
|
3720
|
-
* row even with `draft: true` (Payload only marks it a draft first), so no
|
|
3721
|
-
* restore is a draft save. Writes with no user or with `overrideAccess` are
|
|
3722
|
-
* the server's own and pass, as on the gate.
|
|
3723
|
-
*/
|
|
3724
|
-
const draftSavesOnlyWithoutPublish = async ({ args, operation, req }) => {
|
|
3725
|
-
if (operation !== "update" && operation !== "restoreVersion") return args;
|
|
3726
|
-
const write = args;
|
|
3727
|
-
if (write.overrideAccess || !req.user) return args;
|
|
3728
|
-
if (operation === "update" && write.draft === true && !write.publishAllLocales && !write.publishSpecificLocale && !write.unpublishAllLocales) return args;
|
|
3729
|
-
if (await Promise.resolve(canPublish({ req }))) return args;
|
|
3730
|
-
throw new Forbidden();
|
|
3731
|
-
};
|
|
3732
3746
|
const clearMessages = ({ doc, req }) => {
|
|
3733
3747
|
invalidateMessages(req.payload);
|
|
3734
3748
|
return doc;
|
|
@@ -3751,7 +3765,7 @@ function interfaceTextGlobal() {
|
|
|
3751
3765
|
},
|
|
3752
3766
|
access: {
|
|
3753
3767
|
read: ({ req }) => isAuthenticated(req.user),
|
|
3754
|
-
update: (args) => canUseFeature("content")(args)
|
|
3768
|
+
update: updateUnlessPublishing((args) => canUseFeature("content")(args))
|
|
3755
3769
|
},
|
|
3756
3770
|
versions: {
|
|
3757
3771
|
drafts: true,
|
|
@@ -4148,6 +4162,6 @@ function withJobsOnSwitch(global) {
|
|
|
4148
4162
|
};
|
|
4149
4163
|
}
|
|
4150
4164
|
//#endregion
|
|
4151
|
-
export { LIBRARY_DEFAULT_LOCALE as $,
|
|
4165
|
+
export { LIBRARY_DEFAULT_LOCALE as $, resetRolesMatrix as $t, TRANSLATE_NOW as A, isLockedFeature as An, hideUnlessDeveloper as At, TRANSLATION_STATUS_BAR as B, DUPLICATE_ROLE_NAME_MESSAGE as Bt, isAutosave as C, FEATURES_SLUG as Cn, canManageContent as Ct, shouldSkipUndraftedTranslation as D, PACKAGE_FEATURE_SLUGS as Dn, hasCapability as Dt, shouldSkipDraftedTranslation as E, PACKAGE_FEATURES as En, getRolesMatrix as Et, TRANSLATION_ACTIVITY_PANEL as F, isDeveloperTab as Ft, FAILURE_ADVICE as G, ROLES_FIELD_DESCRIPTION as Gt, readTranslationSettings as H, INVALID_ROLE_NAME_MESSAGE as Ht, TRANSLATION_GRANT as I, isPrivilegedRole as It, monthKey as J, applyRoleSlugsFromNames as Jt, RATE_LIMIT_STREAK as K, ROLES_GLOBAL_DESCRIPTION as Kt, TRANSLATION_KEY_PANEL as L, storedRoles as Lt, BISON_TRANSLATION_CONTEXT as M, isAdminOrSelf as Mt, readTranslateState as N, isAuthenticated as Nt, TRANSACTION_TIMEOUT_MS as O, isFeatureGroupId as On, hasGrant as Ot, withTranslator as P, isDeveloper as Pt, ACTIVE_LOCALES_CACHE_MS as Q, parseRolesMatrix as Qt, TRANSLATION_SETTINGS_SLUG as R, DEFAULT_ROLE_MATRIX as Rt, startJob as S, slugifyRoleName as Sn, canManageBrand as St, localizedCopyUnchanged as T, FEATURE_GROUP_LABELS as Tn, developerOnlyAccess as Tt, resolveModel as U, LAST_USERS_TICK_MESSAGE as Ut, invalidateTranslationSettings as V, DUPLICATE_ROLE_SLUG_MESSAGE as Vt, siteFromInstructions as W, MISSING_SEED_ROLES_MESSAGE as Wt, usageHistory as X, grantsFromStoredRole as Xt, recordUsage as Y, defaultRolesFieldValue as Yt, usageThisMonth as Z, normalizeStoredRoles as Zt, frozenWordForce as _, isRole as _n, canUseFeature as _t, MESSAGES_CACHE_MS as a, defaultFeaturesFieldValue as an, invalidateActiveLocales as at, runJobSlice as b, roleLabel as bn, hideUnlessFeature as bt, importMessages as c, parseFeaturesMatrix as cn, encryptApiKey as ct, unflattenMessages as d, CAPABILITIES as dn, sameRow as dt, roleDescription as en, LIBRARY_LOCALES as et, translationSettingsEndpoints as f, CAPABILITY_FEATURES as fn, translationJob as ft, estimateJob as g, THEME_FEATURE_SLUGS as gn, allowedFeaturesForUser as gt, claimJob as h, ROLE_LABELS as hn, updateUnlessPublishing as ht, INTERFACE_TEXT_SLUG as i, MISSING_PACKAGE_FEATURES_MESSAGE as in, inactiveLocaleRedirect as it, translateDocument as j, isPackageFeatureSlug as jn, isAdmin as jt, runAfterCommit as k, isFeatureSlug as kn, hasRole as kt, interfaceTextGlobal as l, stampFeatureCatalogue as ln, resolveApiKey as lt, TRANSLATION_JOBS_SLUG as m, ROLES as mn, refusePublishWithoutGrant as mt, hasLocalizedFields as n, seedRoleRows as nn, activeAlternates as nt, flattenMessages as o, featureCatalogue as on, withLibraryLocales as ot, LEASE_MS as p, DEFAULT_ROLE_GRANTS as pn, draftSavesOnlyWithoutPublish as pt, TRANSLATION_USAGE_SLUG as q, ROLES_SLUG as qt, translation as r, validateRolesMatrix as rn, activeLocales as rt, getMessages as s, featureGroupLabel as sn, decryptApiKey as st, applyTranslation as t, roleSelectOptions as tn, LIBRARY_LOCALE_CODES as tt, invalidateMessages as u, validateFeaturesMatrix as un, collectLocalizedStrings as ut, jobView as v, isRoleName as vn, getFeaturesMatrix as vt, draftedTranslationDecision as w, FEATURE_GROUPS as wn, canPublish as wt, startBackfill as x, sanitizeRoleNameInput as xn, authenticatedOrPublished as xt, resumeStaleJobs as y, isRoleSlug as yn, hasFeature as yt, TRANSLATION_STATE_SLUG as z, DEVELOPER_DESCRIPTION as zt };
|
|
4152
4166
|
|
|
4153
|
-
//# sourceMappingURL=capability-
|
|
4167
|
+
//# sourceMappingURL=capability-B3Mk0KRh.mjs.map
|