Skip to content

Conversation

@jacobsfletch
Copy link
Member

@jacobsfletch jacobsfletch commented May 21, 2025

You can now specify exactly who can change the constraints within a query preset.

For example, you want to ensure that only "admins" are allowed to set a preset to "everyone".

To do this, you can use the new queryPresets.filterConstraints property. When a user lacks the permission to change a constraint, the option will either be hidden from them or disabled if it is already set.

import { buildConfig } from 'payload' const config = buildConfig({ // ... queryPresets: { // ... filterConstraints: ({ req, options }) => !req.user?.roles?.includes('admin') ? options.filter( (option) => (typeof option === 'string' ? option : option.value) !== 'everyone', ) : options, }, })

The filterConstraints functions takes the same arguments as reduceOptions property on select fields introduced in #12487.


@jacobsfletch jacobsfletch changed the title feat: query preset constraint access feat: query preset constraint filters May 27, 2025
@jacobsfletch jacobsfletch changed the title feat: query preset constraint filters feat: filter query preset constraints May 27, 2025
@jacobsfletch jacobsfletch merged commit 0204f0d into main May 27, 2025
82 checks passed
@jacobsfletch jacobsfletch deleted the feat/query-preset-constraint-options branch May 27, 2025 20:55
@github-actions
Copy link
Contributor

🚀 This is included in version v3.40.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment