Browse Source

Merge pull request #21737 from abpframework/21734

Add comments for extension methods of `IAuthorizationService/IFeatureChecker`.
pull/21744/head
Engincan VESKE 1 year ago
committed by GitHub
parent
commit
89bc8375bf
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 34
      framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs
  2. 12
      framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureCheckerExtensions.cs

34
framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs

@ -108,6 +108,11 @@ public static class AbpAuthorizationServiceExtensions
return (await authorizationService.AuthorizeAsync(resource, policyName)).Succeeded;
}
/// <summary>
/// Checks if CurrentPrincipal meets a specific authorization policy, throwing an <see cref="AbpAuthorizationException"/> if not.
/// </summary>
/// <param name="authorizationService">The <see cref="IAuthorizationService"/> providing authorization.</param>
/// <param name="policyName">The name of the policy to evaluate.</param>
public static async Task CheckAsync(this IAuthorizationService authorizationService, string policyName)
{
if (!await authorizationService.IsGrantedAsync(policyName))
@ -117,6 +122,12 @@ public static class AbpAuthorizationServiceExtensions
}
}
/// <summary>
/// Checks if CurrentPrincipal meets a specific requirement for the specified resource, throwing an <see cref="AbpAuthorizationException"/> if not.
/// </summary>
/// <param name="authorizationService">The <see cref="IAuthorizationService"/> providing authorization.</param>
/// <param name="resource">The resource to evaluate the policy against.</param>
/// <param name="requirement">The requirement to evaluate the policy against.</param>
public static async Task CheckAsync(this IAuthorizationService authorizationService, object resource, IAuthorizationRequirement requirement)
{
if (!await authorizationService.IsGrantedAsync(resource, requirement))
@ -126,6 +137,12 @@ public static class AbpAuthorizationServiceExtensions
}
}
/// <summary>
/// Checks if CurrentPrincipal meets a specific authorization policy against the specified resource, throwing an <see cref="AbpAuthorizationException"/> if not.
/// </summary>
/// <param name="authorizationService">The <see cref="IAuthorizationService"/> providing authorization.</param>
/// <param name="resource">The resource to evaluate the policy against.</param>
/// <param name="policy">The policy to evaluate.</param>
public static async Task CheckAsync(this IAuthorizationService authorizationService, object resource, AuthorizationPolicy policy)
{
if (!await authorizationService.IsGrantedAsync(resource, policy))
@ -135,6 +152,11 @@ public static class AbpAuthorizationServiceExtensions
}
}
/// <summary>
/// Checks if CurrentPrincipal meets a specific authorization policy, throwing an <see cref="AbpAuthorizationException"/> if not.
/// </summary>
/// <param name="authorizationService">The <see cref="IAuthorizationService"/> providing authorization.</param>
/// <param name="policy">The policy to evaluate.</param>
public static async Task CheckAsync(this IAuthorizationService authorizationService, AuthorizationPolicy policy)
{
if (!await authorizationService.IsGrantedAsync(policy))
@ -143,6 +165,12 @@ public static class AbpAuthorizationServiceExtensions
}
}
/// <summary>
/// Checks if CurrentPrincipal meets a specific authorization policy against the specified resource, throwing an <see cref="AbpAuthorizationException"/> if not.
/// </summary>
/// <param name="authorizationService">The <see cref="IAuthorizationService"/> providing authorization.</param>
/// <param name="resource">The resource to evaluate the policy against.</param>
/// <param name="requirements">The requirements to evaluate the policy against.</param>
public static async Task CheckAsync(this IAuthorizationService authorizationService, object resource, IEnumerable<IAuthorizationRequirement> requirements)
{
if (!await authorizationService.IsGrantedAsync(resource, requirements))
@ -152,6 +180,12 @@ public static class AbpAuthorizationServiceExtensions
}
}
/// <summary>
/// Checks if CurrentPrincipal meets a specific authorization policy against the specified resource, throwing an <see cref="AbpAuthorizationException"/> if not.
/// </summary>
/// <param name="authorizationService">The <see cref="IAuthorizationService"/> providing authorization.</param>
/// <param name="resource">The resource to evaluate the policy against.</param>
/// <param name="policyName">The name of the policy to evaluate.</param>
public static async Task CheckAsync(this IAuthorizationService authorizationService, object resource, string policyName)
{
if (!await authorizationService.IsGrantedAsync(resource, policyName))

12
framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureCheckerExtensions.cs

@ -52,6 +52,11 @@ public static class FeatureCheckerExtensions
return false;
}
/// <summary>
/// Checks if the specified feature is enabled and throws an <see cref="AbpAuthorizationException"/> if it is not.
/// </summary>
/// <param name="featureChecker">The <see cref="IFeatureChecker"/></param>
/// <param name="featureName">The name of the feature to be checked.</param>
public static async Task CheckEnabledAsync(this IFeatureChecker featureChecker, string featureName)
{
if (!(await featureChecker.IsEnabledAsync(featureName)))
@ -61,6 +66,13 @@ public static class FeatureCheckerExtensions
}
}
/// <summary>
/// Checks if the specified features are enabled and throws an <see cref="AbpAuthorizationException"/> if they are not.
/// The check can either require all features to be enabled or just one, based on the <paramref name="requiresAll"/> parameter.
/// </summary>
/// <param name="featureChecker">The <see cref="IFeatureChecker"/></param>
/// <param name="requiresAll">True: Requires all features to be enabled. False: Requires at least one of the features to be enabled.</param>
/// <param name="featureNames">The names of the features to be checked.</param>
public static async Task CheckEnabledAsync(this IFeatureChecker featureChecker, bool requiresAll, params string[] featureNames)
{
if (featureNames.IsNullOrEmpty())

Loading…
Cancel
Save