From fc21c494322f9b1d84900b721a56a4dea60487f1 Mon Sep 17 00:00:00 2001 From: RayMMond Date: Tue, 1 Sep 2020 10:39:17 +0800 Subject: [PATCH] fix store related extension method naming, add crossStoreAllowed to base method --- .../StoreOwnerAuthorizationExtensions.cs | 6 +++--- .../MultiStoreAbstractKeyCrudAppService.cs | 17 +++++++++++++++-- .../MultiStoreAbstractKeyReadOnlyAppService.cs | 17 +++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Permissions/StoreOwnerAuthorizationExtensions.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Permissions/StoreOwnerAuthorizationExtensions.cs index 68d32932..45816d5d 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Permissions/StoreOwnerAuthorizationExtensions.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Permissions/StoreOwnerAuthorizationExtensions.cs @@ -6,7 +6,7 @@ namespace EasyAbp.EShop.Stores.Permissions { public static class StoreOwnerAuthorizationExtensions { - public static Task IsCurrentUserStoreOwnerAsync(this IAuthorizationService authorizationService, + public static Task IsCurrentUserGrantedAsync(this IAuthorizationService authorizationService, Guid storeId, string policyName = null, object resource = null) { return authorizationService.IsGrantedAsync(resource, @@ -16,7 +16,7 @@ namespace EasyAbp.EShop.Stores.Permissions public static async Task IsMultiStoreGrantedAsync(this IAuthorizationService authorizationService, Guid? storeId, string policyName, string crossStorePolicyName, object resource = null) { - if (storeId.HasValue && await authorizationService.IsCurrentUserStoreOwnerAsync(storeId.Value, policyName)) + if (storeId.HasValue && await authorizationService.IsCurrentUserGrantedAsync(storeId.Value, policyName)) { return true; } @@ -35,7 +35,7 @@ namespace EasyAbp.EShop.Stores.Permissions public static async Task CheckMultiStorePolicyAsync(this IAuthorizationService authorizationService, Guid? storeId, string policyName, string crossStorePolicyName, object resource = null) { - if (storeId.HasValue && await authorizationService.IsCurrentUserStoreOwnerAsync(storeId.Value, policyName, resource)) + if (storeId.HasValue && await authorizationService.IsCurrentUserGrantedAsync(storeId.Value, policyName, resource)) { return; } diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyCrudAppService.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyCrudAppService.cs index 90e8b5d5..94350693 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyCrudAppService.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyCrudAppService.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using EasyAbp.EShop.Stores.Permissions; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; +using Volo.Abp.Authorization; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; @@ -110,9 +111,21 @@ namespace EasyAbp.EShop.Stores.Stores } - protected virtual async Task CheckMultiStorePolicyAsync(Guid? storeId, string policyName) + protected virtual async Task CheckMultiStorePolicyAsync(Guid? storeId, string policyName, bool crossStoreAllowed = true) { - await AuthorizationService.CheckMultiStorePolicyAsync(storeId, policyName, CrossStorePolicyName); + if (crossStoreAllowed) + { + await AuthorizationService.CheckMultiStorePolicyAsync(storeId, policyName, CrossStorePolicyName); + } + else + { + if (!storeId.HasValue) + { + throw new AbpAuthorizationException("Authorization failed! StoreId can not be null!"); + } + + await AuthorizationService.CheckMultiStorePolicyAsync(storeId.Value, policyName); + } } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyReadOnlyAppService.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyReadOnlyAppService.cs index 73a986f1..fa759510 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyReadOnlyAppService.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyReadOnlyAppService.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using EasyAbp.EShop.Stores.Permissions; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; +using Volo.Abp.Authorization; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; @@ -50,9 +51,21 @@ namespace EasyAbp.EShop.Stores.Stores return MapToGetOutputDto(entity); } - protected virtual async Task CheckMultiStorePolicyAsync(Guid? storeId, string policyName) + protected virtual async Task CheckMultiStorePolicyAsync(Guid? storeId, string policyName, bool crossStoreAllowed = true) { - await AuthorizationService.CheckMultiStorePolicyAsync(storeId, policyName, CrossStorePolicyName); + if (crossStoreAllowed) + { + await AuthorizationService.CheckMultiStorePolicyAsync(storeId, policyName, CrossStorePolicyName); + } + else + { + if (!storeId.HasValue) + { + throw new AbpAuthorizationException("Authorization failed! StoreId can not be null!"); + } + + await AuthorizationService.CheckMultiStorePolicyAsync(storeId.Value, policyName); + } } } } \ No newline at end of file