Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions packages/payload/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1322,18 +1322,69 @@ export type Config = {
* @see https://payloadcms.com/docs/query-presets/overview
*/
queryPresets?: {
/**
* Define collection-level access control that applies to all presets globally.
* This is separate from document-level access (constraints) which users can configure per-preset.
*/
access: {
create?: Access<QueryPreset>
delete?: Access<QueryPreset>
read?: Access<QueryPreset>
update?: Access<QueryPreset>
}
/**
* Define custom document-level access control options for presets.
*
* Payload provides sensible defaults (Only Me, Everyone, Specific Users), but you can
* add custom constraints for more complex patterns like RBAC.
*
* @example
* ```ts
* constraints: {
* read: [
* {
* label: 'Specific Roles',
* value: 'specificRoles',
* fields: [
* {
* name: 'roles',
* type: 'select',
* hasMany: true,
* options: [
* { label: 'Admin', value: 'admin' },
* { label: 'User', value: 'user' },
* ],
* },
* ],
* access: ({ req: { user } }) => ({
* 'access.read.roles': { in: [user?.roles] },
* }),
* },
* ],
* }
* ```
*
* @see https://payloadcms.com/docs/query-presets/overview#custom-access-control
*/
constraints: {
create?: QueryPresetConstraints
delete?: QueryPresetConstraints
read?: QueryPresetConstraints
update?: QueryPresetConstraints
}
/**
* Used to dynamically filter which constraints are available based on the current user, document data,
* or other criteria.
*
* Some examples of this might include:
*
* - Ensuring that only "admins" are allowed to make a preset available to "everyone"
* - Preventing the "onlyMe" option from being selected based on a hypothetical "disablePrivatePresets" checkbox
*
* When a user lacks the permission to set a constraint, the option will either be hidden from them, or disabled if it is already saved to that preset.
*
* @see https://payloadcms.com/docs/query-presets/overview#constraint-access-control
*/
filterConstraints?: SelectField['filterOptions']
labels?: CollectionConfig['labels']
}
Expand Down
12 changes: 12 additions & 0 deletions packages/payload/src/query-presets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,21 @@ export type QueryPreset = {
}

export type QueryPresetConstraint = {
/**
* A function that determines the access control rules for this constraint.
*/
access: Access<QueryPreset>
/**
* An array of fields to render when this constraint is selected.
*/
fields?: Field[]
/**
* The label displayed in the dropdown
*/
label: string
/**
* The value to store in the database when this constraint is selected.
*/
value: string
}

Expand Down