Hey there,
I have a project that uses the default authentication system and besides normal Users there is a special kind of user called “Agent” that is basically a normal User with a specific permission attached.
Now firstly, I will have an endpoint /users
that requires the permission can_view_users
that returns all the users.
Secondly I will have a permission can_view_agents
that means this person should be able to see only the users that have the permission that makes them agents.
With the situation above the doubt is if it’s correct to have the /users
endpoint handle both cases, so in the view logic it would check the permission of the user requesting and would return results based on that permission. So a user with can_view_users
would receive a certain result meanwhile an user with can_view_agents
would receive a different one when calling GET /users
. If the user with the first permission would want to get the result of the second it could probably call GET /users?agents=True
.
I wonder if this is a good design because implementing it doesn’t feel clean to have the same /users
endpoint returning different results based on permission althou I could be wrong.
A possible alternative that I thought of was having the users endpoint as described in the beginning and then a new endpoint /agents
that would return the users that have the permission that make them agents and subsequent paths would only do work on this kind of users.
This means that who has the permission can_view_agents
would be only able to access the /agents
endpoint and not the /users
one nor it has to know it exists.
Would this be a good design or incorrect that both those endpoint would exists ?
I appreciate your feedback,
Cheers