Browse Source
Merge pull request #660 from Nokecy/master
Add Get methods to find and modify a permission or group
pull/666/head
Halil İbrahim Kalkan
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
31 additions and
3 deletions
-
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/IPermissionDefinitionContext.cs
-
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionDefinitionContext.cs
-
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/Authorization_Tests.cs
-
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/AuthorizationTestPermissionDefinitionProvider.cs
|
|
|
@ -6,6 +6,7 @@ namespace Volo.Abp.Authorization.Permissions |
|
|
|
public interface IPermissionDefinitionContext |
|
|
|
{ |
|
|
|
//TODO: Add Get methods to find and modify a permission or group.
|
|
|
|
PermissionGroupDefinition GetGroupOrNull(string name); |
|
|
|
|
|
|
|
PermissionGroupDefinition AddGroup([NotNull] string name, ILocalizableString displayName = null); |
|
|
|
} |
|
|
|
|
|
|
|
@ -23,5 +23,18 @@ namespace Volo.Abp.Authorization.Permissions |
|
|
|
|
|
|
|
return Groups[name] = new PermissionGroupDefinition(name, displayName); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual PermissionGroupDefinition GetGroupOrNull(string name) |
|
|
|
{ |
|
|
|
Check.NotNull(name, nameof(name)); |
|
|
|
|
|
|
|
if (!Groups.ContainsKey(name)) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
return Groups[name]; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Shouldly; |
|
|
|
using Shouldly; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Authorization.Permissions; |
|
|
|
using Volo.Abp.Authorization.TestServices; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
@ -8,10 +9,12 @@ namespace Volo.Abp.Authorization |
|
|
|
public class Authorization_Tests : AuthorizationTestBase |
|
|
|
{ |
|
|
|
private readonly IMyAuthorizedService1 _myAuthorizedService1; |
|
|
|
private readonly IPermissionDefinitionManager _permissionDefinitionManager; |
|
|
|
|
|
|
|
public Authorization_Tests() |
|
|
|
{ |
|
|
|
_myAuthorizedService1 = GetRequiredService<IMyAuthorizedService1>(); |
|
|
|
_permissionDefinitionManager = GetRequiredService<IPermissionDefinitionManager>(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
@ -43,5 +46,11 @@ namespace Volo.Abp.Authorization |
|
|
|
{ |
|
|
|
(await _myAuthorizedService1.AnonymousAsync()).ShouldBe(42); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Permission_Definition_GetGroup() |
|
|
|
{ |
|
|
|
_permissionDefinitionManager.GetGroups().Count.ShouldBe(2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -6,7 +6,12 @@ namespace Volo.Abp.Authorization.TestServices |
|
|
|
{ |
|
|
|
public override void Define(IPermissionDefinitionContext context) |
|
|
|
{ |
|
|
|
var group = context.AddGroup("TestGroup"); |
|
|
|
PermissionGroupDefinition getGroup = context.GetGroupOrNull("TestGetGroup"); |
|
|
|
if (getGroup == null) |
|
|
|
{ |
|
|
|
getGroup = context.AddGroup("TestGetGroup"); |
|
|
|
} |
|
|
|
PermissionGroupDefinition group = context.AddGroup("TestGroup"); |
|
|
|
group.AddPermission("MyAuthorizedService1"); |
|
|
|
} |
|
|
|
} |
|
|
|
|