mirror of https://github.com/abpframework/abp.git
14 changed files with 226 additions and 183 deletions
@ -1,6 +1,8 @@ |
|||
namespace Volo.Abp.Permissions |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Permissions |
|||
{ |
|||
public interface IPermissionDefinitionProvider |
|||
public interface IPermissionDefinitionProvider : ISingletonDependency |
|||
{ |
|||
void Define(IPermissionDefinitionContext context); |
|||
} |
|||
|
|||
@ -1,8 +1,6 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Permissions |
|||
namespace Volo.Abp.Permissions |
|||
{ |
|||
public abstract class PermissionDefinitionProvider : IPermissionDefinitionProvider, ISingletonDependency |
|||
public abstract class PermissionDefinitionProvider : IPermissionDefinitionProvider |
|||
{ |
|||
public abstract void Define(IPermissionDefinitionContext context); |
|||
} |
|||
|
|||
@ -0,0 +1,76 @@ |
|||
using System.Collections.Generic; |
|||
using System.Collections.Immutable; |
|||
|
|||
namespace Volo.Abp.Permissions |
|||
{ |
|||
public class PermissionGroupDefinition //TODO: Consider to make possible a group have sub groups
|
|||
{ |
|||
/// <summary>
|
|||
/// Unique name of the group.
|
|||
/// </summary>
|
|||
public string Name { get; } |
|||
|
|||
public Dictionary<string, object> Properties { get; } |
|||
|
|||
public IReadOnlyList<PermissionDefinition> Permissions => _permissions.ToImmutableList(); |
|||
private readonly List<PermissionDefinition> _permissions; |
|||
|
|||
/// <summary>
|
|||
/// Gets/sets a key-value on the <see cref="Properties"/>.
|
|||
/// </summary>
|
|||
/// <param name="name">Name of the property</param>
|
|||
/// <returns>
|
|||
/// Returns the value in the <see cref="Properties"/> dictionary by given <see cref="name"/>.
|
|||
/// Returns null if given <see cref="name"/> is not present in the <see cref="Properties"/> dictionary.
|
|||
/// </returns>
|
|||
public object this[string name] |
|||
{ |
|||
get => Properties.GetOrDefault(name); |
|||
set => Properties[name] = value; |
|||
} |
|||
|
|||
protected internal PermissionGroupDefinition(string name) |
|||
{ |
|||
Name = name; |
|||
|
|||
Properties = new Dictionary<string, object>(); |
|||
_permissions = new List<PermissionDefinition>(); |
|||
} |
|||
|
|||
public virtual PermissionDefinition AddPermission(string name) |
|||
{ |
|||
var permission = new PermissionDefinition(name); |
|||
|
|||
_permissions.Add(permission); |
|||
|
|||
return permission; |
|||
} |
|||
|
|||
public virtual List<PermissionDefinition> GetPermissionsWithChildren() |
|||
{ |
|||
var permissions = new List<PermissionDefinition>(); |
|||
|
|||
foreach (var permission in _permissions) |
|||
{ |
|||
AddPermissionToListRecursively(permissions, permission); |
|||
} |
|||
|
|||
return permissions; |
|||
} |
|||
|
|||
private void AddPermissionToListRecursively(List<PermissionDefinition> permissions, PermissionDefinition permission) |
|||
{ |
|||
permissions.Add(permission); |
|||
|
|||
foreach (var child in permission.Children) |
|||
{ |
|||
AddPermissionToListRecursively(permissions, child); |
|||
} |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"[{nameof(PermissionGroupDefinition)} {Name}]"; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue