Browse Source
feat: Enhance `GetProviderKeyLookupServiceAsync` to check service availability
pull/24951/head
maliming
1 month ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
18 additions and
4 deletions
modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManager.cs
modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManager_Tests.cs
@ -83,12 +83,20 @@ public class ResourcePermissionManager : IResourcePermissionManager, ISingletonD
return availableServices ;
}
public virtual Task < IResourcePermissionProviderKeyLookupService > GetProviderKeyLookupServiceAsync ( string serviceName )
public virtual async Task < IResourcePermissionProviderKeyLookupService > GetProviderKeyLookupServiceAsync ( string serviceName )
{
var service = _l azyProviderKeyLookupServices . Value . FirstOrDefault ( s = > s . Name = = serviceName ) ;
return service = = null
? throw new AbpException ( "Unknown resource permission provider key lookup service: " + serviceName )
: Task . FromResult ( service ) ;
if ( service = = null )
{
throw new AbpException ( "Unknown resource permission provider key lookup service: " + serviceName ) ;
}
if ( ! await service . IsAvailableAsync ( ) )
{
throw new AbpException ( "The resource permission provider key lookup service '" + serviceName + "' is not available in the current context." ) ;
}
return service ;
}
public virtual async Task < List < PermissionDefinition > > GetAvailablePermissionsAsync ( string resourceName )
@ -42,6 +42,12 @@ public class ResourcePermissionManager_Tests : PermissionTestBase
await _ resourcePermissionManager . GetProviderKeyLookupServiceAsync ( "UndefinedProvider" ) ;
} ) ;
exception . Message . ShouldBe ( "Unknown resource permission provider key lookup service: UndefinedProvider" ) ;
var unavailableException = await Assert . ThrowsAsync < AbpException > ( async ( ) = >
{
await _ resourcePermissionManager . GetProviderKeyLookupServiceAsync ( "TestUnavailable" ) ;
} ) ;
unavailableException . Message . ShouldBe ( "The resource permission provider key lookup service 'TestUnavailable' is not available in the current context." ) ;
}
[Fact]