Permissions and Access Rights within controllers #125
-
Hi @neonexus, I would like to get your suggestion on how to achieve the below usecase regarding access rights and permissions. Say, an user has permission to access to view and add new users but not update or delete users (not ideal; just to give an example) In such cases, how to effectively provide API access? Can I adapt Any help would be appreciated. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Generally speaking, you want to default to using policies for access rights control. On one hand, it helps keep things consistent, on the other, they are independent functions run before your controller, so they help keep things safer as well. So, in this case, I would have the policies "can-delete" / "can-edit", and they would check, depending on your needs, if they have the proper permission level, or have the granular access granted. Make sense? |
Beta Was this translation helpful? Give feedback.
-
Thanks @neonexus. Yeah it does make sense. Just to confirm, in the module.exports.policies = {
'*': true,
AdminController: {
'*': ['isLoggedIn'],
},
}; Now, I adapt it like the below !? module.exports.policies = {
'*': true,
AdminController: {
'*': ['isLoggedIn'],
},
'admin/can-edit': {
'*': ['isClnManager'],
},
'admin/can-delete': {
'*': ['isClnManager'],
},
}; Am I correct? For all the scripts in Please correct me if I am wrong. Thanks. |
Beta Was this translation helpful? Give feedback.
Sorry for the delay.
Your policies should look like:
The order goes "Explicit > Generic". If there isn't an explicit policy set, it goes to the next least-generic policy. So, in this case, there are the 2 routes that are explicitl…