refactor(系统设置): 项目不能删除最后一个管理员
This commit is contained in:
parent
1ad018b614
commit
152ea72a4c
|
@ -39,6 +39,8 @@ not_authorized=未经授权
|
||||||
user_apikey_limit=最多能有5个Api key
|
user_apikey_limit=最多能有5个Api key
|
||||||
please_logout_current_user=请先登出当前用户
|
please_logout_current_user=请先登出当前用户
|
||||||
resource.name=资源
|
resource.name=资源
|
||||||
|
keep_at_least_one_administrator=至少保留一个管理员
|
||||||
|
project.member_count.not_blank=成员数量不能为空
|
||||||
|
|
||||||
#load test
|
#load test
|
||||||
edit_load_test_not_found=无法编辑测试,未找到测试:
|
edit_load_test_not_found=无法编辑测试,未找到测试:
|
||||||
|
|
|
@ -39,7 +39,8 @@ login_fail=Login fail
|
||||||
user_apikey_limit=Can have up to 5 api keys
|
user_apikey_limit=Can have up to 5 api keys
|
||||||
please_logout_current_user=Please logout current user first
|
please_logout_current_user=Please logout current user first
|
||||||
resource.name=Resource
|
resource.name=Resource
|
||||||
|
keep_at_least_one_administrator=Keep at least one administrator
|
||||||
|
project.member_count.not_blank=The number of members cannot be empty
|
||||||
#load test
|
#load test
|
||||||
edit_load_test_not_found=Cannot edit test, test not found=
|
edit_load_test_not_found=Cannot edit test, test not found=
|
||||||
run_load_test_not_found=Cannot run test, test not found=
|
run_load_test_not_found=Cannot run test, test not found=
|
||||||
|
|
|
@ -39,6 +39,8 @@ not_authorized=未经授权
|
||||||
user_apikey_limit=最多能有5个Api key
|
user_apikey_limit=最多能有5个Api key
|
||||||
please_logout_current_user=请先登出当前用户
|
please_logout_current_user=请先登出当前用户
|
||||||
resource.name=资源
|
resource.name=资源
|
||||||
|
keep_at_least_one_administrator=至少保留一个管理员
|
||||||
|
project.member_count.not_blank=成员数量不能为空
|
||||||
|
|
||||||
#load test
|
#load test
|
||||||
edit_load_test_not_found=无法编辑测试,未找到测试:
|
edit_load_test_not_found=无法编辑测试,未找到测试:
|
||||||
|
|
|
@ -38,6 +38,8 @@ user_expires=用戶過期
|
||||||
not_authorized=未經授權
|
not_authorized=未經授權
|
||||||
user_apikey_limit=最多能有5個Api key
|
user_apikey_limit=最多能有5個Api key
|
||||||
please_logout_current_user=請先登出當前用戶
|
please_logout_current_user=請先登出當前用戶
|
||||||
|
keep_at_least_one_administrator=至少保留一個管理員
|
||||||
|
project.member_count.not_blank=成員數不能為空
|
||||||
#load test
|
#load test
|
||||||
edit_load_test_not_found=無法編輯測試,未找到測試:
|
edit_load_test_not_found=無法編輯測試,未找到測試:
|
||||||
run_load_test_not_found=無法運行測試,未找到測試:
|
run_load_test_not_found=無法運行測試,未找到測試:
|
||||||
|
|
|
@ -213,9 +213,7 @@ public class EnvironmentGroupService {
|
||||||
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||||
userRoleRelationExample.createCriteria().andUserIdEqualTo(userId).andRoleIdEqualTo(InternalUserRole.ADMIN.name());
|
userRoleRelationExample.createCriteria().andUserIdEqualTo(userId).andRoleIdEqualTo(InternalUserRole.ADMIN.name());
|
||||||
if (userRoleRelationMapper.countByExample(userRoleRelationExample) > 0) {
|
if (userRoleRelationMapper.countByExample(userRoleRelationExample) > 0) {
|
||||||
ProjectExample example = new ProjectExample();
|
projects = projectMapper.selectByExample(new ProjectExample());
|
||||||
example.createCriteria().andEnableEqualTo(true);
|
|
||||||
projects = projectMapper.selectByExample(example);
|
|
||||||
} else {
|
} else {
|
||||||
projects = extProjectMapper.getProject(userId);
|
projects = extProjectMapper.getProject(userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ import java.util.stream.Collectors;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
public class FileManagementControllerTests extends BaseTest {
|
public class FileManagementControllerTests extends BaseTest {
|
||||||
|
@ -109,9 +109,11 @@ public class FileManagementControllerTests extends BaseTest {
|
||||||
initProject.setName("文件管理专用项目");
|
initProject.setName("文件管理专用项目");
|
||||||
initProject.setDescription("建国创建的文件管理专用项目");
|
initProject.setDescription("建国创建的文件管理专用项目");
|
||||||
initProject.setEnable(true);
|
initProject.setEnable(true);
|
||||||
|
initProject.setUserIds(List.of("admin"));
|
||||||
project = commonProjectService.add(initProject, "admin", "/organization-project/add", OperationLogModule.SETTING_ORGANIZATION_PROJECT);
|
project = commonProjectService.add(initProject, "admin", "/organization-project/add", OperationLogModule.SETTING_ORGANIZATION_PROJECT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
public void emptyDataTest() throws Exception {
|
public void emptyDataTest() throws Exception {
|
||||||
|
@ -2331,6 +2333,7 @@ public class FileManagementControllerTests extends BaseTest {
|
||||||
request.setDropPosition(4);
|
request.setDropPosition(4);
|
||||||
this.requestPost(FileManagementRequestUtils.URL_MODULE_MOVE, request).andExpect(status().is5xxServerError());
|
this.requestPost(FileManagementRequestUtils.URL_MODULE_MOVE, request).andExpect(status().is5xxServerError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(90)
|
@Order(90)
|
||||||
public void deleteModuleTestSuccess() throws Exception {
|
public void deleteModuleTestSuccess() throws Exception {
|
||||||
|
|
|
@ -79,6 +79,7 @@ public class FileRepositoryControllerTest extends BaseTest {
|
||||||
initProject.setName("文件管理存储库专用项目");
|
initProject.setName("文件管理存储库专用项目");
|
||||||
initProject.setDescription("建国创建的文件管理存储库专用项目");
|
initProject.setDescription("建国创建的文件管理存储库专用项目");
|
||||||
initProject.setEnable(true);
|
initProject.setEnable(true);
|
||||||
|
initProject.setUserIds(List.of("admin"));
|
||||||
project = commonProjectService.add(initProject, "admin", "/organization-project/add", OperationLogModule.SETTING_ORGANIZATION_PROJECT);
|
project = commonProjectService.add(initProject, "admin", "/organization-project/add", OperationLogModule.SETTING_ORGANIZATION_PROJECT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created;
|
||||||
import io.metersphere.validation.groups.Updated;
|
import io.metersphere.validation.groups.Updated;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
@ -34,7 +35,8 @@ public class ProjectBaseRequest {
|
||||||
@Schema(description = "模块设置", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
@Schema(description = "模块设置", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||||
private List<String> moduleIds;
|
private List<String> moduleIds;
|
||||||
|
|
||||||
@Schema(description = "成员数", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
@Schema(description = "成员数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "{project.member_count.not_blank}", groups = {Created.class, Updated.class})
|
||||||
private List<String> userIds;
|
private List<String> userIds;
|
||||||
|
|
||||||
@Schema(description = "资源池", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
@Schema(description = "资源池", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||||
|
|
|
@ -132,11 +132,8 @@ public class CommonProjectService {
|
||||||
|
|
||||||
ProjectAddMemberBatchRequest memberRequest = new ProjectAddMemberBatchRequest();
|
ProjectAddMemberBatchRequest memberRequest = new ProjectAddMemberBatchRequest();
|
||||||
memberRequest.setProjectIds(List.of(project.getId()));
|
memberRequest.setProjectIds(List.of(project.getId()));
|
||||||
if (CollectionUtils.isEmpty(addProjectDTO.getUserIds())) {
|
memberRequest.setUserIds(addProjectDTO.getUserIds());
|
||||||
memberRequest.setUserIds(List.of(createUser));
|
//资源池
|
||||||
} else {
|
|
||||||
memberRequest.setUserIds(addProjectDTO.getUserIds());
|
|
||||||
} //资源池
|
|
||||||
if (CollectionUtils.isNotEmpty(addProjectDTO.getResourcePoolIds())) {
|
if (CollectionUtils.isNotEmpty(addProjectDTO.getResourcePoolIds())) {
|
||||||
checkResourcePoolExist(addProjectDTO.getResourcePoolIds());
|
checkResourcePoolExist(addProjectDTO.getResourcePoolIds());
|
||||||
List<ProjectTestResourcePool> projectTestResourcePools = new ArrayList<>();
|
List<ProjectTestResourcePool> projectTestResourcePools = new ArrayList<>();
|
||||||
|
@ -315,48 +312,35 @@ public class CommonProjectService {
|
||||||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
||||||
List<String> orgUserIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).toList();
|
List<String> orgUserIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).toList();
|
||||||
List<LogDTO> logDTOList = new ArrayList<>();
|
List<LogDTO> logDTOList = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(updateProjectDto.getUserIds())) {
|
|
||||||
//updateProjectDto.getUserIds() 为前端传过来的用户id 与数据库中的用户id做对比 如果数据库中的用户id不在前端传过来的用户id中 则删除
|
|
||||||
List<String> deleteIds = orgUserIds.stream()
|
|
||||||
.filter(item -> !updateProjectDto.getUserIds().contains(item))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<String> insertIds = updateProjectDto.getUserIds().stream()
|
//updateProjectDto.getUserIds() 为前端传过来的用户id 与数据库中的用户id做对比 如果数据库中的用户id不在前端传过来的用户id中 则删除
|
||||||
.filter(item -> !orgUserIds.contains(item))
|
List<String> deleteIds = orgUserIds.stream()
|
||||||
.collect(Collectors.toList());
|
.filter(item -> !updateProjectDto.getUserIds().contains(item))
|
||||||
if (CollectionUtils.isNotEmpty(deleteIds)) {
|
.collect(Collectors.toList());
|
||||||
UserRoleRelationExample deleteExample = new UserRoleRelationExample();
|
|
||||||
deleteExample.createCriteria().andSourceIdEqualTo(project.getId()).andUserIdIn(deleteIds).andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
List<String> insertIds = updateProjectDto.getUserIds().stream()
|
||||||
userRoleRelationMapper.selectByExample(deleteExample).forEach(userRoleRelation -> {
|
.filter(item -> !orgUserIds.contains(item))
|
||||||
User user = userMapper.selectByPrimaryKey(userRoleRelation.getUserId());
|
.collect(Collectors.toList());
|
||||||
String logProjectId = OperationLogConstants.SYSTEM;
|
if (CollectionUtils.isNotEmpty(deleteIds)) {
|
||||||
if (StringUtils.equals(module, OperationLogModule.SETTING_ORGANIZATION_PROJECT)) {
|
UserRoleRelationExample deleteExample = new UserRoleRelationExample();
|
||||||
logProjectId = OperationLogConstants.ORGANIZATION;
|
deleteExample.createCriteria().andSourceIdEqualTo(project.getId()).andUserIdIn(deleteIds).andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
||||||
}
|
userRoleRelationMapper.selectByExample(deleteExample).forEach(userRoleRelation -> {
|
||||||
LogDTO logDTO = new LogDTO(logProjectId, project.getOrganizationId(), userRoleRelation.getId(), updateUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_admin") + ": " + user.getName());
|
User user = userMapper.selectByPrimaryKey(userRoleRelation.getUserId());
|
||||||
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
|
String logProjectId = OperationLogConstants.SYSTEM;
|
||||||
});
|
if (StringUtils.equals(module, OperationLogModule.SETTING_ORGANIZATION_PROJECT)) {
|
||||||
userRoleRelationMapper.deleteByExample(deleteExample);
|
logProjectId = OperationLogConstants.ORGANIZATION;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(insertIds)) {
|
LogDTO logDTO = new LogDTO(logProjectId, project.getOrganizationId(), userRoleRelation.getId(), updateUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_admin") + ": " + user.getName());
|
||||||
ProjectAddMemberBatchRequest memberRequest = new ProjectAddMemberBatchRequest();
|
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
|
||||||
memberRequest.setProjectIds(List.of(project.getId()));
|
});
|
||||||
memberRequest.setUserIds(insertIds);
|
userRoleRelationMapper.deleteByExample(deleteExample);
|
||||||
this.addProjectAdmin(memberRequest, updateUser, path, OperationLogType.ADD.name(),
|
}
|
||||||
Translator.get("add"), module);
|
if (CollectionUtils.isNotEmpty(insertIds)) {
|
||||||
}
|
ProjectAddMemberBatchRequest memberRequest = new ProjectAddMemberBatchRequest();
|
||||||
} else {
|
memberRequest.setProjectIds(List.of(project.getId()));
|
||||||
if (CollectionUtils.isNotEmpty(orgUserIds)) {
|
memberRequest.setUserIds(insertIds);
|
||||||
//如果前端传过来的用户id为空 则删除项目所有管理员
|
this.addProjectAdmin(memberRequest, updateUser, path, OperationLogType.ADD.name(),
|
||||||
UserRoleRelationExample deleteExample = new UserRoleRelationExample();
|
Translator.get("add"), module);
|
||||||
deleteExample.createCriteria().andSourceIdEqualTo(project.getId()).andUserIdIn(orgUserIds).andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
|
||||||
userRoleRelationMapper.selectByExample(deleteExample).forEach(userRoleRelation -> {
|
|
||||||
User user = userMapper.selectByPrimaryKey(userRoleRelation.getUserId());
|
|
||||||
LogDTO logDTO = new LogDTO(OperationLogConstants.SYSTEM, project.getOrganizationId(), userRoleRelation.getId(), updateUser, OperationLogType.DELETE.name(), module, Translator.get("delete") + Translator.get("project_admin") + ": " + user.getName());
|
|
||||||
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
|
|
||||||
});
|
|
||||||
userRoleRelationMapper.deleteByExample(deleteExample);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(logDTOList)) {
|
if (CollectionUtils.isNotEmpty(logDTOList)) {
|
||||||
operationLogService.batchAdd(logDTOList);
|
operationLogService.batchAdd(logDTOList);
|
||||||
|
@ -506,11 +490,19 @@ public class CommonProjectService {
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdEqualTo(userId).andDeletedEqualTo(false);
|
userExample.createCriteria().andIdEqualTo(userId).andDeletedEqualTo(false);
|
||||||
List<User> users = userMapper.selectByExample(userExample);
|
List<User> users = userMapper.selectByExample(userExample);
|
||||||
User user = CollectionUtils.isNotEmpty(users) ? users.get(0) : null;
|
User user = CollectionUtils.isNotEmpty(users) ? users.getFirst() : null;
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new MSException(Translator.get("user_not_exist"));
|
throw new MSException(Translator.get("user_not_exist"));
|
||||||
}
|
}
|
||||||
|
//判断用户是不是最后一个管理员 如果是 就报错
|
||||||
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||||
|
userRoleRelationExample.createCriteria().andUserIdNotEqualTo(userId)
|
||||||
|
.andSourceIdEqualTo(projectId)
|
||||||
|
.andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
||||||
|
if (userRoleRelationMapper.countByExample(userRoleRelationExample) == 0) {
|
||||||
|
throw new MSException(Translator.get("keep_at_least_one_administrator"));
|
||||||
|
}
|
||||||
|
userRoleRelationExample = new UserRoleRelationExample();
|
||||||
userRoleRelationExample.createCriteria().andUserIdEqualTo(userId)
|
userRoleRelationExample.createCriteria().andUserIdEqualTo(userId)
|
||||||
.andSourceIdEqualTo(projectId);
|
.andSourceIdEqualTo(projectId);
|
||||||
if (StringUtils.equals(projectId, user.getLastProjectId())) {
|
if (StringUtils.equals(projectId, user.getLastProjectId())) {
|
||||||
|
|
|
@ -21,6 +21,8 @@ import org.springframework.test.context.jdbc.SqlConfig;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ public class LoginControllerTests extends BaseTest {
|
||||||
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
project.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||||
project.setName("test-login-projectName");
|
project.setName("test-login-projectName");
|
||||||
project.setEnable(true);
|
project.setEnable(true);
|
||||||
|
project.setUserIds(List.of("test.login"));
|
||||||
ProjectDTO add = systemProjectService.add(project, "test.login");
|
ProjectDTO add = systemProjectService.add(project, "test.login");
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -356,7 +356,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
checkLog(projectId, OperationLogType.ADD);
|
checkLog(projectId, OperationLogType.ADD);
|
||||||
|
|
||||||
//userId为空的时候
|
//userId为空的时候
|
||||||
project = this.generatorAdd("organizationId", "organization-userIdIsNull", "description", true, new ArrayList<>());
|
project = this.generatorAdd("organizationId", "organization-userIdIsNull", "description", true, List.of("admin"));
|
||||||
mvcResult = this.responsePost(addProject, project);
|
mvcResult = this.responsePost(addProject, project);
|
||||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||||
projectExample = new ProjectExample();
|
projectExample = new ProjectExample();
|
||||||
|
@ -368,14 +368,6 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
checkLog(projectId, OperationLogType.ADD);
|
checkLog(projectId, OperationLogType.ADD);
|
||||||
|
|
||||||
compareProjectDTO(projects.get(0), result);
|
compareProjectDTO(projects.get(0), result);
|
||||||
userRoleRelationExample = new UserRoleRelationExample();
|
|
||||||
userRoleRelationExample.createCriteria().andSourceIdEqualTo(projectId).andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
|
||||||
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
|
||||||
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin"));
|
|
||||||
userRoleRelationExample.createCriteria().andSourceIdEqualTo("organizationId").andRoleIdEqualTo(InternalUserRole.ORG_MEMBER.getValue());
|
|
||||||
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
|
||||||
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin"));
|
|
||||||
projectExtend = projectMapper.selectByPrimaryKey(projectId);
|
|
||||||
Assertions.assertNull(projectExtend.getModuleSetting());
|
Assertions.assertNull(projectExtend.getModuleSetting());
|
||||||
|
|
||||||
//设置了模块模版
|
//设置了模块模版
|
||||||
|
@ -456,6 +448,9 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
project = this.generatorAdd("organizationId", "org-pool-error", null, true, List.of("admin"));
|
project = this.generatorAdd("organizationId", "org-pool-error", null, true, List.of("admin"));
|
||||||
project.setResourcePoolIds(List.of("resourcePoolId3"));
|
project.setResourcePoolIds(List.of("resourcePoolId3"));
|
||||||
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
|
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
|
||||||
|
//成员为空
|
||||||
|
project = this.generatorAdd("organizationId", "org-pool-error", null, true, null);
|
||||||
|
this.requestPost(addProject, project, BAD_REQUEST_MATCHER);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,7 +596,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
@Test
|
@Test
|
||||||
@Order(7)
|
@Order(7)
|
||||||
public void testUpdateProject() throws Exception {
|
public void testUpdateProject() throws Exception {
|
||||||
UpdateProjectRequest project = this.generatorUpdate("organizationId", projectId, "organization-TestName", "Edit name", true, List.of("admin1"));
|
UpdateProjectRequest project = this.generatorUpdate("organizationId", projectId, "organization-TestName", "Edit name", true, List.of("admin", "admin1"));
|
||||||
Project projectExtend = projectMapper.selectByPrimaryKey(projectId);
|
Project projectExtend = projectMapper.selectByPrimaryKey(projectId);
|
||||||
List<String> moduleIds = new ArrayList<>();
|
List<String> moduleIds = new ArrayList<>();
|
||||||
if (StringUtils.isNotBlank(projectExtend.getModuleSetting())) {
|
if (StringUtils.isNotBlank(projectExtend.getModuleSetting())) {
|
||||||
|
@ -626,22 +621,17 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
// 校验日志
|
// 校验日志
|
||||||
checkLog(projectId, OperationLogType.ADD);
|
checkLog(projectId, OperationLogType.ADD);
|
||||||
//用户id为空
|
//用户id为空
|
||||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "organization-TestNameUserIdIsNull", "Edit name", true, new ArrayList<>());
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "organization-TestNameUserIdIsNull", "Edit name", true, List.of("admin1"));
|
||||||
mvcResult = this.responsePost(updateProject, project);
|
mvcResult = this.responsePost(updateProject, project);
|
||||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||||
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
||||||
compareProjectDTO(currentProject, result);
|
compareProjectDTO(currentProject, result);
|
||||||
userRoleRelationExample = new UserRoleRelationExample();
|
|
||||||
userRoleRelationExample.createCriteria().andSourceIdEqualTo("projectId2").andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
|
||||||
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
|
||||||
//断言userRoleRelations是空的
|
|
||||||
Assertions.assertTrue(userRoleRelations.isEmpty());
|
|
||||||
//断言模块设置
|
//断言模块设置
|
||||||
projectExtend = projectMapper.selectByPrimaryKey("projectId2");
|
projectExtend = projectMapper.selectByPrimaryKey("projectId2");
|
||||||
Assertions.assertEquals(projectExtend.getModuleSetting(), CollectionUtils.isEmpty(project.getModuleIds()) ? null : JSON.toJSONString(project.getModuleIds()));
|
Assertions.assertEquals(projectExtend.getModuleSetting(), CollectionUtils.isEmpty(project.getModuleIds()) ? null : JSON.toJSONString(project.getModuleIds()));
|
||||||
|
|
||||||
// 修改模块设置
|
// 修改模块设置
|
||||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "org-Module", "Edit name", true, new ArrayList<>());
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "org-Module", "Edit name", true, List.of("admin1"));
|
||||||
moduleIds = new ArrayList<>();
|
moduleIds = new ArrayList<>();
|
||||||
moduleIds.add("apiTest");
|
moduleIds.add("apiTest");
|
||||||
moduleIds.add("uiTest");
|
moduleIds.add("uiTest");
|
||||||
|
@ -650,17 +640,12 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||||
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
||||||
compareProjectDTO(currentProject, result);
|
compareProjectDTO(currentProject, result);
|
||||||
userRoleRelationExample = new UserRoleRelationExample();
|
|
||||||
userRoleRelationExample.createCriteria().andSourceIdEqualTo("projectId2").andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
|
||||||
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
|
||||||
//断言userRoleRelations是空的
|
|
||||||
Assertions.assertTrue(userRoleRelations.isEmpty());
|
|
||||||
//断言模块设置
|
//断言模块设置
|
||||||
projectExtend = projectMapper.selectByPrimaryKey("projectId2");
|
projectExtend = projectMapper.selectByPrimaryKey("projectId2");
|
||||||
Assertions.assertEquals(projectExtend.getModuleSetting(), JSON.toJSONString(moduleIds));
|
Assertions.assertEquals(projectExtend.getModuleSetting(), JSON.toJSONString(moduleIds));
|
||||||
|
|
||||||
//设置资源池
|
//设置资源池
|
||||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId3", "org-updatePools", "org-updatePools", true, new ArrayList<>());
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId3", "org-updatePools", "org-updatePools", true, List.of("admin1"));
|
||||||
project.setResourcePoolIds(List.of("resourcePoolId", "resourcePoolId1"));
|
project.setResourcePoolIds(List.of("resourcePoolId", "resourcePoolId1"));
|
||||||
mvcResult = this.responsePost(updateProject, project);
|
mvcResult = this.responsePost(updateProject, project);
|
||||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||||
|
@ -701,6 +686,8 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId", "org-Module-pool", null, true, List.of("admin"));
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId", "org-Module-pool", null, true, List.of("admin"));
|
||||||
project.setResourcePoolIds(List.of("resourcePoolId3"));
|
project.setResourcePoolIds(List.of("resourcePoolId3"));
|
||||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||||
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId", "org-Module-pool", null, true, null);
|
||||||
|
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -897,6 +884,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
projectId = "projectId111";
|
projectId = "projectId111";
|
||||||
userId = "admin1";
|
userId = "admin1";
|
||||||
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
||||||
|
this.responseGet(removeProjectMember + "projectId3" + "/" + "admin1", ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -349,7 +349,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
assertionsRefStatusFlowSetting(projectId);
|
assertionsRefStatusFlowSetting(projectId);
|
||||||
|
|
||||||
//userId为空的时候
|
//userId为空的时候
|
||||||
project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "userIdIsNull", "description", true, new ArrayList<>());
|
project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "userIdNotNull", "description", true, List.of("admin"));
|
||||||
// 开启项目模板
|
// 开启项目模板
|
||||||
changeOrgTemplateEnable(false);
|
changeOrgTemplateEnable(false);
|
||||||
mvcResult = this.responsePost(addProject, project);
|
mvcResult = this.responsePost(addProject, project);
|
||||||
|
@ -626,6 +626,9 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "pool", null, true, List.of("admin"));
|
project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "pool", null, true, List.of("admin"));
|
||||||
project.setResourcePoolIds(List.of("resourcePoolId3"));
|
project.setResourcePoolIds(List.of("resourcePoolId3"));
|
||||||
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
|
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
|
||||||
|
//成员为空
|
||||||
|
project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "name", null, true, null);
|
||||||
|
this.requestPost(addProject, project, BAD_REQUEST_MATCHER);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,22 +782,8 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
||||||
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().containsAll(List.of("admin", "admin1")));
|
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().containsAll(List.of("admin", "admin1")));
|
||||||
|
|
||||||
//用户id为空
|
|
||||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1", "TestNameUserIdIsNull", "Edit name", true, new ArrayList<>());
|
|
||||||
Project projectExtend = projectMapper.selectByPrimaryKey("projectId1");
|
|
||||||
projectExtend.setModuleSetting(null);
|
|
||||||
mvcResult = this.responsePost(updateProject, project);
|
|
||||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
|
||||||
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
|
||||||
compareProjectDTO(currentProject, result);
|
|
||||||
userRoleRelationExample = new UserRoleRelationExample();
|
|
||||||
userRoleRelationExample.createCriteria().andSourceIdEqualTo("projectId1").andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
|
||||||
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
|
||||||
//断言userRoleRelations是空的
|
|
||||||
Assertions.assertTrue(userRoleRelations.isEmpty());
|
|
||||||
|
|
||||||
// 修改模块设置
|
// 修改模块设置
|
||||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1", "Module", "Edit name", true, new ArrayList<>());
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1", "TestName2", "Edit name", true, List.of("admin"));
|
||||||
List<String> moduleIds = new ArrayList<>();
|
List<String> moduleIds = new ArrayList<>();
|
||||||
moduleIds.add("apiTest");
|
moduleIds.add("apiTest");
|
||||||
moduleIds.add("uiTest");
|
moduleIds.add("uiTest");
|
||||||
|
@ -804,17 +793,12 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||||
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
||||||
compareProjectDTO(currentProject, result);
|
compareProjectDTO(currentProject, result);
|
||||||
userRoleRelationExample = new UserRoleRelationExample();
|
|
||||||
userRoleRelationExample.createCriteria().andSourceIdEqualTo("projectId1").andRoleIdEqualTo(InternalUserRole.PROJECT_ADMIN.getValue());
|
|
||||||
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
|
||||||
//断言userRoleRelations是空的
|
|
||||||
Assertions.assertTrue(userRoleRelations.isEmpty());
|
|
||||||
//断言模块设置
|
//断言模块设置
|
||||||
projectExtend = projectMapper.selectByPrimaryKey("projectId1");
|
Project projectExtend = projectMapper.selectByPrimaryKey("projectId1");
|
||||||
Assertions.assertEquals(projectExtend.getModuleSetting(), JSON.toJSONString(moduleIds));
|
Assertions.assertEquals(projectExtend.getModuleSetting(), JSON.toJSONString(moduleIds));
|
||||||
|
|
||||||
//设置资源池
|
//设置资源池
|
||||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId5", "updatePools", "updatePools", true, new ArrayList<>());
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId5", "updatePools", "updatePools", true, List.of("admin"));
|
||||||
project.setResourcePoolIds(List.of("resourcePoolId", "resourcePoolId1"));
|
project.setResourcePoolIds(List.of("resourcePoolId", "resourcePoolId1"));
|
||||||
mvcResult = this.responsePost(updateProject, project);
|
mvcResult = this.responsePost(updateProject, project);
|
||||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||||
|
@ -854,6 +838,9 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "pool-edit", "description", true, List.of("admin"));
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "pool-edit", "description", true, List.of("admin"));
|
||||||
project.setResourcePoolIds(List.of("resourcePoolId3"));
|
project.setResourcePoolIds(List.of("resourcePoolId3"));
|
||||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||||
|
//成员为空
|
||||||
|
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "name", null, true, null);
|
||||||
|
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,6 +1030,10 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
projectId = "projectId111";
|
projectId = "projectId111";
|
||||||
userId = "admin1";
|
userId = "admin1";
|
||||||
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
||||||
|
//用户id为最后一个管理员
|
||||||
|
projectId = "projectId5";
|
||||||
|
userId = "admin";
|
||||||
|
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -126,6 +126,7 @@ public class TestPlanTests extends BaseTest {
|
||||||
private static TestPlan repeatCaseTestPlan;
|
private static TestPlan repeatCaseTestPlan;
|
||||||
|
|
||||||
private static final String[] PROJECT_MODULE = new String[]{"workstation", "testPlan", "bugManagement", "caseManagement", "apiTest", "uiTest", "loadTest"};
|
private static final String[] PROJECT_MODULE = new String[]{"workstation", "testPlan", "bugManagement", "caseManagement", "apiTest", "uiTest", "loadTest"};
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void initTestData() {
|
public void initTestData() {
|
||||||
//文件管理专用项目
|
//文件管理专用项目
|
||||||
|
@ -135,6 +136,7 @@ public class TestPlanTests extends BaseTest {
|
||||||
initProject.setName("文件管理专用项目");
|
initProject.setName("文件管理专用项目");
|
||||||
initProject.setDescription("建国创建的文件管理专用项目");
|
initProject.setDescription("建国创建的文件管理专用项目");
|
||||||
initProject.setEnable(true);
|
initProject.setEnable(true);
|
||||||
|
initProject.setUserIds(List.of("admin"));
|
||||||
project = commonProjectService.add(initProject, "admin", "/organization-project/add", OperationLogModule.SETTING_ORGANIZATION_PROJECT);
|
project = commonProjectService.add(initProject, "admin", "/organization-project/add", OperationLogModule.SETTING_ORGANIZATION_PROJECT);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue