Base solution for your next web application
Open Closed

Give permissions to role in Seed / Default #5821


User avatar
0
sbenfares created

Hi,

What is the best way to define permissions for a specific role by code in the Seed actions _(or somewhere else) _?

How is it handled for the admin default user in ANZ ?

I would like to automatically link permissions & roles by code for the first default startup of my app, and not to have to go to the interface.

Thanks


5 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, you can assign permissions during tenant creation.

    See ANZ implementation

    You can also create seed data similar to DefaultTenantBuilder, however, i would consider seed data as tenant specific defaults rather than user specific defaults

  • User Avatar
    0
    sbenfares created

    Thanks but what if i don't have Multitenancy ?

  • User Avatar
    0
    ryancyq created
    Support Team

    You can create your custom permission builder and use it in SeedHelper as it is always called in regardless of multitenancy flag

  • User Avatar
    0
    sbenfares created

    Yes but i need to give access to all permissions like this code :

    
    var fullAdminRole = _roleManager.Roles.Single(r => r.Name == XXXXXX);
    await _roleManager.GrantAllPermissionsAsync(fullAdminRole);
    

    Where is the best place for doing this in startup ? In SeedHelper ?

    If so, how can i get the roleManager, should i get it from DI ?

    Thanks

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, you can refer to the first reply for ANZ implementation