Browse Source

#5550 Add Create, Edit & Delete policy checks to the BlazoriseCrudPageBase

pull/5575/head
Halil İbrahim Kalkan 6 years ago
parent
commit
cc89419800
  1. 87
      framework/src/Volo.Abp.BlazoriseUI/Volo/Abp/BlazoriseUI/BlazoriseCrudPageBase.cs
  2. 133
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor
  3. 23
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs
  4. 300
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor
  5. 34
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs

87
framework/src/Volo.Abp.BlazoriseUI/Volo/Abp/BlazoriseUI/BlazoriseCrudPageBase.cs

@ -4,13 +4,16 @@ using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Blazorise.DataGrid;
using JetBrains.Annotations;
using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.Authorization;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.BlazoriseUI
@ -20,7 +23,6 @@ namespace Volo.Abp.BlazoriseUI
where TAppService : ICrudAppService<TEntityDto, TKey>
where TEntityDto : IEntityDto<TKey>, new()
{
}
public abstract class BlazoriseCrudPageBase<TAppService, TEntityDto, TKey, TGetListInput>
@ -29,7 +31,6 @@ namespace Volo.Abp.BlazoriseUI
where TEntityDto : IEntityDto<TKey>, new()
where TGetListInput : new()
{
}
public abstract class BlazoriseCrudPageBase<TAppService, TEntityDto, TKey, TGetListInput, TCreateInput>
@ -39,10 +40,10 @@ namespace Volo.Abp.BlazoriseUI
where TCreateInput : new()
where TGetListInput : new()
{
}
public abstract class BlazoriseCrudPageBase<TAppService, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
public abstract class BlazoriseCrudPageBase<TAppService, TEntityDto, TKey, TGetListInput, TCreateInput,
TUpdateInput>
: BlazoriseCrudPageBase<TAppService, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TAppService : ICrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntityDto : IEntityDto<TKey>
@ -50,12 +51,13 @@ namespace Volo.Abp.BlazoriseUI
where TUpdateInput : new()
where TGetListInput : new()
{
}
public abstract class BlazoriseCrudPageBase<TAppService, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
public abstract class BlazoriseCrudPageBase<TAppService, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput,
TCreateInput, TUpdateInput>
: OwningComponentBase
where TAppService : ICrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TAppService : ICrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput,
TUpdateInput>
where TGetOutputDto : IEntityDto<TKey>
where TGetListOutputDto : IEntityDto<TKey>
where TCreateInput : new()
@ -65,6 +67,7 @@ namespace Volo.Abp.BlazoriseUI
[Inject] protected TAppService AppService { get; set; }
[Inject] protected IUiMessageService UiMessageService { get; set; }
[Inject] protected IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
[Inject] protected IAuthorizationService AuthorizationService { get; set; }
protected virtual int PageSize { get; } = LimitedResultRequestDto.DefaultMaxResultCount;
@ -78,6 +81,14 @@ namespace Volo.Abp.BlazoriseUI
protected Modal CreateModal;
protected Modal EditModal;
protected string CreatePolicyName { get; set; }
protected string UpdatePolicyName { get; set; }
protected string DeletePolicyName { get; set; }
public bool HasCreatePermission { get; set; }
public bool HasUpdatePermission { get; set; }
public bool HasDeletePermission { get; set; }
protected Type ObjectMapperContext { get; set; }
protected IObjectMapper ObjectMapper
@ -124,9 +135,28 @@ namespace Volo.Abp.BlazoriseUI
protected override async Task OnInitializedAsync()
{
await SetPermissionsAsync();
await GetEntitiesAsync();
}
protected virtual async Task SetPermissionsAsync()
{
if (CreatePolicyName != null)
{
HasCreatePermission = await AuthorizationService.IsGrantedAsync(CreatePolicyName);
}
if (UpdatePolicyName != null)
{
HasUpdatePermission = await AuthorizationService.IsGrantedAsync(UpdatePolicyName);
}
if (DeletePolicyName != null)
{
HasDeletePermission = await AuthorizationService.IsGrantedAsync(DeletePolicyName);
}
}
protected virtual async Task GetEntitiesAsync()
{
var input = await CreateGetListInputAsync();
@ -170,11 +200,12 @@ namespace Volo.Abp.BlazoriseUI
StateHasChanged();
}
protected virtual Task OpenCreateModalAsync()
protected virtual async Task OpenCreateModalAsync()
{
await CheckCreatePolicyAsync();
NewEntity = new TCreateInput();
CreateModal.Show();
return Task.CompletedTask;
}
protected virtual Task CloseCreateModalAsync()
@ -185,6 +216,8 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task OpenEditModalAsync(TKey id)
{
await CheckUpdatePolicyAsync();
var entityDto = await AppService.GetAsync(id);
EditingEntityId = id;
EditingEntity = MapToEditingEntity(entityDto);
@ -204,6 +237,7 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task CreateEntityAsync()
{
await CheckCreatePolicyAsync();
await AppService.CreateAsync(NewEntity);
await GetEntitiesAsync();
CreateModal.Hide();
@ -211,6 +245,7 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task UpdateEntityAsync()
{
await CheckUpdatePolicyAsync();
await AppService.UpdateAsync(EditingEntityId, EditingEntity);
await GetEntitiesAsync();
EditModal.Hide();
@ -218,6 +253,8 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task DeleteEntityAsync(TGetListOutputDto entity)
{
await CheckDeletePolicyAsync();
if (!await UiMessageService.ConfirmAsync(GetDeleteConfirmationMessage(entity)))
{
return;
@ -231,5 +268,37 @@ namespace Volo.Abp.BlazoriseUI
{
return UiLocalizer["ItemWillBeDeletedMessage"];
}
protected virtual async Task CheckCreatePolicyAsync()
{
await CheckPolicyAsync(CreatePolicyName);
}
protected virtual async Task CheckUpdatePolicyAsync()
{
await CheckPolicyAsync(UpdatePolicyName);
}
protected virtual async Task CheckDeletePolicyAsync()
{
await CheckPolicyAsync(DeletePolicyName);
}
/// <summary>
/// Calls IAuthorizationService.CheckAsync for the given <see cref="policyName"/>.
/// Throws <see cref="AbpAuthorizationException"/> if given policy was not granted for the current user.
///
/// Does nothing if <see cref="policyName"/> is null or empty.
/// </summary>
/// <param name="policyName">A policy name to check</param>
protected virtual async Task CheckPolicyAsync([CanBeNull] string policyName)
{
if (string.IsNullOrEmpty(policyName))
{
return;
}
await AuthorizationService.CheckAsync(policyName);
}
}
}

133
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor

@ -7,7 +7,6 @@
@using Volo.Abp.PermissionManagement.Blazor.Components
@inherits RoleManagementBase
@inject IStringLocalizer<IdentityResource> L
@inject IAuthorizationService AuthorizationService
@* ************************* PAGE HEADER ************************* *@
<Row>
@ -15,7 +14,7 @@
<h1>@L["Roles"]</h1>
</Column>
<Column ColumnSize="ColumnSize.Is6">
@if (canCreate)
@if (HasCreatePermission)
{
<Paragraph Alignment="TextAlignment.Right">
<Button Color="Color.Primary" Clicked="OpenCreateModalAsync">@L["NewRole"]</Button>
@ -32,7 +31,7 @@
ShowPager="true"
PageSize="PageSize">
<DataGridColumns>
@if (canEdit || canDelete || canEditPermissions)
@if (ShouldShowEntityActions)
{
<DataGridColumn Width="150px" TItem="IdentityRoleDto" Field="@nameof(IdentityRoleDto.Name)" Sortable="false" Caption="@L["Actions"].Value">
<DisplayTemplate>
@ -41,23 +40,22 @@
@L["Actions"]
</DropdownToggle>
<DropdownMenu>
@if (canEdit)
@if (HasUpdatePermission)
{
<DropdownItem Clicked="() => OpenEditModalAsync(context.As<IdentityRoleDto>().Id)">@L["Edit"]</DropdownItem>
}
@if (canEditPermissions)
@if (HasManagePermissionsPermission)
{
<DropdownItem Clicked="() => PermissionManagementModal.OpenAsync(PermissionProviderName, context.As<IdentityRoleDto>().Name)">@L["Permissions"]</DropdownItem>
}
@if (canDelete)
@if (HasDeletePermission)
{
<DropdownDivider/>
<DropdownItem Clicked="() => DeleteEntityAsync(context.As<IdentityRoleDto>())">@L["Delete"]</DropdownItem>
}
</DropdownMenu>
</Dropdown>
</DisplayTemplate>
</DataGridColumn>
</DataGridColumn>
}
<DataGridColumn TItem="IdentityRoleDto" Field="@nameof(IdentityRoleDto.Name)" Caption="@L["RoleName"].Value">
<DisplayTemplate>
@ -76,72 +74,59 @@
</DataGrid>
@* ************************* CREATE MODAL ************************* *@
<Modal @ref="CreateModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>@L["NewRole"]</ModalTitle>
<CloseButton Clicked="CloseCreateModalAsync" />
</ModalHeader>
<ModalBody>
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Name" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
</Field>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
@if (HasCreatePermission)
{
<Modal @ref="CreateModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>@L["NewRole"]</ModalTitle>
<CloseButton Clicked="CloseCreateModalAsync" />
</ModalHeader>
<ModalBody>
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Name" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
</Field>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
}
@* ************************* EDIT MODAL ************************* *@
<Modal @ref="EditModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>Edit role</ModalTitle>
<CloseButton Clicked="CloseEditModalAsync" />
</ModalHeader>
<ModalBody>
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp" />
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Name" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="@EditingEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="@EditingEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
</Field>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
<PermissionManagementModal @ref="PermissionManagementModal"/>
@code
@if (HasUpdatePermission)
{
bool canCreate;
bool canEdit;
bool canDelete;
bool canEditPermissions;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
<Modal @ref="EditModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>Edit role</ModalTitle>
<CloseButton Clicked="CloseEditModalAsync" />
</ModalHeader>
<ModalBody>
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp" />
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Name" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="@EditingEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="@EditingEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
</Field>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
}
canCreate =await AuthorizationService.IsGrantedAsync(IdentityPermissions.Roles.Create);
canEdit = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Roles.Update);
canDelete = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Roles.Delete);
canEditPermissions = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Roles.ManagePermissions);
}
}
<PermissionManagementModal @ref="PermissionManagementModal"/>

23
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs

@ -1,4 +1,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.BlazoriseUI;
using Volo.Abp.PermissionManagement.Blazor.Components;
@ -11,9 +13,30 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected PermissionManagementModal PermissionManagementModal;
protected bool HasManagePermissionsPermission { get; set; }
protected bool ShouldShowEntityActions { get; set; }
public RoleManagementBase()
{
ObjectMapperContext = typeof(AbpIdentityBlazorModule);
CreatePolicyName = IdentityPermissions.Roles.Create;
UpdatePolicyName = IdentityPermissions.Roles.Update;
DeletePolicyName = IdentityPermissions.Roles.Delete;
}
protected override async Task SetPermissionsAsync()
{
await base.SetPermissionsAsync();
HasManagePermissionsPermission = await AuthorizationService.IsGrantedAsync(
IdentityPermissions.Roles.ManagePermissions
);
ShouldShowEntityActions = HasUpdatePermission ||
HasDeletePermission ||
HasManagePermissionsPermission;
}
}
}

300
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor

@ -2,12 +2,10 @@
@attribute [Authorize(IdentityPermissions.Users.Default)]
@using Microsoft.AspNetCore.Authorization
@using Microsoft.Extensions.Localization
@using Volo.Abp.Application.Dtos
@using Volo.Abp.Identity.Localization
@using Volo.Abp.PermissionManagement.Blazor.Components
@inherits UserManagementBase
@inject IStringLocalizer<IdentityResource> L
@inject IAuthorizationService AuthorizationService
@* ************************* PAGE HEADER ************************* *@
<Row>
@ -15,7 +13,7 @@
<h1>@L["Users"]</h1>
</Column>
<Column ColumnSize="ColumnSize.Is6">
@if (canCreate)
@if (HasCreatePermission)
{
<Paragraph Alignment="TextAlignment.Right">
<Button Color="Color.Primary" Clicked="OpenCreateModalAsync">@L["NewUser"]</Button>
@ -32,7 +30,7 @@
ShowPager="true"
PageSize="PageSize">
<DataGridColumns>
@if (canEdit || canDelete || canEditPermissions)
@if (ShouldShowEntityActions)
{
<DataGridColumn Width="150px" TItem="IdentityUserDto" Field="@nameof(IdentityUserDto.UserName)" Sortable="false" Caption="@L["Actions"].Value">
<DisplayTemplate>
@ -41,15 +39,15 @@
@L["Actions"]
</DropdownToggle>
<DropdownMenu>
@if (canEdit)
@if (HasUpdatePermission)
{
<DropdownItem Clicked="() => OpenEditModalAsync(context.As<IdentityUserDto>().Id)">@L["Edit"]</DropdownItem>
}
@if (canEditPermissions)
@if (HasManagePermissionsPermission)
{
<DropdownItem Clicked="() => PermissionManagementModal.OpenAsync(PermissionProviderName,context.As<IdentityUserDto>().Id.ToString())">@L["Permissions"]</DropdownItem>
<DropdownItem Clicked="() => PermissionManagementModal.OpenAsync(PermissionProviderName, context.As<IdentityUserDto>().Id.ToString())">@L["Permissions"]</DropdownItem>
}
@if (canDelete)
@if (HasDeletePermission)
{
<DropdownDivider/>
<DropdownItem Clicked="() => DeleteEntityAsync(context.As<IdentityUserDto>())">@L["Delete"]</DropdownItem>
@ -78,161 +76,149 @@
</DataGrid>
@* ************************* CREATE MODAL ************************* *@
<Modal @ref="CreateModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>@L["NewUser"]</ModalTitle>
<CloseButton Clicked="CloseCreateModalAsync" />
</ModalHeader>
<ModalBody>
<Tabs @bind-SelectedTab="@_createModalSelectedTab">
<Items>
<Tab Name="UserInformations">@L["UserInformations"]</Tab>
<Tab Name="Roles">@L["Roles"]</Tab>
</Items>
<Content>
<TabPanel Name="UserInformations">
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-text="NewEntity.UserName" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Name" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Surname" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-text="NewEntity.Password" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Email" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-text="NewEntity.PhoneNumber" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.TwoFactorEnabled">@L["DisplayName:TwoFactorEnabled"]</Check>
</Field>
</TabPanel>
<TabPanel Name="Roles">
@if (NewUserRoles != null)
{
@foreach (var role in NewUserRoles)
@if (HasCreatePermission)
{
<Modal @ref="CreateModal">
<ModalBackdrop/>
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>@L["NewUser"]</ModalTitle>
<CloseButton Clicked="CloseCreateModalAsync"/>
</ModalHeader>
<ModalBody>
<Tabs @bind-SelectedTab="@_createModalSelectedTab">
<Items>
<Tab Name="UserInformations">@L["UserInformations"]</Tab>
<Tab Name="Roles">@L["Roles"]</Tab>
</Items>
<Content>
<TabPanel Name="UserInformations">
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-text="NewEntity.UserName"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Name"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Surname"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-text="NewEntity.Password"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Email"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-text="NewEntity.PhoneNumber"/>
</Field>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.TwoFactorEnabled">@L["DisplayName:TwoFactorEnabled"]</Check>
</Field>
</TabPanel>
<TabPanel Name="Roles">
@if (NewUserRoles != null)
{
<Field>
<input type="hidden" @bind-value="@role.Name" />
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check>
</Field>
@foreach (var role in NewUserRoles)
{
<Field>
<input type="hidden" @bind-value="@role.Name"/>
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check>
</Field>
}
}
}
</TabPanel>
</Content>
</Tabs>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
</TabPanel>
</Content>
</Tabs>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
}
@* ************************* EDIT MODAL ************************* *@
<Modal @ref="EditModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>role</ModalTitle>
<CloseButton Clicked="CloseEditModalAsync" />
</ModalHeader>
<ModalBody>
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp" />
@if (HasUpdatePermission)
{
<Modal @ref="EditModal">
<ModalBackdrop/>
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>role</ModalTitle>
<CloseButton Clicked="CloseEditModalAsync"/>
</ModalHeader>
<ModalBody>
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp"/>
<Tabs @bind-SelectedTab="@_editModalSelectedTab">
<Items>
<Tab Name="UserInformations">@L["UserInformations"]</Tab>
<Tab Name="Roles">@L["Roles"]</Tab>
</Items>
<Content>
<TabPanel Name="UserInformations">
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.UserName" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Name" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Surname" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-text="EditingEntity.Password" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Email" />
</Field>
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.PhoneNumber" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="EditingEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field>
<Field>
<Check TValue="bool" @bind-checked="EditingEntity.TwoFactorEnabled">@L["DisplayName:TwoFactorEnabled"]</Check>
</Field>
</TabPanel>
<TabPanel Name="Roles">
@if (EditUserRoles != null)
{
@foreach (var role in EditUserRoles)
<Tabs @bind-SelectedTab="@_editModalSelectedTab">
<Items>
<Tab Name="UserInformations">@L["UserInformations"]</Tab>
<Tab Name="Roles">@L["Roles"]</Tab>
</Items>
<Content>
<TabPanel Name="UserInformations">
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.UserName"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Name"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Surname"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-text="EditingEntity.Password"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Email"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.PhoneNumber"/>
</Field>
<Field>
<Check TValue="bool" @bind-checked="EditingEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field>
<Field>
<Check TValue="bool" @bind-checked="EditingEntity.TwoFactorEnabled">@L["DisplayName:TwoFactorEnabled"]</Check>
</Field>
</TabPanel>
<TabPanel Name="Roles">
@if (EditUserRoles != null)
{
<Field>
<input type="hidden" @bind-value="@role.Name" />
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check>
</Field>
@foreach (var role in EditUserRoles)
{
<Field>
<input type="hidden" @bind-value="@role.Name"/>
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check>
</Field>
}
}
}
</TabPanel>
</Content>
</Tabs>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
</TabPanel>
</Content>
</Tabs>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
}
<PermissionManagementModal @ref="PermissionManagementModal"/>
@code
{
bool canCreate;
bool canEdit;
bool canDelete;
bool canEditPermissions;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
canCreate =await AuthorizationService.IsGrantedAsync(IdentityPermissions.Users.Create);
canEdit = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Users.Update);
canDelete = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Users.Delete);
canEditPermissions = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Users.ManagePermissions);
}
}

34
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.BlazoriseUI;
using Volo.Abp.PermissionManagement.Blazor.Components;
using Volo.Abp.Threading;
namespace Volo.Abp.Identity.Blazor.Pages.Identity
{
@ -13,7 +13,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected const string PermissionProviderName = "U";
protected const string DefaultSelectedTab = "UserInformations";
protected PermissionManagementModal PermissionManagementModal;
protected IReadOnlyList<IdentityRoleDto> Roles;
@ -21,14 +21,21 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected AssignedRoleViewModel[] NewUserRoles;
protected AssignedRoleViewModel[] EditUserRoles;
protected bool ShouldShowEntityActions { get; set; }
protected bool HasManagePermissionsPermission { get; set; }
protected string _createModalSelectedTab = DefaultSelectedTab;
protected string _editModalSelectedTab = DefaultSelectedTab;
public UserManagementBase()
{
ObjectMapperContext = typeof(AbpIdentityBlazorModule);
CreatePolicyName = IdentityPermissions.Users.Create;
UpdatePolicyName = IdentityPermissions.Users.Update;
DeletePolicyName = IdentityPermissions.Users.Delete;
}
protected override async Task OnInitializedAsync()
@ -38,10 +45,23 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
Roles = (await AppService.GetAssignableRolesAsync()).Items;
}
protected override async Task SetPermissionsAsync()
{
await base.SetPermissionsAsync();
HasManagePermissionsPermission = await AuthorizationService.IsGrantedAsync(
IdentityPermissions.Users.ManagePermissions
);
ShouldShowEntityActions = HasUpdatePermission ||
HasDeletePermission ||
HasManagePermissionsPermission;
}
protected override Task OpenCreateModalAsync()
{
_createModalSelectedTab = DefaultSelectedTab;
NewUserRoles = Roles.Select(x => new AssignedRoleViewModel
{
Name = x.Name,
@ -61,7 +81,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected override async Task OpenEditModalAsync(Guid id)
{
_editModalSelectedTab = DefaultSelectedTab;
var userRoleNames = (await AppService.GetRolesAsync(id)).Items.Select(r => r.Name).ToList();
EditUserRoles = Roles.Select(x => new AssignedRoleViewModel

Loading…
Cancel
Save