SetGrantedPermissionsAsync of RoleManager not set all permission to given role.
See original GitHub issueDocumentation
Please check the official documentation before asking questions: https://aspnetboilerplate.com/Pages/Documents
GitHub Issues
GitHub issues are for bug reports, feature requests and other discussions about the framework.
If you’re creating a bug/problem report, please include followings:
- Abp Package Version: 4.2
- Your base framework: .Net Core. Please write in English.
I have a multitenant environment, but not have Tenant admin (all tenant have single users StaticRoleNames.Tenants.User ), just use Tenant for isolation. I have 20 permissions set for StaticRoleDefinition (StaticRoleNames.Tenants.User), but when i set all these permissions on tenant creation only 11 are set, i can’t find the reason. Here is what i’m doing.
using (_unitOfWorkManager.Current.SetTenantId(tenant.Id))
{
//Create static roles for new tenant (Tenant->User Role)
CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id));
await _unitOfWorkManager.Current.SaveChangesAsync(); //To get static role ids
//Tenant static role is the one that contain permissions
var staticRole = _roleManager.RoleManagementConfig.StaticRoles.Single(x => x.RoleName == StaticRoleNames.Tenants.User
&& x.Side == MultiTenancySides.Tenant);
//Get permissions from Tenant
var permissions = new List<Permission>();
foreach (var permission in staticRole.GrantedPermissions)
{
permissions.Add(_permissionManager.GetPermission(permission));
}
//Get the admin role
var providerRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.User);
//Grant selected permission to role
await _roleManager.SetGrantedPermissionsAsync(providerRole, permissions);
// When SetGrantedPermissionsAsync return providerRole has 11 permissions set, and permissions.Count() is 20
await _unitOfWorkManager.Current.SaveChangesAsync();
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Adding permissions to static roles #5856
Roles.AppConfig.Configure where we create all our static roles, however, that method doesn't seem to have access to the RoleManager.
Read more >Articles Tutorials | AspNet Boilerplate
We use the RoleManager to change the permissions of a Role. For example, SetGrantedPermissionsAsync can be used to change all the permissions of...
Read more >The Role Manager feature has not been enabled
roleManager will give you access to see if the role exists, create, etc, plus it is created for the UserManager.
Read more >ABP 权限拦截 第二篇 - topguntopgun
If it's false, at least one of the <see cref="Permissions"/> must be granted. ... to require all given permissions are granted.
Read more >Creating and Managing Roles (C#)
This tutorial examines the steps necessary for configuring the Roles framework. Following that, we will build web pages to create and delete ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@maliming, Solved. Just wrapping GetGrantedPermissions on.
Solve my issue.
@maliming i already find the cause what i can’t get tenant only permission from a Host even, when all the queries are under _unitOfWork.Current.SetTenant(x), where x is not null. The root is on PermissionManager, GetAllPermission, where the AbpSession is always HOST, but the method is not virtual, There is any tip for When GetAllPermission get this line AbpSession.MultiTenancySide is Tenant?