mirror of https://github.com/abpframework/abp.git
30 changed files with 386 additions and 27 deletions
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class ExtensionPropertyFeaturePolicyDto |
||||
|
{ |
||||
|
public string[] Features { get; set; } = default!; |
||||
|
|
||||
|
public bool RequiresAll { get; set; } |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class ExtensionPropertyGlobalFeaturePolicyDto |
||||
|
{ |
||||
|
public string[] Features { get; set; } = default!; |
||||
|
|
||||
|
public bool RequiresAll { get; set; } = default!; |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class ExtensionPropertyPermissionPolicyDto |
||||
|
{ |
||||
|
public string[] PermissionNames { get; set; } = default!; |
||||
|
|
||||
|
public bool RequiresAll { get; set; } |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class ExtensionPropertyPolicyDto |
||||
|
{ |
||||
|
[NotNull] |
||||
|
public ExtensionPropertyGlobalFeaturePolicyDto GlobalFeatures { get; set; } |
||||
|
|
||||
|
[NotNull] |
||||
|
public ExtensionPropertyFeaturePolicyDto Features { get; set; } |
||||
|
|
||||
|
[NotNull] |
||||
|
public ExtensionPropertyPermissionPolicyDto Permissions { get; set; } |
||||
|
|
||||
|
public ExtensionPropertyPolicyDto() |
||||
|
{ |
||||
|
GlobalFeatures = new ExtensionPropertyGlobalFeaturePolicyDto(); |
||||
|
Features = new ExtensionPropertyFeaturePolicyDto(); |
||||
|
Permissions = new ExtensionPropertyPermissionPolicyDto(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
|
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Features; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
|
||||
|
namespace Volo.Abp.ObjectExtending; |
||||
|
|
||||
|
[Dependency(ReplaceServices = true)] |
||||
|
[ExposeServices(typeof(ExtensionPropertyPolicyChecker))] |
||||
|
public class MvcExtensionPropertyPolicyChecker : ExtensionPropertyPolicyChecker |
||||
|
{ |
||||
|
protected IFeatureChecker FeatureChecker { get; } |
||||
|
protected IPermissionChecker PermissionChecker { get; } |
||||
|
|
||||
|
public MvcExtensionPropertyPolicyChecker(IFeatureChecker featureChecker, IPermissionChecker permissionChecker) |
||||
|
{ |
||||
|
FeatureChecker = featureChecker; |
||||
|
PermissionChecker = permissionChecker; |
||||
|
} |
||||
|
|
||||
|
protected override Task<bool> CheckGlobalFeaturesAsync(string featureName) |
||||
|
{ |
||||
|
return Task.FromResult<bool>(GlobalFeatureManager.Instance.IsEnabled(featureName)); |
||||
|
} |
||||
|
|
||||
|
protected async override Task<bool> CheckFeaturesAsync(string featureName) |
||||
|
{ |
||||
|
return await FeatureChecker.IsEnabledAsync(featureName); |
||||
|
} |
||||
|
|
||||
|
protected async override Task<bool> CheckPermissionsAsync(string permissionName) |
||||
|
{ |
||||
|
return await PermissionChecker.IsGrantedAsync(permissionName); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Features; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
using Volo.Abp.ObjectExtending; |
||||
|
|
||||
|
namespace Volo.Abp.BlazoriseUI; |
||||
|
|
||||
|
[Dependency(ReplaceServices = true)] |
||||
|
[ExposeServices(typeof(ExtensionPropertyPolicyChecker))] |
||||
|
public class BlazoriseExtensionPropertyPolicyChecker : ExtensionPropertyPolicyChecker |
||||
|
{ |
||||
|
protected IFeatureChecker FeatureChecker { get; } |
||||
|
protected IPermissionChecker PermissionChecker { get; } |
||||
|
|
||||
|
public BlazoriseExtensionPropertyPolicyChecker(IFeatureChecker featureChecker, IPermissionChecker permissionChecker) |
||||
|
{ |
||||
|
FeatureChecker = featureChecker; |
||||
|
PermissionChecker = permissionChecker; |
||||
|
} |
||||
|
|
||||
|
protected override Task<bool> CheckGlobalFeaturesAsync(string featureName) |
||||
|
{ |
||||
|
return Task.FromResult<bool>(GlobalFeatureManager.Instance.IsEnabled(featureName)); |
||||
|
} |
||||
|
|
||||
|
protected async override Task<bool> CheckFeaturesAsync(string featureName) |
||||
|
{ |
||||
|
return await FeatureChecker.IsEnabledAsync(featureName); |
||||
|
} |
||||
|
|
||||
|
protected async override Task<bool> CheckPermissionsAsync(string permissionName) |
||||
|
{ |
||||
|
return await PermissionChecker.IsGrantedAsync(permissionName); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.Abp.ObjectExtending; |
||||
|
|
||||
|
public class ExtensionPropertyFeaturePolicyConfiguration |
||||
|
{ |
||||
|
public string[] Features { get; set; } = []; |
||||
|
|
||||
|
public bool RequiresAll { get; set; } = default!; |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.Abp.ObjectExtending; |
||||
|
|
||||
|
public class ExtensionPropertyGlobalFeaturePolicyConfiguration |
||||
|
{ |
||||
|
public string[] Features { get; set; } = []; |
||||
|
|
||||
|
public bool RequiresAll { get; set; } = default!; |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.Abp.ObjectExtending; |
||||
|
|
||||
|
public class ExtensionPropertyPermissionPolicyConfiguration |
||||
|
{ |
||||
|
public string[] PermissionNames { get; set; } = []; |
||||
|
|
||||
|
public bool RequiresAll { get; set; } = default!; |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.ObjectExtending; |
||||
|
|
||||
|
public class ExtensionPropertyPolicyChecker : ITransientDependency |
||||
|
{ |
||||
|
public virtual async Task<bool> CheckPolicyAsync([NotNull] ExtensionPropertyPolicyConfiguration policy) |
||||
|
{ |
||||
|
if (!await CheckAsync(policy.GlobalFeatures.Features, policy.GlobalFeatures.RequiresAll, CheckGlobalFeaturesAsync)) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (!await CheckAsync(policy.Features.Features, policy.Features.RequiresAll, CheckFeaturesAsync)) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return await CheckAsync(policy.Permissions.PermissionNames, policy.Permissions.RequiresAll, CheckPermissionsAsync); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<bool> CheckAsync(string[] names, bool requiresAll, Func<string, Task<bool>> checkFunc) |
||||
|
{ |
||||
|
if (names.IsNullOrEmpty()) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
var hasAny = false; |
||||
|
foreach (var name in names) |
||||
|
{ |
||||
|
if (!await checkFunc(name)) |
||||
|
{ |
||||
|
if (requiresAll) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
hasAny = true; |
||||
|
if (!requiresAll) |
||||
|
{ |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return hasAny; |
||||
|
} |
||||
|
|
||||
|
protected virtual Task<bool> CheckGlobalFeaturesAsync(string featureName) |
||||
|
{ |
||||
|
return Task.FromResult(true); |
||||
|
} |
||||
|
|
||||
|
protected virtual Task<bool> CheckFeaturesAsync(string featureName) |
||||
|
{ |
||||
|
return Task.FromResult(true); |
||||
|
} |
||||
|
|
||||
|
protected virtual Task<bool> CheckPermissionsAsync(string permissionName) |
||||
|
{ |
||||
|
return Task.FromResult(true); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
namespace Volo.Abp.ObjectExtending; |
||||
|
|
||||
|
public class ExtensionPropertyPolicyConfiguration |
||||
|
{ |
||||
|
public ExtensionPropertyGlobalFeaturePolicyConfiguration GlobalFeatures { get; set; } |
||||
|
|
||||
|
public ExtensionPropertyFeaturePolicyConfiguration Features { get; set; } |
||||
|
|
||||
|
public ExtensionPropertyPermissionPolicyConfiguration Permissions { get; set; } |
||||
|
|
||||
|
public ExtensionPropertyPolicyConfiguration() |
||||
|
{ |
||||
|
GlobalFeatures = new ExtensionPropertyGlobalFeaturePolicyConfiguration(); |
||||
|
Features = new ExtensionPropertyFeaturePolicyConfiguration(); |
||||
|
Permissions = new ExtensionPropertyPermissionPolicyConfiguration(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue