From c7ff9c480dc7efcb7775b1348f18ca41575f9759 Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Mon, 20 Jul 2020 20:02:40 +0800 Subject: [PATCH] Automatically set UserId to current user's id in get-list methods. --- common.props | 2 +- .../EasyAbp/EShop/Orders/Orders/OrderAppService.cs | 6 ++++++ .../EasyAbp/EShop/Payments/Payments/PaymentAppService.cs | 6 ++++++ .../EasyAbp/EShop/Payments/Refunds/RefundAppService.cs | 6 ++++++ .../Plugins/Baskets/BasketItems/BasketItemAppService.cs | 9 +++++++-- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/common.props b/common.props index 85968187..18a4c1ed 100644 --- a/common.props +++ b/common.props @@ -1,7 +1,7 @@ latest - 0.8.2 + 0.8.3 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application/EasyAbp/EShop/Orders/Orders/OrderAppService.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application/EasyAbp/EShop/Orders/Orders/OrderAppService.cs index d55aa3ee..c9aa4ea7 100644 --- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application/EasyAbp/EShop/Orders/Orders/OrderAppService.cs +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application/EasyAbp/EShop/Orders/Orders/OrderAppService.cs @@ -65,6 +65,12 @@ namespace EasyAbp.EShop.Orders.Orders public override async Task> GetListAsync(GetOrderListDto input) { + if (!input.CustomerUserId.HasValue && + !await AuthorizationService.IsGrantedAsync(OrdersPermissions.Orders.Manage)) + { + input.CustomerUserId = CurrentUser.GetId(); + } + if (input.CustomerUserId != CurrentUser.GetId()) { await AuthorizationService.CheckAsync(OrdersPermissions.Orders.Manage); diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs index 13594975..905723d7 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs @@ -69,6 +69,12 @@ namespace EasyAbp.EShop.Payments.Payments public override async Task> GetListAsync(GetPaymentListDto input) { + if (!input.UserId.HasValue && + !await AuthorizationService.IsGrantedAsync(PaymentsPermissions.Payments.Manage)) + { + input.UserId = CurrentUser.GetId(); + } + if (input.UserId != CurrentUser.GetId()) { await AuthorizationService.CheckAsync(PaymentsPermissions.Payments.Manage); diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs index ba60f060..c42e5321 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs @@ -60,6 +60,12 @@ namespace EasyAbp.EShop.Payments.Refunds public override async Task> GetListAsync(GetRefundListDto input) { + if (!input.UserId.HasValue && + !await AuthorizationService.IsGrantedAsync(PaymentsPermissions.Refunds.Manage)) + { + input.UserId = CurrentUser.GetId(); + } + if (input.UserId != CurrentUser.GetId()) { await AuthorizationService.CheckAsync(PaymentsPermissions.Refunds.Manage); diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Application/EasyAbp/EShop/Plugins/Baskets/BasketItems/BasketItemAppService.cs b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Application/EasyAbp/EShop/Plugins/Baskets/BasketItems/BasketItemAppService.cs index 6ca40125..ca30f1dd 100644 --- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Application/EasyAbp/EShop/Plugins/Baskets/BasketItems/BasketItemAppService.cs +++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Application/EasyAbp/EShop/Plugins/Baskets/BasketItems/BasketItemAppService.cs @@ -78,9 +78,14 @@ namespace EasyAbp.EShop.Plugins.Baskets.BasketItems { await CheckGetListPolicyAsync(); - if (input.UserId != CurrentUser.GetId() && !await IsCurrentUserManagerAsync()) + if (!input.UserId.HasValue && !await IsCurrentUserManagerAsync()) { - throw new AbpAuthorizationException(); + input.UserId = CurrentUser.GetId(); + } + + if (input.UserId != CurrentUser.GetId()) + { + await AuthorizationService.CheckAsync(BasketsPermissions.BasketItem.Manage); } var query = CreateFilteredQuery(input);