fix(系统设置): 用户组添加用户接口参数和操作日志优化
--task=1012267 --user=陈建星 用户组管理-后台 https://www.tapd.cn/55049933/s/1398948
This commit is contained in:
parent
407039162c
commit
f7f380d0b3
|
@ -0,0 +1,5 @@
|
|||
package io.metersphere.sdk.constants;
|
||||
|
||||
public class OperationLogConstants {
|
||||
public static final String SYSTEM = "SYSTEM";
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package io.metersphere.sdk.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OptionDTO {
|
||||
private String id;
|
||||
private String name;
|
||||
}
|
|
@ -3,10 +3,14 @@ package io.metersphere.sdk.dto.request;
|
|||
import io.metersphere.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
*/
|
||||
|
@ -14,12 +18,19 @@ import lombok.Data;
|
|||
public class GlobalUserRoleRelationUpdateRequest {
|
||||
|
||||
@Schema(title = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{user_role_relation.user_id.not_blank}", groups = {Created.class})
|
||||
@NotEmpty(message = "{user_role_relation.user_id.not_blank}", groups = {Created.class, Updated.class})
|
||||
@Valid
|
||||
private List<
|
||||
@NotBlank(message = "{user_role_relation.user_id.not_blank}", groups = {Created.class, Updated.class})
|
||||
@Size(min = 1, max = 50, message = "{user_role_relation.user_id.length_range}", groups = {Created.class, Updated.class})
|
||||
private String userId;
|
||||
String
|
||||
> userIds;
|
||||
|
||||
@Schema(title = "组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{user_role_relation.role_id.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 50, message = "{user_role_relation.role_id.length_range}", groups = {Created.class, Updated.class})
|
||||
private String roleId;
|
||||
|
||||
@Schema(hidden = true)
|
||||
private String createUser;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.sdk.util.JSON;
|
|||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.SessionUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -22,12 +23,12 @@ import org.springframework.expression.ExpressionParser;
|
|||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -223,6 +224,8 @@ public class OperationLogAspect {
|
|||
logDTO.setCreateUser(StringUtils.defaultIfBlank(logDTO.getCreateUser(), localUser.get()));
|
||||
logDTO.setOrganizationId(StringUtils.defaultIfBlank(logDTO.getOrganizationId(), localOrganizationId.get()));
|
||||
logDTO.setProjectId(StringUtils.defaultIfBlank(logDTO.getProjectId(), localProjectId.get()));
|
||||
logDTO.setMethod(getMethod());
|
||||
logDTO.setPath(getPath());
|
||||
});
|
||||
|
||||
// 单条存储
|
||||
|
@ -273,4 +276,23 @@ public class OperationLogAspect {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected String getPath() {
|
||||
HttpServletRequest httpRequest = getHttpRequest();
|
||||
String path = httpRequest == null ? StringUtils.EMPTY : httpRequest.getRequestURI();
|
||||
return path.length() > 255 ? path.substring(0, 255) : path;
|
||||
}
|
||||
|
||||
protected String getMethod() {
|
||||
HttpServletRequest httpRequest = getHttpRequest();
|
||||
return httpRequest == null ? StringUtils.EMPTY : httpRequest.getMethod();
|
||||
}
|
||||
|
||||
private HttpServletRequest getHttpRequest() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes == null) {
|
||||
return null;
|
||||
}
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ package io.metersphere.sdk.log.service;
|
|||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.sdk.domain.OperationLogBlob;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.sdk.dto.OptionDTO;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.log.vo.OperationLogRequest;
|
||||
import io.metersphere.sdk.log.vo.OperationLogResponse;
|
||||
import io.metersphere.sdk.mapper.*;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.Organization;
|
||||
import io.metersphere.system.domain.User;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -105,8 +105,8 @@ public class OperationLogService {
|
|||
List<String> userIds = list.stream().map(OperationLogResponse::getCreateUser).collect(Collectors.toList());
|
||||
List<String> projectIds = list.stream().map(OperationLogResponse::getProjectId).collect(Collectors.toList());
|
||||
List<String> organizationIds = list.stream().map(OperationLogResponse::getOrganizationId).collect(Collectors.toList());
|
||||
List<User> userList = baseUserMapper.selectUserByIdList(userIds);
|
||||
Map<String, String> userMap = userList.stream().collect(Collectors.toMap(User::getId, User::getName));
|
||||
List<OptionDTO> userList = baseUserMapper.selectUserOptionByIds(userIds);
|
||||
Map<String, String> userMap = userList.stream().collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName));
|
||||
List<Project> projects = baseProjectMapper.selectProjectByIdList(projectIds);
|
||||
Map<String, String> projectMap = projects.stream().collect(Collectors.toMap(Project::getId, Project::getName));
|
||||
List<Organization> organizations = baseOrganizationMapper.selectOrganizationByIdList(organizationIds);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.metersphere.sdk.mapper;
|
||||
|
||||
import io.metersphere.sdk.dto.OptionDTO;
|
||||
import io.metersphere.sdk.dto.UserDTO;
|
||||
import io.metersphere.system.domain.User;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
@ -25,7 +26,6 @@ public interface BaseUserMapper {
|
|||
|
||||
List<String> selectUnDeletedUserIdByIdList(@Param("idList") List<String> userIdList);
|
||||
|
||||
List<User> selectUserByIdList(List<String> userIds);
|
||||
|
||||
long deleteUser(String id);
|
||||
List<OptionDTO> selectUserOptionByIds(List<String> userIds);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectUserByIdList" resultType="io.metersphere.system.domain.User">
|
||||
<select id="selectUserOptionByIds" resultType="io.metersphere.sdk.dto.OptionDTO">
|
||||
SELECT id, name
|
||||
FROM user
|
||||
WHERE id IN
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package base.param;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
*/
|
||||
public class NotEmptyParamGenerator extends ParamGenerator {
|
||||
|
||||
/**
|
||||
* 生成空字符串
|
||||
*/
|
||||
@Override
|
||||
public Object invalidGenerate(Annotation annotation, Field field) {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ public class ParamGeneratorFactory {
|
|||
private static final Map<String, ParamGenerator> paramGeneratorMap = new HashMap<>() {{
|
||||
put(Size.class.getName(), new SizeParamGenerator());
|
||||
put(NotBlank.class.getName(), new NotBlankParamGenerator());
|
||||
put(NotEmpty.class.getName(), new NotEmptyParamGenerator());
|
||||
put(NotNull.class.getName(), new NotNullParamGenerator());
|
||||
put(EnumValue.class.getName(), new EnumValueParamGenerator());
|
||||
put(Min.class.getName(), new MinParamGenerator());
|
||||
|
|
|
@ -7,11 +7,9 @@ import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
|||
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
||||
import io.metersphere.sdk.log.annotation.Log;
|
||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.PageUtils;
|
||||
import io.metersphere.sdk.util.Pager;
|
||||
import io.metersphere.sdk.util.SessionUtils;
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||
import io.metersphere.system.service.GlobalUserRoleRelationLogService;
|
||||
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
||||
|
@ -49,11 +47,9 @@ public class GlobalUserRoleRelationController {
|
|||
@Operation(summary = "创建全局用户组和用户的关联关系")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_UPDATE)
|
||||
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = GlobalUserRoleRelationLogService.class)
|
||||
public UserRoleRelation add(@Validated({Created.class}) @RequestBody GlobalUserRoleRelationUpdateRequest request) {
|
||||
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
||||
BeanUtils.copyBean(userRoleRelation, request);
|
||||
userRoleRelation.setCreateUser(SessionUtils.getUserId());
|
||||
return globalUserRoleRelationService.add(userRoleRelation);
|
||||
public void add(@Validated({Created.class}) @RequestBody GlobalUserRoleRelationUpdateRequest request) {
|
||||
request.setCreateUser(SessionUtils.getUserId());
|
||||
globalUserRoleRelationService.add(request);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.sdk.log.constants.OperationLogModule;
|
||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||
|
@ -18,8 +19,6 @@ public class AuthSourceLogService {
|
|||
@Resource
|
||||
private AuthSourceMapper authSourceMapper;
|
||||
|
||||
private static final String PRE_URI = "/system/authsource";
|
||||
|
||||
/**
|
||||
* 添加接口日志
|
||||
*
|
||||
|
@ -28,16 +27,14 @@ public class AuthSourceLogService {
|
|||
*/
|
||||
public LogDTO addLog(AuthSourceRequest request) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
request.getId(),
|
||||
null,
|
||||
OperationLogType.ADD.name(),
|
||||
OperationLogModule.SYSTEM_PARAMETER_SETTING,
|
||||
request.getName());
|
||||
|
||||
dto.setPath(PRE_URI + "/add");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setModifiedValue(JSON.toJSONBytes(request));
|
||||
return dto;
|
||||
}
|
||||
|
@ -50,42 +47,38 @@ public class AuthSourceLogService {
|
|||
*/
|
||||
public LogDTO updateLog(AuthSourceRequest request) {
|
||||
AuthSource authSource = authSourceMapper.selectByPrimaryKey(request.getId());
|
||||
LogDTO dto = null;
|
||||
if (authSource != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
request.getId(),
|
||||
null,
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SYSTEM_PARAMETER_SETTING,
|
||||
request.getName());
|
||||
|
||||
dto.setPath("/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(authSource));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
return dto;
|
||||
}
|
||||
|
||||
public LogDTO updateLog(String id) {
|
||||
AuthSource authSource = authSourceMapper.selectByPrimaryKey(id);
|
||||
LogDTO dto = null;
|
||||
if (authSource != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
id,
|
||||
null,
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SYSTEM_PARAMETER_SETTING,
|
||||
authSource.getName());
|
||||
|
||||
dto.setPath("/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(authSource));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,17 +93,14 @@ public class AuthSourceLogService {
|
|||
return null;
|
||||
}
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
authSource.getId(),
|
||||
null,
|
||||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.SYSTEM_PARAMETER_SETTING,
|
||||
authSource.getName());
|
||||
|
||||
dto.setPath("/delete");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(authSource));
|
||||
return dto;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.sdk.dto.request.PermissionSettingUpdateRequest;
|
||||
import io.metersphere.sdk.dto.request.UserRoleUpdateRequest;
|
||||
|
@ -21,12 +21,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class GlobalUserRoleLogService extends BaseUserRoleService {
|
||||
public class GlobalUserRoleLogService {
|
||||
@Resource
|
||||
private BaseUserRoleService baseUserRoleService;
|
||||
|
||||
private static final String PRE_URI = "/user/role/global";
|
||||
|
||||
/**
|
||||
* 添加接口日志
|
||||
*
|
||||
|
@ -35,16 +33,14 @@ public class GlobalUserRoleLogService extends BaseUserRoleService {
|
|||
*/
|
||||
public LogDTO addLog(UserRoleUpdateRequest request) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
request.getId(),
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
null,
|
||||
null,
|
||||
OperationLogType.ADD.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
request.getName());
|
||||
|
||||
dto.setPath(PRE_URI + "/permission/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
return dto;
|
||||
}
|
||||
|
@ -55,42 +51,38 @@ public class GlobalUserRoleLogService extends BaseUserRoleService {
|
|||
*/
|
||||
public LogDTO updateLog(UserRoleUpdateRequest request) {
|
||||
UserRole userRole = baseUserRoleService.get(request.getId());
|
||||
LogDTO dto = null;
|
||||
if (userRole != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
userRole.getId(),
|
||||
userRole.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
userRole.getName());
|
||||
|
||||
dto.setPath("/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(userRole));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
return dto;
|
||||
}
|
||||
|
||||
public LogDTO updateLog(PermissionSettingUpdateRequest request) {
|
||||
UserRole userRole = get(request.getUserRoleId());
|
||||
UserRole userRole = baseUserRoleService.get(request.getUserRoleId());
|
||||
LogDTO dto = null;
|
||||
if (userRole != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
request.getUserRoleId(),
|
||||
userRole.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
userRole.getName());
|
||||
|
||||
dto.setPath("/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,17 +98,14 @@ public class GlobalUserRoleLogService extends BaseUserRoleService {
|
|||
return null;
|
||||
}
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
userRole.getId(),
|
||||
null,
|
||||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
userRole.getName());
|
||||
|
||||
dto.setPath("/delete");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(userRole));
|
||||
return dto;
|
||||
}
|
||||
|
|
|
@ -1,28 +1,36 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.sdk.dto.OptionDTO;
|
||||
import io.metersphere.sdk.dto.UserDTO;
|
||||
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
||||
import io.metersphere.sdk.log.constants.OperationLogModule;
|
||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||
import io.metersphere.sdk.service.BaseUserRoleRelationService;
|
||||
import io.metersphere.sdk.mapper.BaseUserMapper;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.mapper.UserRoleMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
* @date : 2023-6-12
|
||||
*/
|
||||
@Service
|
||||
public class GlobalUserRoleRelationLogService extends BaseUserRoleRelationService {
|
||||
public class GlobalUserRoleRelationLogService {
|
||||
|
||||
@Resource
|
||||
private UserRoleRelationMapper userRoleRelationMapper;
|
||||
|
||||
private static final String PRE_URI = "/user/role/relation/global";
|
||||
@Resource
|
||||
private BaseUserMapper baseUserMapper;
|
||||
@Resource
|
||||
private UserRoleMapper userRoleMapper;
|
||||
|
||||
/**
|
||||
* 添加接口日志
|
||||
|
@ -31,18 +39,19 @@ public class GlobalUserRoleRelationLogService extends BaseUserRoleRelationServic
|
|||
* @return
|
||||
*/
|
||||
public LogDTO addLog(GlobalUserRoleRelationUpdateRequest request) {
|
||||
UserRole userRole = userRoleMapper.selectByPrimaryKey(request.getRoleId());
|
||||
List<String> userIds = request.getUserIds();
|
||||
List<OptionDTO> users = baseUserMapper.selectUserOptionByIds(userIds);
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
null,
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
userRole.getId(),
|
||||
null,
|
||||
OperationLogType.ADD.name(),
|
||||
OperationLogModule.SYSTEM_USER_ROLE_RELATION,
|
||||
request.getUserId());
|
||||
userRole.getName());
|
||||
|
||||
dto.setPath(PRE_URI + "/add");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
dto.setOriginalValue(JSON.toJSONBytes(users));
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
@ -54,22 +63,22 @@ public class GlobalUserRoleRelationLogService extends BaseUserRoleRelationServic
|
|||
*/
|
||||
public LogDTO deleteLog(String id) {
|
||||
UserRoleRelation userRoleRelation = userRoleRelationMapper.selectByPrimaryKey(id);
|
||||
if (userRoleRelation != null) {
|
||||
UserRole userRole = userRoleMapper.selectByPrimaryKey(userRoleRelation.getRoleId());
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
id,
|
||||
userRoleRelation.getCreateUser(),
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
userRole.getId(),
|
||||
null,
|
||||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.SYSTEM_USER_ROLE_RELATION,
|
||||
userRoleRelation.getUserId());
|
||||
userRole.getName());
|
||||
|
||||
dto.setPath("/delete");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(userRoleRelation));
|
||||
UserDTO userDTO = baseUserMapper.selectById(userRoleRelation.getUserId());
|
||||
OptionDTO optionDTO = new OptionDTO();
|
||||
optionDTO.setId(userDTO.getId());
|
||||
optionDTO.setName(userDTO.getName());
|
||||
// 记录用户id和name
|
||||
dto.setOriginalValue(JSON.toJSONBytes(optionDTO));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
||||
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
||||
import io.metersphere.sdk.service.BaseUserRoleRelationService;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -18,9 +19,6 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
||||
|
||||
@Resource
|
||||
private UserRoleRelationMapper userRoleRelationMapper;
|
||||
@Resource
|
||||
private ExtUserRoleRelationMapper extUserRoleRelationMapper;
|
||||
@Resource
|
||||
|
@ -33,13 +31,17 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
|||
return extUserRoleRelationMapper.listGlobal(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserRoleRelation add(UserRoleRelation userRoleRelation) {
|
||||
UserRole userRole = globalUserRoleService.get(userRoleRelation.getRoleId());
|
||||
public void add(GlobalUserRoleRelationUpdateRequest request) {
|
||||
UserRole userRole = globalUserRoleService.get(request.getRoleId());
|
||||
globalUserRoleService.checkSystemUserGroup(userRole);
|
||||
globalUserRoleService.checkGlobalUserRole(userRole);
|
||||
request.getUserIds().forEach(userId -> {
|
||||
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
||||
BeanUtils.copyBean(userRoleRelation, request);
|
||||
userRoleRelation.setUserId(userId);
|
||||
userRoleRelation.setSourceId(GlobalUserRoleService.SYSTEM_TYPE);
|
||||
return super.add(userRoleRelation);
|
||||
super.add(userRoleRelation);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.sdk.dto.request.PermissionSettingUpdateRequest;
|
||||
import io.metersphere.sdk.log.constants.OperationLogModule;
|
||||
|
@ -21,8 +20,6 @@ public class OrganizationUserRoleLogService {
|
|||
@Resource
|
||||
private UserRoleMapper userRoleMapper;
|
||||
|
||||
private static final String PRE_URI = "/user/role/organization";
|
||||
|
||||
/**
|
||||
* 新增组织-用户组
|
||||
* @param request 接口请求参数
|
||||
|
@ -37,8 +34,7 @@ public class OrganizationUserRoleLogService {
|
|||
OperationLogType.ADD.name(),
|
||||
OperationLogModule.ORGANIZATION_USER_ROLE,
|
||||
request.getName());
|
||||
dto.setPath(PRE_URI + "/add");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
return dto;
|
||||
}
|
||||
|
@ -57,8 +53,7 @@ public class OrganizationUserRoleLogService {
|
|||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.ORGANIZATION_USER_ROLE,
|
||||
request.getName());
|
||||
dto.setPath(PRE_URI + "/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
return dto;
|
||||
}
|
||||
|
@ -78,8 +73,7 @@ public class OrganizationUserRoleLogService {
|
|||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.ORGANIZATION_USER_ROLE,
|
||||
userRole.getName());
|
||||
dto.setPath(PRE_URI + "/delete");
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(userRole));
|
||||
return dto;
|
||||
}
|
||||
|
@ -92,8 +86,6 @@ public class OrganizationUserRoleLogService {
|
|||
public LogDTO updatePermissionSettingLog(PermissionSettingUpdateRequest request) {
|
||||
LogDTO dto = getLog(request.getUserRoleId());
|
||||
dto.setType(OperationLogType.UPDATE.name());
|
||||
dto.setPath(PRE_URI + "/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
return dto;
|
||||
}
|
||||
|
@ -106,8 +98,6 @@ public class OrganizationUserRoleLogService {
|
|||
public LogDTO editMemberLog(OrganizationUserRoleMemberEditRequest request) {
|
||||
LogDTO dto = getLog(request.getUserRoleId());
|
||||
dto.setType(OperationLogType.UPDATE.name());
|
||||
dto.setPath(PRE_URI + "/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
return dto;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package io.metersphere.system.service;
|
|||
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.dto.AddProjectRequest;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
||||
|
@ -20,8 +20,6 @@ public class SystemProjectLogService {
|
|||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
private static final String PRE_URI = "/system/project";
|
||||
|
||||
/**
|
||||
* 添加接口日志
|
||||
*
|
||||
|
@ -29,16 +27,14 @@ public class SystemProjectLogService {
|
|||
*/
|
||||
public LogDTO addLog(AddProjectRequest project) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
null,
|
||||
null,
|
||||
OperationLogType.ADD.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
project.getName());
|
||||
|
||||
dto.setPath(PRE_URI + "/add");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
}
|
||||
|
@ -51,15 +47,13 @@ public class SystemProjectLogService {
|
|||
Project project = projectMapper.selectByPrimaryKey(request.getId());
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
"编辑全局用户组对应的权限配置");
|
||||
dto.setPath("/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
|
@ -71,15 +65,13 @@ public class SystemProjectLogService {
|
|||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
OperationLogType.RECOVER.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
"编辑全局用户组对应的权限配置");
|
||||
dto.setPath("/revoke");
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
|
@ -98,16 +90,14 @@ public class SystemProjectLogService {
|
|||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
"system",
|
||||
"",
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
id,
|
||||
project.getCreateUser(),
|
||||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.SYSTEM_PROJECT,
|
||||
project.getName());
|
||||
|
||||
dto.setPath("/delete");
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
@ -98,32 +99,32 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
|
|||
|
||||
// @@请求成功
|
||||
GlobalUserRoleRelationUpdateRequest request = new GlobalUserRoleRelationUpdateRequest();
|
||||
request.setUserId(ADMIN.getValue());
|
||||
request.setUserIds(Arrays.asList(ADMIN.getValue()));
|
||||
request.setRoleId(nonInternalUserRole.getId());
|
||||
this.requestPostWithOk(DEFAULT_ADD, request);
|
||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||
example.createCriteria()
|
||||
.andRoleIdEqualTo(request.getRoleId())
|
||||
.andUserIdEqualTo(request.getUserId());
|
||||
.andUserIdEqualTo(ADMIN.getValue());
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(userRoleRelationMapper.selectByExample(example)));
|
||||
addUserRoleRelation = userRoleRelationMapper.selectByExample(example).get(0);
|
||||
|
||||
// @@校验日志
|
||||
checkLog(addUserRoleRelation.getId(), OperationLogType.ADD);
|
||||
checkLog(addUserRoleRelation.getRoleId(), OperationLogType.ADD);
|
||||
|
||||
// @@重复添加校验
|
||||
request.setUserId(ADMIN.getValue());
|
||||
request.setUserIds(Arrays.asList(ADMIN.getValue()));
|
||||
request.setRoleId(ADMIN.getValue());
|
||||
assertErrorCode(this.requestPost(DEFAULT_ADD, request), USER_ROLE_RELATION_EXIST);
|
||||
|
||||
// @@操作非系统用户组异常
|
||||
request.setUserId(ADMIN.getValue());
|
||||
request.setUserIds(Arrays.asList(ADMIN.getValue()));
|
||||
request.setRoleId(ORG_ADMIN.getValue());
|
||||
assertErrorCode(this.requestPost(DEFAULT_ADD, request), GLOBAL_USER_ROLE_RELATION_SYSTEM_PERMISSION);
|
||||
|
||||
// @@操作非全局用户组异常
|
||||
UserRole nonGlobalUserRole = getNonGlobalUserRole();
|
||||
request.setUserId(ADMIN.getValue());
|
||||
request.setUserIds(Arrays.asList(ADMIN.getValue()));
|
||||
request.setRoleId(nonGlobalUserRole.getId());
|
||||
assertErrorCode(this.requestPost(DEFAULT_ADD, request), GLOBAL_USER_ROLE_PERMISSION);
|
||||
|
||||
|
@ -143,7 +144,7 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
|
|||
Assertions.assertNull(userRoleRelation);
|
||||
|
||||
// @@校验日志
|
||||
checkLog(addUserRoleRelation.getId(), OperationLogType.DELETE);
|
||||
checkLog(addUserRoleRelation.getRoleId(), OperationLogType.DELETE);
|
||||
|
||||
// @@操作非系统级别用户组异常
|
||||
assertErrorCode(this.requestGet(DEFAULT_DELETE, getNonSystemUserRoleRelation().getId()),
|
||||
|
|
|
@ -3,18 +3,23 @@ package io.metersphere.system.controller.param;
|
|||
import io.metersphere.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
*/
|
||||
@Data
|
||||
public class GlobalUserRoleRelationUpdateRequestDefinition {
|
||||
|
||||
@NotBlank(groups = {Created.class})
|
||||
@Size(min = 1, max = 50, groups = {Created.class, Updated.class})
|
||||
private String userId;
|
||||
@NotEmpty(groups = {Created.class, Updated.class})
|
||||
private List<
|
||||
@NotBlank(groups = {Created.class, Updated.class})
|
||||
@Size(groups = {Created.class, Updated.class})
|
||||
String> userIds;
|
||||
|
||||
@NotBlank(groups = {Created.class})
|
||||
@Size(min = 1, max = 50, groups = {Created.class, Updated.class})
|
||||
|
|
Loading…
Reference in New Issue