refactor(用户组与权限): 权限资源的加载
This commit is contained in:
parent
65c8ad55ee
commit
778676c8da
|
@ -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);
|
||||||
if (groupJson == null) {
|
List<GroupResource> globalResource = microServiceGroupJson.getResource()
|
||||||
groupJson = temp;
|
|
||||||
// 全局权限放系统设置模块
|
|
||||||
if (StringUtils.equals(service, MicroServiceName.SYSTEM_SETTING)) {
|
|
||||||
globalResource = temp.getResource()
|
|
||||||
.stream()
|
.stream()
|
||||||
.filter(gp -> BooleanUtils.isTrue(gp.isGlobal()))
|
.filter(gp -> BooleanUtils.isTrue(gp.isGlobal()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
temp.getResource().removeIf(gp -> BooleanUtils.isTrue(gp.isGlobal()));
|
if (CollectionUtils.isNotEmpty(globalResource)) {
|
||||||
|
globalResources.addAll(globalResource);
|
||||||
|
microServiceGroupJson.getResource().removeIf(gp -> BooleanUtils.isTrue(gp.isGlobal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (groupJson == null) {
|
||||||
|
groupJson = microServiceGroupJson;
|
||||||
} 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())) {
|
||||||
|
|
Loading…
Reference in New Issue