Parent/child permissions grouping

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Parent/child permissions grouping



According to the documentation on Authorization, I can use child permissions to group all related permissions to their parents:



"Permissions can have parent and child permissions. While this does not affect permission checking, it helps to group the permissions in the UI."



As an example, I would like to create a parent Permission "User Management"
with "Create" , "Read", "Update" and "Delete" sub-permissions.


Permission



However, after setting my permission in SetPermissions, the hierarchy is not persisted anywhere so there's no way for me to know how permissions are related to each other from UI's perspective because the JSON returned is all flattened and the AbpPermissions table doesn't look like it maintains this either.


SetPermissions


AbpPermissions



Here's my code snippet (Fig. 1)



Fig1



And here's my AbpPermissions table (Fig. 2)


AbpPermissions



Fig2



I would appreciate any suggestion or any insight on this.



Thanks and best regards.




1 Answer
1



A Permission is already hierachical, with Parent and Children properties.


Permission


Parent


Children



You can retrieve the structure that you defined using:


var rootPermissions = _permissionManager.GetAllPermissions()
.Where(p => p.Parent == null)
.ToList();



You can then recursively iterate the rootPermissions and check if it is granted:


rootPermissions


var isAssigned = _permissionChecker.IsGranted(permission.Name);





Thank you for your answer. Interesting! Indeed the code snippet you provided shows the proper hierarchy when debugging, If I may enquire more though, how does GetAllPermissions establishes the hierarchy? I don't see any referential relation in the DB. Also how come it's not reflected in the json of role permission in the startup template? "permissions":["Pages.Roles","Pages.Contractors","Pages.Contracts","Pages.Setup","Pages.DocumentManagement","Pages.Documents","Pages.ContractManagement","Pages.Events","Users","Users.Create","Users.Edit"] Thank you very much!
– Chuck
Aug 14 at 1:29





The hierarchy that you define in your AuthorizationProvider is persisted in memory — more specifically, in the Permissions property in the base class of PermissionManager.
– aaron
Aug 14 at 1:50


AuthorizationProvider


Permissions


PermissionManager






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered