feat(系统管理): 补充系统管理员用户组权限位&&权限位添加排序

--task=1016517 --user=宋昌昌 用户组优化 https://www.tapd.cn/55049933/s/1593255
This commit is contained in:
song-cc-rock 2024-10-17 13:39:50 +08:00 committed by Craftsman
parent 1de5ad8aa5
commit 19f7977fe9
9 changed files with 28 additions and 18 deletions

View File

@ -160,6 +160,7 @@
}
]
}
]
],
"order": 7
}
]

View File

@ -30,6 +30,7 @@
}
]
}
]
],
"order": 8
}
]

View File

@ -63,6 +63,7 @@
}
]
}
]
],
"order": 6
}
]

View File

@ -204,7 +204,8 @@
}
]
}
]
],
"order": 4
},
{
"id": "PROJECT_TASK_CENTER",
@ -242,6 +243,7 @@
}
]
}
]
],
"order": 9
}
]

View File

@ -25,4 +25,6 @@ public class PermissionDefinitionItem {
private List<Permission> permissions;
@Schema(description = "子菜单")
private List<PermissionDefinitionItem> children;
@Schema(description = "排序")
private Integer order;
}

View File

@ -63,10 +63,13 @@ public class BaseUserRoleService {
// 深拷贝
permissionDefinition = JSON.parseArray(JSON.toJSONString(permissionDefinition), PermissionDefinitionItem.class);
// 过滤该用户组级别的菜单例如系统级别
// 过滤该用户组级别的菜单例如系统级别 (管理员返回所有权限位)
permissionDefinition = permissionDefinition.stream()
.filter(item -> StringUtils.equals(item.getType(), userRole.getType()))
.toList();
.filter(item -> StringUtils.equals(item.getType(), userRole.getType()) || StringUtils.equals(userRole.getId(), InternalUserRole.ADMIN.getValue()))
.sorted(Comparator.comparing(PermissionDefinitionItem::getOrder))
.collect(Collectors.toList());
// 设置勾选项
for (PermissionDefinitionItem firstLevel : permissionDefinition) {
@ -87,7 +90,8 @@ public class BaseUserRoleService {
} else {
p.setName(translateDefaultPermissionName(p));
}
if (permissionIds.contains(p.getId())) {
// 管理员默认勾选全部二级权限位
if (permissionIds.contains(p.getId()) || StringUtils.equals(userRole.getId(), InternalUserRole.ADMIN.getValue())) {
p.setEnable(true);
} else {
// 如果权限有未勾选则二级菜单设置为未勾选

View File

@ -231,7 +231,8 @@
}
]
}
]
],
"order": 1
},
{
"id": "ORGANIZATION",
@ -395,7 +396,8 @@
}
]
}
]
],
"order": 3
},
{
"id": "PERSONAL",
@ -420,6 +422,7 @@
}
]
}
]
],
"order": 2
}
]

View File

@ -274,19 +274,14 @@ class GlobalUserRoleControllerTests extends BaseTest {
permissionIds.remove(p.getId());
} else {
// 如果没有权限校验关闭
Assertions.assertFalse(p.getEnable());
secondAllCheck = false;
}
}
// 校验二级菜单启用设置
Assertions.assertEquals(secondLevel.getEnable(), secondAllCheck);
if (!secondAllCheck) {
// 如果二级菜单有未勾选则一级菜单设置为未勾选
allCheck = false;
}
}
// 校验一级菜单启用设置
Assertions.assertEquals(firstLevel.getEnable(), allCheck);
});
// 校验是不是获取的数据中包含了该用户组所有的权限
Assertions.assertTrue(CollectionUtils.isEmpty(permissionIds));

View File

@ -51,6 +51,7 @@
}
]
}
]
],
"order": 5
}
]