S8ExceptionActionCatalog.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. namespace Admin.NET.Plugin.AiDOP.Const.S8;
  2. /// <summary>
  3. /// S8-ACTION-PERMISSION-1:异常单「操作」的规范编码。
  4. ///
  5. /// <para><b>每一条都对应一个真实存在的 API</b>(见 <see cref="S8ExceptionActionCatalog.All"/> 里的
  6. /// <c>ApiHint</c>)。刻意<b>不</b>凭空造 <c>EXCEPTION_CLOSE</c> 之类的动作 ——
  7. /// S8 没有独立的「关闭」接口,关闭是 <c>approve-verification</c> 通过后的状态机结果,
  8. /// 给它一个可配置的权限位只会让管理员配了一个永远不会被检查的开关。</para>
  9. /// </summary>
  10. public static class S8ExceptionActionCode
  11. {
  12. /// <summary>查看异常(列表 / 详情 / 时间线 / 决策 / 证据 / 筛选项)。</summary>
  13. public const string View = "EXCEPTION_VIEW";
  14. /// <summary>
  15. /// 查看全部异常(跨规则责任池)。
  16. /// <para>在 P1-B 建立配置位,由 P1-C 的可见性收敛真正消费 ——
  17. /// 届时「非责任池成员」将只能看到自己有责任的规则所产生的异常。</para>
  18. /// </summary>
  19. public const string ViewAll = "EXCEPTION_VIEW_ALL";
  20. /// <summary>人工提报异常(<c>POST /reports</c>)。</summary>
  21. public const string Create = "EXCEPTION_CREATE";
  22. /// <summary>认领(<c>POST {id}/claim</c>)。处理人恒为当前登录账号。</summary>
  23. public const string Claim = "EXCEPTION_CLAIM";
  24. /// <summary>转派 / 指派他人(<c>POST {id}/transfer</c>)。与认领分开,权限强于认领。</summary>
  25. public const string Transfer = "EXCEPTION_TRANSFER";
  26. /// <summary>开始处理(<c>POST {id}/start-progress</c>)。</summary>
  27. public const string Start = "EXCEPTION_START";
  28. /// <summary>提交复核(<c>POST {id}/submit-verification</c>)。</summary>
  29. public const string SubmitVerify = "EXCEPTION_SUBMIT_VERIFY";
  30. /// <summary>审核通过 / 退回(<c>POST {id}/approve-verification</c> · <c>{id}/reject-verification</c>)。</summary>
  31. public const string Verify = "EXCEPTION_VERIFY";
  32. /// <summary>升级(<c>POST {id}/upgrade</c>)。</summary>
  33. public const string Upgrade = "EXCEPTION_UPGRADE";
  34. /// <summary>驳回(<c>POST {id}/reject</c>)。</summary>
  35. public const string Reject = "EXCEPTION_REJECT";
  36. /// <summary>补充说明(<c>POST {id}/comment</c>)。</summary>
  37. public const string Comment = "EXCEPTION_COMMENT";
  38. }
  39. /// <summary>一个可配置动作的元信息。</summary>
  40. public sealed record S8ExceptionActionDefinition(
  41. string Code,
  42. string DisplayName,
  43. string ApiHint,
  44. /// <summary>
  45. /// 该动作在<b>旧权限体系</b>中的对应能力码(<c>SysMenu.Permission</c>)。
  46. /// 仅供首次 Provisioning 推导默认值使用 —— 让「本租户原本谁能做」原样延续,
  47. /// 而不是拍脑袋给一套新默认。为 null 表示旧体系里没有对应位(如 ViewAll)。
  48. /// </summary>
  49. string? LegacyPermissionCode,
  50. /// <summary>
  51. /// 该动作还等价于哪些旧能力码(并集推导)。例如「审核」在旧体系里被拆成
  52. /// approve / reject 两个码,任一持有即视为拥有审核能力。
  53. /// </summary>
  54. string[] LegacyPermissionAliases,
  55. int OrderNo);
  56. /// <summary>
  57. /// 动作目录。<b>这是「S8 异常单到底有哪些可授权动作」的唯一出处</b> ——
  58. /// 后端授权、Provisioning 默认值、前端权限矩阵三方共用同一份,
  59. /// 避免出现「页面上能配、后端根本不检查」或反之。
  60. /// </summary>
  61. public static class S8ExceptionActionCatalog
  62. {
  63. public static readonly IReadOnlyList<S8ExceptionActionDefinition> All = new List<S8ExceptionActionDefinition>
  64. {
  65. new(S8ExceptionActionCode.View, "查看异常", "GET /exceptions · {id} · timeline · decisions · evidences",
  66. S8PermissionCatalog.ExceptionRead, Array.Empty<string>(), 10),
  67. new(S8ExceptionActionCode.ViewAll, "查看全部异常", "(P1-C 可见性收敛消费)",
  68. null, Array.Empty<string>(), 20),
  69. new(S8ExceptionActionCode.Create, "提报异常", "POST /reports",
  70. S8PermissionCatalog.ExceptionCreate, Array.Empty<string>(), 30),
  71. new(S8ExceptionActionCode.Claim, "认领", "POST /exceptions/{id}/claim",
  72. S8PermissionCatalog.ExceptionClaim, Array.Empty<string>(), 40),
  73. new(S8ExceptionActionCode.Transfer, "转派", "POST /exceptions/{id}/transfer",
  74. S8PermissionCatalog.ExceptionAssign, Array.Empty<string>(), 50),
  75. new(S8ExceptionActionCode.Start, "开始处理", "POST /exceptions/{id}/start-progress",
  76. S8PermissionCatalog.ExceptionStart, Array.Empty<string>(), 60),
  77. new(S8ExceptionActionCode.SubmitVerify, "提交复核", "POST /exceptions/{id}/submit-verification",
  78. S8PermissionCatalog.VerificationSubmit, Array.Empty<string>(), 70),
  79. new(S8ExceptionActionCode.Verify, "审核(通过 / 退回)",
  80. "POST /exceptions/{id}/approve-verification · reject-verification",
  81. S8PermissionCatalog.VerificationApprove,
  82. new[] { S8PermissionCatalog.VerificationReject }, 80),
  83. new(S8ExceptionActionCode.Upgrade, "升级", "POST /exceptions/{id}/upgrade",
  84. S8PermissionCatalog.ExceptionUpgrade, Array.Empty<string>(), 90),
  85. new(S8ExceptionActionCode.Reject, "驳回", "POST /exceptions/{id}/reject",
  86. S8PermissionCatalog.ExceptionReject, Array.Empty<string>(), 100),
  87. new(S8ExceptionActionCode.Comment, "补充说明", "POST /exceptions/{id}/comment",
  88. S8PermissionCatalog.ExceptionComment, Array.Empty<string>(), 110),
  89. };
  90. private static readonly Dictionary<string, S8ExceptionActionDefinition> ByCode =
  91. All.ToDictionary(x => x.Code, StringComparer.OrdinalIgnoreCase);
  92. /// <summary>动作码是否在目录中。<b>不在目录 = 未知动作 = 一律拒绝</b>(fail closed)。</summary>
  93. public static bool IsKnown(string? code) =>
  94. !string.IsNullOrWhiteSpace(code) && ByCode.ContainsKey(code!);
  95. public static S8ExceptionActionDefinition? Find(string? code) =>
  96. string.IsNullOrWhiteSpace(code) ? null : ByCode.GetValueOrDefault(code!);
  97. }