feat(系统设置): organization add member
This commit is contained in:
parent
a2157ac189
commit
1ec447be2b
|
@ -90,3 +90,4 @@ file_metadata.storage.not_blank=Storage is required
|
||||||
functional_case_template_extend.id.not_blank=ID is required
|
functional_case_template_extend.id.not_blank=ID is required
|
||||||
functional_case_template_extend.step_model.length_range=Step Model length must be between {min} and {max}
|
functional_case_template_extend.step_model.length_range=Step Model length must be between {min} and {max}
|
||||||
functional_case_template_extend.step_model.not_blank=Step Model is required
|
functional_case_template_extend.step_model.not_blank=Step Model is required
|
||||||
|
project_is_null=Project does not exist
|
||||||
|
|
|
@ -90,3 +90,4 @@ file_metadata.storage.not_blank=存储不能为空
|
||||||
functional_case_template_extend.id.not_blank=ID不能为空
|
functional_case_template_extend.id.not_blank=ID不能为空
|
||||||
functional_case_template_extend.step_model.length_range=步骤模型长度必须在{min}-{max}之间
|
functional_case_template_extend.step_model.length_range=步骤模型长度必须在{min}-{max}之间
|
||||||
functional_case_template_extend.step_model.not_blank=步骤模型不能为空
|
functional_case_template_extend.step_model.not_blank=步骤模型不能为空
|
||||||
|
project_not_exist=项目不存在
|
||||||
|
|
|
@ -90,3 +90,4 @@ file_metadata.storage.not_blank=存儲不能為空
|
||||||
functional_case_template_extend.id.not_blank=ID不能為空
|
functional_case_template_extend.id.not_blank=ID不能為空
|
||||||
functional_case_template_extend.step_model.length_range=步驟模型長度必須在{min}-{max}之間
|
functional_case_template_extend.step_model.length_range=步驟模型長度必須在{min}-{max}之間
|
||||||
functional_case_template_extend.step_model.not_blank=步驟模型不能為空
|
functional_case_template_extend.step_model.not_blank=步驟模型不能為空
|
||||||
|
project_is_null=項目不存在
|
||||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.sdk.log.constants.OperationLogType;
|
||||||
import io.metersphere.sdk.util.PageUtils;
|
import io.metersphere.sdk.util.PageUtils;
|
||||||
import io.metersphere.sdk.util.Pager;
|
import io.metersphere.sdk.util.Pager;
|
||||||
import io.metersphere.sdk.util.SessionUtils;
|
import io.metersphere.sdk.util.SessionUtils;
|
||||||
|
import io.metersphere.system.dto.IdNameStructureDTO;
|
||||||
import io.metersphere.system.dto.OrgUserExtend;
|
import io.metersphere.system.dto.OrgUserExtend;
|
||||||
import io.metersphere.system.request.*;
|
import io.metersphere.system.request.*;
|
||||||
import io.metersphere.system.service.OrganizationService;
|
import io.metersphere.system.service.OrganizationService;
|
||||||
|
@ -24,6 +25,7 @@ import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author song-cc-rock
|
* @author song-cc-rock
|
||||||
*/
|
*/
|
||||||
|
@ -53,14 +55,14 @@ public class OrganizationController {
|
||||||
@PostMapping("/role/update-member")
|
@PostMapping("/role/update-member")
|
||||||
@Operation(summary = "添加组织成员至用户组")
|
@Operation(summary = "添加组织成员至用户组")
|
||||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_UPDATE)
|
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_UPDATE)
|
||||||
public void updateMemberRole(@Validated @RequestBody OrganizationMemberExtendRequest organizationMemberExtendRequest) {
|
public void addMemberRole(@Validated @RequestBody OrganizationMemberExtendRequest organizationMemberExtendRequest) {
|
||||||
organizationService.updateMemberRole(organizationMemberExtendRequest, SessionUtils.getUserId());
|
organizationService.addMemberRole(organizationMemberExtendRequest, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/update-member")
|
@PostMapping("/update-member")
|
||||||
@Operation(summary = "更新用户组")
|
@Operation(summary = "更新用户")
|
||||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_UPDATE)
|
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_UPDATE)
|
||||||
public void updateMember(@Validated @RequestBody OrganizationMemberExtendRequest organizationMemberExtendRequest) {
|
public void updateMember(@Validated @RequestBody OrganizationMemberUpdateRequest organizationMemberExtendRequest) {
|
||||||
organizationService.updateMember(organizationMemberExtendRequest, SessionUtils.getUserId());
|
organizationService.updateMember(organizationMemberExtendRequest, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,4 +85,25 @@ public class OrganizationController {
|
||||||
organizationService.removeMember(organizationId, userId);
|
organizationService.removeMember(organizationId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/project/list/{organizationId}")
|
||||||
|
@Operation(summary = "获取当前组织下的所有项目")
|
||||||
|
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_UPDATE)
|
||||||
|
public List<IdNameStructureDTO> getProjectList(@PathVariable(value = "organizationId") String organizationId) {
|
||||||
|
return organizationService.getProjectList(organizationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/user/role/list/{organizationId}")
|
||||||
|
@Operation(summary = "获取当前组织下的所有自定义用户组以及组织级别的用户组")
|
||||||
|
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_UPDATE)
|
||||||
|
public List<IdNameStructureDTO> getUserRoleList(@PathVariable(value = "organizationId") String organizationId) {
|
||||||
|
return organizationService.getUserRoleList(organizationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/not-exist/user/list/{organizationId}")
|
||||||
|
@Operation(summary = "获取不在当前组织的所有用户")
|
||||||
|
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_UPDATE)
|
||||||
|
public List<IdNameStructureDTO> getUserList(@PathVariable(value = "organizationId") String organizationId) {
|
||||||
|
return organizationService.getUserList(organizationId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package io.metersphere.system.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class IdNameStructureDTO {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author guoyuqi
|
* @author guoyuqi
|
||||||
|
@ -15,8 +15,8 @@ import java.util.Map;
|
||||||
public class OrgUserExtend extends User {
|
public class OrgUserExtend extends User {
|
||||||
|
|
||||||
@Schema(title = "项目ID名称集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(title = "项目ID名称集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private Map<String,String> projectIdNameMap;;
|
private List<IdNameStructureDTO> projectIdNameMap;;
|
||||||
|
|
||||||
@Schema(title = "用户组ID名称集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(title = "用户组ID名称集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private Map<String,String> userRoleIdNameMap;
|
private List<IdNameStructureDTO> userRoleIdNameMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
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 java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author guoyuqi
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class OrganizationMemberUpdateRequest implements Serializable {
|
||||||
|
/**
|
||||||
|
* 组织ID
|
||||||
|
*/
|
||||||
|
@Schema(title = "组织ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotBlank(message = "{organization.id.not_blank}")
|
||||||
|
private String organizationId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成员ID
|
||||||
|
*/
|
||||||
|
@Schema(title = "成员ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotBlank(message = "{organization.member.not_blank}")
|
||||||
|
private String memberId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户组ID集合
|
||||||
|
*/
|
||||||
|
@Schema(title = "用户组ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "{userGroupId.id.not_null}")
|
||||||
|
private List<String> userRoleIds;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目ID集合
|
||||||
|
*/
|
||||||
|
@Schema(title = "项目ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private List<String> projectIds;
|
||||||
|
}
|
|
@ -5,6 +5,8 @@ import io.metersphere.project.domain.ProjectExample;
|
||||||
import io.metersphere.project.mapper.ProjectMapper;
|
import io.metersphere.project.mapper.ProjectMapper;
|
||||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||||
import io.metersphere.sdk.constants.InternalUserRole;
|
import io.metersphere.sdk.constants.InternalUserRole;
|
||||||
|
import io.metersphere.sdk.constants.UserRoleEnum;
|
||||||
|
import io.metersphere.sdk.constants.UserRoleType;
|
||||||
import io.metersphere.sdk.dto.LogDTO;
|
import io.metersphere.sdk.dto.LogDTO;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.log.constants.OperationLogModule;
|
import io.metersphere.sdk.log.constants.OperationLogModule;
|
||||||
|
@ -14,15 +16,12 @@ import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.*;
|
import io.metersphere.system.domain.*;
|
||||||
import io.metersphere.system.dto.OrgUserExtend;
|
import io.metersphere.system.dto.*;
|
||||||
import io.metersphere.system.dto.OrganizationDTO;
|
|
||||||
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
|
|
||||||
import io.metersphere.system.dto.UserExtend;
|
import io.metersphere.system.dto.UserExtend;
|
||||||
import io.metersphere.system.mapper.*;
|
import io.metersphere.system.mapper.*;
|
||||||
import io.metersphere.system.request.*;
|
import io.metersphere.system.request.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.ibatis.session.ExecutorType;
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
@ -67,6 +66,17 @@ public class OrganizationService {
|
||||||
return buildOrgAdminInfo(organizationDTOS);
|
return buildOrgAdminInfo(organizationDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<OrganizationDTO> buildOrgAdminInfo(List<OrganizationDTO> organizationDTOS) {
|
||||||
|
if (CollectionUtils.isEmpty(organizationDTOS)) {
|
||||||
|
return organizationDTOS;
|
||||||
|
}
|
||||||
|
organizationDTOS.forEach(organizationDTO -> {
|
||||||
|
List<User> orgAdminList = extOrganizationMapper.getOrgAdminList(organizationDTO.getId());
|
||||||
|
organizationDTO.setOrgAdmins(orgAdminList);
|
||||||
|
});
|
||||||
|
return organizationDTOS;
|
||||||
|
}
|
||||||
|
|
||||||
public List<OrganizationDTO> listAll() {
|
public List<OrganizationDTO> listAll() {
|
||||||
return extOrganizationMapper.listAll();
|
return extOrganizationMapper.listAll();
|
||||||
}
|
}
|
||||||
|
@ -93,7 +103,7 @@ public class OrganizationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMemberBySystem(OrganizationMemberBatchRequest batchRequest, String createUserId) {
|
public void addMemberBySystem(OrganizationMemberBatchRequest batchRequest, String createUserId) {
|
||||||
checkOrgExist(batchRequest.getOrganizationIds());
|
checkOrgExistByIds(batchRequest.getOrganizationIds());
|
||||||
Map<String, User> userMap = checkUserExist(batchRequest.getMemberIds());
|
Map<String, User> userMap = checkUserExist(batchRequest.getMemberIds());
|
||||||
List<UserRoleRelation> userRoleRelations = new ArrayList<>();
|
List<UserRoleRelation> userRoleRelations = new ArrayList<>();
|
||||||
batchRequest.getOrganizationIds().forEach(organizationId -> {
|
batchRequest.getOrganizationIds().forEach(organizationId -> {
|
||||||
|
@ -122,6 +132,13 @@ public class OrganizationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织级别获取组织成员
|
||||||
|
*
|
||||||
|
* @param organizationRequest
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public List<OrgUserExtend> getMemberListByOrg(OrganizationRequest organizationRequest) {
|
public List<OrgUserExtend> getMemberListByOrg(OrganizationRequest organizationRequest) {
|
||||||
//根据组织ID获取所有组织用户关系表
|
//根据组织ID获取所有组织用户关系表
|
||||||
String organizationId = organizationRequest.getOrganizationId();
|
String organizationId = organizationRequest.getOrganizationId();
|
||||||
|
@ -142,21 +159,24 @@ public class OrganizationService {
|
||||||
userRoleRelationExample.createCriteria().andUserIdIn(new ArrayList<>(userMap.keySet())).andSourceIdIn(sourceIds);
|
userRoleRelationExample.createCriteria().andUserIdIn(new ArrayList<>(userMap.keySet())).andSourceIdIn(sourceIds);
|
||||||
List<UserRoleRelation> userRoleRelationsByUsers = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
List<UserRoleRelation> userRoleRelationsByUsers = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
||||||
//根据关系表查询出用户的关联组织和用户组
|
//根据关系表查询出用户的关联组织和用户组
|
||||||
Map<String, Map<String, String>> userIdprojectIdMap = new HashMap<>();
|
Map<String, List<IdNameStructureDTO>> userIdprojectIdMap = new HashMap<>();
|
||||||
Map<String, Set<String>> userIdRoleIdMap = new HashMap<>();
|
Map<String, Set<String>> userIdRoleIdMap = new HashMap<>();
|
||||||
for (UserRoleRelation userRoleRelationsByUser : userRoleRelationsByUsers) {
|
for (UserRoleRelation userRoleRelationsByUser : userRoleRelationsByUsers) {
|
||||||
String projectId = userRoleRelationsByUser.getSourceId();
|
String projectId = userRoleRelationsByUser.getSourceId();
|
||||||
String roleId = userRoleRelationsByUser.getRoleId();
|
String roleId = userRoleRelationsByUser.getRoleId();
|
||||||
String userId = userRoleRelationsByUser.getUserId();
|
String userId = userRoleRelationsByUser.getUserId();
|
||||||
Map<String, String> pIdNameMap = userIdprojectIdMap.get(userId);
|
List<IdNameStructureDTO> pIdNameList = userIdprojectIdMap.get(userId);
|
||||||
if (MapUtils.isEmpty(pIdNameMap)) {
|
if (CollectionUtils.isEmpty(pIdNameList)) {
|
||||||
pIdNameMap = new HashMap<>();
|
pIdNameList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
String projectName = projectIdNameMap.get(projectId);
|
String projectName = projectIdNameMap.get(projectId);
|
||||||
if (StringUtils.isNotBlank(projectName)) {
|
if (StringUtils.isNotBlank(projectName)) {
|
||||||
pIdNameMap.put(projectId, projectName);
|
IdNameStructureDTO idNameStructureDTO = new IdNameStructureDTO();
|
||||||
|
idNameStructureDTO.setId(projectId);
|
||||||
|
idNameStructureDTO.setName(projectName);
|
||||||
|
pIdNameList.add(idNameStructureDTO);
|
||||||
}
|
}
|
||||||
userIdprojectIdMap.put(userId, pIdNameMap);
|
userIdprojectIdMap.put(userId, pIdNameList);
|
||||||
|
|
||||||
Set<String> roleIds = userIdRoleIdMap.get(userId);
|
Set<String> roleIds = userIdRoleIdMap.get(userId);
|
||||||
if (CollectionUtils.isEmpty(roleIds)) {
|
if (CollectionUtils.isEmpty(roleIds)) {
|
||||||
|
@ -166,23 +186,29 @@ public class OrganizationService {
|
||||||
userIdRoleIdMap.put(userId, roleIds);
|
userIdRoleIdMap.put(userId, roleIds);
|
||||||
}
|
}
|
||||||
for (OrgUserExtend orgUserExtend : orgUserExtends) {
|
for (OrgUserExtend orgUserExtend : orgUserExtends) {
|
||||||
Map<String, String> pIdNameMap = userIdprojectIdMap.get(orgUserExtend.getId());
|
List<IdNameStructureDTO> projectList = userIdprojectIdMap.get(orgUserExtend.getId());
|
||||||
if (MapUtils.isNotEmpty(pIdNameMap)) {
|
if (CollectionUtils.isNotEmpty(projectList)) {
|
||||||
//移除当前组织id
|
orgUserExtend.setProjectIdNameMap(projectList);
|
||||||
orgUserExtend.setProjectIdNameMap(projectIdNameMap);
|
|
||||||
}
|
}
|
||||||
Set<String> userRoleIds = userIdRoleIdMap.get(orgUserExtend.getId());
|
Set<String> userRoleIds = userIdRoleIdMap.get(orgUserExtend.getId());
|
||||||
UserRoleExample userRoleExample = new UserRoleExample();
|
UserRoleExample userRoleExample = new UserRoleExample();
|
||||||
userRoleExample.createCriteria().andIdIn(new ArrayList<>(userRoleIds));
|
userRoleExample.createCriteria().andIdIn(new ArrayList<>(userRoleIds));
|
||||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||||
Map<String, String> userRoleIdNameMap = userRoles.stream().collect(Collectors.toMap(UserRole::getId, UserRole::getName));
|
List<IdNameStructureDTO> userRoleList = new ArrayList<>();
|
||||||
orgUserExtend.setUserRoleIdNameMap(userRoleIdNameMap);
|
setUserRoleList(userRoleList, userRoles);
|
||||||
|
orgUserExtend.setUserRoleIdNameMap(userRoleList);
|
||||||
}
|
}
|
||||||
return orgUserExtends;
|
return orgUserExtends;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除组织成员
|
||||||
|
*
|
||||||
|
* @param organizationId
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
public void removeMember(String organizationId, String userId) {
|
public void removeMember(String organizationId, String userId) {
|
||||||
checkOrgExist(List.of(organizationId));
|
checkOrgExistById(organizationId);
|
||||||
//删除组织下项目与成员的关系
|
//删除组织下项目与成员的关系
|
||||||
List<String> projectIds = getProjectIds(organizationId);
|
List<String> projectIds = getProjectIds(organizationId);
|
||||||
if (CollectionUtils.isNotEmpty(projectIds)) {
|
if (CollectionUtils.isNotEmpty(projectIds)) {
|
||||||
|
@ -196,25 +222,15 @@ public class OrganizationService {
|
||||||
userRoleRelationMapper.deleteByExample(example);
|
userRoleRelationMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OrganizationDTO> buildOrgAdminInfo(List<OrganizationDTO> organizationDTOS) {
|
|
||||||
if (CollectionUtils.isEmpty(organizationDTOS)) {
|
|
||||||
return organizationDTOS;
|
|
||||||
}
|
|
||||||
organizationDTOS.forEach(organizationDTO -> {
|
|
||||||
List<User> orgAdminList = extOrganizationMapper.getOrgAdminList(organizationDTO.getId());
|
|
||||||
organizationDTO.setOrgAdmins(orgAdminList);
|
|
||||||
});
|
|
||||||
return organizationDTOS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrganizationProjectOptionsDTO> getOrganizationOptions() {
|
public List<OrganizationProjectOptionsDTO> getOrganizationOptions() {
|
||||||
return extOrganizationMapper.selectOrganizationOptions();
|
return extOrganizationMapper.selectOrganizationOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMemberByOrg(OrganizationMemberExtendRequest organizationMemberExtendRequest, String createUserId) {
|
public void addMemberByOrg(OrganizationMemberExtendRequest organizationMemberExtendRequest, String createUserId) {
|
||||||
checkOrgExist(List.of(organizationMemberExtendRequest.getOrganizationId()));
|
String organizationId = organizationMemberExtendRequest.getOrganizationId();
|
||||||
|
checkOrgExistById(organizationId);
|
||||||
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getMemberIds());
|
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getMemberIds());
|
||||||
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds());
|
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds(), organizationId);
|
||||||
setRelationByMemberAndGroupIds(organizationMemberExtendRequest, createUserId, userMap, userRoleMap, true);
|
setRelationByMemberAndGroupIds(organizationMemberExtendRequest, createUserId, userMap, userRoleMap, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,20 +243,14 @@ public class OrganizationService {
|
||||||
if (userMap.get(memberId) == null) {
|
if (userMap.get(memberId) == null) {
|
||||||
throw new MSException("id:" + memberId + Translator.get("user.not.exist"));
|
throw new MSException("id:" + memberId + Translator.get("user.not.exist"));
|
||||||
}
|
}
|
||||||
organizationMemberExtendRequest.getUserRoleIds().forEach(userGroupId -> {
|
organizationMemberExtendRequest.getUserRoleIds().forEach(userRoleId -> {
|
||||||
if (userRoleMap.get(userGroupId) != null) {
|
if (userRoleMap.get(userRoleId) != null) {
|
||||||
//过滤已存在的关系
|
//过滤已存在的关系
|
||||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||||
example.createCriteria().andSourceIdEqualTo(organizationId).andUserIdEqualTo(memberId).andRoleIdEqualTo(userGroupId);
|
example.createCriteria().andSourceIdEqualTo(organizationId).andUserIdEqualTo(memberId).andRoleIdEqualTo(userRoleId);
|
||||||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
||||||
if (CollectionUtils.isEmpty(userRoleRelations)) {
|
if (CollectionUtils.isEmpty(userRoleRelations)) {
|
||||||
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, organizationId, userRoleId);
|
||||||
userRoleRelation.setId(UUID.randomUUID().toString());
|
|
||||||
userRoleRelation.setUserId(memberId);
|
|
||||||
userRoleRelation.setSourceId(organizationId);
|
|
||||||
userRoleRelation.setRoleId(userGroupId);
|
|
||||||
userRoleRelation.setCreateTime(System.currentTimeMillis());
|
|
||||||
userRoleRelation.setCreateUser(createUserId);
|
|
||||||
userRoleRelationMapper.insert(userRoleRelation);
|
userRoleRelationMapper.insert(userRoleRelation);
|
||||||
//add Log
|
//add Log
|
||||||
String path = add ? "/organization/add-member" : "/organization/role/update-member";
|
String path = add ? "/organization/add-member" : "/organization/role/update-member";
|
||||||
|
@ -271,41 +281,38 @@ public class OrganizationService {
|
||||||
logDTOList.add(dto);
|
logDTOList.add(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMemberRole(OrganizationMemberExtendRequest organizationMemberExtendRequest, String userId) {
|
/**
|
||||||
|
* 添加组织成员至用户组
|
||||||
|
* @param organizationMemberExtendRequest
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
|
public void addMemberRole(OrganizationMemberExtendRequest organizationMemberExtendRequest, String userId) {
|
||||||
String organizationId = organizationMemberExtendRequest.getOrganizationId();
|
String organizationId = organizationMemberExtendRequest.getOrganizationId();
|
||||||
checkOrgExist(List.of(organizationId));
|
checkOrgExistById(organizationId);
|
||||||
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getMemberIds());
|
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getMemberIds());
|
||||||
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds());
|
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds(), organizationId);
|
||||||
//在新增组织成员与用户组和组织的关系
|
//在新增组织成员与用户组和组织的关系
|
||||||
setRelationByMemberAndGroupIds(organizationMemberExtendRequest, userId, userMap, userRoleMap, false);
|
setRelationByMemberAndGroupIds(organizationMemberExtendRequest, userId, userMap, userRoleMap, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMemberToProject(OrgMemberExtendProjectRequest orgMemberExtendProjectRequest, String userId) {
|
public void addMemberToProject(OrgMemberExtendProjectRequest orgMemberExtendProjectRequest, String userId) {
|
||||||
String requestOrganizationId = orgMemberExtendProjectRequest.getOrganizationId();
|
String requestOrganizationId = orgMemberExtendProjectRequest.getOrganizationId();
|
||||||
checkOrgExist(List.of(requestOrganizationId));
|
checkOrgExistById(requestOrganizationId);
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
|
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
|
||||||
List<LogDTO> logDTOList = new ArrayList<>();
|
List<LogDTO> logDTOList = new ArrayList<>();
|
||||||
List<String> projectIds = orgMemberExtendProjectRequest.getProjectIds();
|
List<String> projectIds = orgMemberExtendProjectRequest.getProjectIds();
|
||||||
//用户不在当前组织内过掉
|
//用户不在当前组织内过掉
|
||||||
Map<String, User> userMap = checkUserExist(orgMemberExtendProjectRequest.getMemberIds());
|
Map<String, User> userMap = checkUserExist(orgMemberExtendProjectRequest.getMemberIds());
|
||||||
orgMemberExtendProjectRequest.getMemberIds().forEach(memberId -> {
|
List<String> userIds = userMap.values().stream().map(User::getId).toList();
|
||||||
if (userMap.get(memberId) == null) {
|
userIds.forEach(memberId -> {
|
||||||
return;
|
|
||||||
}
|
|
||||||
projectIds.forEach(projectId -> {
|
projectIds.forEach(projectId -> {
|
||||||
//过滤已存在的关系
|
//过滤已存在的关系
|
||||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||||
example.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(memberId).andRoleIdEqualTo(InternalUserRole.PROJECT_MEMBER.getValue());
|
example.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(memberId).andRoleIdEqualTo(InternalUserRole.PROJECT_MEMBER.getValue());
|
||||||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
||||||
if (CollectionUtils.isEmpty(userRoleRelations)) {
|
if (CollectionUtils.isEmpty(userRoleRelations)) {
|
||||||
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
UserRoleRelation userRoleRelation = buildUserRoleRelation(userId, memberId, projectId, InternalUserRole.PROJECT_MEMBER.getValue());
|
||||||
userRoleRelation.setId(UUID.randomUUID().toString());
|
|
||||||
userRoleRelation.setUserId(memberId);
|
|
||||||
userRoleRelation.setSourceId(projectId);
|
|
||||||
userRoleRelation.setRoleId(InternalUserRole.PROJECT_MEMBER.getValue());
|
|
||||||
userRoleRelation.setCreateTime(System.currentTimeMillis());
|
|
||||||
userRoleRelation.setCreateUser(userId);
|
|
||||||
userRoleRelationMapper.insert(userRoleRelation);
|
userRoleRelationMapper.insert(userRoleRelation);
|
||||||
//add Log
|
//add Log
|
||||||
setLog(requestOrganizationId, projectId, "/organization/project/add-member", OperationLogModule.PROJECT_PROJECT_MEMBER, "", logDTOList, memberId, userRoleRelation, true);
|
setLog(requestOrganizationId, projectId, "/organization/project/add-member", OperationLogModule.PROJECT_PROJECT_MEMBER, "", logDTOList, memberId, userRoleRelation, true);
|
||||||
|
@ -380,52 +387,169 @@ public class OrganizationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMember(OrganizationMemberExtendRequest organizationMemberExtendRequest, String createUserId) {
|
/**
|
||||||
String organizationId = organizationMemberExtendRequest.getOrganizationId();
|
* 更新用户
|
||||||
List<String> memberIds = organizationMemberExtendRequest.getMemberIds();
|
*
|
||||||
|
* @param organizationMemberUpdateRequest
|
||||||
|
* @param createUserId
|
||||||
|
*/
|
||||||
|
public void updateMember(OrganizationMemberUpdateRequest organizationMemberUpdateRequest, String createUserId) {
|
||||||
|
String organizationId = organizationMemberUpdateRequest.getOrganizationId();
|
||||||
//校验组织是否存在
|
//校验组织是否存在
|
||||||
checkOrgExist(List.of(organizationId));
|
checkOrgExistById(organizationId);
|
||||||
|
//校验用户是否存在
|
||||||
|
String memberId = organizationMemberUpdateRequest.getMemberId();
|
||||||
|
User user = userMapper.selectByPrimaryKey(memberId);
|
||||||
|
if (user == null) {
|
||||||
|
throw new MSException(Translator.get("user.not.exist"));
|
||||||
|
}
|
||||||
//校验成员是否是当前组织的成员
|
//校验成员是否是当前组织的成员
|
||||||
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||||
userRoleRelationExample.createCriteria().andUserIdIn(memberIds).andSourceIdEqualTo(organizationId);
|
userRoleRelationExample.createCriteria().andUserIdEqualTo(memberId).andSourceIdEqualTo(organizationId);
|
||||||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
||||||
List<String> userIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().collect(Collectors.toList());
|
if (CollectionUtils.isEmpty(userRoleRelations)) {
|
||||||
Map<String, User> userMap = checkUserExist(userIds);
|
throw new MSException(Translator.get("organization_member_not_exist"));
|
||||||
//删除旧的关系
|
}
|
||||||
userRoleRelationExample = new UserRoleRelationExample();
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
userRoleRelationExample.createCriteria().andUserIdIn(userIds).andSourceIdEqualTo(organizationId);
|
List<LogDTO> logDTOList = new ArrayList<>();
|
||||||
userRoleRelationMapper.deleteByExample(userRoleRelationExample);
|
//更新用户组
|
||||||
//检查用户组是否是组织级别用户组
|
List<String> userRoleIds = organizationMemberUpdateRequest.getUserRoleIds();
|
||||||
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds());
|
updateUserRoleRelation(createUserId, organizationId, memberId, userRoleIds, sqlSession, logDTOList);
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
//更新项目
|
||||||
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
|
List<String> projectIds = organizationMemberUpdateRequest.getProjectIds();
|
||||||
List<LogDTO> logDTOList = new ArrayList<>();
|
if (CollectionUtils.isNotEmpty(projectIds)) {
|
||||||
userIds.forEach(userId -> {
|
updateProjectUserRelation(createUserId, organizationId, memberId, projectIds, sqlSession, logDTOList);
|
||||||
organizationMemberExtendRequest.getUserRoleIds().forEach(userRoleId -> {
|
|
||||||
if (userRoleMap.get(userRoleId) == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
|
||||||
userRoleRelation.setId(UUID.randomUUID().toString());
|
|
||||||
userRoleRelation.setUserId(userId);
|
|
||||||
userRoleRelation.setSourceId(organizationId);
|
|
||||||
userRoleRelation.setRoleId(userRoleId);
|
|
||||||
userRoleRelation.setCreateTime(System.currentTimeMillis());
|
|
||||||
userRoleRelation.setCreateUser(createUserId);
|
|
||||||
userRoleRelationMapper.insert(userRoleRelation);
|
|
||||||
//add Log
|
|
||||||
String path = "/organization/update-member";
|
|
||||||
setLog(organizationId, "system", path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, userId, userRoleRelation, false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
//写入操作日志
|
//写入操作日志
|
||||||
operationLogService.batchAdd(logDTOList);
|
operationLogService.batchAdd(logDTOList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkOrgExist(List<String> organizationIds) {
|
private void updateProjectUserRelation(String createUserId, String organizationId, String memberId, List<String> projectIds, SqlSession sqlSession, List<LogDTO> logDTOList) {
|
||||||
|
Map<String, Project> projectMap = checkProjectExist(projectIds, organizationId);
|
||||||
|
List<String> projectInDBInOrgIds = projectMap.values().stream().map(Project::getId).collect(Collectors.toList());
|
||||||
|
//删除旧的关系
|
||||||
|
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||||
|
userRoleRelationExample.createCriteria().andUserIdEqualTo(memberId).andSourceIdIn(projectInDBInOrgIds);
|
||||||
|
userRoleRelationMapper.deleteByExample(userRoleRelationExample);
|
||||||
|
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
|
||||||
|
projectInDBInOrgIds.forEach(projectId -> {
|
||||||
|
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, projectId, InternalUserRole.PROJECT_MEMBER.getValue());
|
||||||
|
userRoleRelationMapper.insert(userRoleRelation);
|
||||||
|
//add Log
|
||||||
|
String path = "/organization/update-member";
|
||||||
|
setLog(organizationId, "system", path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, memberId, userRoleRelation, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserRoleRelation buildUserRoleRelation(String createUserId, String memberId, String sourceId, String roleId) {
|
||||||
|
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
||||||
|
userRoleRelation.setId(UUID.randomUUID().toString());
|
||||||
|
userRoleRelation.setUserId(memberId);
|
||||||
|
userRoleRelation.setSourceId(sourceId);
|
||||||
|
userRoleRelation.setRoleId(roleId);
|
||||||
|
userRoleRelation.setCreateTime(System.currentTimeMillis());
|
||||||
|
userRoleRelation.setCreateUser(createUserId);
|
||||||
|
return userRoleRelation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateUserRoleRelation(String createUserId, String organizationId, String memberId, List<String> userRoleIds, SqlSession sqlSession, List<LogDTO> logDTOList) {
|
||||||
|
//检查用户组是否是组织级别用户组
|
||||||
|
Map<String, UserRole> userRoleMap = checkUseRoleExist(userRoleIds, organizationId);
|
||||||
|
List<String> userRoleInDBInOrgIds = userRoleMap.values().stream().map(UserRole::getId).collect(Collectors.toList());
|
||||||
|
//删除旧的关系
|
||||||
|
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||||
|
userRoleRelationExample.createCriteria().andUserIdEqualTo(memberId).andRoleIdIn(userRoleInDBInOrgIds);
|
||||||
|
userRoleRelationMapper.deleteByExample(userRoleRelationExample);
|
||||||
|
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
|
||||||
|
userRoleInDBInOrgIds.forEach(userRoleId -> {
|
||||||
|
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, organizationId, userRoleId);
|
||||||
|
userRoleRelationMapper.insert(userRoleRelation);
|
||||||
|
//add Log
|
||||||
|
String path = "/organization/update-member";
|
||||||
|
setLog(organizationId, "system", path, OperationLogModule.ORGANIZATION_MEMBER, "成员", logDTOList, memberId, userRoleRelation, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前组织下的所有项目
|
||||||
|
*
|
||||||
|
* @param organizationId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<IdNameStructureDTO> getProjectList(String organizationId) {
|
||||||
|
//校验组织是否存在
|
||||||
|
checkOrgExistById(organizationId);
|
||||||
|
List<IdNameStructureDTO> projectList = new ArrayList<>();
|
||||||
|
ProjectExample projectExample = new ProjectExample();
|
||||||
|
projectExample.createCriteria().andOrganizationIdEqualTo(organizationId);
|
||||||
|
List<Project> projects = projectMapper.selectByExample(projectExample);
|
||||||
|
for (Project project : projects) {
|
||||||
|
IdNameStructureDTO idNameStructureDTO = new IdNameStructureDTO();
|
||||||
|
idNameStructureDTO.setId(project.getId());
|
||||||
|
idNameStructureDTO.setName(project.getName());
|
||||||
|
projectList.add(idNameStructureDTO);
|
||||||
|
}
|
||||||
|
return projectList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前组织下的所有自定义用户组以及组织级别的用户组
|
||||||
|
*
|
||||||
|
* @param organizationId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<IdNameStructureDTO> getUserRoleList(String organizationId) {
|
||||||
|
//校验组织是否存在
|
||||||
|
checkOrgExistById(organizationId);
|
||||||
|
List<String> scopeIds = Arrays.asList(UserRoleEnum.GLOBAL.toString(), organizationId);
|
||||||
|
List<IdNameStructureDTO> userRoleList = new ArrayList<>();
|
||||||
|
UserRoleExample userRoleExample = new UserRoleExample();
|
||||||
|
userRoleExample.createCriteria().andTypeEqualTo(UserRoleType.ORGANIZATION.toString()).andScopeIdIn(scopeIds);
|
||||||
|
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||||
|
setUserRoleList(userRoleList, userRoles);
|
||||||
|
return userRoleList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setUserRoleList(List<IdNameStructureDTO> userRoleList, List<UserRole> userRoles) {
|
||||||
|
for (UserRole userRole : userRoles) {
|
||||||
|
IdNameStructureDTO idNameStructureDTO = new IdNameStructureDTO();
|
||||||
|
idNameStructureDTO.setId(userRole.getId());
|
||||||
|
idNameStructureDTO.setName(userRole.getName());
|
||||||
|
userRoleList.add(idNameStructureDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取不在当前组织的所有用户
|
||||||
|
*
|
||||||
|
* @param organizationId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<IdNameStructureDTO> getUserList(String organizationId) {
|
||||||
|
//校验组织是否存在
|
||||||
|
checkOrgExistById(organizationId);
|
||||||
|
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||||
|
userRoleRelationExample.createCriteria().andSourceIdEqualTo(organizationId);
|
||||||
|
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
|
||||||
|
List<String> userIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().toList();
|
||||||
|
UserExample userExample = new UserExample();
|
||||||
|
if (CollectionUtils.isNotEmpty(userIds)) {
|
||||||
|
userExample.createCriteria().andIdNotIn(userIds);
|
||||||
|
}
|
||||||
|
List<User> users = userMapper.selectByExample(userExample);
|
||||||
|
List<IdNameStructureDTO> userList = new ArrayList<>();
|
||||||
|
for (User user : users) {
|
||||||
|
IdNameStructureDTO idNameStructureDTO = new IdNameStructureDTO();
|
||||||
|
idNameStructureDTO.setId(user.getId());
|
||||||
|
idNameStructureDTO.setName(user.getName());
|
||||||
|
userList.add(idNameStructureDTO);
|
||||||
|
}
|
||||||
|
return userList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkOrgExistByIds(List<String> organizationIds) {
|
||||||
OrganizationExample example = new OrganizationExample();
|
OrganizationExample example = new OrganizationExample();
|
||||||
example.createCriteria().andIdIn(organizationIds);
|
example.createCriteria().andIdIn(organizationIds);
|
||||||
if (organizationMapper.countByExample(example) < organizationIds.size()) {
|
if (organizationMapper.countByExample(example) < organizationIds.size()) {
|
||||||
|
@ -433,9 +557,23 @@ public class OrganizationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, UserRole> checkUseRoleExist(List<String> userRoleIds) {
|
private void checkOrgExistById(String organizationId) {
|
||||||
|
Organization organization = organizationMapper.selectByPrimaryKey(organizationId);
|
||||||
|
if (organization == null) {
|
||||||
|
throw new MSException(Translator.get("organization_not_exist"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查组织级别的用户组是否存在
|
||||||
|
* @param userRoleIds
|
||||||
|
* @param organizationId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Map<String, UserRole> checkUseRoleExist(List<String> userRoleIds, String organizationId) {
|
||||||
UserRoleExample userRoleExample = new UserRoleExample();
|
UserRoleExample userRoleExample = new UserRoleExample();
|
||||||
userRoleExample.createCriteria().andIdIn(userRoleIds).andTypeEqualTo("ORGANIZATION");
|
List<String> scopeIds = Arrays.asList(UserRoleEnum.GLOBAL.toString(), organizationId);
|
||||||
|
userRoleExample.createCriteria().andIdIn(userRoleIds).andTypeEqualTo(UserRoleType.ORGANIZATION.toString()).andScopeIdIn(scopeIds);
|
||||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||||
if (CollectionUtils.isEmpty(userRoles)) {
|
if (CollectionUtils.isEmpty(userRoles)) {
|
||||||
throw new MSException(Translator.get("user_role_not_exist"));
|
throw new MSException(Translator.get("user_role_not_exist"));
|
||||||
|
@ -453,4 +591,14 @@ public class OrganizationService {
|
||||||
}
|
}
|
||||||
return users.stream().collect(Collectors.toMap(User::getId, user -> user));
|
return users.stream().collect(Collectors.toMap(User::getId, user -> user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Project> checkProjectExist(List<String> projectIds, String organizationId) {
|
||||||
|
ProjectExample projectExample = new ProjectExample();
|
||||||
|
projectExample.createCriteria().andIdIn(projectIds).andOrganizationIdEqualTo(organizationId);
|
||||||
|
List<Project> projects = projectMapper.selectByExample(projectExample);
|
||||||
|
if (CollectionUtils.isEmpty(projects)) {
|
||||||
|
throw new MSException(Translator.get("project_not_exist"));
|
||||||
|
}
|
||||||
|
return projects.stream().collect(Collectors.toMap(Project::getId, project -> project));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,11 @@ import io.metersphere.sdk.constants.SessionConstants;
|
||||||
import io.metersphere.sdk.controller.handler.ResultHolder;
|
import io.metersphere.sdk.controller.handler.ResultHolder;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.Pager;
|
import io.metersphere.sdk.util.Pager;
|
||||||
|
import io.metersphere.system.dto.IdNameStructureDTO;
|
||||||
import io.metersphere.system.dto.OrgUserExtend;
|
import io.metersphere.system.dto.OrgUserExtend;
|
||||||
import io.metersphere.system.request.OrgMemberExtendProjectRequest;
|
import io.metersphere.system.request.OrgMemberExtendProjectRequest;
|
||||||
import io.metersphere.system.request.OrganizationMemberExtendRequest;
|
import io.metersphere.system.request.OrganizationMemberExtendRequest;
|
||||||
|
import io.metersphere.system.request.OrganizationMemberUpdateRequest;
|
||||||
import io.metersphere.system.request.OrganizationRequest;
|
import io.metersphere.system.request.OrganizationRequest;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
@ -56,32 +58,11 @@ public class OrganizationControllerTests extends BaseTest {
|
||||||
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
|
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
|
||||||
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
|
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
|
||||||
organizationMemberRequest.setMemberIds(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_3"));
|
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());
|
this.requestPost(ORGANIZATION_LIST_ADD_MEMBER, organizationMemberRequest, status().isOk());
|
||||||
// 批量添加成员成功后, 验证是否添加成功
|
// 批量添加成员成功后, 验证是否添加成功
|
||||||
OrganizationRequest organizationRequest = new OrganizationRequest();
|
listByKeyWord("testUserOne", "sys_default_organization_3", true, "sys_default_org_role_id_3", null, false, null, null);
|
||||||
organizationRequest.setCurrent(1);
|
|
||||||
organizationRequest.setPageSize(10);
|
|
||||||
organizationRequest.setKeyword("testUserOne");
|
|
||||||
organizationRequest.setOrganizationId("sys_default_organization_3");
|
|
||||||
MvcResult mvcResult = this.responsePost(organizationRequest);
|
|
||||||
// 获取返回值
|
|
||||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
|
||||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
|
||||||
// 返回请求正常
|
|
||||||
Assertions.assertNotNull(resultHolder);
|
|
||||||
Pager<?> pageData = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), Pager.class);
|
|
||||||
// 返回值不为空
|
|
||||||
Assertions.assertNotNull(pageData);
|
|
||||||
// 返回值的页码和当前页码相同
|
|
||||||
Assertions.assertEquals(pageData.getCurrent(), organizationRequest.getCurrent());
|
|
||||||
// 返回的数据量不超过规定要返回的数据量相同
|
|
||||||
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(pageData.getList())).size() <= organizationRequest.getPageSize());
|
|
||||||
// 返回值中取出第一条数据, 并判断是否包含关键字admin
|
|
||||||
OrgUserExtend orgUserExtend = JSON.parseArray(JSON.toJSONString(pageData.getList()), OrgUserExtend.class).get(0);
|
|
||||||
Assertions.assertTrue(StringUtils.contains(orgUserExtend.getName(), organizationRequest.getKeyword())
|
|
||||||
|| StringUtils.contains(orgUserExtend.getEmail(), organizationRequest.getKeyword())
|
|
||||||
|| StringUtils.contains(orgUserExtend.getPhone(), organizationRequest.getKeyword()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -89,80 +70,96 @@ public class OrganizationControllerTests extends BaseTest {
|
||||||
public void addMemberByOrgError() throws Exception {
|
public void addMemberByOrgError() throws Exception {
|
||||||
//组织ID正确
|
//组织ID正确
|
||||||
// 成员选择为空
|
// 成员选择为空
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
||||||
// 成员都不存在
|
// 成员都不存在
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_userX", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_userX", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
||||||
// 成员有一个不存在
|
// 成员有一个不存在
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user3", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user3", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
||||||
// 用户组为空
|
// 用户组为空
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
||||||
// 用户组都不存在
|
// 用户组都不存在
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_X", "sys_default_org_role_id_Y"), status().is5xxServerError());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_X", "sys_default_org_role_id_Y"), status().is5xxServerError());
|
||||||
// 用户组有一个不存在
|
// 用户组有一个不存在
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_Y"), status().isOk());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_Y"), status().isOk());
|
||||||
//成员和用户组都为空
|
//成员和用户组都为空
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
||||||
// 组织不存在
|
// 组织不存在
|
||||||
// 成员选择为空
|
// 成员选择为空
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "default-organization-x", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "default-organization-x", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
||||||
// 用户组不存在
|
// 用户组不存在
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
||||||
//成员和用户组都为空
|
//成员和用户组都为空
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "default-organization-x", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "default-organization-x", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
||||||
//成员和用户组存在
|
//成员和用户组存在
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
||||||
//组织为空
|
//组织为空
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, null, Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
addOrganizationMemberError(ORGANIZATION_LIST_ADD_MEMBER, null, Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
public void updateOrgMemberSuccess() throws Exception {
|
@Sql(scripts = {"/dml/init_sys_org_project.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||||
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
|
public void updateOrgMemberSuccessWithAll() throws Exception {
|
||||||
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
|
OrganizationMemberUpdateRequest organizationMemberUpdateRequest = new OrganizationMemberUpdateRequest();
|
||||||
organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user", "sys_default_user2"));
|
organizationMemberUpdateRequest.setOrganizationId("sys_default_organization_3");
|
||||||
organizationMemberRequest.setUserRoleIds(List.of("sys_default_org_role_id_2"));
|
organizationMemberUpdateRequest.setMemberId("sys_default_user2");
|
||||||
this.requestPost(ORGANIZATION_UPDATE_MEMBER, organizationMemberRequest, status().isOk());
|
organizationMemberUpdateRequest.setUserRoleIds(List.of("sys_default_org_role_id_1"));
|
||||||
|
organizationMemberUpdateRequest.setProjectIds(List.of("sys_org_projectId"));
|
||||||
|
this.requestPost(ORGANIZATION_UPDATE_MEMBER, organizationMemberUpdateRequest, status().isOk());
|
||||||
// 批量添加成员成功后, 验证是否添加成功
|
// 批量添加成员成功后, 验证是否添加成功
|
||||||
listByKeyWord("testUserTwo","sys_default_organization_3", true, "sys_default_org_role_id_2");
|
listByKeyWord("testUserTwo", "sys_default_organization_3", true, "sys_default_org_role_id_1", "sys_org_projectId", false, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
public void updateOrgMemberError() throws Exception {
|
public void updateOrgMemberSuccessWithNoProjectIds() throws Exception {
|
||||||
//组织ID正确
|
OrganizationMemberUpdateRequest organizationMemberUpdateRequest = new OrganizationMemberUpdateRequest();
|
||||||
// 成员选择为空
|
organizationMemberUpdateRequest.setOrganizationId("sys_default_organization_3");
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
organizationMemberUpdateRequest.setMemberId("sys_default_user2");
|
||||||
// 成员都不存在
|
organizationMemberUpdateRequest.setUserRoleIds(List.of("sys_default_org_role_id_4"));
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_userX", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
this.requestPost(ORGANIZATION_UPDATE_MEMBER, organizationMemberUpdateRequest, status().isOk());
|
||||||
// 成员有一个不存在
|
// 批量添加成员成功后, 验证是否添加成功
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user3", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
listByKeyWord("testUserTwo", "sys_default_organization_3", true, "sys_default_org_role_id_4", null, false, null, null);
|
||||||
// 用户组为空
|
}
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
|
||||||
// 用户组都不存在
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_X", "sys_default_org_role_id_Y"), status().is5xxServerError());
|
|
||||||
// 用户组有一个不存在是过滤是成功的
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_Y"), status().isOk());
|
|
||||||
//成员和用户组都为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
|
||||||
// 组织不存在
|
|
||||||
// 成员选择为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "default-organization-x", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
|
||||||
// 用户组不存在
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
|
||||||
//成员和用户组都为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "default-organization-x", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
|
||||||
//成员和用户组存在
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
|
||||||
//组织为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, null, Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(3)
|
||||||
|
public void updateOrgMemberSuccessWithPartRoles() throws Exception {
|
||||||
|
OrganizationMemberUpdateRequest organizationMemberUpdateRequest = new OrganizationMemberUpdateRequest();
|
||||||
|
organizationMemberUpdateRequest.setOrganizationId("sys_default_organization_3");
|
||||||
|
organizationMemberUpdateRequest.setMemberId("sys_default_user");
|
||||||
|
organizationMemberUpdateRequest.setUserRoleIds(List.of("sys_default_org_role_id_5", "sys_default_org_role_id_Y"));
|
||||||
|
organizationMemberUpdateRequest.setProjectIds(List.of("sys_org_projectId1", "sys_org_projectId_Y"));
|
||||||
|
this.requestPost(ORGANIZATION_UPDATE_MEMBER, organizationMemberUpdateRequest, status().isOk());
|
||||||
|
// 批量添加成员成功后, 验证是否添加成功
|
||||||
|
listByKeyWord("testUserOne", "sys_default_organization_3", true, "sys_default_org_role_id_5", "sys_org_projectId1", true, "sys_default_org_role_id_Y", "sys_org_projectId_Y");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
|
public void updateOrgMemberError() throws Exception {
|
||||||
|
//组织ID正确
|
||||||
|
// 成员为空
|
||||||
|
updateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", null, Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), Arrays.asList("sys_org_projectId", "sys_org_projectId1"), status().isBadRequest());
|
||||||
|
//成员不存在
|
||||||
|
updateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", "sys_default_userX", Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), Arrays.asList("sys_org_projectId", "sys_org_projectId1"), status().is5xxServerError());
|
||||||
|
// 组织ID不存在
|
||||||
|
updateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_X", "sys_default_user2", Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), Arrays.asList("sys_org_projectId", "sys_org_projectId1"), status().is5xxServerError());
|
||||||
|
// 用户组为空
|
||||||
|
updateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", "sys_default_user2", Collections.emptyList(), Arrays.asList("sys_org_projectId", "sys_org_projectId1"), status().isBadRequest());
|
||||||
|
// 用户组都不存在
|
||||||
|
updateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", "sys_default_user2", Arrays.asList("sys_default_org_role_id_X", "sys_default_org_role_id_Y"), Arrays.asList("sys_org_projectId", "sys_org_projectId1"), status().is5xxServerError());
|
||||||
|
// 项目组都不存在
|
||||||
|
updateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", "sys_default_user2", Arrays.asList("sys_default_org_role_id_4", "sys_default_org_role_id_2"), Arrays.asList("sys_org_projectId_W", "sys_org_projectId1_Q"), status().is5xxServerError());
|
||||||
|
// 成员不是当前组织的
|
||||||
|
updateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER, "sys_default_organization_3", "sys_default_user4", Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), Arrays.asList("sys_org_projectId", "sys_org_projectId1"), status().is5xxServerError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(5)
|
||||||
public void updateOrgMemberToRoleSuccess() throws Exception {
|
public void updateOrgMemberToRoleSuccess() throws Exception {
|
||||||
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
|
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
|
||||||
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
|
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
|
||||||
|
@ -170,41 +167,67 @@ public class OrganizationControllerTests extends BaseTest {
|
||||||
organizationMemberRequest.setUserRoleIds(List.of("sys_default_org_role_id_4"));
|
organizationMemberRequest.setUserRoleIds(List.of("sys_default_org_role_id_4"));
|
||||||
this.requestPost(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, organizationMemberRequest, status().isOk());
|
this.requestPost(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, organizationMemberRequest, status().isOk());
|
||||||
// 批量添加成员成功后, 验证是否添加成功
|
// 批量添加成员成功后, 验证是否添加成功
|
||||||
listByKeyWord("testUserTwo","sys_default_organization_3", true, "sys_default_org_role_id_4");
|
listByKeyWord("testUserTwo", "sys_default_organization_3", true, "sys_default_org_role_id_4", null, false, null, null);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(5)
|
|
||||||
public void updateOrgMemberToRoleError() throws Exception {
|
|
||||||
//组织ID正确
|
|
||||||
// 成员选择为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
|
||||||
// 成员都不存在
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Arrays.asList("sys_default_userX", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
|
||||||
// 成员有一个不存在
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Arrays.asList("sys_default_user3", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
|
||||||
// 用户组不存在
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
|
||||||
//成员和用户组都为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
|
||||||
// 组织不存在
|
|
||||||
// 成员选择为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "default-organization-x", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
|
||||||
// 用户组不存在
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
|
||||||
//成员和用户组都为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "default-organization-x", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
|
||||||
//成员和用户组存在
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
|
||||||
//组织为空
|
|
||||||
addOrUpdateOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, null, Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(6)
|
@Order(6)
|
||||||
|
public void updateOrgMemberToRoleError() throws Exception {
|
||||||
|
//组织ID正确
|
||||||
|
// 成员选择为空
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
||||||
|
// 成员都不存在
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Arrays.asList("sys_default_userX", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
||||||
|
// 成员有一个不存在
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Arrays.asList("sys_default_user3", "sys_default_userY"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
||||||
|
// 用户组不存在
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
||||||
|
//成员和用户组都为空
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "sys_default_organization_3", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
||||||
|
// 组织不存在
|
||||||
|
// 成员选择为空
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "default-organization-x", Collections.emptyList(), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
||||||
|
// 用户组不存在
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
||||||
|
//成员和用户组都为空
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "default-organization-x", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
||||||
|
//成员和用户组存在
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, "default-organization-x", Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().is5xxServerError());
|
||||||
|
//组织为空
|
||||||
|
addOrganizationMemberError(ORGANIZATION_UPDATE_MEMBER_TO_ROLE, null, Arrays.asList("sys_default_user", "sys_default_user2"), Arrays.asList("sys_default_org_role_id_2", "sys_default_org_role_id_3"), status().isBadRequest());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(7)
|
||||||
|
public void addOrgMemberToProjectSuccess() throws Exception {
|
||||||
|
OrgMemberExtendProjectRequest organizationMemberRequest = new OrgMemberExtendProjectRequest();
|
||||||
|
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
|
||||||
|
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());
|
||||||
|
// 批量添加成员成功后, 验证是否添加成功
|
||||||
|
listByKeyWord("testUserOne", "sys_default_organization_3", true, InternalUserRole.PROJECT_MEMBER.getValue(), "sys_org_projectId2", false, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(8)
|
||||||
|
public void addOrgMemberToProjectError() throws Exception {
|
||||||
|
// 成员选择为空
|
||||||
|
addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Arrays.asList("projectId1", "projectId2"), status().isBadRequest());
|
||||||
|
// 项目集合不存在
|
||||||
|
addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
||||||
|
//成员和项目集合都为空
|
||||||
|
addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
||||||
|
// 成员选择为空
|
||||||
|
addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_X", Collections.emptyList(), Arrays.asList("projectId1", "projectId2"), status().isBadRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(9)
|
||||||
public void getOrgMemberListSuccess() throws Exception {
|
public void getOrgMemberListSuccess() throws Exception {
|
||||||
listByKeyWord("testUserOne","sys_default_organization_3", false ,null);
|
listByKeyWord("testUserOne", "sys_default_organization_3", false, null, null, false, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -254,32 +277,6 @@ public class OrganizationControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(9)
|
|
||||||
@Sql(scripts = {"/dml/init_sys_org_project.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
|
||||||
public void addOrgMemberToProjectSuccess() throws Exception {
|
|
||||||
OrgMemberExtendProjectRequest organizationMemberRequest = new OrgMemberExtendProjectRequest();
|
|
||||||
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
|
|
||||||
organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user", "test_user_one"));
|
|
||||||
organizationMemberRequest.setProjectIds(Arrays.asList("sys_org_projectId", "sys_org_projectId1"));
|
|
||||||
this.requestPost(ORGANIZATION_PROJECT_ADD_MEMBER, organizationMemberRequest, status().isOk());
|
|
||||||
// 批量添加成员成功后, 验证是否添加成功
|
|
||||||
listByKeyWord("testUserOne","sys_default_organization_3", true, InternalUserRole.PROJECT_MEMBER.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(10)
|
|
||||||
public void addOrgMemberToProjectError() throws Exception {
|
|
||||||
// 成员选择为空
|
|
||||||
addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Arrays.asList("projectId1", "projectId2"), status().isBadRequest());
|
|
||||||
// 项目集合不存在
|
|
||||||
addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_3", Arrays.asList("sys_default_user", "sys_default_user2"), Collections.emptyList(), status().isBadRequest());
|
|
||||||
//成员和项目集合都为空
|
|
||||||
addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_3", Collections.emptyList(), Collections.emptyList(), status().isBadRequest());
|
|
||||||
// 成员选择为空
|
|
||||||
addOrUpdateOrganizationProjectMemberError(ORGANIZATION_PROJECT_ADD_MEMBER, "sys_default_organization_X", Collections.emptyList(), Arrays.asList("projectId1", "projectId2"), status().isBadRequest());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(11)
|
@Order(11)
|
||||||
public void removeOrgMemberSuccess() throws Exception {
|
public void removeOrgMemberSuccess() throws Exception {
|
||||||
|
@ -299,7 +296,156 @@ public class OrganizationControllerTests extends BaseTest {
|
||||||
this.requestGet(ORGANIZATION_REMOVE_MEMBER + "/default-organization-x/admin-x", status().is5xxServerError());
|
this.requestGet(ORGANIZATION_REMOVE_MEMBER + "/default-organization-x/admin-x", status().is5xxServerError());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listByKeyWord(String keyWord,String orgId,boolean compare, String userRoleId) throws Exception {
|
@Test
|
||||||
|
@Order(14)
|
||||||
|
public void getProjectListByOrgSuccess() throws Exception {
|
||||||
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/organization/project/list/sys_default_organization_3")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
String contentAsString = mvcResult.getResponse().getContentAsString();
|
||||||
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
|
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class);
|
||||||
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
|
||||||
|
List<String> ids = projectList.stream().map(IdNameStructureDTO::getId).toList();
|
||||||
|
Assertions.assertTrue(ids.contains("sys_org_projectId"));
|
||||||
|
List<String> names = projectList.stream().map(IdNameStructureDTO::getName).toList();
|
||||||
|
Assertions.assertTrue(names.contains("sys_org_projectId"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(15)
|
||||||
|
public void getProjectEmptyListByOrg() throws Exception {
|
||||||
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/organization/project/list/sys_default_organization_5")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
String contentAsString = mvcResult.getResponse().getContentAsString();
|
||||||
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
|
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class);
|
||||||
|
Assertions.assertTrue(CollectionUtils.isEmpty(projectList));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(16)
|
||||||
|
public void getProjectListByOrgError() throws Exception {
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get("/organization/project/list/sys_default_organization_x")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().is5xxServerError()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(17)
|
||||||
|
public void getUserRoleListByOrgSuccess() throws Exception {
|
||||||
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/organization/user/role/list/sys_default_organization_3")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
String contentAsString = mvcResult.getResponse().getContentAsString();
|
||||||
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
|
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class);
|
||||||
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
|
||||||
|
List<String> ids = projectList.stream().map(IdNameStructureDTO::getId).toList();
|
||||||
|
Assertions.assertTrue(ids.contains("sys_default_org_role_id_3"));
|
||||||
|
List<String> names = projectList.stream().map(IdNameStructureDTO::getName).toList();
|
||||||
|
Assertions.assertTrue(names.contains("sys_default_org_role_id_3"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(18)
|
||||||
|
public void getUserRoleEmptyListByOrg() throws Exception {
|
||||||
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/organization/user/role/list/sys_default_organization_6")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
|
List<IdNameStructureDTO> userRoleList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class);
|
||||||
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(userRoleList));
|
||||||
|
List<String> ids = userRoleList.stream().map(IdNameStructureDTO::getId).toList();
|
||||||
|
Assertions.assertTrue(ids.contains("org_admin"));
|
||||||
|
Assertions.assertTrue(ids.contains("org_member"));
|
||||||
|
List<String> names = userRoleList.stream().map(IdNameStructureDTO::getName).toList();
|
||||||
|
Assertions.assertTrue(names.contains("组织管理员"));
|
||||||
|
Assertions.assertTrue(names.contains("组织成员"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(19)
|
||||||
|
public void getUserRoleListByOrgError() throws Exception {
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get("/organization/user/role/list/sys_default_organization_x")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().is5xxServerError()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(20)
|
||||||
|
public void getNotExistUserListByOrgSuccess() throws Exception {
|
||||||
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/organization/not-exist/user/list/sys_default_organization_3")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
String contentAsString = mvcResult.getResponse().getContentAsString();
|
||||||
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
|
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class);
|
||||||
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
|
||||||
|
List<String> ids = projectList.stream().map(IdNameStructureDTO::getId).toList();
|
||||||
|
Assertions.assertTrue(ids.contains("sys_default_user5"));
|
||||||
|
List<String> names = projectList.stream().map(IdNameStructureDTO::getName).toList();
|
||||||
|
Assertions.assertTrue(names.contains("testUserFive"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(21)
|
||||||
|
public void getNotExistUserListWithNoRelation() throws Exception {
|
||||||
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/organization/not-exist/user/list/sys_default_organization_5")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
String contentAsString = mvcResult.getResponse().getContentAsString();
|
||||||
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
|
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class);
|
||||||
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(22)
|
||||||
|
public void getNotExistUserListByOrgError() throws Exception {
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get("/organization/not-exist/user/list/sys_default_organization_x")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().is5xxServerError()).andDo(print())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void listByKeyWord(String keyWord, String orgId, boolean compare, String userRoleId, String projectId, boolean checkPart, String noUserRoleId, String noProjectId) throws Exception {
|
||||||
OrganizationRequest organizationRequest = new OrganizationRequest();
|
OrganizationRequest organizationRequest = new OrganizationRequest();
|
||||||
organizationRequest.setCurrent(1);
|
organizationRequest.setCurrent(1);
|
||||||
organizationRequest.setPageSize(10);
|
organizationRequest.setPageSize(10);
|
||||||
|
@ -324,11 +470,35 @@ public class OrganizationControllerTests extends BaseTest {
|
||||||
|| StringUtils.contains(orgUserExtend.getEmail(), organizationRequest.getKeyword())
|
|| StringUtils.contains(orgUserExtend.getEmail(), organizationRequest.getKeyword())
|
||||||
|| StringUtils.contains(orgUserExtend.getPhone(), organizationRequest.getKeyword()));
|
|| StringUtils.contains(orgUserExtend.getPhone(), organizationRequest.getKeyword()));
|
||||||
if (compare) {
|
if (compare) {
|
||||||
Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap().get(userRoleId));
|
Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap());
|
||||||
|
List<String> userRoleIds = orgUserExtend.getUserRoleIdNameMap().stream().map(IdNameStructureDTO::getId).toList();
|
||||||
|
Assertions.assertTrue(userRoleIds.contains(userRoleId));
|
||||||
|
List<String> userRoleNames = orgUserExtend.getUserRoleIdNameMap().stream().map(IdNameStructureDTO::getName).toList();
|
||||||
|
Assertions.assertTrue(userRoleNames.contains(userRoleId) || userRoleNames.contains("项目成员"));
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(projectId)) {
|
||||||
|
Assertions.assertNotNull(orgUserExtend.getProjectIdNameMap());
|
||||||
|
List<String> projectIds = orgUserExtend.getProjectIdNameMap().stream().map(IdNameStructureDTO::getId).toList();
|
||||||
|
Assertions.assertTrue(projectIds.contains(projectId));
|
||||||
|
List<String> projectNames = orgUserExtend.getProjectIdNameMap().stream().map(IdNameStructureDTO::getName).toList();
|
||||||
|
Assertions.assertTrue(projectNames.contains(projectId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (checkPart) {
|
||||||
|
Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap());
|
||||||
|
List<String> userRoleIds = orgUserExtend.getUserRoleIdNameMap().stream().map(IdNameStructureDTO::getId).toList();
|
||||||
|
Assertions.assertFalse(userRoleIds.contains(noUserRoleId));
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(noProjectId)) {
|
||||||
|
Assertions.assertNotNull(orgUserExtend.getProjectIdNameMap());
|
||||||
|
List<String> projectIds = orgUserExtend.getProjectIdNameMap().stream().map(IdNameStructureDTO::getId).toList();
|
||||||
|
Assertions.assertFalse(projectIds.contains(noProjectId));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addOrUpdateOrganizationMemberError(String url, String organizationId, List<String> memberIds, List<String> userGroupIds, ResultMatcher resultMatcher) throws Exception {
|
private void addOrganizationMemberError(String url, String organizationId, List<String> memberIds, List<String> userGroupIds, ResultMatcher resultMatcher) throws Exception {
|
||||||
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
|
OrganizationMemberExtendRequest organizationMemberRequest = new OrganizationMemberExtendRequest();
|
||||||
organizationMemberRequest.setOrganizationId(organizationId);
|
organizationMemberRequest.setOrganizationId(organizationId);
|
||||||
organizationMemberRequest.setMemberIds(memberIds);
|
organizationMemberRequest.setMemberIds(memberIds);
|
||||||
|
@ -336,6 +506,16 @@ public class OrganizationControllerTests extends BaseTest {
|
||||||
this.requestPost(url, organizationMemberRequest, resultMatcher);
|
this.requestPost(url, organizationMemberRequest, resultMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateOrganizationMemberError(String url, String organizationId, String memberId, List<String> userRoleIds, List<String> projectIds, ResultMatcher resultMatcher) throws Exception {
|
||||||
|
OrganizationMemberUpdateRequest organizationMemberUpdateRequest = new OrganizationMemberUpdateRequest();
|
||||||
|
organizationMemberUpdateRequest.setOrganizationId(organizationId);
|
||||||
|
organizationMemberUpdateRequest.setMemberId(memberId);
|
||||||
|
organizationMemberUpdateRequest.setUserRoleIds(userRoleIds);
|
||||||
|
organizationMemberUpdateRequest.setProjectIds(projectIds);
|
||||||
|
this.requestPost(url, organizationMemberUpdateRequest, resultMatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addOrUpdateOrganizationProjectMemberError(String url, String organizationId, List<String> memberIds, List<String> projectIds, ResultMatcher resultMatcher) throws Exception {
|
private void addOrUpdateOrganizationProjectMemberError(String url, String organizationId, List<String> memberIds, List<String> projectIds, ResultMatcher resultMatcher) throws Exception {
|
||||||
OrgMemberExtendProjectRequest organizationMemberRequest = new OrgMemberExtendProjectRequest();
|
OrgMemberExtendProjectRequest organizationMemberRequest = new OrgMemberExtendProjectRequest();
|
||||||
organizationMemberRequest.setOrganizationId(organizationId);
|
organizationMemberRequest.setOrganizationId(organizationId);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
# 插入测试数据
|
# 插入测试数据
|
||||||
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('sys_org_projectId', null, 'sys_default_organization_3', 'sys_org_projectId', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('sys_org_projectId', null, 'sys_default_organization_3', 'sys_org_projectId', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('sys_org_projectId', null, 'sys_default_organization_3', 'sys_org_projectId', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('sys_org_projectId1', null, 'sys_default_organization_3', 'sys_org_projectId1', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('sys_org_projectId1', null, 'sys_default_organization_3', 'sys_org_projectId1', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('sys_org_projectId2', null, 'sys_default_organization_3', 'sys_org_projectId2', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('sys_org_projectId3', null, 'sys_default_organization_3', 'sys_org_projectId3', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,15 @@ INSERT INTO user(id, name, email, password, create_time, update_time, language,
|
||||||
('sys_default_user2', 'testUserTwo', 'testUserTwo@metersphere.io', MD5('calong'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
('sys_default_user2', 'testUserTwo', 'testUserTwo@metersphere.io', MD5('calong'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
||||||
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user) VALUE
|
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user) VALUE
|
||||||
('sys_default_user3', 'testUserThree', 'testUserThree@metersphere.io', MD5('calong'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
('sys_default_user3', 'testUserThree', 'testUserThree@metersphere.io', MD5('calong'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
||||||
|
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user) VALUE
|
||||||
|
('sys_default_user4', 'testUserFour', 'testUserFour@metersphere.io', MD5('calong'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
||||||
|
|
||||||
|
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user) VALUE
|
||||||
|
('sys_default_user5', 'testUserFive', 'testUserFive@metersphere.io', MD5('calong'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
||||||
|
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user) VALUE
|
||||||
|
('sys_default_user6', 'testUserSix', 'testUserSix@metersphere.io', MD5('calong'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO user_role(id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUE
|
INSERT INTO user_role(id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUE
|
||||||
('sys_default_org_role_id_3', 'sys_default_org_role_id_3', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'sys_default_organization_3');
|
('sys_default_org_role_id_3', 'sys_default_org_role_id_3', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'sys_default_organization_3');
|
||||||
|
@ -29,3 +38,9 @@ INSERT INTO user_role(id, name, description, internal, type, create_time, update
|
||||||
('sys_default_org_role_id_2', 'sys_default_org_role_id_2', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'sys_default_organization_3');
|
('sys_default_org_role_id_2', 'sys_default_org_role_id_2', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'sys_default_organization_3');
|
||||||
INSERT INTO user_role(id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUE
|
INSERT INTO user_role(id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUE
|
||||||
('sys_default_org_role_id_4', 'sys_default_org_role_id_4', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'sys_default_organization_3');
|
('sys_default_org_role_id_4', 'sys_default_org_role_id_4', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'sys_default_organization_3');
|
||||||
|
INSERT INTO user_role(id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUE
|
||||||
|
('sys_default_org_role_id_5', 'sys_default_org_role_id_5', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'sys_default_organization_3');
|
||||||
|
|
||||||
|
INSERT INTO user_role_relation(id, user_id, role_id, source_id, create_time, create_user) VALUE
|
||||||
|
('gyq_user_role_relation_test', 'sys_default_user4', 'sys_default_org_role_id_5', 'sys_default_organization_6', UNIX_TIMESTAMP() * 1000, 'admin');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue