fix(系统设置): 项目级别用户组初始化基本信息权限

This commit is contained in:
song-cc-rock 2024-07-25 11:05:17 +08:00 committed by Craftsman
parent 81fc9ec069
commit a58083f3b1
2 changed files with 18 additions and 13 deletions

View File

@ -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

View File

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