Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

PermissionChecker return alltime False value #4278


User avatar
0
olivierroecker created

In an ApplicationService, i would check if a user have a Permission.

But when i use the PermissionChecker.IsGranted function, it return the false value... in all case...

See my code :

public async Task DoRecurrentReportAsync()
        {
            using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
            {
                var query = _userManager.Users.Where(p => p.IsActive).ToList();
                foreach(var user in query)
                {
                    if (user.TenantId.HasValue)
                    {
                        var userIdentifier = new UserIdentifier(user.TenantId.Value, user.Id);
                        var checker = PermissionChecker.IsGranted(userIdentifier, true, new string[] { AppPermissions.Pages_Tenant_Contracts });
                        if (checker)
                        {
                            await SendContractsDashboard(user.TenantId.Value, user.Id);
                        }
                    }
                }
            }
        }

Thanks for your help


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

    Can you inject IAbpSession try:

    using (_abpSession.Use(user.TenantId, user.Id))
    {
        var checker = PermissionChecker.IsGranted(userIdentifier, true, new string[] { AppPermissions.Pages_Tenant_Contracts });
        if (checker)
        {
            await SendContractsDashboard(user.TenantId.Value, user.Id);
        }
    }
    

    Tip: Wrap your code in the following for formatting and readability:

    [code]
    

    [/code:1a4rnbf5] A shortcut is to highlight your code and click on the </> button in the formatting toolbar.

  • User Avatar
    0
    olivierroecker created

    Perfect... Thanks....