From 19f7977fe9cad6a1af58e30e54a7c634b51b3662 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Thu, 17 Oct 2024 13:39:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BB=84=E6=9D=83=E9=99=90=E4=BD=8D&&?= =?UTF-8?q?=E6=9D=83=E9=99=90=E4=BD=8D=E6=B7=BB=E5=8A=A0=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --task=1016517 --user=宋昌昌 用户组优化 https://www.tapd.cn/55049933/s/1593255 --- .../api-test/src/main/resources/permission.json | 3 ++- .../src/main/resources/permission.json | 3 ++- .../src/main/resources/permission.json | 3 ++- .../src/main/resources/permission.json | 6 ++++-- .../dto/permission/PermissionDefinitionItem.java | 2 ++ .../system/service/BaseUserRoleService.java | 12 ++++++++---- .../src/main/resources/permission.json | 9 ++++++--- .../controller/GlobalUserRoleControllerTests.java | 5 ----- .../test-plan/src/main/resources/permission.json | 3 ++- 9 files changed, 28 insertions(+), 18 deletions(-) diff --git a/backend/services/api-test/src/main/resources/permission.json b/backend/services/api-test/src/main/resources/permission.json index ec014f571a..8efc32e5a9 100644 --- a/backend/services/api-test/src/main/resources/permission.json +++ b/backend/services/api-test/src/main/resources/permission.json @@ -160,6 +160,7 @@ } ] } - ] + ], + "order": 7 } ] \ No newline at end of file diff --git a/backend/services/bug-management/src/main/resources/permission.json b/backend/services/bug-management/src/main/resources/permission.json index 0c5c982b84..dcb61eb359 100644 --- a/backend/services/bug-management/src/main/resources/permission.json +++ b/backend/services/bug-management/src/main/resources/permission.json @@ -30,6 +30,7 @@ } ] } - ] + ], + "order": 8 } ] \ No newline at end of file diff --git a/backend/services/case-management/src/main/resources/permission.json b/backend/services/case-management/src/main/resources/permission.json index 0bb76eb3ea..d07c25a354 100644 --- a/backend/services/case-management/src/main/resources/permission.json +++ b/backend/services/case-management/src/main/resources/permission.json @@ -63,6 +63,7 @@ } ] } - ] + ], + "order": 6 } ] diff --git a/backend/services/project-management/src/main/resources/permission.json b/backend/services/project-management/src/main/resources/permission.json index bdb26b2d3b..3a64414e67 100644 --- a/backend/services/project-management/src/main/resources/permission.json +++ b/backend/services/project-management/src/main/resources/permission.json @@ -204,7 +204,8 @@ } ] } - ] + ], + "order": 4 }, { "id": "PROJECT_TASK_CENTER", @@ -242,6 +243,7 @@ } ] } - ] + ], + "order": 9 } ] \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/permission/PermissionDefinitionItem.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/permission/PermissionDefinitionItem.java index 8e007cf4a0..c21ad96c2f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/permission/PermissionDefinitionItem.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/permission/PermissionDefinitionItem.java @@ -25,4 +25,6 @@ public class PermissionDefinitionItem { private List permissions; @Schema(description = "子菜单") private List children; + @Schema(description = "排序") + private Integer order; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseUserRoleService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseUserRoleService.java index 755ba8fbab..61da37b6bc 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseUserRoleService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseUserRoleService.java @@ -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 { // 如果权限有未勾选,则二级菜单设置为未勾选 diff --git a/backend/services/system-setting/src/main/resources/permission.json b/backend/services/system-setting/src/main/resources/permission.json index 5f39647acf..cd81d8eefb 100644 --- a/backend/services/system-setting/src/main/resources/permission.json +++ b/backend/services/system-setting/src/main/resources/permission.json @@ -231,7 +231,8 @@ } ] } - ] + ], + "order": 1 }, { "id": "ORGANIZATION", @@ -395,7 +396,8 @@ } ] } - ] + ], + "order": 3 }, { "id": "PERSONAL", @@ -420,6 +422,7 @@ } ] } - ] + ], + "order": 2 } ] diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/GlobalUserRoleControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/GlobalUserRoleControllerTests.java index d6ee601a07..6a551e6103 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/GlobalUserRoleControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/GlobalUserRoleControllerTests.java @@ -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)); diff --git a/backend/services/test-plan/src/main/resources/permission.json b/backend/services/test-plan/src/main/resources/permission.json index f40036a5e1..2125030e64 100644 --- a/backend/services/test-plan/src/main/resources/permission.json +++ b/backend/services/test-plan/src/main/resources/permission.json @@ -51,6 +51,7 @@ } ] } - ] + ], + "order": 5 } ]