How to give permissions to a role?
I'm using a new DataSeed to insert two new roles to my database, but the problem is that those roles are created without permissions.
IdentityRole firstRole = new IdentityRole(_guidGenerator.Create(), "Role1");
IdentityRole secondRole = new IdentityRole(_guidGenerator.Create(), "Role 2");
await _rolesRepository.InsertAsync(firstRole );
await _rolesRepository.InsertAsync(secondRole );
And I'm also using a StandardPermissionDefinitionProvider : PermissionDefinitionProvider to control permission access to the views, it's working.
var bandGroup = context.AddGroup(PermissionNames.Bands.Root, L(PermissionNames.Bands.Root), MultiTenancySides.Host);
bandGroup.AddPermission(PermissionNames.Bands.Add, L(PermissionNames.Bands.Add), MultiTenancySides.Host);
bandGroup.AddPermission(PermissionNames.Bands.Delete, L(PermissionNames.Bands.Delete), MultiTenancySides.Host);
bandGroup.AddPermission(PermissionNames.Bands.Edit, L(PermissionNames.Bands.Edit), MultiTenancySides.Host);
bandGroup.AddPermission(PermissionNames.Bands.List, L(PermissionNames.Bands.List), MultiTenancySides.Host);
My doubt is, how do I set bandGroup permissions to Role 1? Should I use a custom dataseed? Which table should I seed?
NOTE: Tried to look at the documentation but the url https://docs.abp.io/en/abp/latest/Modules/Permission-Management has nothing about it
Hi,
You can use IPermissionManager dependency to assign different permissions to a role.
Inject the IPermissionManager and use the following extension method.
Task SetForRoleAsync(string roleName, string permissionName, bool isGranted)
Thanks, this worked!