How can I use hooks or other means to override user query parameters?

Hi everyone,

I’m using Directus version 11.9.2 and I want to override user-provided query parameters using a hook.

Specifically, I want to enforce a filter condition like:

filter: {
  status:  true 
}

I tried to use a hook like this:

action('MyCollection.items.read', (payload) => {	
		console.log(payload);
	});

But I still don’t get it after checking the docs. Filters and Actions only seem to return responses.

Currently, my known methods: policies, client
or is there a better way to handle this?

Thanks in advance!

Hi! :waving_hand:

You can refer to the official Directus documentation on access control here:
:link: https://directus.io/docs/guides/auth/access-control

To achieve what you’re looking for, go to Roles & Permissions in the admin panel. Then, under the Read permission for the specific collection, set a filter like this:

{
  "status": {
    "_eq": "published"
  }
}

This ensures that users with that role will only be able to fetch items where the status is set to "published".

I believe this is exactly what you wanted to achieve.

Let me know if you need any help setting it up!