From a58083f3b1d1c5e3ef114c54385a53e99e87b3ed Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Thu, 25 Jul 2024 11:05:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BA=A7=E5=88=AB=E7=94=A8=E6=88=B7=E7=BB=84?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=9F=BA=E6=9C=AC=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/service/ProjectUserRoleService.java | 14 +++++--------- .../system/service/BaseUserRoleService.java | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java index 1f23969791..c999edc04b 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java @@ -12,7 +12,10 @@ import io.metersphere.sdk.constants.InternalUserRole; import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.Translator; -import io.metersphere.system.domain.*; +import io.metersphere.system.domain.User; +import io.metersphere.system.domain.UserRole; +import io.metersphere.system.domain.UserRoleRelation; +import io.metersphere.system.domain.UserRoleRelationExample; import io.metersphere.system.dto.permission.PermissionDefinitionItem; import io.metersphere.system.dto.sdk.request.PermissionSettingUpdateRequest; import io.metersphere.system.mapper.UserRoleMapper; @@ -82,14 +85,7 @@ public class ProjectUserRoleService extends BaseUserRoleService { userRole.setInternal(false); userRole.setType(UserRoleType.PROJECT.name()); checkNewRoleExist(userRole); - UserRole role = super.add(userRole); - // 初始化项目-基本信息权限 - UserRolePermission initPermission = new UserRolePermission(); - initPermission.setId(IDGenerator.nextStr()); - initPermission.setRoleId(role.getId()); - initPermission.setPermissionId("PROJECT_BASE_INFO:READ"); - userRolePermissionMapper.insert(initPermission); - return role; + return super.add(userRole); } @Override 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 a801b1202e..755ba8fbab 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 @@ -2,19 +2,18 @@ package io.metersphere.system.service; import io.metersphere.sdk.constants.InternalUserRole; import io.metersphere.sdk.constants.UserRoleEnum; +import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; import io.metersphere.system.config.PermissionCache; -import io.metersphere.system.domain.User; -import io.metersphere.system.domain.UserRole; -import io.metersphere.system.domain.UserRoleExample; -import io.metersphere.system.domain.UserRoleRelation; +import io.metersphere.system.domain.*; import io.metersphere.system.dto.permission.Permission; import io.metersphere.system.dto.permission.PermissionDefinitionItem; import io.metersphere.system.dto.sdk.request.PermissionSettingUpdateRequest; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserRoleMapper; +import io.metersphere.system.mapper.UserRolePermissionMapper; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.utils.ServiceUtils; import jakarta.annotation.Resource; @@ -42,6 +41,8 @@ public class BaseUserRoleService { @Resource private UserRoleMapper userRoleMapper; @Resource + private UserRolePermissionMapper userRolePermissionMapper; + @Resource private UserMapper userMapper; @Resource protected BaseUserRolePermissionService baseUserRolePermissionService; @@ -141,6 +142,14 @@ public class BaseUserRoleService { userRole.setCreateTime(System.currentTimeMillis()); userRole.setUpdateTime(System.currentTimeMillis()); userRoleMapper.insert(userRole); + if (StringUtils.equals(userRole.getType(), UserRoleType.PROJECT.name())) { + // 项目级别用户组, 初始化基本信息权限 + UserRolePermission initPermission = new UserRolePermission(); + initPermission.setId(IDGenerator.nextStr()); + initPermission.setRoleId(userRole.getId()); + initPermission.setPermissionId("PROJECT_BASE_INFO:READ"); + userRolePermissionMapper.insert(initPermission); + } return userRole; }