From 13099f702a8442f031124608f18f4894f234b8c7 Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Fri, 19 Mar 2021 10:23:06 +0300 Subject: [PATCH] Remove RequiredPolicy from entity actions and use Visible property. --- .../Web/Extensibility/EntityActions/EntityAction.cs | 3 +-- framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 2 +- .../Components/AbpExtensibleDataGrid.razor | 6 ++---- .../Components/AbpExtensibleDataGrid.razor.cs | 11 ----------- .../Components/EntityAction.razor | 2 +- .../Components/EntityAction.razor.cs | 6 ++---- .../Components/EntityActions.razor.cs | 2 +- .../Pages/Identity/RoleManagement.razor.cs | 6 +++--- .../Pages/Identity/UserManagement.razor.cs | 6 +++--- .../Pages/TenantManagement/TenantManagement.razor.cs | 6 +++--- 10 files changed, 17 insertions(+), 33 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/EntityActions/EntityAction.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/EntityActions/EntityAction.cs index 018bea1740..61bea5c27a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/EntityActions/EntityAction.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/EntityActions/EntityAction.cs @@ -7,12 +7,11 @@ namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.EntityActions { public string Text { get; set; } public Func Clicked { get; set; } - public string RequiredPolicy { get; set; } public Func ConfirmationMessage { get; set; } public bool Primary { get; set; } public object Color { get; set; } public string Icon { get; set; } - public Func> Visible { get; set; } + public Func Visible { get; set; } public bool Equals(EntityAction other) { return string.Equals(Text, other?.Text, StringComparison.OrdinalIgnoreCase); diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index 3875297873..e97c8bf805 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -214,11 +214,11 @@ namespace Volo.Abp.BlazoriseUI protected override async Task OnInitializedAsync() { + await SetPermissionsAsync(); await SetEntityActionsAsync(); await SetTableColumnsAsync(); await SetToolbarItemsAsync(); await SetBreadcrumbItemsAsync(); - await SetPermissionsAsync(); } protected virtual async Task SetPermissionsAsync() diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor index f5e4da45ee..f060450ffd 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor @@ -25,23 +25,21 @@ if (action.ConfirmationMessage != null) { } else { } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor.cs index a6c9498467..72a58f94a5 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor.cs @@ -46,16 +46,5 @@ namespace Volo.Abp.BlazoriseUI.Components builder.CloseComponent(); }; } - - protected async Task VisibleCore(EntityAction action, TItem item) - { - var isVisible = true; - if (action.Visible != null) - { - isVisible = await action.Visible.Invoke(item); - } - - return isVisible; - } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor index e282f3c062..8e4544e09c 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor @@ -1,6 +1,6 @@ @typeparam TItem -@if (IsVisible && HasPermission) +@if (Visible && HasPermission) { if (ParentActions.Type == ActionType.Dropdown) { diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs index 33418ecf88..822cca49d3 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.BlazoriseUI.Components public partial class EntityAction : ComponentBase { [Parameter] - public bool IsVisible { get; set; } = true; + public bool Visible { get; set; } internal bool HasPermission { get; set; } = true; @@ -36,9 +36,6 @@ namespace Volo.Abp.BlazoriseUI.Components [Parameter] public string Icon { get; set; } - [Parameter] - public Func> Visible { get; set; } - [CascadingParameter] public EntityActions ParentActions { get; set; } @@ -52,6 +49,7 @@ namespace Volo.Abp.BlazoriseUI.Components { await base.OnInitializedAsync(); await SetDefaultValuesAsync(); + if (!RequiredPolicy.IsNullOrEmpty()) { HasPermission = await AuthorizationService.IsGrantedAsync(RequiredPolicy); diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs index 319c2d9c89..7d8460b79f 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs @@ -52,7 +52,7 @@ namespace Volo.Abp.BlazoriseUI.Components { if (ParentEntityActionsColumn != null) { - ParentEntityActionsColumn.Displayable = Actions.Any(t => t.IsVisible && t.HasPermission); + ParentEntityActionsColumn.Displayable = Actions.Any(t => t.Visible && t.HasPermission); } await InvokeAsync(StateHasChanged); diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs index 71cb2e45ff..f0a222f765 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs @@ -48,13 +48,13 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity new EntityAction { Text = L["Edit"], - RequiredPolicy = UpdatePolicyName, + Visible = (data) => HasUpdatePermission, Clicked = async (data) => { await OpenEditModalAsync(data.As()); } }, new EntityAction { Text = L["Permissions"], - RequiredPolicy = ManagePermissionsPolicyName, + Visible = (data) => HasManagePermissionsPermission, Clicked = async (data) => { await PermissionManagementModal.OpenAsync(PermissionProviderName, @@ -64,7 +64,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity new EntityAction { Text = L["Delete"], - RequiredPolicy = DeletePolicyName, + Visible = (data) => HasDeletePermission, Clicked = async (data) => await DeleteEntityAsync(data.As()), ConfirmationMessage = (data) => GetDeleteConfirmationMessage(data.As()) } diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs index 0ae7f6f9c4..c9084bd14d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs @@ -137,13 +137,13 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity new EntityAction { Text = L["Edit"], - RequiredPolicy = UpdatePolicyName, + Visible = (data) => HasUpdatePermission, Clicked = async (data) => await OpenEditModalAsync(data.As()) }, new EntityAction { Text = L["Permissions"], - RequiredPolicy = ManagePermissionsPolicyName, + Visible = (data) => HasManagePermissionsPermission, Clicked = async (data) => { await PermissionManagementModal.OpenAsync(PermissionProviderName, @@ -153,7 +153,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity new EntityAction { Text = L["Delete"], - RequiredPolicy = DeletePolicyName, + Visible = (data) => HasDeletePermission, Clicked = async (data) => await DeleteEntityAsync(data.As()), ConfirmationMessage = (data) => GetDeleteConfirmationMessage(data.As()) } diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs index 73d382c6e6..cb5ecc3413 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs @@ -70,13 +70,13 @@ namespace Volo.Abp.TenantManagement.Blazor.Pages.TenantManagement new EntityAction { Text = L["Edit"], - RequiredPolicy = UpdatePolicyName, + Visible = (data) => HasUpdatePermission, Clicked = async (data) => { await OpenEditModalAsync(data.As()); } }, new EntityAction { Text = L["Features"], - RequiredPolicy = ManageFeaturesPolicyName, + Visible = (data) => HasManageFeaturesPermission, Clicked = async (data) => { var tenant = data.As(); @@ -86,7 +86,7 @@ namespace Volo.Abp.TenantManagement.Blazor.Pages.TenantManagement new EntityAction { Text = L["Delete"], - RequiredPolicy = DeletePolicyName, + Visible = (data) => HasDeletePermission, Clicked = async (data) => await DeleteEntityAsync(data.As()), ConfirmationMessage = (data) => GetDeleteConfirmationMessage(data.As()) }