This commit is contained in:
liqiang-fit2cloud 2022-12-28 18:03:16 +08:00
commit 2d1d0cec5e
1 changed files with 18 additions and 17 deletions

View File

@ -200,7 +200,7 @@ public class GroupService {
private GroupJson loadPermissionJsonFromService() { private GroupJson loadPermissionJsonFromService() {
GroupJson groupJson = null; GroupJson groupJson = null;
List<GroupResource> globalResource = new ArrayList<>(); List<GroupResource> globalResources = new ArrayList<>();
try { try {
for (String service : servicePermissionLoadOrder) { for (String service : servicePermissionLoadOrder) {
Object obj = stringRedisTemplate.opsForHash().get(RedisKey.MS_PERMISSION_KEY, service); Object obj = stringRedisTemplate.opsForHash().get(RedisKey.MS_PERMISSION_KEY, service);
@ -208,25 +208,26 @@ public class GroupService {
LogUtil.warn("permission json file is null. service name: " + service); LogUtil.warn("permission json file is null. service name: " + service);
continue; continue;
} }
GroupJson temp = JSON.parseObject((String) obj, GroupJson.class); GroupJson microServiceGroupJson = JSON.parseObject((String) obj, GroupJson.class);
List<GroupResource> globalResource = microServiceGroupJson.getResource()
.stream()
.filter(gp -> BooleanUtils.isTrue(gp.isGlobal()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(globalResource)) {
globalResources.addAll(globalResource);
microServiceGroupJson.getResource().removeIf(gp -> BooleanUtils.isTrue(gp.isGlobal()));
}
if (groupJson == null) { if (groupJson == null) {
groupJson = temp; groupJson = microServiceGroupJson;
// 全局权限放系统设置模块
if (StringUtils.equals(service, MicroServiceName.SYSTEM_SETTING)) {
globalResource = temp.getResource()
.stream()
.filter(gp -> BooleanUtils.isTrue(gp.isGlobal()))
.collect(Collectors.toList());
temp.getResource().removeIf(gp -> BooleanUtils.isTrue(gp.isGlobal()));
}
} else { } else {
groupJson.getResource().addAll(temp.getResource()); groupJson.getResource().addAll(microServiceGroupJson.getResource());
groupJson.getPermissions().addAll(temp.getPermissions()); groupJson.getPermissions().addAll(microServiceGroupJson.getPermissions());
} }
} }
// 拼装权限的时候放在最后 // 拼装时通用权限Resource放在最后
if (groupJson != null && !globalResource.isEmpty()) { if (groupJson != null && !globalResources.isEmpty()) {
groupJson.getResource().addAll(globalResource); groupJson.getResource().addAll(globalResources);
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
@ -337,7 +338,7 @@ public class GroupService {
} else { } else {
grs = resources grs = resources
.stream() .stream()
.filter(g -> g.getId().startsWith(group.getType()) || g.getId().startsWith(PERSONAL_PREFIX)) .filter(g -> g.getId().startsWith(group.getType()) || BooleanUtils.isTrue(g.isGlobal()))
.collect(Collectors.toList()); .collect(Collectors.toList());
permissions.forEach(p -> { permissions.forEach(p -> {
if (permissionList.contains(p.getId())) { if (permissionList.contains(p.getId())) {