|
@@ -24,22 +24,22 @@ namespace VCommon.VApplication.Authorization
|
|
|
|
|
|
public IReadOnlyCollection<PermissionNode> Roots => _roots;
|
|
|
|
|
|
- public PermissionNode CreateRootNode(string code, string name, string description = null, string nameForOperator = null, string descriptionForOperator = null, MultiTenancySides side = MultiTenancySides.Both)
|
|
|
+ public PermissionNode CreateRootNode(string code, string name, string description = null, string nameForOperator = null, string descriptionForOperator = null, MultiTenancySides side = MultiTenancySides.Both, object customData = null)
|
|
|
{
|
|
|
if (CodeHashSet.Contains(code)) throw new ArgumentException($"重复的权限代码:{code},名称:{name}");
|
|
|
- var node = new PermissionNode(this, code, name, description, nameForOperator, descriptionForOperator, side);
|
|
|
+ var node = new PermissionNode(this, code, name, description, nameForOperator, descriptionForOperator, side, customData);
|
|
|
_roots.Add(node);
|
|
|
_allNode.Add(node);
|
|
|
CodeHashSet.Add(code);
|
|
|
return node;
|
|
|
}
|
|
|
|
|
|
- public IReadOnlyCollection<PermissionNodeOutput> Filter(MultiTenancySides side, IReadOnlyCollection<string> licPerms)
|
|
|
+ public IReadOnlyCollection<PermissionNodeOutput> Filter(MultiTenancySides side, IReadOnlyCollection<string> licPerms, object customData = null)
|
|
|
{
|
|
|
- return FltTree(_roots, side, licPerms == null ? null : new HashSet<string>(licPerms));
|
|
|
+ return FltTree(_roots, side, licPerms == null ? null : new HashSet<string>(licPerms), customData: customData);
|
|
|
}
|
|
|
|
|
|
- private static IReadOnlyCollection<PermissionNodeOutput> FltTree(IReadOnlyCollection<PermissionNode> nodesFrom, MultiTenancySides side, IReadOnlySet<string> licPerms, List<PermissionNodeOutput> output = null)
|
|
|
+ private static IReadOnlyCollection<PermissionNodeOutput> FltTree(IReadOnlyCollection<PermissionNode> nodesFrom, MultiTenancySides side, IReadOnlySet<string> licPerms, List<PermissionNodeOutput> output = null, object customData = null)
|
|
|
{
|
|
|
output ??= new List<PermissionNodeOutput>();
|
|
|
|
|
@@ -49,6 +49,8 @@ namespace VCommon.VApplication.Authorization
|
|
|
|
|
|
if (node.TenancySide != MultiTenancySides.Both && node.TenancySide != side) continue;
|
|
|
|
|
|
+ if (customData == null || false == customData.Equals(node.CustomData)) continue;
|
|
|
+
|
|
|
var copy = side == MultiTenancySides.Tenant
|
|
|
? new PermissionNodeOutput(node.Code, node.Name, node.Description)
|
|
|
: new PermissionNodeOutput(node.Code, node.NameForOperator ?? node.Name, node.DescriptionForOperator ?? node.Description);
|
|
@@ -69,5 +71,13 @@ namespace VCommon.VApplication.Authorization
|
|
|
_codeHashSet = null;
|
|
|
return toReturn;
|
|
|
}
|
|
|
+
|
|
|
+ public void Lookup(Action<PermissionNode> visit)
|
|
|
+ {
|
|
|
+ foreach (var node in Roots)
|
|
|
+ {
|
|
|
+ node.Traverse(visit);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|