Browse Source

Fix null policyName problem of StoreOwnerAuthorizationExtensions

pull/148/head
gdlcf88 4 years ago
parent
commit
5f67757ea9
  1. 17
      modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Authorization/StoreOwnerAuthorizationExtensions.cs

17
modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Shared/EasyAbp/EShop/Stores/Authorization/StoreOwnerAuthorizationExtensions.cs

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Authorization;
namespace EasyAbp.EShop.Stores.Authorization
@ -7,14 +8,14 @@ namespace EasyAbp.EShop.Stores.Authorization
public static class StoreOwnerAuthorizationExtensions
{
public static Task<bool> IsCurrentUserGrantedAsync(this IAuthorizationService authorizationService,
Guid storeId, string policyName = null)
Guid storeId, [CanBeNull] string policyName = null)
{
return authorizationService.IsGrantedAsync(new StoreInfo {StoreId = storeId},
new StorePermissionAuthorizationRequirement(policyName));
}
public static async Task<bool> IsMultiStoreGrantedAsync(this IAuthorizationService authorizationService,
Guid? storeId, string policyName, string crossStorePolicyName)
Guid? storeId, [CanBeNull] string policyName, [NotNull] string crossStorePolicyName)
{
if (storeId.HasValue && await authorizationService.IsCurrentUserGrantedAsync(storeId.Value, policyName))
{
@ -22,18 +23,18 @@ namespace EasyAbp.EShop.Stores.Authorization
}
return await authorizationService.IsGrantedAsync(crossStorePolicyName)
&& await authorizationService.IsGrantedAsync(policyName);
&& (policyName.IsNullOrEmpty() || await authorizationService.IsGrantedAsync(policyName));
}
public static Task CheckMultiStorePolicyAsync(this IAuthorizationService authorizationService,
Guid storeId, string policyName)
Guid storeId, [CanBeNull] string policyName)
{
return authorizationService.CheckAsync(new StoreInfo {StoreId = storeId},
new StorePermissionAuthorizationRequirement(policyName));
}
public static async Task CheckMultiStorePolicyAsync(this IAuthorizationService authorizationService,
Guid? storeId, string policyName, string crossStorePolicyName)
Guid? storeId, [CanBeNull] string policyName, [NotNull] string crossStorePolicyName)
{
if (storeId.HasValue && await authorizationService.IsCurrentUserGrantedAsync(storeId.Value, policyName))
{
@ -41,6 +42,12 @@ namespace EasyAbp.EShop.Stores.Authorization
}
await authorizationService.CheckAsync(crossStorePolicyName);
if (string.IsNullOrEmpty(policyName))
{
return;
}
await authorizationService.CheckAsync(policyName);
}
}

Loading…
Cancel
Save