Skip to content

fix: allow custom admin user collection in query presets constraints #12202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2025

Conversation

sam-gab
Copy link
Contributor

@sam-gab sam-gab commented Apr 23, 2025

Query preset "Specific User" constraints is currently fixed to users collection.
However, this will fail if one has a custom admin user collection.

Query preset is currently fixed to `user` collection. 
However, this will fail if one has a custom admin user collection.
@sam-gab sam-gab changed the title fix: Allow custom admin user collection fix(payload): Allow custom admin user collection Apr 23, 2025
@sam-gab sam-gab changed the title fix(payload): Allow custom admin user collection fix(cpa): Allow custom admin user collection Apr 23, 2025
@sam-gab sam-gab changed the title fix(cpa): Allow custom admin user collection fix(cpa): allow custom admin user collection Apr 23, 2025
@sam-gab sam-gab changed the title fix(cpa): allow custom admin user collection fix(cpa): allow custom admin user collection in query presets constraints Apr 23, 2025
@jacobsfletch jacobsfletch changed the title fix(cpa): allow custom admin user collection in query presets constraints fix: allow custom admin user collection in query presets constraints Apr 25, 2025
jacobsfletch and others added 2 commits April 24, 2025 22:36
It seems `relatedTo` can't be undefined in a relationship field type - hence the lint errors. 
I could be wrong, and the lint error is coming from somewhere else. I don't have this set up locally - updating directly on github.
@sam-gab
Copy link
Contributor Author

sam-gab commented Apr 30, 2025

@jacobsfletch I added the fallback as it seems relatedTo can't be undefined in a relationship field type - hence the lint errors.

Could you please help me check why the workflow is stuck? Thank you... 😃

@jacobsfletch
Copy link
Member

@sam-gab the fallback should not be added just to satisfy lint. In this case we need to either update the types to reflect the sanitized fallback or assert the type directly.

@sam-gab
Copy link
Contributor Author

sam-gab commented Apr 30, 2025

@jacobsfletch Apologies mate, maybe I'm just blur - don't quite understand what you mean. Do you mean I need to:

  1. Update the relationTo param for a relationship field type to be an optional field? Or
  2. Update the admin param in the payload configs to be a required field? Or
  3. Assert that config.admin.user is always provided for the Query Preset constraint feature to work?

@jacobsfletch
Copy link
Member

jacobsfletch commented May 1, 2025

@sam-gab the args passed into the getConstraints function does in fact have a resolved admin.user, but the types are incorrectly defining it as optional. This means we can safely assert the type on that property in order to satisfy lint.

For example:

{
  // ...
  relationTo: config.admin.user as string
}

This works because the config arg is typed as Config, but in reality is Partial<SanitizedConfig>. See this line.

For now, we can keep the fallback as you have it, although it would technically never be used.

The more permanent fix here, on the other hand, would be to properly type the args passed into this function so that neither a type assertion or a fallback is necessary. I think for now, we can merge your change as is, and just mark it with a todo.

@jacobsfletch jacobsfletch merged commit b9868c4 into payloadcms:main May 1, 2025
76 checks passed
Copy link
Contributor

github-actions bot commented May 5, 2025

🚀 This is included in version v3.37.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants