System Information
- Strapi Version: 4.15.2
- Operating System: Alpine Linux edge
- Database: PostgreSQL
- Node Version: 18.18.2
- NPM Version: 10.2.3
- Yarn Version: 1.22.19
I have a very common scenario with a Collection type “Note” which has a text field and a relation to a User from users-permissions. The user should only be able to retrieve his own notes, and not the notes of other users, also no information about other users should be accessible.
Before Strapi 4.13, this simple trick in a controller would work:
find(ctx){
ctx.query.filters = { ...(ctx.query.filters as any), user: ctx.state.user.id };
return super.find(ctx);
}
As I understand, in newer versions of Strapi, filtering by the field not directly accessible by user is forbidden, and this code would produce the error “Invalid parameter user”. It would only work if explicitly checking User:find()
permission, and I only want to check User:me()
.
What would be the correct way to implement this function in Strapi 4.13+? Should I use Entity API or DB API?