Refactoring if condition to ensure CanCreateUser permission

Fixing UsersControllerTests
This commit is contained in:
rockstardev 2020-03-18 18:40:21 -05:00
parent 47c1164003
commit 0a8abaf7d5

View file

@ -90,10 +90,10 @@ namespace BTCPayServer.Controllers.RestApi.Users
return Forbid(AuthenticationSchemes.ApiKey);
}
if (!isAdmin && policies.LockSubscription)
// check if we have permission to create users
var canCreateUser = (await _authorizationService.AuthorizeAsync(User, null, new PolicyRequirement(Policies.CanCreateUser.Key))).Succeeded;
if (!canCreateUser)
{
// If we are not admin and subscriptions are locked, we need to check the Policies.CanCreateUser.Key permission
if (!isAuth || !(await _authorizationService.AuthorizeAsync(User, null, new PolicyRequirement(Policies.CanCreateUser.Key))).Succeeded)
return Forbid(AuthenticationSchemes.ApiKey);
}