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

Updating user permissions issue #632


User avatar
0
aranhico created

Hello, first of all, thank you so much for your great work on abp. I'm having some trouble while updating permissions on users, this is my code:

public async Task UpdateUserPermissions(UpdateUserPermissionsInput input)
        {
           CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant);

            User user = await UserManager.GetUserByIdAsync(input.id);
            await UserManager.ResetAllPermissionsAsync(user); // this line doesn't reset the permissions but if i used it "sepparatedlly" it works
            // 

            List<Permission> list = PermissionManager.GetAllPermissions().ToList();
          
            list = list.Where(x => input.Permissions.Contains(x.Name)).ToList();
            await UserManager.SetGrantedPermissionsAsync(user, list);
}

maybe my problem has something to do with the async/await, i believe I don't plenty understand it, maybe some of you can point me good litterature on the subject?

again, thank you !


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Why did you disabled AbpDataFilters.MayHaveTenant? I suppose no need for it.

    Also, you should not need to use ResetAllPermissionsAsync since SetGrantedPermissionsAsync removes other permissions automatically.

    Also, ResetAllPermissionsAsync does not clear permissions, just clears user specific permissions.

    Have a nice day.

  • User Avatar
    0
    aranhico created

    I disabled AbpDataFilters.MayHaveTenant because I'm trying to centralize things in just one tenant.

    SetGrantedPermissionsAsync its not prohibiting other permissions, i dont know why! That's why I tried to use ResetAllPermissionsAsync, to reset all user permissions

  • User Avatar
    0
    aranhico created

    I'm really sorry, the problem was getting the permissions for the user because i wasn't filtering by isgranted = true. thank very much for your help, and thank you for the excellent work

  • User Avatar
    0
    hikalkan created
    Support Team

    No problem, have a nice day :)