Skip to content

Fix filtering on private api routes#35

Draft
godismyjudge95 wants to merge 1 commit into
tv2regionerne:mainfrom
godismyjudge95:fixing-filters
Draft

Fix filtering on private api routes#35
godismyjudge95 wants to merge 1 commit into
tv2regionerne:mainfrom
godismyjudge95:fixing-filters

Conversation

@godismyjudge95

Copy link
Copy Markdown

Currently filtering does not work because none of the controllers implement the required allowedFilters method:
https://github.com/statamic/cms/blob/5.x/src/Http/Controllers/API/ApiController.php#L132-L134

Which means all filters are just discarded.

This PR adds in a simplified version of Statamic core's method:
https://github.com/statamic/cms/blob/5.x/src/Http/Controllers/API/UsersController.php#L39-L44

to the VerifiesPrivateAPI trait.


To enable filtering one can follow the steps outlined in the Statamic docs - https://statamic.dev/rest-api#enabling-filters
But make the changes specified to the config/private-api.php file instead of config/statamic/api.php


Setting this to draft as I plan to implement this for all the controllers unless that is not desired.

@steveparks

Copy link
Copy Markdown
Contributor

I've tested this PR by applying it as a patch locally, and can confirm:

  1. It fixes filtering on the /api/private/users endpoint, and results are returned accurately
  2. If trying to filter on a field that hasn't been specified in config/private-api.php, it returns an error that it is a forbidden filter and doesn't return data.

This works for me!

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