PermissionNode.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. namespace VCommon.VApplication.Authorization
  4. {
  5. public class PermissionNode
  6. {
  7. private readonly PermissionTree _tree;
  8. private readonly List<PermissionNode> _children = new List<PermissionNode>();
  9. /// <summary>
  10. /// 权限代码, 产品内唯一
  11. /// </summary>
  12. public string Code { get; }
  13. /// <summary>
  14. /// 面向用户的显示名称
  15. /// </summary>
  16. public string Name { get; }
  17. /// <summary>
  18. /// 面向用户的描述
  19. /// </summary>
  20. public string Description { get; }
  21. /// <summary>
  22. /// 面向运营商的显示名称
  23. /// </summary>
  24. public string NameForOperator { get; }
  25. /// <summary>
  26. /// 面向运营商的描述
  27. /// </summary>
  28. public string DescriptionForOperator { get; }
  29. public MultiTenancySides TenancySide { get; }
  30. public IReadOnlyList<PermissionNode> Children => _children;
  31. internal PermissionNode(PermissionTree tree, string code, string name, string description, string nameForOperator, string descriptionForOperator, MultiTenancySides side = MultiTenancySides.Both)
  32. {
  33. _tree = tree;
  34. Code = code;
  35. Name = name;
  36. Description = description;
  37. NameForOperator = nameForOperator;
  38. DescriptionForOperator = descriptionForOperator;
  39. TenancySide = side;
  40. }
  41. public PermissionNode CreateChildNode(string code, string name, string description = null, string nameForOperator = null, string descriptionForOperator = null, MultiTenancySides side = MultiTenancySides.Both)
  42. {
  43. if (_tree.CodeHashSet.Contains(code)) throw new ArgumentException($"重复的权限代码:{code},名称:{name}");
  44. var node = new PermissionNode(_tree, code, name, description, nameForOperator, descriptionForOperator, side);
  45. _children.Add(node);
  46. _tree._allNode.Add(node);
  47. _tree.CodeHashSet.Add(code);
  48. return node;
  49. }
  50. }
  51. }