Browse Source

fix store related extension method naming, add crossStoreAllowed to base method

pull/81/head
RayMMond 6 years ago
parent
commit
fc21c49432
  1. 6
      modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Permissions/StoreOwnerAuthorizationExtensions.cs
  2. 17
      modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyCrudAppService.cs
  3. 17
      modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Stores/MultiStoreAbstractKeyReadOnlyAppService.cs

6
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<bool> IsCurrentUserStoreOwnerAsync(this IAuthorizationService authorizationService,
public static Task<bool> 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<bool> 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;
}

17
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);
}
}
}
}

17
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);
}
}
}
}
Loading…
Cancel
Save