Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comments for extension methods of IAuthorizationService/IFeatureChecker. #21737

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public static async Task<bool> IsGrantedAsync(this IAuthorizationService authori
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))
Expand All @@ -117,6 +122,12 @@ public static async Task CheckAsync(this IAuthorizationService authorizationServ
}
}

/// <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))
Expand All @@ -126,6 +137,12 @@ public static async Task CheckAsync(this IAuthorizationService authorizationServ
}
}

/// <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))
Expand All @@ -135,6 +152,11 @@ public static async Task CheckAsync(this IAuthorizationService authorizationServ
}
}

/// <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))
Expand All @@ -143,6 +165,12 @@ public static async Task CheckAsync(this IAuthorizationService authorizationServ
}
}

/// <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))
Expand All @@ -152,6 +180,12 @@ public static async Task CheckAsync(this IAuthorizationService authorizationServ
}
}

/// <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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static async Task<bool> IsEnabledAsync(this IFeatureChecker featureChecke
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)))
Expand All @@ -61,6 +66,13 @@ public static async Task CheckEnabledAsync(this IFeatureChecker featureChecker,
}
}

/// <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())
Expand Down
Loading