Skip to content

feat: Add IsAvailableAsync to resource permission management providers#24951

Merged
oykuermann merged 5 commits intorel-10.2from
feat/resource-permission-provider-availability
Mar 2, 2026
Merged

feat: Add IsAvailableAsync to resource permission management providers#24951
oykuermann merged 5 commits intorel-10.2from
feat/resource-permission-provider-availability

Conversation

@maliming
Copy link
Member

Introduces IsAvailableAsync() to IResourcePermissionManagementProvider and IResourcePermissionProviderKeyLookupService, allowing providers to opt out in certain contexts.

ResourcePermissionManager respects this flag in permission checks, writes, and UI lookup service listing.

OpenIddict and IdentityServer client providers override IsAvailableAsync() to return false when the current context is a tenant (host-only concept).

Introduces `IsAvailableAsync()` to `IResourcePermissionManagementProvider` and `IResourcePermissionProviderKeyLookupService`, allowing providers to opt out in certain contexts.

`ResourcePermissionManager` respects this flag in permission checks, writes, and UI lookup service listing.

OpenIddict and IdentityServer client providers override `IsAvailableAsync()` to return `false` when the current context is a tenant (host-only concept).
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an availability mechanism for resource permission management providers, allowing providers to conditionally opt out based on context (e.g., multi-tenancy). The primary use case is making OpenIddict and IdentityServer client-related providers available only at the host level, not in tenant contexts.

Changes:

  • Added IsAvailableAsync() method to IResourcePermissionManagementProvider and IResourcePermissionProviderKeyLookupService interfaces with default implementations
  • Updated ResourcePermissionManager to respect availability checks in permission reads, writes, and UI lookup service listings
  • Implemented host-only logic for OpenIddict and IdentityServer client providers by checking CurrentTenant.Id == null

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
IResourcePermissionManagementProvider.cs Added IsAvailableAsync() method to interface
IResourcePermissionProviderKeyLookupService.cs Added IsAvailableAsync() method to interface
ResourcePermissionManagementProvider.cs Added default implementation of IsAvailableAsync() returning true
ResourcePermissionManager.cs Updated to filter unavailable services in GetProviderKeyLookupServicesAsync(), skip unavailable providers in GetInternalAsync(), and validate availability in SetAsync()
ApplicationResourcePermissionManagementProvider.cs Overridden IsAvailableAsync() to return false when in tenant context
ApplicationResourcePermissionProviderKeyLookupService.cs Overridden IsAvailableAsync() to return false when in tenant context, injected ICurrentTenant
ClientResourcePermissionManagementProvider.cs Overridden IsAvailableAsync() to return false when in tenant context
ClientResourcePermissionProviderKeyLookupService.cs Overridden IsAvailableAsync() to return false when in tenant context, injected ICurrentTenant
UserResourcePermissionProviderKeyLookupService.cs Added IsAvailableAsync() returning true (always available)
RoleResourcePermissionProviderKeyLookupService.cs Added IsAvailableAsync() returning true (always available)
TestUnavailableResourcePermissionManagementProvider.cs Test provider that always returns unavailable
TestUnavailableResourcePermissionProviderKeyLookupService.cs Test lookup service that always returns unavailable
TestResourcePermissionProviderKeyLookupService.cs Added IsAvailableAsync() returning true for existing test service
AbpPermissionManagementTestBaseModule.cs Registered test unavailable providers
ResourcePermissionManager_Tests.cs Added tests for availability filtering and unavailable provider error handling
Comments suppressed due to low confidence (1)

modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManager.cs:92

  • The GetProviderKeyLookupServiceAsync method should check if the service is available before returning it. Currently, it returns unavailable services, which is inconsistent with GetProviderKeyLookupServicesAsync (which filters by availability). This could allow callers to obtain and use a service that returns false from IsAvailableAsync(). Consider adding an availability check or throwing an exception if the requested service exists but is not available in the current context.
    public virtual  Task<IResourcePermissionProviderKeyLookupService> GetProviderKeyLookupServiceAsync(string serviceName)
    {
        var service = _lazyProviderKeyLookupServices.Value.FirstOrDefault(s => s.Name == serviceName);
        return service == null
            ? throw new AbpException("Unknown resource permission provider key lookup service: " + serviceName)
            : Task.FromResult(service);
    }

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/IResourcePermissionProviderKeyLookupService.cs:18

  • Adding IsAvailableAsync() to this public interface is a breaking change for any external implementations of IResourcePermissionProviderKeyLookupService. If maintaining compatibility matters, consider a new optional interface for availability (checked via is pattern) so existing implementations continue to work and default to available.
public interface IResourcePermissionProviderKeyLookupService
{
    public string Name { get; }

    Task<bool> IsAvailableAsync();

    public ILocalizableString DisplayName { get; }

    Task<List<ResourcePermissionProviderKeyInfo>> SearchAsync(string filter = null, int page = 1, CancellationToken cancellationToken = default);

    Task<List<ResourcePermissionProviderKeyInfo>> SearchAsync(string[] keys, CancellationToken cancellationToken = default);

@oykuermann oykuermann merged commit 25756e2 into rel-10.2 Mar 2, 2026
3 of 4 checks passed
@oykuermann oykuermann deleted the feat/resource-permission-provider-availability branch March 2, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants