feat(系统设置): 项目增加修改名称接口
This commit is contained in:
parent
499661e55d
commit
2002916edb
|
@ -30,7 +30,7 @@ public class ProjectBaseRequest {
|
|||
@Schema(description = "是否启用")
|
||||
private Boolean enable;
|
||||
|
||||
@Schema(description = "模块设置")
|
||||
@Schema(description = "模块设置", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
private List<String> moduleIds;
|
||||
|
||||
@Schema(description = "成员数", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
|
|
|
@ -16,7 +16,6 @@ import io.metersphere.sdk.dto.UserDTO;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.*;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
|
@ -25,8 +24,8 @@ import io.metersphere.system.mapper.OrganizationMapper;
|
|||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.system.mapper.TestResourcePoolOrganizationMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import io.metersphere.system.service.CommonProjectService;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import io.metersphere.system.utils.ServiceUtils;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -115,11 +114,6 @@ public class ProjectService {
|
|||
checkProjectNotExist(project.getId());
|
||||
projectDTO.setOrganizationName(organizationMapper.selectByPrimaryKey(updateProjectDto.getOrganizationId()).getName());
|
||||
BeanUtils.copyBean(projectDTO, project);
|
||||
//判断是否有模块设置
|
||||
if (CollectionUtils.isNotEmpty(updateProjectDto.getModuleIds())) {
|
||||
project.setModuleSetting(JSON.toJSONString(updateProjectDto.getModuleIds()));
|
||||
projectDTO.setModuleIds(updateProjectDto.getModuleIds());
|
||||
}
|
||||
|
||||
projectMapper.updateByPrimaryKeySelective(project);
|
||||
return projectDTO;
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.metersphere.sdk.util.PageUtils;
|
|||
import io.metersphere.sdk.util.Pager;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
|
@ -165,4 +166,12 @@ public class OrganizationProjectController {
|
|||
return organizationProjectService.getTestResourcePoolOptions(organizationId);
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
@Operation(summary = "系统设置-组织-项目-修改项目名称")
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.renameLog(#request)", msClass = OrganizationProjectLogService.class)
|
||||
public void rename(@RequestBody @Validated({Updated.class}) UpdateProjectNameRequest request) {
|
||||
organizationProjectService.rename(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import io.metersphere.sdk.util.Pager;
|
|||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
|
@ -160,4 +161,12 @@ public class SystemProjectController {
|
|||
return systemProjectService.getTestResourcePoolOptions(organizationId);
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-项目-修改项目名称")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.renameLog(#request)", msClass = SystemProjectLogService.class)
|
||||
public void rename(@RequestBody @Validated({Updated.class}) UpdateProjectNameRequest request) {
|
||||
systemProjectService.rename(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package io.metersphere.system.dto;
|
||||
|
||||
import io.metersphere.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class UpdateProjectNameRequest {
|
||||
|
||||
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{project.id.not_blank}", groups = {Updated.class})
|
||||
@Size(min = 1, max = 50, message = "{project.id.length_range}", groups = {Updated.class})
|
||||
private String id;
|
||||
|
||||
@Schema(description = "组织ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{project.organization_id.not_blank}", groups = {Created.class, Updated.class})
|
||||
@Size(min = 1, max = 50, message = "{project.organization_id.length_range}", groups = {Created.class, Updated.class})
|
||||
private String organizationId;
|
||||
|
||||
@Schema(description = "项目名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{project.name.not_blank}", groups = {Created.class, Updated.class})
|
||||
@Size(min = 1, max = 255, message = "{project.name.length_range}", groups = {Created.class, Updated.class})
|
||||
private String name;
|
||||
}
|
|
@ -19,10 +19,7 @@ import io.metersphere.sdk.util.JSON;
|
|||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.*;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.ProjectResourcePoolDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
|
@ -289,6 +286,10 @@ public class CommonProjectService {
|
|||
projectTestResourcePools.add(projectTestResourcePool);
|
||||
});
|
||||
projectTestResourcePoolMapper.batchInsert(projectTestResourcePools);
|
||||
} else {
|
||||
ProjectTestResourcePoolExample projectTestResourcePoolExample = new ProjectTestResourcePoolExample();
|
||||
projectTestResourcePoolExample.createCriteria().andProjectIdEqualTo(project.getId());
|
||||
projectTestResourcePoolMapper.deleteByExample(projectTestResourcePoolExample);
|
||||
}
|
||||
|
||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||
|
@ -342,6 +343,9 @@ public class CommonProjectService {
|
|||
if (CollectionUtils.isNotEmpty(updateProjectDto.getModuleIds())) {
|
||||
project.setModuleSetting(JSON.toJSONString(updateProjectDto.getModuleIds()));
|
||||
projectDTO.setModuleIds(updateProjectDto.getModuleIds());
|
||||
} else {
|
||||
project.setModuleSetting(null);
|
||||
projectDTO.setModuleIds(new ArrayList<>());
|
||||
}
|
||||
|
||||
projectMapper.updateByPrimaryKeySelective(project);
|
||||
|
@ -607,4 +611,18 @@ public class CommonProjectService {
|
|||
new OptionDTO(testResourcePool.getId(), testResourcePool.getName())
|
||||
).toList();
|
||||
}
|
||||
|
||||
public void rename(UpdateProjectNameRequest request, String userId) {
|
||||
checkProjectNotExist(request.getId());
|
||||
Project project = new Project();
|
||||
project.setId(request.getId());
|
||||
project.setName(request.getName());
|
||||
project.setOrganizationId(request.getOrganizationId());
|
||||
checkProjectExistByName(project);
|
||||
project.setCreateTime(null);
|
||||
project.setCreateUser(null);
|
||||
project.setUpdateUser(userId);
|
||||
project.setUpdateTime(System.currentTimeMillis());
|
||||
projectMapper.updateByPrimaryKeySelective(project);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.project.mapper.ProjectMapper;
|
|||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
|
@ -61,6 +62,24 @@ public class OrganizationProjectLogService {
|
|||
return null;
|
||||
}
|
||||
|
||||
public LogDTO renameLog(UpdateProjectNameRequest request) {
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getId());
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
project.getId(),
|
||||
project.getOrganizationId(),
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SETTING_ORGANIZATION_PROJECT,
|
||||
project.getName());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public LogDTO updateLog(String id) {
|
||||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.system.domain.UserRoleRelation;
|
|||
import io.metersphere.system.domain.UserRoleRelationExample;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
|
@ -133,4 +134,8 @@ public class OrganizationProjectService {
|
|||
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
|
||||
return commonProjectService.getTestResourcePoolOptions(organizationId);
|
||||
}
|
||||
|
||||
public void rename(UpdateProjectNameRequest project, String userId) {
|
||||
commonProjectService.rename(project, userId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.sdk.constants.HttpMethodConstants;
|
|||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.sdk.dto.LogDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
|
@ -62,6 +63,24 @@ public class SystemProjectLogService {
|
|||
return null;
|
||||
}
|
||||
|
||||
public LogDTO renameLog(UpdateProjectNameRequest request) {
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getId());
|
||||
if (project != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
project.getId(),
|
||||
project.getCreateUser(),
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SETTING_SYSTEM_ORGANIZATION,
|
||||
project.getName());
|
||||
|
||||
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public LogDTO updateLog(String id) {
|
||||
Project project = projectMapper.selectByPrimaryKey(id);
|
||||
if (project != null) {
|
||||
|
|
|
@ -4,10 +4,7 @@ import io.metersphere.project.domain.Project;
|
|||
import io.metersphere.sdk.dto.OptionDTO;
|
||||
import io.metersphere.sdk.dto.UserExtend;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.ExtSystemProjectMapper;
|
||||
|
@ -103,4 +100,8 @@ public class SystemProjectService {
|
|||
return commonProjectService.getTestResourcePoolOptions(organizationId);
|
||||
|
||||
}
|
||||
|
||||
public void rename(UpdateProjectNameRequest project, String userId) {
|
||||
commonProjectService.rename(project, userId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,13 @@ import io.metersphere.sdk.constants.PermissionConstants;
|
|||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.sdk.dto.*;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Pager;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.domain.UserRoleRelationExample;
|
||||
import io.metersphere.system.dto.OrganizationDTO;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.request.OrganizationProjectRequest;
|
||||
|
@ -73,6 +70,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
private final static String getAdminList = prefix + "/user-admin-list/";
|
||||
private final static String getMemberList = prefix + "/user-member-list/";
|
||||
private final static String getPoolOptions = prefix + "/pool-options/";
|
||||
private final static String updateName = prefix + "/rename";
|
||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
|
||||
|
@ -860,4 +858,45 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getPoolOptions + DEFAULT_ORGANIZATION_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
public void testUpdateName() throws Exception {
|
||||
UpdateProjectNameRequest project = new UpdateProjectNameRequest();
|
||||
project.setId("projectId1");
|
||||
project.setName("org-updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
requestPost(updateName, project);
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
||||
Assertions.assertEquals(currentProject.getName(), project.getName());
|
||||
checkLog(project.getId(), OperationLogType.UPDATE);
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE, updateName, project);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(25)
|
||||
public void testUpdateNameError() throws Exception {
|
||||
//项目名称存在 500
|
||||
UpdateProjectNameRequest project = new UpdateProjectNameRequest();
|
||||
project.setId("projectId2");
|
||||
project.setName("org-updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
//参数组织Id为空
|
||||
project.setOrganizationId(null);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目Id为空
|
||||
project.setId(null);
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目名称为空
|
||||
project.setName(null);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目不存在
|
||||
project.setId("1111");
|
||||
project.setName("updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,7 @@ import io.metersphere.sdk.util.Translator;
|
|||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.domain.*;
|
||||
import io.metersphere.system.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.StatusFlowSettingDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.job.CleanProjectJob;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.OrganizationParameterMapper;
|
||||
|
@ -72,6 +69,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
private final static String enableProject = prefix + "/enable/";
|
||||
private final static String userList = prefix + "/user-list";
|
||||
private final static String getPoolOptions = prefix + "/pool-options";
|
||||
private final static String updateName = prefix + "/rename";
|
||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
|
||||
|
@ -994,4 +992,46 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
Assertions.assertTrue(CollectionUtils.isEmpty(baseTemplateService.getByScopeId(id)));
|
||||
Assertions.assertTrue(CollectionUtils.isEmpty(baseStatusItemService.getByScopeId(id)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
public void testUpdateName() throws Exception {
|
||||
UpdateProjectNameRequest project = new UpdateProjectNameRequest();
|
||||
project.setId("projectId1");
|
||||
project.setName("updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
requestPost(updateName, project);
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
||||
Assertions.assertEquals(currentProject.getName(), project.getName());
|
||||
checkLog(project.getId(), OperationLogType.UPDATE);
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE, updateName, project);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(25)
|
||||
public void testUpdateNameError() throws Exception {
|
||||
//项目名称存在 500
|
||||
UpdateProjectNameRequest project = new UpdateProjectNameRequest();
|
||||
project.setId("projectId2");
|
||||
project.setName("updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
//参数组织Id为空
|
||||
project.setOrganizationId(null);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目Id为空
|
||||
project.setId(null);
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目名称为空
|
||||
project.setName(null);
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目不存在
|
||||
project.setId("1111");
|
||||
project.setName("updateName");
|
||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue