feat: REQ-1650
This commit is contained in:
parent
1a8cdc41ee
commit
02537e43d4
@ -57,4 +57,10 @@ public class RoleUserReq {
|
||||
*/
|
||||
private Set<Long> updateRoleIds;
|
||||
|
||||
|
||||
/**
|
||||
* 该请求是否是权限回收
|
||||
*/
|
||||
private boolean isRecycleModel;
|
||||
|
||||
}
|
||||
|
||||
@ -51,14 +51,14 @@ public class RoleUserService implements SaasRoleUserService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdate(RoleUserReq req) {
|
||||
|
||||
Set<Long> updateRoleIds = req.getUpdateRoleIds();
|
||||
// 角色校验(不能将角色修改为管理员角色)
|
||||
if(CollectionUtils.isNotEmpty(updateRoleIds)){
|
||||
List<SaasRole> roles = saasRoleDao.listByIds(updateRoleIds);
|
||||
if (roles.stream().anyMatch(e -> RoleTypeEnum.getRoleType(e.getRoleType()).isAdminRole())) {
|
||||
throw new ServiceException("暂不支持更换管理员角色");
|
||||
}
|
||||
}
|
||||
Set<Long> updateRoleIds = req.getUpdateRoleIds();
|
||||
// 角色校验(不能将角色修改为管理员角色)
|
||||
if (CollectionUtils.isNotEmpty(updateRoleIds)) {
|
||||
List<SaasRole> roles = saasRoleDao.listByIds(updateRoleIds);
|
||||
if (roles.stream().anyMatch(e -> RoleTypeEnum.getRoleType(e.getRoleType()).isAdminRole())) {
|
||||
throw new ServiceException("暂不支持更换/移除管理员角色");
|
||||
}
|
||||
}
|
||||
|
||||
// 查询用户所有角色
|
||||
List<SaasRoleUserRelation> existsRoleUser = roleUserRelationDao.query(req.getIdentityId(), req.getIdentityType().getCode(), req.getWorkspaceId(), req.getOuId());
|
||||
@ -76,14 +76,22 @@ public class RoleUserService implements SaasRoleUserService {
|
||||
.identityId(req.getIdentityId()).identityType(req.getIdentityType())
|
||||
.build();
|
||||
|
||||
// 删除现有非管理员的角色
|
||||
if (CollectionUtils.isNotEmpty(notAdminRole)) {
|
||||
roleUserRelationDao.deleteByUser(workspaceModel, notAdminRole);
|
||||
}
|
||||
// 清空所有角色
|
||||
if (CollectionUtil.isEmpty(updateRoleIds)) {
|
||||
return;
|
||||
}
|
||||
// 删除现有非管理员的角色
|
||||
if (CollectionUtils.isNotEmpty(notAdminRole)) {
|
||||
//如果该接口支持 权限回收,那么参数UpdateRoleIds就是待删除的权限合集
|
||||
if (req.isRecycleModel()) {
|
||||
notAdminRole.clear();
|
||||
//回收角色权限,只移除用户传参的权限
|
||||
notAdminRole.addAll(req.getUpdateRoleIds());
|
||||
roleUserRelationDao.deleteByUser(workspaceModel, notAdminRole);
|
||||
return;
|
||||
}
|
||||
roleUserRelationDao.deleteByUser(workspaceModel, notAdminRole);
|
||||
}
|
||||
// 清空所有角色
|
||||
if (CollectionUtil.isEmpty(updateRoleIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
roleUserRelationDao.saveBatch(updateRoleIds.stream().map(e -> {
|
||||
SaasRoleUserRelation saasRoleUserRelation = new SaasRoleUserRelation();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user