Base solution for your next web application
Open Closed

Issue with retrieving Permissions (tenant-specific permissions) from the database for a given tenant #9073


User avatar
0
csona created

What I'm trying to do

  • Each edition has a default tenant associated with it. This tenant can have some predefined users, roles, organizational units etc.
  • When a new tenant is created using this edition, it will copy the relevant items from the default tenant

Issue that I'm facing

  • In TenantManager.CreateWithAdminUserAsync, retrieve the role permissions using following statements
using (_unitOfWorkManager.Current.SetTenantId(defaultTenant.Id))
{
    var defaultTenantRolePermissions = await _roleManager.GetGrantedPermissionsAsync(defaultTenantRole);
}
  • While retrieving the permissions, following permissions are not returned from GetGrantedPermissionsAsync method Pages.Tenant.Dashboard Pages.Administration.Tenant.Settings

However, this method works fine for all other permissions. Is there anything missing or needs to be done differently?

Thanks in advance.


14 Answer(s)
  • User Avatar
    0
    musa.demir created

    Are you sure your role has that permissions?

  • User Avatar
    0
    csona created

    Yes, permissions in the source role are set correctly. But while retrieving those permissions using GetGrantedPermissionsAsync, only some of them are returned. Please find the database snapshots below

  • User Avatar
    0
    csona created

    This behavior is consistent for all the permissions that are tenant-specific (i.e. defined with multiTenancySides: MultiTenancySides.Tenant). All the permissions common to both host and tenant are retrieved correctly from GetGrantedPermissionsAsync.

  • User Avatar
    0
    csona created

    Following image shows the problem clearly

    • FullUser role (Role Id: 5) with defaulTenant (Tenant Id: 2) has 7 permissions in database.
    • While retrieving these permissions using RoleManager.GetGrantedPermissionsAsync, only 4 permissions are returned and the permission Pages.Tenant.Dashboard is not retrieved.

    Can anybody please explain what is wrong with this or what am I missing? Thanks in advance.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @csona,

    In order to understand your problem and offer a solution, is it possible for you to share your project and your database with [email protected] ?

    Thanks,

  • User Avatar
    0
    csona created

    Hi @ismcagdas,

    Thank you for the reply. I have sent an email with required details as you have requested to [email protected]

    • Archived copy of source code
    • Database backup file
    • Steps describing the user actions and problem
    • Other relevant images

    Please let me know if you need anything else from our side.

    Thanks again.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @csona,

    Thanks, we will get back to you via email.

  • User Avatar
    0
    csona created

    Hi @ismcagdas,

    Thank you for the update.

  • User Avatar
    0
    musa.demir created

    Hi @csona

    When I try it with your sql backup, what I saw was your role does not have permissions:

    Then I select related permissions and check again. It worked as expected.

  • User Avatar
    0
    csona created

    Hi @demirmusa,

    Thank you for your reply.

    Pleaes find below the database details from the database backup that we had sent attached in the email (GrowthPlanDB.bak).

    • "DefaultStarterTenant" tenant has a role named "Full User" which has the permissions set as can be seen in the image below.

    • "Full User" role for above mentioned tenant has following permissions as per the database entries
      • Pages.Administration.AuditLogs
      • Pages.Administration
      • Pages
      • Pages.Administration.Tenant.Settings
      • Pages.Administration
      • Pages
      • Pages.Administration.UiCustomization
      • Pages.Administration
      • Pages
      • Pages.Tenant.Dashboard
      • Pages
      • Pages.DxDataGrid
      • Pages

    Please let me know if we are misinterpreting or misunderstanding something.

    Thanks.

  • User Avatar
    0
    musa.demir created

    Thanks @csona

    I reproduced the problem. I will check it.

  • User Avatar
    0
    musa.demir created

    Hi @csona

    Since PermissionManager also use session information you should set session too. Can you please check if that work for you.

    using (CurrentUnitOfWork.SetTenantId(2))
    {
    +   using (AbpSession.Use(2, null))//add this
        {
            var defaultTenantRolePermissions = await _roleManager.GetGrantedPermissionsAsync(5);
            return defaultTenantRolePermissions.Select(permission => permission.Name).ToList();
        }
    }
    
  • User Avatar
    1
    csona created

    Hi @demirmusa ,

    We are verifying the solution that you have mentioned above and it seems to be working fine. We'll do some more testing and update accordingly.

    Thank you so much for your time and help.

  • User Avatar
    0
    musa.demir created

    You are always welcome 🙂