mirror of https://github.com/EasyAbp/EShop.git
Browse Source
Move order creation permission check to BasicOrderCancellationAuthorizationHandler Resolve #105pull/107/head 1.6.0
7 changed files with 106 additions and 13 deletions
@ -0,0 +1,60 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Orders.Authorization; |
|||
using EasyAbp.EShop.Stores.StoreOwners; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace EasyAbp.EShop.Orders.Orders |
|||
{ |
|||
public class BasicOrderCancellationAuthorizationHandler : OrderCancellationAuthorizationHandler |
|||
{ |
|||
private readonly IStoreOwnerStore _storeOwnerStore; |
|||
private readonly IPermissionChecker _permissionChecker; |
|||
private readonly ICurrentUser _currentUser; |
|||
|
|||
public BasicOrderCancellationAuthorizationHandler( |
|||
IStoreOwnerStore storeOwnerStore, |
|||
IPermissionChecker permissionChecker, |
|||
ICurrentUser currentUser) |
|||
{ |
|||
_storeOwnerStore = storeOwnerStore; |
|||
_permissionChecker = permissionChecker; |
|||
_currentUser = currentUser; |
|||
} |
|||
|
|||
protected override async Task HandleOrderCreationAsync(AuthorizationHandlerContext context, |
|||
OrderOperationAuthorizationRequirement requirement, Order resource) |
|||
{ |
|||
if (!await _permissionChecker.IsGrantedAsync(OrdersPermissions.Orders.Cancel)) |
|||
{ |
|||
context.Fail(); |
|||
return; |
|||
} |
|||
|
|||
if (!resource.IsPaid()) |
|||
{ |
|||
context.Succeed(requirement); |
|||
return; |
|||
} |
|||
|
|||
if (resource.CustomerUserId != _currentUser.GetId()) |
|||
{ |
|||
if (!await _permissionChecker.IsGrantedAsync(OrdersPermissions.Orders.Manage)) |
|||
{ |
|||
context.Fail(); |
|||
return; |
|||
} |
|||
|
|||
|
|||
if (await _storeOwnerStore.IsStoreOwnerAsync(resource.StoreId, _currentUser.GetId()) || |
|||
await _permissionChecker.IsGrantedAsync(OrdersPermissions.Orders.CrossStore)) |
|||
{ |
|||
context.Succeed(requirement); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
|
|||
namespace EasyAbp.EShop.Orders.Orders |
|||
{ |
|||
public abstract class OrderCancellationAuthorizationHandler : AuthorizationHandler<OrderOperationAuthorizationRequirement, Order> |
|||
{ |
|||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, OrderOperationAuthorizationRequirement requirement, |
|||
Order resource) |
|||
{ |
|||
if (requirement.OrderOperation != OrderOperation.Cancellation) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await HandleOrderCreationAsync(context, requirement, resource); |
|||
} |
|||
|
|||
protected abstract Task HandleOrderCreationAsync(AuthorizationHandlerContext context, |
|||
OrderOperationAuthorizationRequirement requirement, Order resource); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue