using MiGu.Server.Configs; namespace MiGu.Server.Auth; /// /// RBAC 角色。一个角色 = 一组「页面 + 操作码 + 控件可见性」授权,归属某个 scope。 /// /// Platform / RCSMonitor / *(通用,对两个 scope 都生效)。 /// :可访问页面 Key 集合(见 );含 * 表示该 scope 全部页面。 /// :细粒度操作码(如 ops.car.pause);含 * 表示全部操作。 /// :控件级可见性(hidden / readonly / interactive)。 /// :内置系统角色,禁止删除(可改名/调权限但保底不被误删)。 /// /// public sealed class RbacRole { public string Id { get; set; } = ""; public string Name { get; set; } = ""; public string Description { get; set; } = ""; public string Scope { get; set; } = PageCatalog.ScopePlatform; public List Pages { get; set; } = new(); public List Ops { get; set; } = new(); public List WidgetGrants { get; set; } = new(); public bool System { get; set; } } /// /// RBAC 用户。密码以 PBKDF2-SHA256 哈希存储( / 均为 base64)。 /// 一个用户可拥有多个角色,其有效权限 = 当前 scope 下各角色授权的并集。 /// public sealed class RbacUser { public string Id { get; set; } = ""; public string Username { get; set; } = ""; public string DisplayName { get; set; } = ""; public bool Enabled { get; set; } = true; public List RoleIds { get; set; } = new(); public string Salt { get; set; } = ""; public string PasswordHash { get; set; } = ""; } /// rbac.json 的根对象(内存 + 文件持久化)。 public sealed class RbacSnapshot { public int Version { get; set; } = 1; public List Roles { get; set; } = new(); public List Users { get; set; } = new(); } // ─────────────────────────── API DTO ─────────────────────────── /// 对外用户视图:绝不含 Salt / PasswordHash。 为该用户可登录的 scope 集合。 public sealed record RbacUserDto( string Id, string Username, string DisplayName, bool Enabled, List RoleIds, List Scopes); public sealed record CreateUserRequest( string Username, string? DisplayName, string Password, List? RoleIds, bool Enabled = true); public sealed record UpdateUserRequest( string? DisplayName, List? RoleIds, bool? Enabled); public sealed record SetPasswordRequest(string Password); public sealed record SaveRoleRequest( string? Id, string Name, string? Description, string Scope, List? Pages, List? Ops, List? WidgetGrants);