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; }