feat(permission): 权限查询支持指定角色

This commit is contained in:
zhansihu 2023-11-27 18:10:49 +08:00
parent 9aeb17c480
commit 0232279c83
2 changed files with 35 additions and 9 deletions

View File

@ -56,6 +56,9 @@ public class IdentityAuthReq {
@Builder.Default
private Set<String> featureCode = new HashSet<>();
/** 指定角色ID - 预览用,不需要用户已配置角色 **/
private List<Long> specifyRoleIds;
@Data
@Builder

View File

@ -316,17 +316,40 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
userRoleInfoMap.setWorkspaceJoinType(WorkspaceJoinType.matchValue(e.getWorkspaceJoinType()));
queryKey.putIfAbsent(KeyUtil.buildKeyBySeparator(e.getWorkspaceId(), e.getOuId()), userRoleInfoMap);
});
stopWatch.start("query role user relation");
List<SaasRoleUserRelation> saasRoleUserRelations = roleUserService.queryByWorkspaceIdOrOu(identityAuthReq.getIdentityId(), identityAuthReq.getIdentityType(), queryWorkspace, queryOuId);
stopWatch.stop();
if (CollectionUtil.isEmpty(saasRoleUserRelations)) {
return result;
}
// 有工作台和单位的查询条件通过单位与工作台在过滤一次
if (CollectionUtil.isNotEmpty(queryInfo)) {
saasRoleUserRelations = saasRoleUserRelations.stream().filter(roleUserService -> queryKey.containsKey(KeyUtil.buildKeyBySeparator(roleUserService.getWorkspaceId(), roleUserService.getOuId()))).collect(Collectors.toList());
final List<SaasRoleUserRelation> saasRoleUserRelations = new ArrayList<>();
if (CollectionUtil.isNotEmpty(identityAuthReq.getSpecifyRoleIds())) {
//指定了角色 则不需要去查用户角色关系
// mock 看做已有所有角色
queryKey.values().forEach(k -> {
List<SaasRoleUserRelation> relations = identityAuthReq.getSpecifyRoleIds().stream().map(id -> {
SaasRoleUserRelation relation = new SaasRoleUserRelation();
relation.setRoleId(id);
relation.setOuId(k.getOuId());
relation.setWorkspaceId(k.getWorkspaceId());
relation.setIdentityId(identityAuthReq.getIdentityId());
relation.setIdentityType(identityAuthReq.getIdentityType().getCode());
return relation;
}).collect(Collectors.toList());
saasRoleUserRelations.addAll(relations);
});
} else {
stopWatch.start("query role user relation");
List<SaasRoleUserRelation> relations = roleUserService.queryByWorkspaceIdOrOu(identityAuthReq.getIdentityId(), identityAuthReq.getIdentityType(), queryWorkspace, queryOuId);
stopWatch.stop();
if (CollectionUtil.isEmpty(relations)) {
return result;
}
// 有工作台和单位的查询条件通过单位与工作台在过滤一次
if (CollectionUtil.isNotEmpty(queryInfo)) {
saasRoleUserRelations.addAll(relations.stream()
.filter(roleUserService -> queryKey.containsKey(
KeyUtil.buildKeyBySeparator(roleUserService.getWorkspaceId(), roleUserService.getOuId())))
.collect(Collectors.toList()));
}
}
Set<Long> realWorkspaceId = saasRoleUserRelations.stream().map(SaasRoleUserRelation::getWorkspaceId).collect(Collectors.toSet());
Set<Long> realOuId = saasRoleUserRelations.stream().map(SaasRoleUserRelation::getOuId).collect(Collectors.toSet());
//工作台对应产品 key = workapceId