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 System.Threading.Tasks;
using Blazorise; using Blazorise;
using Blazorise.DataGrid; using Blazorise.DataGrid;
using JetBrains.Annotations;
using Localization.Resources.AbpUi; using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Components.WebAssembly; using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.Authorization;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
namespace Volo.Abp.BlazoriseUI namespace Volo.Abp.BlazoriseUI
@ -20,7 +23,6 @@ namespace Volo.Abp.BlazoriseUI
where TAppService : ICrudAppService<TEntityDto, TKey> where TAppService : ICrudAppService<TEntityDto, TKey>
where TEntityDto : IEntityDto<TKey>, new() where TEntityDto : IEntityDto<TKey>, new()
{ {
} }
public abstract class BlazoriseCrudPageBase<TAppService, TEntityDto, TKey, TGetListInput> public abstract class BlazoriseCrudPageBase<TAppService, TEntityDto, TKey, TGetListInput>
@ -29,7 +31,6 @@ namespace Volo.Abp.BlazoriseUI
where TEntityDto : IEntityDto<TKey>, new() where TEntityDto : IEntityDto<TKey>, new()
where TGetListInput : new() where TGetListInput : new()
{ {
} }
public abstract class BlazoriseCrudPageBase<TAppService, TEntityDto, TKey, TGetListInput, TCreateInput> public abstract class BlazoriseCrudPageBase<TAppService, TEntityDto, TKey, TGetListInput, TCreateInput>
@ -39,10 +40,10 @@ namespace Volo.Abp.BlazoriseUI
where TCreateInput : new() where TCreateInput : new()
where TGetListInput : 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> : BlazoriseCrudPageBase<TAppService, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TAppService : ICrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput> where TAppService : ICrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntityDto : IEntityDto<TKey> where TEntityDto : IEntityDto<TKey>
@ -50,12 +51,13 @@ namespace Volo.Abp.BlazoriseUI
where TUpdateInput : new() where TUpdateInput : new()
where TGetListInput : 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 : OwningComponentBase
where TAppService : ICrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput> where TAppService : ICrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput,
TUpdateInput>
where TGetOutputDto : IEntityDto<TKey> where TGetOutputDto : IEntityDto<TKey>
where TGetListOutputDto : IEntityDto<TKey> where TGetListOutputDto : IEntityDto<TKey>
where TCreateInput : new() where TCreateInput : new()
@ -65,6 +67,7 @@ namespace Volo.Abp.BlazoriseUI
[Inject] protected TAppService AppService { get; set; } [Inject] protected TAppService AppService { get; set; }
[Inject] protected IUiMessageService UiMessageService { get; set; } [Inject] protected IUiMessageService UiMessageService { get; set; }
[Inject] protected IStringLocalizer<AbpUiResource> UiLocalizer { get; set; } [Inject] protected IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
[Inject] protected IAuthorizationService AuthorizationService { get; set; }
protected virtual int PageSize { get; } = LimitedResultRequestDto.DefaultMaxResultCount; protected virtual int PageSize { get; } = LimitedResultRequestDto.DefaultMaxResultCount;
@ -78,6 +81,14 @@ namespace Volo.Abp.BlazoriseUI
protected Modal CreateModal; protected Modal CreateModal;
protected Modal EditModal; 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 Type ObjectMapperContext { get; set; }
protected IObjectMapper ObjectMapper protected IObjectMapper ObjectMapper
@ -124,9 +135,28 @@ namespace Volo.Abp.BlazoriseUI
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await SetPermissionsAsync();
await GetEntitiesAsync(); 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() protected virtual async Task GetEntitiesAsync()
{ {
var input = await CreateGetListInputAsync(); var input = await CreateGetListInputAsync();
@ -170,11 +200,12 @@ namespace Volo.Abp.BlazoriseUI
StateHasChanged(); StateHasChanged();
} }
protected virtual Task OpenCreateModalAsync() protected virtual async Task OpenCreateModalAsync()
{ {
await CheckCreatePolicyAsync();
NewEntity = new TCreateInput(); NewEntity = new TCreateInput();
CreateModal.Show(); CreateModal.Show();
return Task.CompletedTask;
} }
protected virtual Task CloseCreateModalAsync() protected virtual Task CloseCreateModalAsync()
@ -185,6 +216,8 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task OpenEditModalAsync(TKey id) protected virtual async Task OpenEditModalAsync(TKey id)
{ {
await CheckUpdatePolicyAsync();
var entityDto = await AppService.GetAsync(id); var entityDto = await AppService.GetAsync(id);
EditingEntityId = id; EditingEntityId = id;
EditingEntity = MapToEditingEntity(entityDto); EditingEntity = MapToEditingEntity(entityDto);
@ -204,6 +237,7 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task CreateEntityAsync() protected virtual async Task CreateEntityAsync()
{ {
await CheckCreatePolicyAsync();
await AppService.CreateAsync(NewEntity); await AppService.CreateAsync(NewEntity);
await GetEntitiesAsync(); await GetEntitiesAsync();
CreateModal.Hide(); CreateModal.Hide();
@ -211,6 +245,7 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task UpdateEntityAsync() protected virtual async Task UpdateEntityAsync()
{ {
await CheckUpdatePolicyAsync();
await AppService.UpdateAsync(EditingEntityId, EditingEntity); await AppService.UpdateAsync(EditingEntityId, EditingEntity);
await GetEntitiesAsync(); await GetEntitiesAsync();
EditModal.Hide(); EditModal.Hide();
@ -218,6 +253,8 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task DeleteEntityAsync(TGetListOutputDto entity) protected virtual async Task DeleteEntityAsync(TGetListOutputDto entity)
{ {
await CheckDeletePolicyAsync();
if (!await UiMessageService.ConfirmAsync(GetDeleteConfirmationMessage(entity))) if (!await UiMessageService.ConfirmAsync(GetDeleteConfirmationMessage(entity)))
{ {
return; return;
@ -231,5 +268,37 @@ namespace Volo.Abp.BlazoriseUI
{ {
return UiLocalizer["ItemWillBeDeletedMessage"]; 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 @using Volo.Abp.PermissionManagement.Blazor.Components
@inherits RoleManagementBase @inherits RoleManagementBase
@inject IStringLocalizer<IdentityResource> L @inject IStringLocalizer<IdentityResource> L
@inject IAuthorizationService AuthorizationService
@* ************************* PAGE HEADER ************************* *@ @* ************************* PAGE HEADER ************************* *@
<Row> <Row>
@ -15,7 +14,7 @@
<h1>@L["Roles"]</h1> <h1>@L["Roles"]</h1>
</Column> </Column>
<Column ColumnSize="ColumnSize.Is6"> <Column ColumnSize="ColumnSize.Is6">
@if (canCreate) @if (HasCreatePermission)
{ {
<Paragraph Alignment="TextAlignment.Right"> <Paragraph Alignment="TextAlignment.Right">
<Button Color="Color.Primary" Clicked="OpenCreateModalAsync">@L["NewRole"]</Button> <Button Color="Color.Primary" Clicked="OpenCreateModalAsync">@L["NewRole"]</Button>
@ -32,7 +31,7 @@
ShowPager="true" ShowPager="true"
PageSize="PageSize"> PageSize="PageSize">
<DataGridColumns> <DataGridColumns>
@if (canEdit || canDelete || canEditPermissions) @if (ShouldShowEntityActions)
{ {
<DataGridColumn Width="150px" TItem="IdentityRoleDto" Field="@nameof(IdentityRoleDto.Name)" Sortable="false" Caption="@L["Actions"].Value"> <DataGridColumn Width="150px" TItem="IdentityRoleDto" Field="@nameof(IdentityRoleDto.Name)" Sortable="false" Caption="@L["Actions"].Value">
<DisplayTemplate> <DisplayTemplate>
@ -41,23 +40,22 @@
@L["Actions"] @L["Actions"]
</DropdownToggle> </DropdownToggle>
<DropdownMenu> <DropdownMenu>
@if (canEdit) @if (HasUpdatePermission)
{ {
<DropdownItem Clicked="() => OpenEditModalAsync(context.As<IdentityRoleDto>().Id)">@L["Edit"]</DropdownItem> <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> <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> <DropdownItem Clicked="() => DeleteEntityAsync(context.As<IdentityRoleDto>())">@L["Delete"]</DropdownItem>
} }
</DropdownMenu> </DropdownMenu>
</Dropdown> </Dropdown>
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
} }
<DataGridColumn TItem="IdentityRoleDto" Field="@nameof(IdentityRoleDto.Name)" Caption="@L["RoleName"].Value"> <DataGridColumn TItem="IdentityRoleDto" Field="@nameof(IdentityRoleDto.Name)" Caption="@L["RoleName"].Value">
<DisplayTemplate> <DisplayTemplate>
@ -76,72 +74,59 @@
</DataGrid> </DataGrid>
@* ************************* CREATE MODAL ************************* *@ @* ************************* CREATE MODAL ************************* *@
<Modal @ref="CreateModal"> @if (HasCreatePermission)
<ModalBackdrop /> {
<ModalContent IsCentered="true"> <Modal @ref="CreateModal">
<ModalHeader> <ModalBackdrop />
<ModalTitle>@L["NewRole"]</ModalTitle> <ModalContent IsCentered="true">
<CloseButton Clicked="CloseCreateModalAsync" /> <ModalHeader>
</ModalHeader> <ModalTitle>@L["NewRole"]</ModalTitle>
<ModalBody> <CloseButton Clicked="CloseCreateModalAsync" />
<Field> </ModalHeader>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel> <ModalBody>
<TextEdit @bind-text="NewEntity.Name" /> <Field>
</Field> <FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<Field> <TextEdit @bind-text="NewEntity.Name" />
<Check TValue="bool" @bind-checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check> </Field>
<Check TValue="bool" @bind-checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check> <Field>
</Field> <Check TValue="bool" @bind-checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
</ModalBody> <Check TValue="bool" @bind-checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
<ModalFooter> </Field>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button> </ModalBody>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button> <ModalFooter>
</ModalFooter> <Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
</ModalContent> <Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
</Modal> </ModalFooter>
</ModalContent>
</Modal>
}
@* ************************* EDIT MODAL ************************* *@ @* ************************* EDIT MODAL ************************* *@
<Modal @ref="EditModal"> @if (HasUpdatePermission)
<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
{ {
bool canCreate; <Modal @ref="EditModal">
bool canEdit; <ModalBackdrop />
bool canDelete; <ModalContent IsCentered="true">
bool canEditPermissions; <ModalHeader>
<ModalTitle>Edit role</ModalTitle>
protected override async Task OnInitializedAsync() <CloseButton Clicked="CloseEditModalAsync" />
{ </ModalHeader>
await base.OnInitializedAsync(); <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); <PermissionManagementModal @ref="PermissionManagementModal"/>
canEdit = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Roles.Update);
canDelete = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Roles.Delete);
canEditPermissions = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Roles.ManagePermissions);
}
}

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

@ -1,4 +1,6 @@
using System; using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.BlazoriseUI; using Volo.Abp.BlazoriseUI;
using Volo.Abp.PermissionManagement.Blazor.Components; using Volo.Abp.PermissionManagement.Blazor.Components;
@ -11,9 +13,30 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected PermissionManagementModal PermissionManagementModal; protected PermissionManagementModal PermissionManagementModal;
protected bool HasManagePermissionsPermission { get; set; }
protected bool ShouldShowEntityActions { get; set; }
public RoleManagementBase() public RoleManagementBase()
{ {
ObjectMapperContext = typeof(AbpIdentityBlazorModule); 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)] @attribute [Authorize(IdentityPermissions.Users.Default)]
@using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Authorization
@using Microsoft.Extensions.Localization @using Microsoft.Extensions.Localization
@using Volo.Abp.Application.Dtos
@using Volo.Abp.Identity.Localization @using Volo.Abp.Identity.Localization
@using Volo.Abp.PermissionManagement.Blazor.Components @using Volo.Abp.PermissionManagement.Blazor.Components
@inherits UserManagementBase @inherits UserManagementBase
@inject IStringLocalizer<IdentityResource> L @inject IStringLocalizer<IdentityResource> L
@inject IAuthorizationService AuthorizationService
@* ************************* PAGE HEADER ************************* *@ @* ************************* PAGE HEADER ************************* *@
<Row> <Row>
@ -15,7 +13,7 @@
<h1>@L["Users"]</h1> <h1>@L["Users"]</h1>
</Column> </Column>
<Column ColumnSize="ColumnSize.Is6"> <Column ColumnSize="ColumnSize.Is6">
@if (canCreate) @if (HasCreatePermission)
{ {
<Paragraph Alignment="TextAlignment.Right"> <Paragraph Alignment="TextAlignment.Right">
<Button Color="Color.Primary" Clicked="OpenCreateModalAsync">@L["NewUser"]</Button> <Button Color="Color.Primary" Clicked="OpenCreateModalAsync">@L["NewUser"]</Button>
@ -32,7 +30,7 @@
ShowPager="true" ShowPager="true"
PageSize="PageSize"> PageSize="PageSize">
<DataGridColumns> <DataGridColumns>
@if (canEdit || canDelete || canEditPermissions) @if (ShouldShowEntityActions)
{ {
<DataGridColumn Width="150px" TItem="IdentityUserDto" Field="@nameof(IdentityUserDto.UserName)" Sortable="false" Caption="@L["Actions"].Value"> <DataGridColumn Width="150px" TItem="IdentityUserDto" Field="@nameof(IdentityUserDto.UserName)" Sortable="false" Caption="@L["Actions"].Value">
<DisplayTemplate> <DisplayTemplate>
@ -41,15 +39,15 @@
@L["Actions"] @L["Actions"]
</DropdownToggle> </DropdownToggle>
<DropdownMenu> <DropdownMenu>
@if (canEdit) @if (HasUpdatePermission)
{ {
<DropdownItem Clicked="() => OpenEditModalAsync(context.As<IdentityUserDto>().Id)">@L["Edit"]</DropdownItem> <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/> <DropdownDivider/>
<DropdownItem Clicked="() => DeleteEntityAsync(context.As<IdentityUserDto>())">@L["Delete"]</DropdownItem> <DropdownItem Clicked="() => DeleteEntityAsync(context.As<IdentityUserDto>())">@L["Delete"]</DropdownItem>
@ -78,161 +76,149 @@
</DataGrid> </DataGrid>
@* ************************* CREATE MODAL ************************* *@ @* ************************* CREATE MODAL ************************* *@
<Modal @ref="CreateModal"> @if (HasCreatePermission)
<ModalBackdrop /> {
<ModalContent IsCentered="true"> <Modal @ref="CreateModal">
<ModalHeader> <ModalBackdrop/>
<ModalTitle>@L["NewUser"]</ModalTitle> <ModalContent IsCentered="true">
<CloseButton Clicked="CloseCreateModalAsync" /> <ModalHeader>
</ModalHeader> <ModalTitle>@L["NewUser"]</ModalTitle>
<ModalBody> <CloseButton Clicked="CloseCreateModalAsync"/>
<Tabs @bind-SelectedTab="@_createModalSelectedTab"> </ModalHeader>
<Items> <ModalBody>
<Tab Name="UserInformations">@L["UserInformations"]</Tab> <Tabs @bind-SelectedTab="@_createModalSelectedTab">
<Tab Name="Roles">@L["Roles"]</Tab> <Items>
</Items> <Tab Name="UserInformations">@L["UserInformations"]</Tab>
<Content> <Tab Name="Roles">@L["Roles"]</Tab>
<TabPanel Name="UserInformations"> </Items>
<Field> <Content>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel> <TabPanel Name="UserInformations">
<TextEdit @bind-text="NewEntity.UserName" /> <Field>
</Field> <FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<Field> <TextEdit @bind-text="NewEntity.UserName"/>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel> </Field>
<TextEdit @bind-text="NewEntity.Name" /> <Field>
</Field> <FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<Field> <TextEdit @bind-text="NewEntity.Name"/>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel> </Field>
<TextEdit @bind-text="NewEntity.Surname" /> <Field>
</Field> <FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<Field> <TextEdit @bind-text="NewEntity.Surname"/>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel> </Field>
<TextEdit Role="TextRole.Password" @bind-text="NewEntity.Password" /> <Field>
</Field> <FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<Field> <TextEdit Role="TextRole.Password" @bind-text="NewEntity.Password"/>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel> </Field>
<TextEdit @bind-text="NewEntity.Email" /> <Field>
</Field> <FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<Field> <TextEdit @bind-text="NewEntity.Email"/>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel> </Field>
<TextEdit @bind-text="NewEntity.PhoneNumber" /> <Field>
</Field> <FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<Field> <TextEdit @bind-text="NewEntity.PhoneNumber"/>
<Check TValue="bool" @bind-checked="@NewEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check> </Field>
</Field> <Field>
<Field> <Check TValue="bool" @bind-checked="@NewEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
<Check TValue="bool" @bind-checked="@NewEntity.TwoFactorEnabled">@L["DisplayName:TwoFactorEnabled"]</Check> </Field>
</Field> <Field>
</TabPanel> <Check TValue="bool" @bind-checked="@NewEntity.TwoFactorEnabled">@L["DisplayName:TwoFactorEnabled"]</Check>
<TabPanel Name="Roles"> </Field>
@if (NewUserRoles != null) </TabPanel>
{ <TabPanel Name="Roles">
@foreach (var role in NewUserRoles) @if (NewUserRoles != null)
{ {
<Field> @foreach (var role in NewUserRoles)
<input type="hidden" @bind-value="@role.Name" /> {
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check> <Field>
</Field> <input type="hidden" @bind-value="@role.Name"/>
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check>
</Field>
}
} }
} </TabPanel>
</TabPanel> </Content>
</Content> </Tabs>
</Tabs> </ModalBody>
</ModalBody> <ModalFooter>
<ModalFooter> <Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button> <Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button> </ModalFooter>
</ModalFooter> </ModalContent>
</ModalContent> </Modal>
</Modal> }
@* ************************* EDIT MODAL ************************* *@ @* ************************* EDIT MODAL ************************* *@
<Modal @ref="EditModal"> @if (HasUpdatePermission)
<ModalBackdrop /> {
<ModalContent IsCentered="true"> <Modal @ref="EditModal">
<ModalHeader> <ModalBackdrop/>
<ModalTitle>role</ModalTitle> <ModalContent IsCentered="true">
<CloseButton Clicked="CloseEditModalAsync" /> <ModalHeader>
</ModalHeader> <ModalTitle>role</ModalTitle>
<ModalBody> <CloseButton Clicked="CloseEditModalAsync"/>
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp" /> </ModalHeader>
<ModalBody>
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp"/>
<Tabs @bind-SelectedTab="@_editModalSelectedTab"> <Tabs @bind-SelectedTab="@_editModalSelectedTab">
<Items> <Items>
<Tab Name="UserInformations">@L["UserInformations"]</Tab> <Tab Name="UserInformations">@L["UserInformations"]</Tab>
<Tab Name="Roles">@L["Roles"]</Tab> <Tab Name="Roles">@L["Roles"]</Tab>
</Items> </Items>
<Content> <Content>
<TabPanel Name="UserInformations"> <TabPanel Name="UserInformations">
<Field> <Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel> <FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.UserName" /> <TextEdit @bind-text="EditingEntity.UserName"/>
</Field> </Field>
<Field> <Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel> <FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Name" /> <TextEdit @bind-text="EditingEntity.Name"/>
</Field> </Field>
<Field> <Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel> <FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Surname" /> <TextEdit @bind-text="EditingEntity.Surname"/>
</Field> </Field>
<Field> <Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel> <FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-text="EditingEntity.Password" /> <TextEdit Role="TextRole.Password" @bind-text="EditingEntity.Password"/>
</Field> </Field>
<Field> <Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel> <FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Email" /> <TextEdit @bind-text="EditingEntity.Email"/>
</Field> </Field>
<Field> <Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel> <FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.PhoneNumber" /> <TextEdit @bind-text="EditingEntity.PhoneNumber"/>
</Field> </Field>
<Field> <Field>
<Check TValue="bool" @bind-checked="EditingEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check> <Check TValue="bool" @bind-checked="EditingEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field> </Field>
<Field> <Field>
<Check TValue="bool" @bind-checked="EditingEntity.TwoFactorEnabled">@L["DisplayName:TwoFactorEnabled"]</Check> <Check TValue="bool" @bind-checked="EditingEntity.TwoFactorEnabled">@L["DisplayName:TwoFactorEnabled"]</Check>
</Field> </Field>
</TabPanel> </TabPanel>
<TabPanel Name="Roles"> <TabPanel Name="Roles">
@if (EditUserRoles != null) @if (EditUserRoles != null)
{
@foreach (var role in EditUserRoles)
{ {
<Field> @foreach (var role in EditUserRoles)
<input type="hidden" @bind-value="@role.Name" /> {
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check> <Field>
</Field> <input type="hidden" @bind-value="@role.Name"/>
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check>
</Field>
}
} }
} </TabPanel>
</TabPanel> </Content>
</Content> </Tabs>
</Tabs> </ModalBody>
</ModalBody> <ModalFooter>
<ModalFooter> <Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button>
<Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button> <Button Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button>
<Button Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button> </ModalFooter>
</ModalFooter> </ModalContent>
</ModalContent> </Modal>
</Modal> }
<PermissionManagementModal @ref="PermissionManagementModal"/> <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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.BlazoriseUI; using Volo.Abp.BlazoriseUI;
using Volo.Abp.PermissionManagement.Blazor.Components; using Volo.Abp.PermissionManagement.Blazor.Components;
using Volo.Abp.Threading;
namespace Volo.Abp.Identity.Blazor.Pages.Identity 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 PermissionProviderName = "U";
protected const string DefaultSelectedTab = "UserInformations"; protected const string DefaultSelectedTab = "UserInformations";
protected PermissionManagementModal PermissionManagementModal; protected PermissionManagementModal PermissionManagementModal;
protected IReadOnlyList<IdentityRoleDto> Roles; protected IReadOnlyList<IdentityRoleDto> Roles;
@ -21,14 +21,21 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected AssignedRoleViewModel[] NewUserRoles; protected AssignedRoleViewModel[] NewUserRoles;
protected AssignedRoleViewModel[] EditUserRoles; protected AssignedRoleViewModel[] EditUserRoles;
protected bool ShouldShowEntityActions { get; set; }
protected bool HasManagePermissionsPermission { get; set; }
protected string _createModalSelectedTab = DefaultSelectedTab; protected string _createModalSelectedTab = DefaultSelectedTab;
protected string _editModalSelectedTab = DefaultSelectedTab; protected string _editModalSelectedTab = DefaultSelectedTab;
public UserManagementBase() public UserManagementBase()
{ {
ObjectMapperContext = typeof(AbpIdentityBlazorModule); ObjectMapperContext = typeof(AbpIdentityBlazorModule);
CreatePolicyName = IdentityPermissions.Users.Create;
UpdatePolicyName = IdentityPermissions.Users.Update;
DeletePolicyName = IdentityPermissions.Users.Delete;
} }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
@ -38,10 +45,23 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
Roles = (await AppService.GetAssignableRolesAsync()).Items; 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() protected override Task OpenCreateModalAsync()
{ {
_createModalSelectedTab = DefaultSelectedTab; _createModalSelectedTab = DefaultSelectedTab;
NewUserRoles = Roles.Select(x => new AssignedRoleViewModel NewUserRoles = Roles.Select(x => new AssignedRoleViewModel
{ {
Name = x.Name, Name = x.Name,
@ -61,7 +81,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected override async Task OpenEditModalAsync(Guid id) protected override async Task OpenEditModalAsync(Guid id)
{ {
_editModalSelectedTab = DefaultSelectedTab; _editModalSelectedTab = DefaultSelectedTab;
var userRoleNames = (await AppService.GetRolesAsync(id)).Items.Select(r => r.Name).ToList(); var userRoleNames = (await AppService.GetRolesAsync(id)).Items.Select(r => r.Name).ToList();
EditUserRoles = Roles.Select(x => new AssignedRoleViewModel EditUserRoles = Roles.Select(x => new AssignedRoleViewModel

Loading…
Cancel
Save