| 12345678910111213141516171819202122232425262728 |
- namespace Admin.NET.Plugin.AiDOP.Infrastructure;
- /// <summary>
- /// 严格租户解析:只信认证后的 JWT。无有效租户或超管未选目标租户则抛异常。
- /// 业务数据的查询与写入一律用 <see cref="ResolveOrThrow"/>。
- /// </summary>
- public static class AidopTenantScope
- {
- /// <summary>
- /// 超管未选目标租户时的拒绝哨兵(框架默认租户)。绝不作为业务数据归属。
- /// </summary>
- public static long MainTenantId => SqlSugarConst.DefaultTenantId;
- /// <summary>
- /// 严格可信租户解析:只来自认证后 JWT;无 Token(<=0) 或超管未选主租户 → 拒绝;
- /// 不读前端 tenantId、无默认回退。
- /// </summary>
- public static long ResolveOrThrow(UserManager userManager)
- {
- ArgumentNullException.ThrowIfNull(userManager);
- var tid = userManager.TenantId;
- if (tid <= 0)
- throw Oops.Oh("无法确定当前租户,请重新登录或选择目标租户");
- if (userManager.SuperAdmin && tid == MainTenantId)
- throw Oops.Oh("超级管理员操作前必须选择目标租户");
- return tid;
- }
- }
|