Remove explicit fail call in admin authorization
This commit is contained in:
parent
ae723cecaf
commit
1906d0de0d
1 changed files with 3 additions and 16 deletions
|
@ -2,6 +2,7 @@ using DrinkRateAPI.DbEntities;
|
|||
using DrinkRateAPI.Services;
|
||||
|
||||
namespace DrinkRateAPI.AuthorizationPolicies;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
public class AdminOnlyRequirement : IAuthorizationRequirement
|
||||
|
@ -22,28 +23,14 @@ public class AdminOnlyHandler : AuthorizationHandler<AdminOnlyRequirement>
|
|||
}
|
||||
|
||||
protected override async Task HandleRequirementAsync(
|
||||
AuthorizationHandlerContext context,
|
||||
AuthorizationHandlerContext context,
|
||||
AdminOnlyRequirement requirement)
|
||||
{
|
||||
DbUserProfile userProfile;
|
||||
|
||||
try
|
||||
{
|
||||
userProfile = await _applicationUserService.UserProfileByApplicationUserAsync(context.User);
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
context.Fail();
|
||||
return;
|
||||
}
|
||||
var userProfile = await _applicationUserService.UserProfileByApplicationUserAsync(context.User);
|
||||
|
||||
if (_userProfileService.IsUserProfileAdmin(userProfile))
|
||||
{
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Fail();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue