How to Handle Parent-Child Resource Access Control in AdonisJS Policies? #4718
Unanswered
patrickphat
asked this question in
Help
Replies: 1 comment
-
By the way, when define policies in async function, it seems like typescript inference is no longer work. For instance:
Only non async policies got type-safety |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi AdonisJS community,
I’m working on an application where I need to manage hierarchical resources with parent-child relationships and enforce access control through policies.
Here’s my specific use case:
My question is about best practices for handling access control in this scenario, particularly in the context of AdonisJS policies. Should a policy for the Page model implicitly check the permissions of the Site model, or is there a better approach?
My current approach:
I created a SitePolicy that checks if the user can edit the site.
For the PagePolicy, I check if the user has permission to edit the parent site using the
site()
relationship inside the policy. Here’s an example of what I’m doing in the PagePolicy (in pseudo code):My Concerns:
I’d appreciate any guidance on best practices or alternative approaches for managing hierarchical access control with AdonisJS policies.
Thanks in advance for your help!
Beta Was this translation helpful? Give feedback.
All reactions