Add extension to ClaimsPrincipal
This commit is contained in:
@ -76,7 +76,7 @@
|
|||||||
ChangeState(PageState.Loading);
|
ChangeState(PageState.Loading);
|
||||||
|
|
||||||
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
if (state.User.IsInRole(AppRole.ADMINISTRATOR_TYPE) || state.User.IsInRole(AppRole.OPERATOR_TYPE))
|
if (state.User.IsOperatorOrHigher())
|
||||||
{
|
{
|
||||||
campaigns = await HeadquartersService.GetCampaignsAsync();
|
campaigns = await HeadquartersService.GetCampaignsAsync();
|
||||||
|
|
||||||
|
|||||||
@ -72,7 +72,7 @@
|
|||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
|
|
||||||
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
if (state.User.IsInRole(AppRole.ADMINISTRATOR_TYPE))
|
if (state.User.IsAdministrator())
|
||||||
{
|
{
|
||||||
currentUserId = state.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
currentUserId = state.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
||||||
usersWithRoles = await UsersService.GetUsersWithRoleAsync();
|
usersWithRoles = await UsersService.GetUsersWithRoleAsync();
|
||||||
|
|||||||
@ -57,7 +57,7 @@
|
|||||||
ChangeState(PageState.Loading);
|
ChangeState(PageState.Loading);
|
||||||
|
|
||||||
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
if (state.User.IsInRole(AppRole.ADMINISTRATOR_TYPE) || state.User.IsInRole(AppRole.OPERATOR_TYPE))
|
if (state.User.IsOperatorOrHigher())
|
||||||
{
|
{
|
||||||
operations = await HeadquartersService.GetOperationsAsync();
|
operations = await HeadquartersService.GetOperationsAsync();
|
||||||
|
|
||||||
|
|||||||
@ -80,7 +80,7 @@
|
|||||||
|
|
||||||
var finalState = SyncedPageState.Idle;
|
var finalState = SyncedPageState.Idle;
|
||||||
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
if (state.User.IsInRole(AppRole.ADMINISTRATOR_TYPE) || state.User.IsInRole(AppRole.OPERATOR_TYPE))
|
if (state.User.IsOperatorOrHigher())
|
||||||
{
|
{
|
||||||
var operationInProgress = await HeadquartersService.HasActiveCampaignAsync(Campaign.CampaignType.ExportCommonRegistryElements_15_7_0_1);
|
var operationInProgress = await HeadquartersService.HasActiveCampaignAsync(Campaign.CampaignType.ExportCommonRegistryElements_15_7_0_1);
|
||||||
if (operationInProgress)
|
if (operationInProgress)
|
||||||
|
|||||||
@ -80,7 +80,7 @@
|
|||||||
|
|
||||||
var finalState = SyncedPageState.Idle;
|
var finalState = SyncedPageState.Idle;
|
||||||
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
if (state.User.IsInRole(AppRole.ADMINISTRATOR_TYPE) || state.User.IsInRole(AppRole.OPERATOR_TYPE))
|
if (state.User.IsOperatorOrHigher())
|
||||||
{
|
{
|
||||||
var operationInProgress = await HeadquartersService.HasActiveCampaignAsync(Campaign.CampaignType.ExportPrivateRegistryElements_15_7_0_1);
|
var operationInProgress = await HeadquartersService.HasActiveCampaignAsync(Campaign.CampaignType.ExportPrivateRegistryElements_15_7_0_1);
|
||||||
if (operationInProgress)
|
if (operationInProgress)
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
@using Hcs.WebApp.Components.Shared
|
@using Hcs.WebApp.Components.Shared
|
||||||
@using Hcs.WebApp.Data.Hcs
|
@using Hcs.WebApp.Data.Hcs
|
||||||
@using Hcs.WebApp.Data.Identity
|
@using Hcs.WebApp.Data.Identity
|
||||||
|
@using Hcs.WebApp.Utils
|
||||||
@using Microsoft.AspNetCore.Components.Authorization
|
@using Microsoft.AspNetCore.Components.Authorization
|
||||||
@using Microsoft.AspNetCore.Components.Forms
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
|
|||||||
18
Hcs.WebApp/Utils/ClaimsPrincipalExtensions.cs
Normal file
18
Hcs.WebApp/Utils/ClaimsPrincipalExtensions.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using Hcs.WebApp.Data.Identity;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
namespace Hcs.WebApp.Utils
|
||||||
|
{
|
||||||
|
public static class ClaimsPrincipalExtensions
|
||||||
|
{
|
||||||
|
public static bool IsAdministrator(this ClaimsPrincipal claimsPrincipal)
|
||||||
|
{
|
||||||
|
return claimsPrincipal.IsInRole(AppRole.ADMINISTRATOR_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsOperatorOrHigher(this ClaimsPrincipal claimsPrincipal)
|
||||||
|
{
|
||||||
|
return claimsPrincipal.IsInRole(AppRole.OPERATOR_TYPE) || claimsPrincipal.IsInRole(AppRole.ADMINISTRATOR_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user