fix: 全局权限优化 — 7 项问题修复
1. 菜单权限修复:补充 10 个菜单的 permission 字段 + 修复 menu_service
回退逻辑(admin 直接跳过过滤,非 admin 无关联则不显示)+ 收紧前端过滤
2. 管理员重置密码:新增 POST /users/{id}/reset-password 端点 + 前端按钮
3. 告警处理人姓名:AlertResponse 添加 acknowledged_by_name 字段
4. Tab 权限过滤:PatientDetail 6 个 Tab 按权限过滤 + 状态字段 Tooltip
5. 消息中心 UI:添加 Popconfirm/AuthButton,移除 inline isDark
This commit is contained in:
@@ -49,20 +49,33 @@ impl MenuService {
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// 获取当前租户下指定角色可见的菜单树。
|
||||
///
|
||||
/// `role_codes` 为当前用户的角色 code 列表(如 ["admin"]、["doctor"])。
|
||||
/// 方法内部将 code 转换为 ID,再通过 menu_roles 表过滤。
|
||||
/// 如果角色没有任何菜单关联,返回全部菜单(admin 兜底)。
|
||||
pub async fn get_menu_tree(
|
||||
tenant_id: Uuid,
|
||||
role_codes: &[String],
|
||||
db: &sea_orm::DatabaseConnection,
|
||||
) -> ConfigResult<Vec<MenuResp>> {
|
||||
// 0. 将角色 code 转换为 UUID
|
||||
// 0. admin 角色直接返回全部菜单,跳过 menu_roles 过滤
|
||||
if role_codes.iter().any(|c| c == "admin") {
|
||||
let all_menus = menu::Entity::find()
|
||||
.filter(menu::Column::TenantId.eq(tenant_id))
|
||||
.filter(menu::Column::DeletedAt.is_null())
|
||||
.order_by_asc(menu::Column::SortOrder)
|
||||
.all(db)
|
||||
.await
|
||||
.map_err(|e| ConfigError::Validation(e.to_string()))?;
|
||||
|
||||
let mut children_map: HashMap<Option<Uuid>, Vec<&menu::Model>> = HashMap::new();
|
||||
for m in &all_menus {
|
||||
children_map.entry(m.parent_id).or_default().push(m);
|
||||
}
|
||||
let roots = children_map.get(&None).cloned().unwrap_or_default();
|
||||
return Ok(Self::build_tree(&roots, &children_map));
|
||||
}
|
||||
|
||||
// 1. 将角色 code 转换为 UUID
|
||||
let role_ids = Self::resolve_role_ids(tenant_id, role_codes, db).await?;
|
||||
|
||||
// 1. 查询租户下所有未删除的菜单,按 sort_order 排序
|
||||
// 2. 查询租户下所有未删除的菜单,按 sort_order 排序
|
||||
let all_menus = menu::Entity::find()
|
||||
.filter(menu::Column::TenantId.eq(tenant_id))
|
||||
.filter(menu::Column::DeletedAt.is_null())
|
||||
@@ -71,7 +84,7 @@ impl MenuService {
|
||||
.await
|
||||
.map_err(|e| ConfigError::Validation(e.to_string()))?;
|
||||
|
||||
// 2. 如果 role_ids 非空,通过 menu_roles 表过滤
|
||||
// 3. 通过 menu_roles 表过滤
|
||||
let visible_menu_ids: Option<Vec<Uuid>> = if !role_ids.is_empty() {
|
||||
let mr_rows = menu_role::Entity::find()
|
||||
.filter(menu_role::Column::TenantId.eq(tenant_id))
|
||||
@@ -83,14 +96,12 @@ impl MenuService {
|
||||
|
||||
let ids: Vec<Uuid> = mr_rows.iter().map(|mr| mr.menu_id).collect();
|
||||
if ids.is_empty() {
|
||||
// 角色未关联菜单时回退到显示全部菜单,
|
||||
// 避免种子数据阶段 menu_roles 为空导致所有有角色用户看不到菜单
|
||||
None
|
||||
Some(vec![]) // 无菜单关联 = 不显示
|
||||
} else {
|
||||
Some(ids)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
Some(vec![]) // 无角色 = 不显示任何菜单
|
||||
};
|
||||
|
||||
// 3. 按 parent_id 分组构建 HashMap
|
||||
|
||||
Reference in New Issue
Block a user