refactor(系统设置): 组织用户组功能
This commit is contained in:
parent
df20aec81a
commit
226b9840d6
|
@ -65,6 +65,11 @@ INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'o
|
|||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_admin', 'ORGANIZATION_USER:READ');
|
||||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_admin', 'ORGANIZATION_TEMPLATE:READ+CUSTOM');
|
||||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_admin', 'ORGANIZATION_USER:READ+ADD');
|
||||
-- 初始化组织-用户组菜单权限(默认)
|
||||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_admin', 'ORGANIZATION_USER_ROLE:READ');
|
||||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_admin', 'ORGANIZATION_USER_ROLE:READ+ADD');
|
||||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_admin', 'ORGANIZATION_USER_ROLE:READ+UPDATE');
|
||||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_admin', 'ORGANIZATION_USER_ROLE:READ+DELETE');
|
||||
-- 组织成员权限
|
||||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_member', 'ORGANIZATION_PROJECT_MANAGER:READ+UPLOAD_JAR');
|
||||
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (uuid(), 'org_member', 'ORGANIZATION_MESSAGE:READ');
|
||||
|
|
|
@ -19,6 +19,8 @@ import io.metersphere.system.request.OrganizationUserRoleMemberRequest;
|
|||
import io.metersphere.system.service.OrganizationUserRoleLogService;
|
||||
import io.metersphere.system.service.OrganizationUserRoleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
|
@ -40,6 +42,7 @@ public class OrganizationUserRoleController {
|
|||
|
||||
@GetMapping("/list/{organizationId}")
|
||||
@Operation(summary = "获取组织用户组列表")
|
||||
@Parameter(name = "organizationId", description = "当前组织ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ)
|
||||
public List<UserRole> list(@PathVariable String organizationId) {
|
||||
return organizationUserRoleService.list(organizationId);
|
||||
|
@ -69,6 +72,7 @@ public class OrganizationUserRoleController {
|
|||
@GetMapping("/delete/{id}")
|
||||
@Operation(summary = "删除组织用户组")
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ_DELETE)
|
||||
@Parameter(name = "id", description = "用户组ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = OrganizationUserRoleLogService.class)
|
||||
public void delete(@PathVariable String id) {
|
||||
organizationUserRoleService.delete(id);
|
||||
|
@ -76,6 +80,7 @@ public class OrganizationUserRoleController {
|
|||
|
||||
@GetMapping("/permission/setting/{id}")
|
||||
@Operation(summary = "获取组织用户组对应的权限配置")
|
||||
@Parameter(name = "id", description = "用户组ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ)
|
||||
public List<PermissionDefinitionItem> getPermissionSetting(@PathVariable String id) {
|
||||
return organizationUserRoleService.getPermissionSetting(id);
|
||||
|
|
|
@ -38,9 +38,7 @@
|
|||
urr.source_id = #{request.organizationId}
|
||||
</if>
|
||||
<if test="request.keyword != null">
|
||||
and (u.name like CONCAT('%', #{request.keyword},'%')
|
||||
or u.email like CONCAT('%', #{request.keyword},'%')
|
||||
or u.phone like CONCAT('%', #{request.keyword},'%'))
|
||||
and u.name like concat('%', #{request.keyword},'%')
|
||||
</if>
|
||||
</where>
|
||||
order by u.update_time desc
|
||||
|
|
|
@ -16,6 +16,6 @@
|
|||
select u.* from user_role_relation urr left join user u on urr.user_id = u.id
|
||||
where urr.source_id = #{request.organizationId}
|
||||
and urr.role_id = #{request.userRoleId}
|
||||
and u.name like concat('%',#{request.userName},'%')
|
||||
and u.name like concat('%',#{request.userKeyWord},'%')
|
||||
</select>
|
||||
</mapper>
|
|
@ -13,4 +13,6 @@ public interface ExtUserRoleRelationMapper {
|
|||
List<UserRoleRelation> selectGlobalRoleByUserId(String userId);
|
||||
|
||||
List<UserRoleRelationUserDTO> listGlobal(@Param("request") GlobalUserRoleRelationQueryRequest request);
|
||||
|
||||
void batchInsert(@Param("list") List<UserRoleRelation> list);
|
||||
}
|
||||
|
|
|
@ -30,4 +30,12 @@
|
|||
)
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<insert id="batchInsert" parameterType="java.util.List">
|
||||
insert into user_role_relation (id, user_id, role_id, source_id, create_time, create_user)
|
||||
values
|
||||
<foreach collection="list" item="item" separator="," >
|
||||
(#{item.id}, #{item.userId}, #{item.roleId}, #{item.sourceId}, #{item.createTime}, #{item.createUser})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.system.request;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
@ -8,6 +9,7 @@ import java.io.Serializable;
|
|||
* @author song-cc-rock
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OrganizationDeleteRequest implements Serializable {
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,11 +7,13 @@ import jakarta.validation.constraints.NotBlank;
|
|||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OrganizationEditRequest implements Serializable {
|
||||
|
||||
@Schema(title = "组织ID")
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package io.metersphere.system.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OrganizationMemberBatchRequest extends OrganizationMemberRequest{
|
||||
|
||||
/**
|
||||
* 组织ID集合
|
||||
*/
|
||||
@Schema(title = "组织ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "{organization.id.not_blank}")
|
||||
private List<String> organizationIds;
|
||||
}
|
|
@ -3,6 +3,7 @@ package io.metersphere.system.request;
|
|||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -11,6 +12,7 @@ import java.util.List;
|
|||
* @author guoyuqi
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OrganizationMemberExtendRequest extends OrganizationMemberRequest {
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
@ -12,6 +13,7 @@ import java.util.List;
|
|||
* @author song-cc-rock
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OrganizationMemberRequest implements Serializable {
|
||||
|
||||
/**
|
||||
|
@ -24,7 +26,7 @@ public class OrganizationMemberRequest implements Serializable {
|
|||
/**
|
||||
* 成员ID集合
|
||||
*/
|
||||
@Schema(title = "成员ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "{member.id.not_null}")
|
||||
@Schema(title = "成员ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "{user.id.not_blank}")
|
||||
private List<String> memberIds;
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OrganizationUserRoleEditRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -2,12 +2,16 @@ package io.metersphere.system.request;
|
|||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OrganizationUserRoleMemberEditRequest implements Serializable {
|
||||
|
||||
@Schema(title = "组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
@ -20,8 +24,7 @@ public class OrganizationUserRoleMemberEditRequest implements Serializable {
|
|||
@Size(min = 1, max = 50, message = "{organization.id.length_range}")
|
||||
private String organizationId;
|
||||
|
||||
@Schema(title = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{user.id.not_blank}")
|
||||
@Size(min = 1, max = 50, message = "{user.id.length_range}")
|
||||
private String userId;
|
||||
@Schema(title = "成员ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "{user.id.not_blank}")
|
||||
private List<String> userIds;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OrganizationUserRoleMemberRequest extends BasePageRequest {
|
||||
|
||||
@Schema(title = "组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
@ -21,6 +21,6 @@ public class OrganizationUserRoleMemberRequest extends BasePageRequest {
|
|||
@Size(min = 1, max = 50, message = "{organization.id.length_range}")
|
||||
private String organizationId;
|
||||
|
||||
@Schema(title = "用户名")
|
||||
private String userName;
|
||||
@Schema(title = "搜索关键字")
|
||||
private String userKeyWord;
|
||||
}
|
||||
|
|
|
@ -19,10 +19,7 @@ import io.metersphere.system.dto.OrganizationDTO;
|
|||
import io.metersphere.system.dto.OrganizationProjectOptionsDto;
|
||||
import io.metersphere.system.dto.UserExtend;
|
||||
import io.metersphere.system.mapper.*;
|
||||
import io.metersphere.system.request.OrgMemberExtendProjectRequest;
|
||||
import io.metersphere.system.request.OrganizationMemberExtendRequest;
|
||||
import io.metersphere.system.request.OrganizationMemberRequest;
|
||||
import io.metersphere.system.request.OrganizationRequest;
|
||||
import io.metersphere.system.request.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
|
@ -47,13 +44,15 @@ import java.util.stream.Collectors;
|
|||
public class OrganizationService {
|
||||
|
||||
@Resource
|
||||
OrganizationMapper organizationMapper;
|
||||
private OrganizationMapper organizationMapper;
|
||||
@Resource
|
||||
ExtOrganizationMapper extOrganizationMapper;
|
||||
private ExtOrganizationMapper extOrganizationMapper;
|
||||
@Resource
|
||||
UserRoleRelationMapper userRoleRelationMapper;
|
||||
private UserRoleRelationMapper userRoleRelationMapper;
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
private ExtUserRoleRelationMapper extUserRoleRelationMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
@Resource
|
||||
|
@ -86,20 +85,26 @@ public class OrganizationService {
|
|||
return extOrganizationMapper.listMember(request);
|
||||
}
|
||||
|
||||
|
||||
public void addMemberBySystem(OrganizationMemberRequest organizationMemberRequest, String createUserId) {
|
||||
String organizationId = organizationMemberRequest.getOrganizationId();
|
||||
checkOrgExist(organizationId);
|
||||
Map<String, User> userMap = checkUserExist(organizationMemberRequest.getMemberIds());
|
||||
for (String userId : organizationMemberRequest.getMemberIds()) {
|
||||
OrganizationMemberBatchRequest batchRequest = new OrganizationMemberBatchRequest();
|
||||
batchRequest.setOrganizationIds(List.of(organizationMemberRequest.getOrganizationId()));
|
||||
batchRequest.setMemberIds(organizationMemberRequest.getMemberIds());
|
||||
addMemberBySystem(batchRequest, createUserId);
|
||||
}
|
||||
|
||||
public void addMemberBySystem(OrganizationMemberBatchRequest batchRequest, String createUserId) {
|
||||
checkOrgExist(batchRequest.getOrganizationIds());
|
||||
Map<String, User> userMap = checkUserExist(batchRequest.getMemberIds());
|
||||
List<UserRoleRelation> userRoleRelations = new ArrayList<>();
|
||||
batchRequest.getOrganizationIds().forEach(organizationId -> {
|
||||
for (String userId : batchRequest.getMemberIds()) {
|
||||
if (userMap.get(userId) == null) {
|
||||
throw new MSException("id:" + userId + Translator.get("user.not.exist"));
|
||||
}
|
||||
//过滤已存在的关系
|
||||
//组织用户成员关系已存在, 不再重复添加
|
||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||
example.createCriteria().andSourceIdEqualTo(organizationId).andUserIdEqualTo(userId).andRoleIdEqualTo(InternalUserRole.ORG_MEMBER.getValue());
|
||||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(userRoleRelations)) {
|
||||
if (userRoleRelationMapper.countByExample(example) > 0) {
|
||||
continue;
|
||||
}
|
||||
UserRoleRelation userRoleRelation = new UserRoleRelation();
|
||||
|
@ -109,7 +114,11 @@ public class OrganizationService {
|
|||
userRoleRelation.setRoleId(InternalUserRole.ORG_MEMBER.getValue());
|
||||
userRoleRelation.setCreateTime(System.currentTimeMillis());
|
||||
userRoleRelation.setCreateUser(createUserId);
|
||||
userRoleRelationMapper.insert(userRoleRelation);
|
||||
userRoleRelations.add(userRoleRelation);
|
||||
}
|
||||
});
|
||||
if (CollectionUtils.isNotEmpty(userRoleRelations)) {
|
||||
extUserRoleRelationMapper.batchInsert(userRoleRelations);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +182,7 @@ public class OrganizationService {
|
|||
}
|
||||
|
||||
public void removeMember(String organizationId, String userId) {
|
||||
checkOrgExist(organizationId);
|
||||
checkOrgExist(List.of(organizationId));
|
||||
//删除组织下项目与成员的关系
|
||||
List<String> projectIds = getProjectIds(organizationId);
|
||||
if (CollectionUtils.isNotEmpty(projectIds)) {
|
||||
|
@ -203,33 +212,12 @@ public class OrganizationService {
|
|||
}
|
||||
|
||||
public void addMemberByOrg(OrganizationMemberExtendRequest organizationMemberExtendRequest, String createUserId) {
|
||||
checkOrgExist(organizationMemberExtendRequest.getOrganizationId());
|
||||
checkOrgExist(List.of(organizationMemberExtendRequest.getOrganizationId()));
|
||||
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getMemberIds());
|
||||
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds());
|
||||
setRelationByMemberAndGroupIds(organizationMemberExtendRequest, createUserId, userMap, userRoleMap, true);
|
||||
}
|
||||
|
||||
private Map<String, UserRole> checkUseRoleExist(List<String> userRoleIds) {
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andIdIn(userRoleIds).andTypeEqualTo("ORGANIZATION");
|
||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||
if (CollectionUtils.isEmpty(userRoles)) {
|
||||
throw new MSException(Translator.get("user_role_not_exist"));
|
||||
}
|
||||
return userRoles.stream().collect(Collectors.toMap(UserRole::getId, user -> user));
|
||||
|
||||
}
|
||||
|
||||
private Map<String, User> checkUserExist(List<String> memberIds) {
|
||||
UserExample userExample = new UserExample();
|
||||
userExample.createCriteria().andIdIn(memberIds);
|
||||
List<User> users = userMapper.selectByExample(userExample);
|
||||
if (CollectionUtils.isEmpty(users)) {
|
||||
throw new MSException(Translator.get("user.not.exist"));
|
||||
}
|
||||
return users.stream().collect(Collectors.toMap(User::getId, user -> user));
|
||||
}
|
||||
|
||||
private void setRelationByMemberAndGroupIds(OrganizationMemberExtendRequest organizationMemberExtendRequest, String createUserId, Map<String, User> userMap, Map<String, UserRole> userRoleMap, boolean add) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
|
||||
|
@ -285,23 +273,16 @@ public class OrganizationService {
|
|||
|
||||
public void updateMemberRole(OrganizationMemberExtendRequest organizationMemberExtendRequest, String userId) {
|
||||
String organizationId = organizationMemberExtendRequest.getOrganizationId();
|
||||
checkOrgExist(organizationId);
|
||||
checkOrgExist(List.of(organizationId));
|
||||
Map<String, User> userMap = checkUserExist(organizationMemberExtendRequest.getMemberIds());
|
||||
Map<String, UserRole> userRoleMap = checkUseRoleExist(organizationMemberExtendRequest.getUserRoleIds());
|
||||
//在新增组织成员与用户组和组织的关系
|
||||
setRelationByMemberAndGroupIds(organizationMemberExtendRequest, userId, userMap, userRoleMap, false);
|
||||
}
|
||||
|
||||
private void checkOrgExist(String organizationId) {
|
||||
Organization organization = organizationMapper.selectByPrimaryKey(organizationId);
|
||||
if (organization == null) {
|
||||
throw new MSException(Translator.get("organization_not_exist"));
|
||||
}
|
||||
}
|
||||
|
||||
public void addMemberToProject(OrgMemberExtendProjectRequest orgMemberExtendProjectRequest, String userId) {
|
||||
String requestOrganizationId = orgMemberExtendProjectRequest.getOrganizationId();
|
||||
checkOrgExist(requestOrganizationId);
|
||||
checkOrgExist(List.of(requestOrganizationId));
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
|
||||
List<LogDTO> logDTOList = new ArrayList<>();
|
||||
|
@ -340,8 +321,7 @@ public class OrganizationService {
|
|||
|
||||
/**
|
||||
* 删除组织用户日志
|
||||
*
|
||||
* @return
|
||||
* @return 日志内容
|
||||
*/
|
||||
public List<LogDTO> batchDelLog(String organizationId, String userId) {
|
||||
List<String> projectIds = getProjectIds(organizationId);
|
||||
|
@ -405,7 +385,7 @@ public class OrganizationService {
|
|||
List<String> memberIds = organizationMemberExtendRequest.getMemberIds();
|
||||
|
||||
//校验组织是否存在
|
||||
checkOrgExist(organizationId);
|
||||
checkOrgExist(List.of(organizationId));
|
||||
//校验成员是否是当前组织的成员
|
||||
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||
userRoleRelationExample.createCriteria().andUserIdIn(memberIds).andSourceIdEqualTo(organizationId);
|
||||
|
@ -444,4 +424,33 @@ public class OrganizationService {
|
|||
//写入操作日志
|
||||
operationLogService.batchAdd(logDTOList);
|
||||
}
|
||||
|
||||
private void checkOrgExist(List<String> organizationIds) {
|
||||
OrganizationExample example = new OrganizationExample();
|
||||
example.createCriteria().andIdIn(organizationIds);
|
||||
if (organizationMapper.countByExample(example) < organizationIds.size()) {
|
||||
throw new MSException(Translator.get("organization_not_exist"));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, UserRole> checkUseRoleExist(List<String> userRoleIds) {
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andIdIn(userRoleIds).andTypeEqualTo("ORGANIZATION");
|
||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||
if (CollectionUtils.isEmpty(userRoles)) {
|
||||
throw new MSException(Translator.get("user_role_not_exist"));
|
||||
}
|
||||
return userRoles.stream().collect(Collectors.toMap(UserRole::getId, user -> user));
|
||||
|
||||
}
|
||||
|
||||
private Map<String, User> checkUserExist(List<String> memberIds) {
|
||||
UserExample userExample = new UserExample();
|
||||
userExample.createCriteria().andIdIn(memberIds);
|
||||
List<User> users = userMapper.selectByExample(userExample);
|
||||
if (CollectionUtils.isEmpty(users)) {
|
||||
throw new MSException(Translator.get("user.not.exist"));
|
||||
}
|
||||
return users.stream().collect(Collectors.toMap(User::getId, user -> user));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,21 +85,24 @@ public class OrganizationUserRoleService extends BaseUserRoleService {
|
|||
}
|
||||
|
||||
public void addMember(OrganizationUserRoleMemberEditRequest request, String createUserId) {
|
||||
checkMemberParam(request.getUserId(), request.getUserRoleId());
|
||||
request.getUserIds().forEach(userId -> {
|
||||
checkMemberParam(userId, request.getUserRoleId());
|
||||
UserRoleRelation relation = new UserRoleRelation();
|
||||
relation.setId(UUID.randomUUID().toString());
|
||||
relation.setUserId(request.getUserId());
|
||||
relation.setUserId(userId);
|
||||
relation.setRoleId(request.getUserRoleId());
|
||||
relation.setSourceId(request.getOrganizationId());
|
||||
relation.setCreateTime(System.currentTimeMillis());
|
||||
relation.setCreateUser(createUserId);
|
||||
userRoleRelationMapper.insert(relation);
|
||||
});
|
||||
}
|
||||
|
||||
public void removeMember(OrganizationUserRoleMemberEditRequest request) {
|
||||
checkMemberParam(request.getUserId(), request.getUserRoleId());
|
||||
String removeUserId = request.getUserIds().get(0);
|
||||
checkMemberParam(removeUserId, request.getUserRoleId());
|
||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||
example.createCriteria().andUserIdEqualTo(request.getUserId())
|
||||
example.createCriteria().andUserIdEqualTo(removeUserId)
|
||||
.andRoleIdEqualTo(request.getUserRoleId())
|
||||
.andSourceIdEqualTo(request.getOrganizationId());
|
||||
userRoleRelationMapper.deleteByExample(example);
|
||||
|
|
|
@ -267,7 +267,7 @@ public class OrganizationUserRoleControllerTests extends BaseTest {
|
|||
OrganizationUserRoleMemberRequest request = new OrganizationUserRoleMemberRequest();
|
||||
request.setOrganizationId("default-organization-2");
|
||||
request.setUserRoleId("default-org-role-id-3");
|
||||
request.setUserName("admin");
|
||||
request.setKeyword("admin");
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
MvcResult mvcResult = this.responsePost(ORGANIZATION_USER_ROLE_LIST_MEMBER, request);
|
||||
|
@ -287,8 +287,8 @@ public class OrganizationUserRoleControllerTests extends BaseTest {
|
|||
List<User> userList = JSON.parseArray(JSON.toJSONString(pageData.getList()), User.class);
|
||||
if(CollectionUtils.isNotEmpty(userList)) {
|
||||
User user = userList.get(0);
|
||||
Assertions.assertTrue(StringUtils.contains(user.getName(), request.getUserName())
|
||||
|| StringUtils.contains(user.getId(), request.getUserName()));
|
||||
Assertions.assertTrue(StringUtils.contains(user.getName(), request.getKeyword())
|
||||
|| StringUtils.contains(user.getId(), request.getKeyword()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ public class OrganizationUserRoleControllerTests extends BaseTest {
|
|||
OrganizationUserRoleMemberEditRequest request = new OrganizationUserRoleMemberEditRequest();
|
||||
request.setOrganizationId("default-organization-2");
|
||||
request.setUserRoleId("default-org-role-id-3");
|
||||
request.setUserId("admin");
|
||||
request.setUserIds(List.of("admin"));
|
||||
this.requestPost(ORGANIZATION_USER_ROLE_ADD_MEMBER, request, status().isOk());
|
||||
}
|
||||
|
||||
|
@ -326,13 +326,13 @@ public class OrganizationUserRoleControllerTests extends BaseTest {
|
|||
public void testOrganizationUserRoleAddMemberError() throws Exception {
|
||||
OrganizationUserRoleMemberEditRequest request = new OrganizationUserRoleMemberEditRequest();
|
||||
request.setOrganizationId("default-organization-2");
|
||||
request.setUserId("admin-x");
|
||||
request.setUserIds(List.of("admin-x"));
|
||||
request.setUserRoleId("default-org-role-id-3");
|
||||
// 用户不存在
|
||||
this.requestPost(ORGANIZATION_USER_ROLE_ADD_MEMBER, request, status().is5xxServerError());
|
||||
request = new OrganizationUserRoleMemberEditRequest();
|
||||
request.setOrganizationId("default-organization-2");
|
||||
request.setUserId("admin");
|
||||
request.setUserIds(List.of("admin"));
|
||||
request.setUserRoleId("default-org-role-id-x");
|
||||
// 用户组不存在
|
||||
this.requestPost(ORGANIZATION_USER_ROLE_ADD_MEMBER, request, status().is5xxServerError());
|
||||
|
@ -344,7 +344,7 @@ public class OrganizationUserRoleControllerTests extends BaseTest {
|
|||
OrganizationUserRoleMemberEditRequest request = new OrganizationUserRoleMemberEditRequest();
|
||||
request.setOrganizationId("default-organization-2");
|
||||
request.setUserRoleId("default-org-role-id-3");
|
||||
request.setUserId("admin");
|
||||
request.setUserIds(List.of("admin"));
|
||||
this.requestPost(ORGANIZATION_USER_ROLE_REMOVE_MEMBER, request, status().isOk());
|
||||
}
|
||||
|
||||
|
@ -353,13 +353,13 @@ public class OrganizationUserRoleControllerTests extends BaseTest {
|
|||
public void testOrganizationUserRoleRemoveMemberError() throws Exception {
|
||||
OrganizationUserRoleMemberEditRequest request = new OrganizationUserRoleMemberEditRequest();
|
||||
request.setOrganizationId("default-organization-2");
|
||||
request.setUserId("admin-x");
|
||||
request.setUserIds(List.of("admin-x"));
|
||||
request.setUserRoleId("default-org-role-id-3");
|
||||
// 用户不存在
|
||||
this.requestPost(ORGANIZATION_USER_ROLE_REMOVE_MEMBER, request, status().is5xxServerError());
|
||||
request = new OrganizationUserRoleMemberEditRequest();
|
||||
request.setOrganizationId("default-organization-2");
|
||||
request.setUserId("admin");
|
||||
request.setUserIds(List.of("admin"));
|
||||
request.setUserRoleId("default-org-role-id-x");
|
||||
// 用户组不存在
|
||||
this.requestPost(ORGANIZATION_USER_ROLE_REMOVE_MEMBER, request, status().is5xxServerError());
|
||||
|
|
|
@ -25,10 +25,7 @@ import org.springframework.test.web.servlet.ResultMatcher;
|
|||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
|
@ -210,7 +207,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
public void testAddOrganizationMemberSuccess() throws Exception {
|
||||
OrganizationMemberRequest organizationMemberRequest = new OrganizationMemberRequest();
|
||||
organizationMemberRequest.setOrganizationId("default-organization-3");
|
||||
organizationMemberRequest.setMemberIds(Arrays.asList("admin", "default-admin"));
|
||||
organizationMemberRequest.setMemberIds(List.of("admin", "default-admin"));
|
||||
this.requestPost(ORGANIZATION_ADD_MEMBER, organizationMemberRequest, status().isOk());
|
||||
// 批量添加成员成功后, 验证是否添加成功
|
||||
OrganizationRequest organizationRequest = new OrganizationRequest();
|
||||
|
@ -243,7 +240,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
public void testAddOrganizationMemberSuccessWithRepeatUser() throws Exception {
|
||||
OrganizationMemberRequest organizationMemberRequest = new OrganizationMemberRequest();
|
||||
organizationMemberRequest.setOrganizationId("default-organization-3");
|
||||
organizationMemberRequest.setMemberIds(Arrays.asList("admin", "admin","default-admin"));
|
||||
organizationMemberRequest.setMemberIds(List.of("admin"));
|
||||
this.requestPost(ORGANIZATION_ADD_MEMBER, organizationMemberRequest, status().isOk());
|
||||
// 批量添加成员成功后, 验证是否添加成功
|
||||
OrganizationRequest organizationRequest = new OrganizationRequest();
|
||||
|
|
Loading…
Reference in New Issue