question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SetGrantedPermissionsAsync of RoleManager not set all permission to given role.

See original GitHub issue

Documentation

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:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
osalas891123commented, Apr 1, 2019

@maliming, Solved. Just wrapping GetGrantedPermissions on.

using(AbpSession.Set(tenantId, null)){
...
}

Solve my issue.

0reactions
osalas891123commented, Apr 1, 2019

@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?

.WhereIf(tenancyFilter, p => p.MultiTenancySides.HasFlag(**AbpSession.MultiTenancySide**))
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found