feat:(REQ-3282) 收口更新用户角色的接口
This commit is contained in:
parent
55a64d39b9
commit
057a8f6710
@ -1,36 +0,0 @@
|
||||
package cn.axzo.tyr.client.model.req;
|
||||
|
||||
import cn.axzo.tyr.client.model.base.WorkspaceOUPair;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限查询请求
|
||||
*
|
||||
* @version V1.0
|
||||
* @author: ZhanSiHu
|
||||
* @date: 2024/4/7 16:23
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PermissionQueryReq {
|
||||
|
||||
@NotNull(message = "人员ID不能为空")
|
||||
private Long personId;
|
||||
|
||||
@NotEmpty(message = "单位标识对不能为空")
|
||||
private List<WorkspaceOUPair> workspaceOUPairs;
|
||||
|
||||
private String terminal;
|
||||
|
||||
private List<String> featureCodes;
|
||||
|
||||
}
|
||||
@ -27,6 +27,13 @@ public class UpsertUserRoleReq {
|
||||
@NotNull(message = "operatorId不能为空")
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
* 更新用户角色的场景
|
||||
* 记录日持,方便排查问题
|
||||
*/
|
||||
@Builder.Default
|
||||
private String scene = "更新用户角色";
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@ -48,6 +55,11 @@ public class UpsertUserRoleReq {
|
||||
@NotNull(message = "personId不能为空")
|
||||
private Long personId;
|
||||
|
||||
/**
|
||||
* 人岗架部门id
|
||||
*/
|
||||
private Long nodeId;
|
||||
|
||||
/**
|
||||
* 增量新增的角色id
|
||||
*/
|
||||
@ -77,5 +89,11 @@ public class UpsertUserRoleReq {
|
||||
* 删除用户的角色code
|
||||
*/
|
||||
private Set<String> removeRoleCodes;
|
||||
|
||||
public String buildKey() {
|
||||
return this.getIdentityId() + "_" + this.getIdentityType().getCode() +
|
||||
"_" + this.getPersonId() + "_" + this.getWorkspaceId() +
|
||||
"_" + this.getOuId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,6 +167,12 @@
|
||||
<artifactId>config-api</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.platform</groupId>
|
||||
<artifactId>axzo-log-api</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@ -31,7 +31,9 @@ public enum BizResultCode implements IResultCode {
|
||||
TERMINAL_CODE_EXIST("100021", "端code已经存在,请修改"),
|
||||
TERMINAL_NOT_FOUND("100022", "原端不存在:{}"),
|
||||
FEATURE_CODE_OVER_LENGTH("100023", "组件code不能超过100个字符:{}"),
|
||||
TERMINAL_NAME_EXIST("100024", "端名字已经存在,请修改");
|
||||
TERMINAL_NAME_EXIST("100024", "端名字已经存在,请修改"),
|
||||
ROLE_ID_NOF_FOUND("100025", "角色ID不存在:{}"),
|
||||
ROLE_CODE_NOF_FOUND("100026", "角色CODE不存在:{}");
|
||||
|
||||
|
||||
private String errorCode;
|
||||
|
||||
@ -52,7 +52,8 @@ public class RoleUserV2Controller implements RoleUserApi {
|
||||
|
||||
@Override
|
||||
public ApiResult<Void> upsertUserRole(UpsertUserRoleReq req) {
|
||||
return null;
|
||||
saasRoleUserRelationService.upsert(req);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
private PageRoleUserRelationParam from(PageRoleUserReq req) {
|
||||
|
||||
@ -88,7 +88,7 @@ public class SaasRoleDao extends ServiceImpl<SaasRoleMapper, SaasRole> {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return lambdaQuery().in(BaseEntity::getId, roleIds)
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL)
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.eq(SaasRole::getRoleType, RoleTypeEnum.INIT.getValue())
|
||||
.list();
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package cn.axzo.tyr.server.service;
|
||||
|
||||
import cn.axzo.basics.profiles.common.enums.IdentityType;
|
||||
import cn.axzo.framework.domain.page.PageResp;
|
||||
import cn.axzo.tyr.client.model.permission.IdentityAndAccountDTO;
|
||||
import cn.axzo.tyr.client.model.permission.IdentityKey;
|
||||
import cn.axzo.tyr.client.model.permission.QueryIdentityByPermissionDTO;
|
||||
@ -10,11 +9,10 @@ import cn.axzo.tyr.client.model.req.QuerySuperAdminReq;
|
||||
import cn.axzo.tyr.client.model.req.UpdateUserJobReq;
|
||||
import cn.axzo.tyr.client.model.req.WorkspaceUpdateUserRoleDTO;
|
||||
import cn.axzo.tyr.client.model.res.SuperAminInfoResp;
|
||||
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
|
||||
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
|
||||
import cn.axzo.tyr.feign.req.UpsertUserRoleReq;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -35,21 +33,10 @@ public interface SaasRoleUserRelationService extends IService<SaasRoleUserRelati
|
||||
|
||||
cn.axzo.foundation.page.PageResp<SaasRoleUserV2DTO> page(PageRoleUserRelationParam param);
|
||||
|
||||
void upsert(UpsertParam param);
|
||||
void upsert(UpsertUserRoleReq param);
|
||||
|
||||
void batchRemove(BatchRemoveParam param);
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
class UpsertParam {
|
||||
|
||||
private List<SaasRoleUserRelation> saasRoleUserRelations;
|
||||
|
||||
private Long operator;
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
|
||||
@ -15,10 +15,13 @@ import cn.axzo.framework.auth.domain.ContextInfo;
|
||||
import cn.axzo.framework.auth.domain.ContextInfoHolder;
|
||||
import cn.axzo.framework.rocketmq.Event;
|
||||
import cn.axzo.karma.client.model.dto.ProjectWorkBaseDTO;
|
||||
import cn.axzo.log.platform.client.feign.LogApi;
|
||||
import cn.axzo.log.platform.client.model.req.LogAddReq;
|
||||
import cn.axzo.maokai.api.client.OrganizationalUnitApi;
|
||||
import cn.axzo.maokai.api.vo.response.OrganizationalUnitVO;
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import cn.axzo.pudge.core.service.ServiceException;
|
||||
import cn.axzo.tyr.client.common.enums.RoleResourceTypeEnum;
|
||||
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
|
||||
import cn.axzo.tyr.client.model.enums.SaasJobTypeEnum;
|
||||
import cn.axzo.tyr.client.model.permission.IdentityAndAccountDTO;
|
||||
@ -37,9 +40,11 @@ import cn.axzo.tyr.client.model.res.SuperAminInfoResp;
|
||||
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
|
||||
import cn.axzo.tyr.feign.req.UpsertUserRoleReq;
|
||||
import cn.axzo.tyr.server.common.util.NumUtil;
|
||||
import cn.axzo.tyr.server.config.MqProducer;
|
||||
import cn.axzo.tyr.server.event.payload.SaasRoleUserRelationRemovePayload;
|
||||
import cn.axzo.tyr.server.event.payload.SaasRoleUserRelationUpsertPayload;
|
||||
import cn.axzo.tyr.server.model.QueryUserRoleReq;
|
||||
import cn.axzo.tyr.server.repository.dao.SaasRoleDao;
|
||||
import cn.axzo.tyr.server.repository.dao.SaasRoleUserRelationDao;
|
||||
@ -51,6 +56,7 @@ import cn.axzo.tyr.server.service.SaasRoleGroupService;
|
||||
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
|
||||
import cn.axzo.tyr.server.util.RpcInternalUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -76,9 +82,13 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cn.axzo.tyr.server.config.exception.BizResultCode.REMOVE_USER_ROLE_ERROR;
|
||||
import static cn.axzo.tyr.server.config.exception.BizResultCode.ROLE_CODE_NOF_FOUND;
|
||||
import static cn.axzo.tyr.server.config.exception.BizResultCode.ROLE_ID_NOF_FOUND;
|
||||
import static cn.axzo.tyr.server.event.inner.EventTypeEnum.SAAS_ROLE_USER_RELATION_REMOVED;
|
||||
import static cn.axzo.tyr.server.event.inner.EventTypeEnum.SAAS_ROLE_USER_RELATION_UPSERT;
|
||||
|
||||
/**
|
||||
* @author haiyangjin
|
||||
@ -104,6 +114,8 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
|
||||
private OrganizationalUnitApi organizationalUnitApi;
|
||||
@Autowired
|
||||
private SaasRoleGroupService saasRoleGroupService;
|
||||
@Autowired
|
||||
private LogApi logApi;
|
||||
|
||||
private static final String TARGET_TYPE = "saasRoleUserRelationId";
|
||||
|
||||
@ -196,8 +208,72 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void upsert(UpsertParam param) {
|
||||
public void upsert(UpsertUserRoleReq param) {
|
||||
|
||||
// check数据完整性
|
||||
|
||||
// check roleId
|
||||
checkRoleId(param);
|
||||
// check roleCode
|
||||
Map<String, SaasRoleRes> roles = checkRoleCode(param);
|
||||
|
||||
// 查询用户的历史记录
|
||||
Map<String, List<SaasRoleUserV2DTO>> roleUserMap = listRoleUserRelation(param).stream()
|
||||
.collect(Collectors.groupingBy(e -> e.getIdentityId() + "_" + e.getIdentityType() +
|
||||
"_" + e.getSaasRoleUser().getPersonId() + "_" + e.getWorkspaceId() + "_" + e.getOuId()));
|
||||
// 根据入参解析insert、delete的记录
|
||||
List<SaasRoleUserRelation> upsert = Lists.newArrayList();
|
||||
assembleInsertData(roleUserMap, param, roles, upsert);
|
||||
|
||||
assembleDeleteData(roleUserMap, param, roles, upsert);
|
||||
|
||||
// 批量insert、delete
|
||||
if (CollectionUtils.isEmpty(upsert)) {
|
||||
return;
|
||||
}
|
||||
this.saveOrUpdateBatch(upsert);
|
||||
|
||||
// 发送mq
|
||||
List<SaasRoleUserRelation> inserts = upsert.stream()
|
||||
.filter(saasRoleUserRelation -> Objects.isNull(saasRoleUserRelation.getIsDelete()) || Objects.equals(TableIsDeleteEnum.NORMAL.value, saasRoleUserRelation.getIsDelete()))
|
||||
.collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(inserts)) {
|
||||
Event event = Event.builder()
|
||||
.targetType(TARGET_TYPE)
|
||||
.eventCode(SAAS_ROLE_USER_RELATION_UPSERT.getEventCode())
|
||||
.data(SaasRoleUserRelationUpsertPayload.builder()
|
||||
.newValues(inserts)
|
||||
.build())
|
||||
.build();
|
||||
mqProducer.send(event);
|
||||
}
|
||||
|
||||
List<SaasRoleUserRelation> deletes = upsert.stream()
|
||||
.filter(saasRoleUserRelation -> Objects.nonNull(saasRoleUserRelation.getIsDelete()) && !Objects.equals(TableIsDeleteEnum.NORMAL.value, saasRoleUserRelation.getIsDelete()))
|
||||
.collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(deletes)) {
|
||||
Event event = Event.builder()
|
||||
.targetType(TARGET_TYPE)
|
||||
.eventCode(SAAS_ROLE_USER_RELATION_REMOVED.getEventCode())
|
||||
.data(SaasRoleUserRelationRemovePayload.builder()
|
||||
.values(deletes)
|
||||
.build())
|
||||
.build();
|
||||
mqProducer.send(event);
|
||||
}
|
||||
|
||||
logApi.addLog(LogAddReq.builder()
|
||||
.scene("UPSERT_USER_ROLE")
|
||||
.level("INFO")
|
||||
.tags(Lists.newArrayList(param.getUserRoles().stream()
|
||||
.map(UpsertUserRoleReq.UserRoleReq::getPersonId)
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.toList())))
|
||||
.message(new JSONObject()
|
||||
.fluentPut("param", param)
|
||||
.fluentPut("upsert", upsert)
|
||||
.toJSONString())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -684,4 +760,235 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
|
||||
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
private void checkRoleId(UpsertUserRoleReq param) {
|
||||
Set<Long> allRoleIds = Sets.newHashSet();
|
||||
Set<Long> insertRoleIds = param.getUserRoles().stream()
|
||||
.map(UpsertUserRoleReq.UserRoleReq::getInsertRoleIds)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<Long> fullRoleIds = param.getUserRoles().stream()
|
||||
.map(UpsertUserRoleReq.UserRoleReq::getFullRoleIds)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<Long> removeRoleIds = param.getUserRoles().stream()
|
||||
.map(UpsertUserRoleReq.UserRoleReq::getRemoveRoleIds)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
allRoleIds.addAll(insertRoleIds);
|
||||
allRoleIds.addAll(fullRoleIds);
|
||||
allRoleIds.addAll(removeRoleIds);
|
||||
if (CollectionUtils.isEmpty(allRoleIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<SaasRoleRes> dbRoles = roleService.list(ListRoleReq.builder()
|
||||
.roleIds(Lists.newArrayList(allRoleIds))
|
||||
.build());
|
||||
|
||||
if (!Objects.equals(allRoleIds.size(), dbRoles.size())) {
|
||||
Sets.SetView<Long> difference = Sets.difference(allRoleIds, dbRoles.stream().map(SaasRoleRes::getId).collect(Collectors.toSet()));
|
||||
throw ROLE_ID_NOF_FOUND.toException(ROLE_ID_NOF_FOUND.getErrorMessage(), difference.stream().sorted().collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, SaasRoleRes> checkRoleCode(UpsertUserRoleReq param) {
|
||||
Set<String> allRoleCodes = Sets.newHashSet();
|
||||
Set<String> insertRoleCodes = param.getUserRoles().stream()
|
||||
.map(UpsertUserRoleReq.UserRoleReq::getInsertRoleCodes)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<String> fullRoleCodes = param.getUserRoles().stream()
|
||||
.map(UpsertUserRoleReq.UserRoleReq::getFullRoleCodes)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<String> removeRoleCodes = param.getUserRoles().stream()
|
||||
.map(UpsertUserRoleReq.UserRoleReq::getRemoveRoleCodes)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
allRoleCodes.addAll(insertRoleCodes);
|
||||
allRoleCodes.addAll(fullRoleCodes);
|
||||
allRoleCodes.addAll(removeRoleCodes);
|
||||
if (CollectionUtils.isEmpty(allRoleCodes)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
List<SaasRoleRes> dbRoles = roleService.list(ListRoleReq.builder()
|
||||
.roleCodes(allRoleCodes)
|
||||
.build());
|
||||
|
||||
if (!Objects.equals(allRoleCodes.size(), dbRoles.size())) {
|
||||
Sets.SetView<String> difference = Sets.difference(allRoleCodes, dbRoles.stream().map(SaasRoleRes::getRoleCode).collect(Collectors.toSet()));
|
||||
throw ROLE_CODE_NOF_FOUND.toException(ROLE_CODE_NOF_FOUND.getErrorMessage(), difference.stream().sorted().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return dbRoles.stream()
|
||||
.collect(Collectors.toMap(SaasRoleRes::getRoleCode, Function.identity(), (f, s) -> f));
|
||||
}
|
||||
|
||||
private List<SaasRoleUserV2DTO> listRoleUserRelation(UpsertUserRoleReq param) {
|
||||
return this.listV2(ListRoleUserRelationParam.builder()
|
||||
.batchPersons(param.getUserRoles().stream()
|
||||
.map(e -> ListRoleUserRelationParam.BatchPerson.builder()
|
||||
.identityId(e.getIdentityId())
|
||||
.identityType(e.getIdentityType().getCode())
|
||||
.personId(e.getPersonId())
|
||||
.workspaceId(e.getWorkspaceId())
|
||||
.ouId(e.getOuId())
|
||||
.resourceId(e.getNodeId())
|
||||
.build())
|
||||
.collect(Collectors.toList()))
|
||||
.build());
|
||||
}
|
||||
|
||||
private SaasRoleUserRelation from(UpsertUserRoleReq.UserRoleReq userRoleReq,
|
||||
UpsertUserRoleReq param) {
|
||||
SaasRoleUserRelation saasRoleUserRelation = new SaasRoleUserRelation();
|
||||
saasRoleUserRelation.setNaturalPersonId(userRoleReq.getPersonId());
|
||||
saasRoleUserRelation.setIdentityId(userRoleReq.getIdentityId());
|
||||
saasRoleUserRelation.setIdentityType(userRoleReq.getIdentityType().getCode());
|
||||
saasRoleUserRelation.setWorkspaceId(userRoleReq.getWorkspaceId());
|
||||
saasRoleUserRelation.setOuId(userRoleReq.getOuId());
|
||||
saasRoleUserRelation.setCreateBy(param.getOperatorId());
|
||||
saasRoleUserRelation.setResourceId(userRoleReq.getNodeId());
|
||||
// 目前都是node,所以没有让接口传入,后续如果放开了,可以增加默认值
|
||||
saasRoleUserRelation.setResourceType(RoleResourceTypeEnum.NODE.code);
|
||||
return saasRoleUserRelation;
|
||||
}
|
||||
|
||||
private void assembleInsertData(Map<String, List<SaasRoleUserV2DTO>> roleUserMap,
|
||||
UpsertUserRoleReq param,
|
||||
Map<String, SaasRoleRes> roles,
|
||||
List<SaasRoleUserRelation> upsert) {
|
||||
List<SaasRoleUserRelation> resultByInsertRoleIds = param.getUserRoles().stream()
|
||||
.flatMap(e -> {
|
||||
Set<Long> allInsertRoleIds = Optional.ofNullable(e.getInsertRoleIds())
|
||||
.orElseGet(Sets::newHashSet);
|
||||
|
||||
allInsertRoleIds.addAll(Optional.ofNullable(e.getInsertRoleCodes())
|
||||
.map(roleCodes -> roleCodes.stream()
|
||||
.map(roleCode -> roles.get(roleCode).getId())
|
||||
.collect(Collectors.toSet()))
|
||||
.orElseGet(Sets::newHashSet));
|
||||
|
||||
return allInsertRoleIds.stream()
|
||||
.map(roleId -> {
|
||||
SaasRoleUserRelation saasRoleUserRelation = from(e, param);
|
||||
saasRoleUserRelation.setRoleId(roleId);
|
||||
return saasRoleUserRelation;
|
||||
});
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
upsert.addAll(resultByInsertRoleIds);
|
||||
|
||||
|
||||
List<SaasRoleUserRelation> resultByFullRoleIds = param.getUserRoles().stream()
|
||||
.flatMap(e -> {
|
||||
Set<Long> allFullRoleIds = Optional.ofNullable(e.getFullRoleIds())
|
||||
.orElseGet(Sets::newHashSet);
|
||||
|
||||
allFullRoleIds.addAll(Optional.ofNullable(e.getFullRoleCodes())
|
||||
.map(roleCodes -> roleCodes.stream()
|
||||
.map(roleCode -> roles.get(roleCode).getId())
|
||||
.collect(Collectors.toSet()))
|
||||
.orElseGet(Sets::newHashSet));
|
||||
|
||||
Set<Long> roleIds = Optional.ofNullable(roleUserMap.get(e.buildKey()))
|
||||
.map(roleUsers -> roleUsers.stream()
|
||||
.filter(roleUser -> Objects.isNull(e.getNodeId()) || Objects.equals(e.getNodeId(), roleUser.getResourceId()))
|
||||
.map(SaasRoleUserV2DTO::getRoleId)
|
||||
.collect(Collectors.toSet()))
|
||||
.orElseGet(Sets::newHashSet);
|
||||
|
||||
return allFullRoleIds.stream()
|
||||
.filter(roleId -> !roleIds.contains(roleId))
|
||||
.map(roleId -> {
|
||||
SaasRoleUserRelation saasRoleUserRelation = from(e, param);
|
||||
saasRoleUserRelation.setRoleId(roleId);
|
||||
return saasRoleUserRelation;
|
||||
});
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
upsert.addAll(resultByFullRoleIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装delete的数据是需要完整的信息,执行sql的时候,不会全部字段去更新,
|
||||
* 是为了发送mq,方便消费mq的业务进行操作,因为软删除的是查询不到的不应该拿去做业务
|
||||
* @param roleUserMap
|
||||
* @param param
|
||||
* @param roles
|
||||
* @param upsert
|
||||
*/
|
||||
private void assembleDeleteData(Map<String, List<SaasRoleUserV2DTO>> roleUserMap,
|
||||
UpsertUserRoleReq param,
|
||||
Map<String, SaasRoleRes> roles,
|
||||
List<SaasRoleUserRelation> upsert) {
|
||||
List<SaasRoleUserRelation> resultByRemoveRoles = param.getUserRoles().stream()
|
||||
.flatMap(e -> {
|
||||
Set<Long> allRemoveRoleIds = Optional.ofNullable(e.getRemoveRoleIds())
|
||||
.orElseGet(Sets::newHashSet);
|
||||
allRemoveRoleIds.addAll(Optional.ofNullable(e.getRemoveRoleCodes())
|
||||
.map(roleCodes -> roleCodes.stream()
|
||||
.map(roleCode -> roles.get(roleCode).getId())
|
||||
.collect(Collectors.toSet()))
|
||||
.orElseGet(Sets::newHashSet));
|
||||
List<SaasRoleUserV2DTO> saasRoleUsers = Optional.ofNullable(roleUserMap.get(e.buildKey()))
|
||||
.orElseGet(Lists::newArrayList);
|
||||
|
||||
return saasRoleUsers.stream()
|
||||
.filter(roleUser -> Objects.isNull(e.getNodeId()) || Objects.equals(e.getNodeId(), roleUser.getResourceId()))
|
||||
.filter(roleUser -> allRemoveRoleIds.contains(roleUser.getRoleId()))
|
||||
.map(roleUser -> {
|
||||
SaasRoleUserRelation saasRoleUserRelation = new SaasRoleUserRelation();
|
||||
BeanUtils.copyProperties(roleUser, saasRoleUserRelation);
|
||||
saasRoleUserRelation.setIsDelete(roleUser.getId());
|
||||
saasRoleUserRelation.setUpdateBy(param.getOperatorId());
|
||||
return saasRoleUserRelation;
|
||||
});
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
upsert.addAll(resultByRemoveRoles);
|
||||
|
||||
List<SaasRoleUserRelation> resultByFullRoles = param.getUserRoles().stream()
|
||||
.flatMap(e -> {
|
||||
Set<Long> allFullRoleIds = Optional.ofNullable(e.getFullRoleIds())
|
||||
.orElseGet(Sets::newHashSet);
|
||||
|
||||
allFullRoleIds.addAll(Optional.ofNullable(e.getFullRoleCodes())
|
||||
.map(roleCodes -> roleCodes.stream()
|
||||
.map(roleCode -> roles.get(roleCode).getId())
|
||||
.collect(Collectors.toSet()))
|
||||
.orElseGet(Sets::newHashSet));
|
||||
if (CollectionUtils.isEmpty(allFullRoleIds)) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
List<SaasRoleUserV2DTO> saasRoleUsers = Optional.ofNullable(roleUserMap.get(e.buildKey()))
|
||||
.orElseGet(Lists::newArrayList);
|
||||
|
||||
return saasRoleUsers.stream()
|
||||
.filter(roleUser -> Objects.isNull(e.getNodeId()) || Objects.equals(e.getNodeId(), roleUser.getResourceId()))
|
||||
.filter(roleUser -> !allFullRoleIds.contains(roleUser.getRoleId()))
|
||||
.map(roleUser -> {
|
||||
SaasRoleUserRelation saasRoleUserRelation = new SaasRoleUserRelation();
|
||||
BeanUtils.copyProperties(roleUser, saasRoleUserRelation);
|
||||
saasRoleUserRelation.setIsDelete(roleUser.getId());
|
||||
saasRoleUserRelation.setUpdateBy(param.getOperatorId());
|
||||
return saasRoleUserRelation;
|
||||
});
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
upsert.addAll(resultByFullRoles);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,10 +3,17 @@ package cn.axzo.tyr.base;
|
||||
import cn.axzo.apollo.workspace.api.workspace.WorkspaceApi;
|
||||
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
||||
import cn.axzo.client.feign.FeatureCodeCachedApi;
|
||||
import cn.axzo.framework.jackson.utility.JSON;
|
||||
import cn.axzo.framework.rocketmq.Event;
|
||||
import cn.axzo.framework.rocketmq.EventProducer;
|
||||
import cn.axzo.log.platform.client.feign.LogApi;
|
||||
import cn.axzo.log.platform.client.model.req.LogAddReq;
|
||||
import cn.axzo.log.platform.client.model.req.LogBatchAddReq;
|
||||
import cn.axzo.log.platform.client.model.req.LogFindReq;
|
||||
import cn.axzo.log.platform.client.model.resp.LogResp;
|
||||
import cn.axzo.maokai.api.client.OrgUserApi;
|
||||
import cn.axzo.thrones.client.saas.ServicePkgClient;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
@ -17,7 +24,10 @@ import redis.embedded.RedisServer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@ -55,6 +65,8 @@ public class TestConfig {
|
||||
private OrgUserApi orgUserApi;
|
||||
@MockBean
|
||||
private FeatureCodeCachedApi featureCodeCachedApi;
|
||||
@MockBean
|
||||
private LogApi logApi;
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.axzo.apollo.workspace.api.workspace.WorkspaceApi;
|
||||
import cn.axzo.apollo.workspace.api.workspace.res.SimpleWorkspaceRes;
|
||||
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
||||
import cn.axzo.basics.profiles.dto.basic.PersonProfileDto;
|
||||
import cn.axzo.foundation.exception.BusinessException;
|
||||
import cn.axzo.framework.domain.web.result.ApiListResult;
|
||||
import cn.axzo.maokai.api.client.OrgUserApi;
|
||||
import cn.axzo.maokai.api.vo.response.OrgUserRes;
|
||||
@ -16,6 +17,7 @@ import cn.axzo.tyr.base.BaseTest;
|
||||
import cn.axzo.tyr.base.MysqlDataLoader;
|
||||
import cn.axzo.tyr.client.common.enums.FeatureResourceType;
|
||||
import cn.axzo.tyr.client.model.enums.IdentityType;
|
||||
import cn.axzo.tyr.client.model.req.ChangeGroupLeaderRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.ListPermissionFromRoleGroupReq;
|
||||
import cn.axzo.tyr.client.model.res.ListPermissionFromRoleGroupResp;
|
||||
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
|
||||
@ -29,8 +31,10 @@ import cn.axzo.tyr.feign.enums.IdentityTypeEnum;
|
||||
import cn.axzo.tyr.feign.enums.RolePermissionTagEnum;
|
||||
import cn.axzo.tyr.feign.enums.RoleTypeEnum;
|
||||
import cn.axzo.tyr.feign.req.PageRoleUserReq;
|
||||
import cn.axzo.tyr.feign.req.UpsertUserRoleReq;
|
||||
import cn.axzo.tyr.feign.resp.RoleUserResp;
|
||||
import cn.axzo.tyr.server.controller.roleuser.RoleUserController;
|
||||
import cn.axzo.tyr.server.service.RoleService;
|
||||
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
|
||||
import cn.axzo.tyr.server.service.SaasRoleUserService;
|
||||
import cn.axzo.tyr.server.service.TyrSaasAuthService;
|
||||
@ -49,6 +53,8 @@ import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.axzo.tyr.server.config.exception.BizResultCode.ROLE_CODE_NOF_FOUND;
|
||||
import static cn.axzo.tyr.server.config.exception.BizResultCode.ROLE_ID_NOF_FOUND;
|
||||
import static cn.axzo.tyr.server.repository.entity.SaasPgroupPermissionRelation.NEW_FEATURE;
|
||||
|
||||
class RoleUserV2ControllerTest extends BaseTest {
|
||||
@ -1218,4 +1224,49 @@ class RoleUserV2ControllerTest extends BaseTest {
|
||||
.getData()
|
||||
.getData();
|
||||
}
|
||||
|
||||
@Test
|
||||
void upsertUserRole() {
|
||||
|
||||
BusinessException businessException = Assertions.assertThrows(BusinessException.class, () -> {
|
||||
UpsertUserRoleReq upsertUserRoleReq = UpsertUserRoleReq.builder()
|
||||
.userRoles(Sets.newHashSet(UpsertUserRoleReq.UserRoleReq.builder()
|
||||
.insertRoleIds(Sets.newHashSet(11L))
|
||||
.build()))
|
||||
.build();
|
||||
roleUserV2Controller.upsertUserRole(upsertUserRoleReq);
|
||||
});
|
||||
|
||||
Assertions.assertEquals(businessException.getErrorCode(), ROLE_ID_NOF_FOUND.getErrorCode());
|
||||
Assertions.assertEquals(businessException.getErrorMsg(), "角色ID不存在:[11]");
|
||||
|
||||
businessException = Assertions.assertThrows(BusinessException.class, () -> {
|
||||
UpsertUserRoleReq upsertUserRoleReq = UpsertUserRoleReq.builder()
|
||||
.userRoles(Sets.newHashSet(UpsertUserRoleReq.UserRoleReq.builder()
|
||||
.insertRoleIds(Sets.newHashSet(11L))
|
||||
.fullRoleIds(Sets.newHashSet(33L, 11L, 22L))
|
||||
.removeRoleIds(Sets.newHashSet(3L))
|
||||
.build()))
|
||||
.build();
|
||||
roleUserV2Controller.upsertUserRole(upsertUserRoleReq);
|
||||
});
|
||||
|
||||
Assertions.assertEquals(businessException.getErrorCode(), ROLE_ID_NOF_FOUND.getErrorCode());
|
||||
Assertions.assertEquals(businessException.getErrorMsg(), "角色ID不存在:[3, 11, 22, 33]");
|
||||
|
||||
businessException = Assertions.assertThrows(BusinessException.class, () -> {
|
||||
UpsertUserRoleReq upsertUserRoleReq = UpsertUserRoleReq.builder()
|
||||
.userRoles(Sets.newHashSet(UpsertUserRoleReq.UserRoleReq.builder()
|
||||
.insertRoleCodes(Sets.newHashSet("AA"))
|
||||
.fullRoleCodes(Sets.newHashSet("BB, CC"))
|
||||
.removeRoleCodes(Sets.newHashSet("db"))
|
||||
.build()))
|
||||
.build();
|
||||
roleUserV2Controller.upsertUserRole(upsertUserRoleReq);
|
||||
});
|
||||
|
||||
Assertions.assertEquals(businessException.getErrorCode(), ROLE_CODE_NOF_FOUND.getErrorCode());
|
||||
Assertions.assertEquals(businessException.getErrorMsg(), "角色CODE不存在:[AA, BB, CC, db]");
|
||||
|
||||
}
|
||||
}
|
||||
@ -4,11 +4,16 @@ import cn.axzo.foundation.exception.BusinessException;
|
||||
import cn.axzo.foundation.page.PageResp;
|
||||
import cn.axzo.tyr.base.BaseTest;
|
||||
import cn.axzo.tyr.base.MysqlDataLoader;
|
||||
import cn.axzo.tyr.client.common.enums.RoleResourceTypeEnum;
|
||||
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
|
||||
import cn.axzo.tyr.client.model.req.ChangeGroupLeaderRoleReq;
|
||||
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
|
||||
import cn.axzo.tyr.feign.enums.IdentityTypeEnum;
|
||||
import cn.axzo.tyr.feign.req.UpsertUserRoleReq;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
|
||||
import cn.axzo.tyr.server.service.RoleService;
|
||||
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
@ -28,6 +33,8 @@ class SaasRoleUserRelationServiceImplTest extends BaseTest {
|
||||
private SaasRoleUserRelationService saasRoleUserRelationService;
|
||||
@Autowired
|
||||
private MysqlDataLoader mysqlDataLoader;
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@BeforeEach
|
||||
@Override
|
||||
@ -40,12 +47,12 @@ class SaasRoleUserRelationServiceImplTest extends BaseTest {
|
||||
void batchRemove() {
|
||||
|
||||
List<SaasRoleUserV2DTO> saasRoleUsers = saasRoleUserRelationService.listV2(ListRoleUserRelationParam.builder().build());
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 4);
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 9);
|
||||
|
||||
SaasRoleUserRelationService.BatchRemoveParam batchRemoveParam =
|
||||
SaasRoleUserRelationService.BatchRemoveParam.builder().build();
|
||||
saasRoleUserRelationService.batchRemove(batchRemoveParam);
|
||||
Assertions.assertEquals(saasRoleUserRelationService.listV2(ListRoleUserRelationParam.builder().build()).size(), 4);
|
||||
Assertions.assertEquals(saasRoleUserRelationService.listV2(ListRoleUserRelationParam.builder().build()).size(), 9);
|
||||
|
||||
BusinessException businessException = assertThrows(BusinessException.class, ()->{
|
||||
saasRoleUserRelationService.batchRemove(SaasRoleUserRelationService.BatchRemoveParam.builder()
|
||||
@ -57,7 +64,7 @@ class SaasRoleUserRelationServiceImplTest extends BaseTest {
|
||||
saasRoleUserRelationService.batchRemove(SaasRoleUserRelationService.BatchRemoveParam.builder()
|
||||
.ids(Sets.newHashSet(16399L, 16400L))
|
||||
.build());
|
||||
Assertions.assertEquals(saasRoleUserRelationService.listV2(ListRoleUserRelationParam.builder().build()).size(), 2);
|
||||
Assertions.assertEquals(saasRoleUserRelationService.listV2(ListRoleUserRelationParam.builder().build()).size(), 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -118,4 +125,220 @@ class SaasRoleUserRelationServiceImplTest extends BaseTest {
|
||||
result = saasRoleUserRelationService.listV2(list);
|
||||
Assertions.assertEquals(result.size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void upsertUserRole() {
|
||||
ListRoleUserRelationParam listRoleUserRelationParam = ListRoleUserRelationParam.builder()
|
||||
.personId(1776L)
|
||||
.resourceType(RoleResourceTypeEnum.NODE.code)
|
||||
.resourceId(17990L)
|
||||
.build();
|
||||
List<SaasRoleUserV2DTO> saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 1);
|
||||
// 清空role
|
||||
saasRoleUserRelationService.upsert(UpsertUserRoleReq.builder()
|
||||
.userRoles(Sets.newHashSet(
|
||||
UpsertUserRoleReq.UserRoleReq.builder()
|
||||
.identityId(10256L)
|
||||
.identityType(IdentityTypeEnum.WORKER)
|
||||
.personId(1776L)
|
||||
.workspaceId(195L)
|
||||
.ouId(7784L)
|
||||
.nodeId(17990L)
|
||||
.removeRoleIds(Sets.newHashSet(100008L))
|
||||
.build()
|
||||
))
|
||||
.operatorId(11L)
|
||||
.build());
|
||||
saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 0);
|
||||
// 清空role
|
||||
|
||||
// 更换role
|
||||
saasRoleUserRelationService.upsert(UpsertUserRoleReq.builder()
|
||||
.userRoles(Sets.newHashSet(
|
||||
UpsertUserRoleReq.UserRoleReq.builder()
|
||||
.identityId(10256L)
|
||||
.identityType(IdentityTypeEnum.WORKER)
|
||||
.personId(1776L)
|
||||
.workspaceId(195L)
|
||||
.ouId(7784L)
|
||||
.nodeId(17990L)
|
||||
.fullRoleIds(Sets.newHashSet(100009L))
|
||||
.build()
|
||||
))
|
||||
.operatorId(11L)
|
||||
.build());
|
||||
saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityId(), 10256L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityType(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getSaasRoleUser().getPersonId(), 1776L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getRoleId(), 100009L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getWorkspaceId(), 195L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getOuId(), 7784L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceId(), 17990L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceType(), RoleResourceTypeEnum.NODE.code);
|
||||
// 更换role
|
||||
|
||||
// 增加和删除role
|
||||
saasRoleUserRelationService.upsert(UpsertUserRoleReq.builder()
|
||||
.userRoles(Sets.newHashSet(
|
||||
UpsertUserRoleReq.UserRoleReq.builder()
|
||||
.identityId(10256L)
|
||||
.identityType(IdentityTypeEnum.WORKER)
|
||||
.personId(1776L)
|
||||
.workspaceId(195L)
|
||||
.ouId(7784L)
|
||||
.nodeId(17990L)
|
||||
.insertRoleIds(Sets.newHashSet(100010L))
|
||||
.build()
|
||||
))
|
||||
.operatorId(11L)
|
||||
.build());
|
||||
saasRoleUserRelationService.upsert(UpsertUserRoleReq.builder()
|
||||
.userRoles(Sets.newHashSet(
|
||||
UpsertUserRoleReq.UserRoleReq.builder()
|
||||
.identityId(10256L)
|
||||
.identityType(IdentityTypeEnum.WORKER)
|
||||
.personId(1776L)
|
||||
.workspaceId(195L)
|
||||
.ouId(7784L)
|
||||
.nodeId(17990L)
|
||||
.removeRoleIds(Sets.newHashSet(100009L))
|
||||
.insertRoleIds(Sets.newHashSet(100147L))
|
||||
.build()
|
||||
))
|
||||
.operatorId(11L)
|
||||
.build());
|
||||
saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 2);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityId(), 10256L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityType(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getSaasRoleUser().getPersonId(), 1776L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getRoleId(), 100010L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getWorkspaceId(), 195L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getOuId(), 7784L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceId(), 17990L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceType(), RoleResourceTypeEnum.NODE.code);
|
||||
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getIdentityId(), 10256L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getIdentityType(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getSaasRoleUser().getPersonId(), 1776L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getRoleId(), 100147L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getWorkspaceId(), 195L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getOuId(), 7784L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getResourceId(), 17990L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getResourceType(), RoleResourceTypeEnum.NODE.code);
|
||||
// 增加role
|
||||
}
|
||||
|
||||
@Test
|
||||
void upsertUserRoleReplaceChangeGroupLeaderRole() {
|
||||
// old
|
||||
// 清空role
|
||||
ListRoleUserRelationParam listRoleUserRelationParam = ListRoleUserRelationParam.builder()
|
||||
.personId(1776L)
|
||||
.resourceType(RoleResourceTypeEnum.NODE.code)
|
||||
.resourceId(17990L)
|
||||
.build();
|
||||
List<SaasRoleUserV2DTO> saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 1);
|
||||
roleService.changeGroupLeaderRole(Lists.newArrayList(
|
||||
ChangeGroupLeaderRoleReq.builder().groupNodeId(listRoleUserRelationParam.getResourceId())
|
||||
.groupLeaderPersonId(listRoleUserRelationParam.getPersonId()).build()
|
||||
));
|
||||
saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 0);
|
||||
// 清空role
|
||||
|
||||
// 更换role
|
||||
roleService.changeGroupLeaderRole(Lists.newArrayList(
|
||||
ChangeGroupLeaderRoleReq.builder().groupNodeId(listRoleUserRelationParam.getResourceId())
|
||||
.groupNodeId(listRoleUserRelationParam.getResourceId())
|
||||
.groupLeaderPersonId(listRoleUserRelationParam.getPersonId())
|
||||
.workspaceId(195L)
|
||||
.ouId(7784L)
|
||||
.groupLeaderIdentityId(10256L)
|
||||
.roleIdList(Lists.newArrayList(100009L)).build()
|
||||
));
|
||||
saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityId(), 10256L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityType(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getSaasRoleUser().getPersonId(), 1776L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getRoleId(), 100009L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getWorkspaceId(), 195L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getOuId(), 7784L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceId(), 17990L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceType(), RoleResourceTypeEnum.NODE.code);
|
||||
// 更换role
|
||||
|
||||
// 增加role
|
||||
roleService.changeGroupLeaderRole(Lists.newArrayList(
|
||||
ChangeGroupLeaderRoleReq.builder().groupNodeId(listRoleUserRelationParam.getResourceId())
|
||||
.groupNodeId(listRoleUserRelationParam.getResourceId())
|
||||
.groupLeaderPersonId(listRoleUserRelationParam.getPersonId())
|
||||
.workspaceId(195L)
|
||||
.ouId(7784L)
|
||||
.groupLeaderIdentityId(10256L)
|
||||
.roleIdList(Lists.newArrayList(100009L, 100010L)).build()
|
||||
));
|
||||
saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 2);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityId(), 10256L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityType(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getSaasRoleUser().getPersonId(), 1776L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getRoleId(), 100009L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getWorkspaceId(), 195L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getOuId(), 7784L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceId(), 17990L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceType(), RoleResourceTypeEnum.NODE.code);
|
||||
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getIdentityId(), 10256L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getIdentityType(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getSaasRoleUser().getPersonId(), 1776L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getRoleId(), 100010L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getWorkspaceId(), 195L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getOuId(), 7784L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getResourceId(), 17990L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getResourceType(), RoleResourceTypeEnum.NODE.code);
|
||||
// 增加role
|
||||
|
||||
// 增加和删除role
|
||||
roleService.changeGroupLeaderRole(Lists.newArrayList(
|
||||
ChangeGroupLeaderRoleReq.builder().groupNodeId(listRoleUserRelationParam.getResourceId())
|
||||
.groupNodeId(listRoleUserRelationParam.getResourceId())
|
||||
.groupLeaderPersonId(listRoleUserRelationParam.getPersonId())
|
||||
.workspaceId(195L)
|
||||
.ouId(7784L)
|
||||
.groupLeaderIdentityId(10256L)
|
||||
.roleIdList(Lists.newArrayList(100147L, 100010L)).build()
|
||||
));
|
||||
saasRoleUsers = saasRoleUserRelationService.listV2(listRoleUserRelationParam);
|
||||
Assertions.assertEquals(saasRoleUsers.size(), 2);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityId(), 10256L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getIdentityType(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getSaasRoleUser().getPersonId(), 1776L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getRoleId(), 100010L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getWorkspaceId(), 195L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getOuId(), 7784L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceId(), 17990L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(0).getResourceType(), RoleResourceTypeEnum.NODE.code);
|
||||
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getIdentityId(), 10256L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getIdentityType(), 1);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getSaasRoleUser().getPersonId(), 1776L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getRoleId(), 100147L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getWorkspaceId(), 195L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getOuId(), 7784L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getResourceId(), 17990L);
|
||||
Assertions.assertEquals(saasRoleUsers.get(1).getResourceType(), RoleResourceTypeEnum.NODE.code);
|
||||
// 增加role
|
||||
// old
|
||||
}
|
||||
}
|
||||
@ -15,4 +15,45 @@ VALUES (3417, '商务副经理', '', 'init', 'cms:mafb_business_vice_officer', -
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (3418, '生产副经理', '', 'init', 'cms:mafb_productivity_vice_officer', -1, -1, 5, 2, 0, '2023-10-23 17:50:00', '2024-08-13 10:25:41', -1, 2006333, 1, 65535, 0, null, 0, '', 1, 3, 1);
|
||||
|
||||
|
||||
INSERT INTO saas_role_group (id, workspace_type_code, ou_type_code, name, workspace_id, ou_id, parent_id, sort, code, category_code, is_delete, create_at, update_at, path)
|
||||
VALUES (32, '2', '9', '小组长权限', -1, -1, 46, 7, 'projectTeamGPLeader', 'workspace_groupleader', 0, '2024-01-20 18:51:37', '2024-09-10 10:18:44', '46,32,');
|
||||
|
||||
INSERT INTO saas_role_group_relation (id, role_id, saas_role_group_id, is_delete, create_at, update_at)
|
||||
VALUES (165, 100009, 32, 0, '2024-01-20 18:51:37', '2024-01-20 18:51:37');
|
||||
INSERT INTO saas_role_group_relation (id, role_id, saas_role_group_id, is_delete, create_at, update_at)
|
||||
VALUES (166, 100010, 32, 0, '2024-01-20 18:51:37', '2024-01-20 18:51:37');
|
||||
INSERT INTO saas_role_group_relation (id, role_id, saas_role_group_id, is_delete, create_at, update_at)
|
||||
VALUES (167, 100008, 32, 0, '2024-01-20 18:51:37', '2024-01-20 18:51:37');
|
||||
INSERT INTO saas_role_group_relation (id, role_id, saas_role_group_id, is_delete, create_at, update_at)
|
||||
VALUES (180, 100147, 32, 0, '2024-02-20 10:11:17', '2024-02-20 10:11:17');
|
||||
INSERT INTO saas_role_group_relation (id, role_id, saas_role_group_id, is_delete, create_at, update_at)
|
||||
VALUES (218, 100379, 32, 0, '2024-04-28 14:56:11', '2024-04-28 14:56:11');
|
||||
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (100008, '小组内工人记工', '', 'init', 'cms:bz_subteam_worker_order', -1, -1, 9, 2, 0, '2024-01-20 18:51:37', '2024-10-25 14:18:42', 0, 89629, 1, 65535, 0, null, 0, '', 1, 1, 1);
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (100009, '小组任务终止、转单、撤销', '', 'init', 'cms:bz_subteam_task_manage', -1, -1, 9, 2, 0, '2024-01-20 18:51:37', '2024-11-20 09:48:19', 0, 89629, 1, 65535, 0, null, 0, '', 1, 2, 1);
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (100010, '发起考勤补卡', '', 'init', 'cms:bz_subteam_absence&attendance', -1, -1, 9, 2, 0, '2024-01-20 18:51:37', '2024-08-07 11:10:57', 0, 81, 1, 65535, 0, null, 0, '', 1, 3, 1);
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (100147, '提交发薪申请、查看发薪记录', '', 'init', 'cms:bz_subteam_salary_apply&recoder', -1, -1, 9, 2, 0, '2024-02-20 10:11:17', '2024-08-13 10:26:11', 2003028, 29024, 1, 65535, 0, null, 0, '', 1, 4, 1);
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (100379, '通讯录', '', 'init', 'XZZ-tongxunlu', -1, -1, 9, 2, 0, '2024-04-28 14:56:11', '2024-12-18 15:44:56', 2008237, 9000400266, 1, 65535, 0, null, 0, '', 1, 5, 1);
|
||||
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (197763, 10256, 100008, 1, 1776, 195, 7784, 2, 17990, 0, '2024-01-20 18:51:41', '2024-01-20 18:51:41', 0, 0, 2);
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (197766, 10344, 100008, 1, 1513, 195, 7334, 2, 17988, 0, '2024-01-20 18:51:41', '2024-01-20 18:51:41', 0, 0, 2);
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (197769, 20276, 100008, 1, 13130, 195, 7334, 2, 17985, 0, '2024-01-20 18:51:41', '2024-01-20 18:51:41', 0, 0, 2);
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (197775, 38205, 100008, 1, 31786, 3488, 9414, 2, 11629, 0, '2024-01-20 18:51:41', '2024-01-20 18:51:41', 0, 0, 2);
|
||||
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (100019, '项目二维码管理', '', 'init', 'cms:bz_project_qrcode_manage', -1, -1, 9, 2, 0, '2024-01-20 18:51:37', '2024-10-25 14:18:42', 0, 89629, 1, 65535, 0, null, 0, '', 1, 1, 1);
|
||||
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (197764, 10256, 100019, 1, 1776, 195, 7784, 0, 0, 0, '2024-01-20 18:51:41', '2024-01-20 18:51:41', 0, 0, 2);
|
||||
|
||||
#-->SaasRoleUserRelationServiceImplTest.sql
|
||||
Loading…
Reference in New Issue
Block a user