Base solution for your next web application
Open Closed

Default "User" role to include a permission #2029


User avatar
0
marklawton created

Hi,

When I create a new tenant, I would like the default "User" role to include the "Pages_Tenant_Dashboard" permission by default?

I can see in the "CreateWithAdminUserAsync" method in TentantManager.cs there is some code that adds ALL permissions for the default "Admin" role. However, I cannot figure out how to add a single permission for the default "User" role.

I tried a few different things, but found the Core project doesn't include a way to get a list of permissions? If it did, I could try inserting a line something like below;

await _userRole = _roleManager.GrantPermissionAsync(userRole, myPermission);

But can't find a way to set "myPermission" here?

Any help much appreciated!


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Inject IPermissionManager into TenantManager and use it like this.

    await _roleManager.GrantPermissionAsync(userRole, _permissionManager.GetPermission(AppPermissions.Pages_Tenant_Dashboard));
    
  • User Avatar
    0
    marklawton created

    Excellent, injecting IPermissionManager into TenantManager worked beautifully!

    Thank you ismcagdas :D