refactor: org member change request

This commit is contained in:
guoyuqi 2023-08-28 10:56:32 +08:00 committed by 刘瑞斌
parent 07fe3541de
commit 9c8e81e9f3
5 changed files with 44 additions and 12 deletions

View File

@ -12,7 +12,7 @@ import java.util.List;
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class OrgMemberExtendProjectRequest extends OrganizationMemberRequest{
public class OrgMemberExtendProjectRequest extends OrganizationMemberRequestByOrg{
/**
* 项目ID集合

View File

@ -13,7 +13,7 @@ import java.util.List;
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class OrganizationMemberExtendRequest extends OrganizationMemberRequest {
public class OrganizationMemberExtendRequest extends OrganizationMemberRequestByOrg {
/**
* 用户组ID集合

View File

@ -0,0 +1,32 @@
package io.metersphere.system.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.List;
/**
* @author guoyuqi
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class OrganizationMemberRequestByOrg implements Serializable {
/**
* 组织ID
*/
@Schema(description = "组织ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{organization.id.not_blank}")
private String organizationId;
/**
* 成员ID集合
*/
@Schema(description = "成员ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{user.id.not_blank}")
private List<String> memberIds;
}

View File

@ -315,7 +315,7 @@ public class OrganizationService {
public void addMemberByOrg(OrganizationMemberExtendRequest organizationMemberExtendRequest, String createUserId) {
String organizationId = organizationMemberExtendRequest.getOrganizationId();
checkOrgExistById(organizationId);
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getUserIds());
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getMemberIds());
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds(), organizationId);
setRelationByMemberAndGroupIds(organizationMemberExtendRequest, createUserId, userMap, userRoleMap, true);
}
@ -325,7 +325,7 @@ public class OrganizationService {
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
List<LogDTO> logDTOList = new ArrayList<>();
String organizationId = organizationMemberExtendRequest.getOrganizationId();
organizationMemberExtendRequest.getUserIds().forEach(memberId -> {
organizationMemberExtendRequest.getMemberIds().forEach(memberId -> {
if (userMap.get(memberId) == null) {
throw new MSException("id:" + memberId + Translator.get("user.not.exist"));
}
@ -376,7 +376,7 @@ public class OrganizationService {
public void addMemberRole(OrganizationMemberExtendRequest organizationMemberExtendRequest, String userId) {
String organizationId = organizationMemberExtendRequest.getOrganizationId();
checkOrgExistById(organizationId);
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getUserIds());
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getMemberIds());
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds(), organizationId);
//在新增组织成员与用户组和组织的关系
setRelationByMemberAndGroupIds(organizationMemberExtendRequest, userId, userMap, userRoleMap, false);
@ -390,7 +390,7 @@ public class OrganizationService {
List<LogDTO> logDTOList = new ArrayList<>();
List<String> projectIds = orgMemberExtendProjectRequest.getProjectIds();
//用户不在当前组织内过掉
Map<String, User> userMap = checkUserExist(orgMemberExtendProjectRequest.getUserIds());
Map<String, User> userMap = checkUserExist(orgMemberExtendProjectRequest.getMemberIds());
List<String> userIds = userMap.values().stream().map(User::getId).toList();
userIds.forEach(memberId -> {
projectIds.forEach(projectId -> {

View File

@ -56,7 +56,7 @@ public class OrganizationControllerTests extends BaseTest {
public void addMemberByOrgSuccess() throws Exception {
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
organizationMemberRequest.setUserIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setUserRoleIds(Arrays.asList("sys_default_org_role_id_3", "sys_default_project_role_id_1"));
this.requestPost(ORGANIZATION_LIST_ADD_MEMBER, organizationMemberRequest, status().isOk());
// 批量添加成员成功后, 验证是否添加成功
@ -127,7 +127,7 @@ public class OrganizationControllerTests extends BaseTest {
public void updateOrgMemberSuccessWithNoSysProjectIds() throws Exception {
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
organizationMemberRequest.setOrganizationId("sys_default_organization_7");
organizationMemberRequest.setUserIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setUserRoleIds(Arrays.asList("sys_default_org_role_id_7", "sys_default_project_role_id_8"));
this.requestPost(ORGANIZATION_LIST_ADD_MEMBER, organizationMemberRequest, status().isOk());
@ -180,7 +180,7 @@ public class OrganizationControllerTests extends BaseTest {
public void updateOrgMemberToRoleSuccess() throws Exception {
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
organizationMemberRequest.setUserIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setUserRoleIds(List.of("sys_default_org_role_id_4"));
this.requestPost(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, organizationMemberRequest, status().isOk());
// 批量添加成员成功后, 验证是否添加成功
@ -221,7 +221,7 @@ public class OrganizationControllerTests extends BaseTest {
public void addOrgMemberToProjectSuccess() throws Exception {
OrgMemberExtendProjectRequest organizationMemberRequest = new OrgMemberExtendProjectRequest();
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
organizationMemberRequest.setUserIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setProjectIds(Arrays.asList("sys_org_projectId2", "sys_org_projectId3"));
this.requestPost(ORGANIZATION_PROJECT_ADD_MEMBER, organizationMemberRequest, status().isOk());
// 批量添加成员成功后, 验证是否添加成功
@ -516,7 +516,7 @@ public class OrganizationControllerTests extends BaseTest {
private void addOrganizationMemberError(String url, String organizationId, List<String> userIds, List<String> userGroupIds, ResultMatcher resultMatcher) throws Exception {
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
organizationMemberRequest.setOrganizationId(organizationId);
organizationMemberRequest.setUserIds(userIds);
organizationMemberRequest.setMemberIds(userIds);
organizationMemberRequest.setUserRoleIds(userGroupIds);
this.requestPost(url, organizationMemberRequest, resultMatcher);
}
@ -534,7 +534,7 @@ public class OrganizationControllerTests extends BaseTest {
private void addOrUpdateOrganizationProjectMemberError(String url, String organizationId, List<String> userIds, List<String> projectIds, ResultMatcher resultMatcher) throws Exception {
OrgMemberExtendProjectRequest organizationMemberRequest = new OrgMemberExtendProjectRequest();
organizationMemberRequest.setOrganizationId(organizationId);
organizationMemberRequest.setUserIds(userIds);
organizationMemberRequest.setMemberIds(userIds);
organizationMemberRequest.setProjectIds(projectIds);
this.requestPost(url, organizationMemberRequest, resultMatcher);
}