小组权限缓存层从小组应用上移到pal应用中,测试缓存方法在获取权限接口中兼容旧版权限应用

This commit is contained in:
anhc 2022-07-01 17:59:26 +08:00
parent 0081b0e1bb
commit 03793a6d5f
7 changed files with 182 additions and 151 deletions

View File

@ -141,126 +141,6 @@ public class CooperationQueryAPIManager {
}
}
public List<TeamInfo> getAllTeamInfo(){
List<TeamInfo> list = new ArrayList<>();
List<CoeCooperationTeamModel> allTeam = new CoeCooperationTeamDao().getAllTeam();
for (CoeCooperationTeamModel teamModel : allTeam) {
TeamInfo teamInfo = new TeamInfo();
teamInfo.setTeamId(teamModel.getId());
List<UserInfo> userInfos = this.getUserInfoByTeamId(teamModel.getId());
teamInfo.setUsers(userInfos);
List<String> permVerIds = new CoeCooperationTeamPermDao().getCooperationTeamPermVerIds(teamModel.getId());
teamInfo.getVersionIds().addAll(permVerIds);
list.add(teamInfo);
}
return list;
}
public List<UserInfo> getUserInfoByTeamId(String teamId){
List<UserInfo> list = new ArrayList<>();
Map<String,UserInfo> userMap = new HashMap<>();
List<CoeCooperationMemberModel> memberModels = new CoeCooperationMemberDao().queryUserListByTeam(teamId);
for (CoeCooperationMemberModel memberModel : memberModels) {
UserInfo userInfo = userMap.get(memberModel.getUserId());
if (null == userInfo){
userInfo = new UserInfo();
userInfo.setUserid(memberModel.getUserId());
userInfo.getRoleIds().add(memberModel.getRoleId());
}else {
userInfo.getRoleIds().add(memberModel.getRoleId());
}
userMap.put(memberModel.getUserId(),userInfo);
}
for (UserInfo userInfo : userMap.values()) {
List<String> roleIds = userInfo.getRoleIds();
Set<String> appPerm = this.getAppPerm(roleIds);
userInfo.setAppPermission(appPerm);
Set<String> actionPerm = this.getActionPerm(roleIds);
userInfo.setOperatePermission(actionPerm);
boolean allDataPerm = this.isAllDataPerm(roleIds);
userInfo.setIsAllDataPermission(allDataPerm);
if (!allDataPerm){
Map<String, Set<String>> dataPerm = this.getDataPerm(teamId, roleIds);
userInfo.setDataPermission(dataPerm);
}
}
list.addAll(userMap.values());
return list;
}
private Set<String> getAppPerm(List<String> roleIds){
Set<String> set = new HashSet<>();
for (String roleId : roleIds) {
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId);
if (null == roleModel){
continue;
}
//设置全局app权限
List<String> appPerm = Arrays.stream(roleModel.getAppPerm().split(",")).collect(Collectors.toList());
set.addAll(appPerm);
}
return set;
}
private Set<String> getActionPerm(List<String> roleIds){
Set<String> set = new HashSet<>();
for (String roleId : roleIds) {
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId);
if (null == roleModel){
continue;
}
//设置全局操作权限
List<String> actionPermList = Arrays.stream(roleModel.getActionPerm().split(",")).collect(Collectors.toList());
set.addAll(actionPermList);
}
return set;
}
private boolean isAllDataPerm(List<String> roleIds){
for (String roleId : roleIds) {
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId);
if (null == roleModel){
continue;
}
if (roleModel.getDataPerm().equals("all")){
return true;
}
}
return false;
}
private Map<String,Set<String>> getDataPerm(String teamId,List<String> roleIds){
Map<String,Set<String>> map = new HashMap<>();
for (String roleId : roleIds) {
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId);
if (null == roleModel) {
continue;
}
//获取角色下数据权限,设置数据权限
List<CoeCooperationRolePermModel> rolePerms = new CoeCooperationRolePermDao().getRolePermByTeamIdAndRoleId(teamId, roleId);
for (CoeCooperationRolePermModel rolePerm : rolePerms) {
Set<String> dataPerm = map.get(rolePerm.getPalVersionId());
if (null == dataPerm){
dataPerm = new HashSet<>();
}
if (StringUtils.isNotEmpty(rolePerm.getActionPerm())){
dataPerm.addAll(Arrays.asList(rolePerm.getActionPerm().split(",").clone()));
}
map.put(rolePerm.getPalVersionId(), dataPerm);
}
}
return map;
}
/**
* 根据父节点获取权限范围内的子流程小组权限范围内
* @param wsId

View File

@ -32,8 +32,6 @@ public class Plugins implements PluginListener {
params2.put("deletedClass", "");
list.add(new AppExtensionProfile("PAL小组->回收站", "aslp://com.actionsoft.apps.coe.pal.cooperation/registerApp", params2));
//小组用户权限信息cache
list.add(new CachePluginProfile(CooperationCache.class));
return list;
}
}

View File

@ -2,6 +2,9 @@ package com.actionsoft.apps.coe.pal.cooperation;
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.cooperation.cache.CooperationCache;
import com.actionsoft.apps.coe.pal.cooperation.cache.model.TeamInfo;
import com.actionsoft.apps.coe.pal.cooperation.cache.model.UserInfo;
import com.actionsoft.apps.coe.pal.cooperation.constant.CoeCooperationConst;
import com.actionsoft.apps.coe.pal.cooperation.dao.*;
import com.actionsoft.apps.coe.pal.cooperation.model.*;
@ -24,10 +27,12 @@ import com.actionsoft.bpms.util.UtilString;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.AppAPI;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang.StringUtils;
import javax.servlet.RequestDispatcher;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Created by sunlh
@ -580,28 +585,43 @@ public class CoeCooperationAPIManager {
* @param ro havingWritePermhavingRemovePermhavingVersionManagePerm 返回true false
*/
public void queryCooperationMemberActionPerm(String teamId, String userId, ResponseObject ro) {
// 权限获取
boolean havingWritePerm = true;
boolean havingRemovePerm = true;
boolean havingVersionManagePerm = true;
int validUserPermDataCount = 0;// 当前小组成员有效(流程表中存在)的数据权限数量
if (!UtilString.isEmpty(teamId) && isInstall()) {
CoeCooperationRoleModel role = queryCooperationRoleByUser(teamId, userId);
if (role != null) {
if (role.getActionPerm() == null) {
role.setActionPerm("");
};
havingWritePerm = role.getActionPerm().contains(CoeCooperationConst.ACTION_WRITE);// 新增修改权限
havingRemovePerm = role.getActionPerm().contains(CoeCooperationConst.ACTION_DELETE);// 删除权限
havingVersionManagePerm = role.getActionPerm().contains(CoeCooperationConst.ACTION_VERSION);// 版本管理权限
boolean isOlderVersion = SDK.getAppAPI().getPropertyBooleanValue("com.actionsoft.apps.coe.pal", "IsOlderVersion", true);
if (isOlderVersion){
// 权限获取
boolean havingWritePerm = true;
boolean havingRemovePerm = true;
boolean havingVersionManagePerm = true;
int validUserPermDataCount = 0;// 当前小组成员有效(流程表中存在)的数据权限数量
if (!UtilString.isEmpty(teamId) && isInstall()) {
Set<String> userOperatePermission = CooperationCache.getUserOperatePermission(teamId, userId);
havingWritePerm = userOperatePermission.contains(CoeCooperationConst.ACTION_WRITE);// 新增修改权限
havingRemovePerm = userOperatePermission.contains(CoeCooperationConst.ACTION_DELETE);// 删除权限
havingVersionManagePerm = userOperatePermission.contains(CoeCooperationConst.ACTION_VERSION);// 版本管理权限
}
ro.put("isOlderVersion", isOlderVersion);
ro.put("havingWritePerm", havingWritePerm);// 新增修改权限
ro.put("havingRemovePerm", havingRemovePerm);// 删除权限
ro.put("havingVersionManagePerm", havingVersionManagePerm);// 版本管理权限
Set<String> permDataVerIdList = CooperationCache.getUserDataVisitablePermission(teamId, userId,true);
validUserPermDataCount = permDataVerIdList != null ? permDataVerIdList.size() : 0;
ro.put("validUserPermDataCount", validUserPermDataCount);
}else {
boolean havingCreatePerm = true;
boolean havingBatchPerm = true;
int validUserPermDataCount = 0;
if (!UtilString.isEmpty(teamId) && isInstall()) {
Set<String> userOperatePermission = CooperationCache.getUserOperatePermission(teamId, userId);
havingCreatePerm = userOperatePermission.contains(CoeCooperationConst.ACTION_CREATE_PROCESS);
havingBatchPerm = userOperatePermission.contains(CoeCooperationConst.ACTION_BATCH);
}
ro.put("isOlderVersion", !isOlderVersion);// 新增修改权限
ro.put("havingCreatePerm", havingCreatePerm);// 新增修改权限
ro.put("havingBatchPerm", havingBatchPerm);// 删除权限
Set<String> dataVisitablePermission = CooperationCache.getUserDataVisitablePermission(teamId, userId,true);
validUserPermDataCount = dataVisitablePermission != null ? dataVisitablePermission.size() : 0;
ro.put("validUserPermDataCount", validUserPermDataCount);
}
ro.put("havingWritePerm", havingWritePerm);// 新增修改权限
ro.put("havingRemovePerm", havingRemovePerm);// 删除权限
ro.put("havingVersionManagePerm", havingVersionManagePerm);// 版本管理权限
List<String> permDataVerIdList = queryCooperationRoleDataPermByTeamUser(teamId, userId, true);
validUserPermDataCount = permDataVerIdList != null ? permDataVerIdList.size() : 0;
ro.put("validUserPermDataCount", validUserPermDataCount);
}
/**
@ -735,4 +755,125 @@ public class CoeCooperationAPIManager {
return false;
}
public List<TeamInfo> getAllTeamInfo(){
List<TeamInfo> list = new ArrayList<>();
List<CoeCooperationTeamModel> allTeam = new CoeCooperationTeamDao().getAllTeam();
for (CoeCooperationTeamModel teamModel : allTeam) {
TeamInfo teamInfo = new TeamInfo();
teamInfo.setTeamId(teamModel.getId());
List<UserInfo> userInfos = this.getUserInfoByTeamId(teamModel.getId());
teamInfo.setUsers(userInfos);
List<String> permVerIds = new CoeCooperationTeamPermDao().getCooperationTeamPermVerIds(teamModel.getId());
teamInfo.getVersionIds().addAll(permVerIds);
list.add(teamInfo);
}
return list;
}
public List<UserInfo> getUserInfoByTeamId(String teamId){
List<UserInfo> list = new ArrayList<>();
Map<String,UserInfo> userMap = new HashMap<>();
List<CoeCooperationMemberModel> memberModels = new CoeCooperationMemberDao().queryUserListByTeam(teamId);
for (CoeCooperationMemberModel memberModel : memberModels) {
UserInfo userInfo = userMap.get(memberModel.getUserId());
if (null == userInfo){
userInfo = new UserInfo();
userInfo.setUserid(memberModel.getUserId());
userInfo.getRoleIds().add(memberModel.getRoleId());
}else {
userInfo.getRoleIds().add(memberModel.getRoleId());
}
userMap.put(memberModel.getUserId(),userInfo);
}
for (UserInfo userInfo : userMap.values()) {
List<String> roleIds = userInfo.getRoleIds();
Set<String> appPerm = this.getAppPerm(roleIds);
userInfo.setAppPermission(appPerm);
Set<String> actionPerm = this.getActionPerm(roleIds);
userInfo.setOperatePermission(actionPerm);
boolean allDataPerm = this.isAllDataPerm(roleIds);
userInfo.setIsAllDataPermission(allDataPerm);
if (!allDataPerm){
Map<String, Set<String>> dataPerm = this.getDataPerm(teamId, roleIds);
userInfo.setDataPermission(dataPerm);
}
}
list.addAll(userMap.values());
return list;
}
private Set<String> getAppPerm(List<String> roleIds){
Set<String> set = new HashSet<>();
for (String roleId : roleIds) {
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId);
if (null == roleModel){
continue;
}
//设置全局app权限
List<String> appPerm = Arrays.stream(roleModel.getAppPerm().split(",")).collect(Collectors.toList());
set.addAll(appPerm);
}
return set;
}
private Set<String> getActionPerm(List<String> roleIds){
Set<String> set = new HashSet<>();
for (String roleId : roleIds) {
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId);
if (null == roleModel){
continue;
}
//设置全局操作权限
List<String> actionPermList = Arrays.stream(roleModel.getActionPerm().split(",")).collect(Collectors.toList());
set.addAll(actionPermList);
}
return set;
}
private boolean isAllDataPerm(List<String> roleIds){
for (String roleId : roleIds) {
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId);
if (null == roleModel){
continue;
}
if (roleModel.getDataPerm().equals("all")){
return true;
}
}
return false;
}
private Map<String,Set<String>> getDataPerm(String teamId,List<String> roleIds){
Map<String,Set<String>> map = new HashMap<>();
for (String roleId : roleIds) {
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId);
if (null == roleModel) {
continue;
}
//获取角色下数据权限,设置数据权限
List<CoeCooperationRolePermModel> rolePerms = new CoeCooperationRolePermDao().getRolePermByTeamIdAndRoleId(teamId, roleId);
for (CoeCooperationRolePermModel rolePerm : rolePerms) {
Set<String> dataPerm = map.get(rolePerm.getPalVersionId());
if (null == dataPerm){
dataPerm = new HashSet<>();
}
if (StringUtils.isNotEmpty(rolePerm.getActionPerm())){
dataPerm.addAll(Arrays.asList(rolePerm.getActionPerm().split(",").clone()));
}
map.put(rolePerm.getPalVersionId(), dataPerm);
}
}
return map;
}
}

View File

@ -1,19 +1,21 @@
package com.actionsoft.apps.coe.pal.cooperation.cache;
import com.actionsoft.apps.coe.pal.cooperation.CooperationQueryAPIManager;
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.cooperation.CoeCooperationAPIManager;
import com.actionsoft.apps.coe.pal.cooperation.cache.model.TeamInfo;
import com.actionsoft.apps.coe.pal.cooperation.cache.model.UserInfo;
import com.actionsoft.apps.coe.pal.cooperation.constant.CoeCooperationConst;
import com.actionsoft.apps.coe.pal.cooperation.constant.Constant;
import com.actionsoft.apps.coe.pal.cooperation.extend.CooperationAppManager;
import com.actionsoft.apps.coe.pal.cooperation.extend.CooperationAppProfile;
import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache;
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel;
import com.actionsoft.apps.resource.plugin.profile.CachePluginProfile;
import com.actionsoft.bpms.commons.cache.Cache;
import com.actionsoft.bpms.commons.cache.CacheManager;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.util.ConsolePrinter;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.AppAPI;
import com.alibaba.fastjson.JSONArray;
import java.util.*;
import java.util.stream.Collectors;
@ -25,13 +27,13 @@ public class CooperationCache extends Cache<String, TeamInfo> {
@Override
protected void load() {
List<TeamInfo> allTeamInfo = CooperationQueryAPIManager.getInstance().getAllTeamInfo();
List<TeamInfo> allTeamInfo = CoeCooperationAPIManager.getInstance().getAllTeamInfo();
for (TeamInfo teamInfo : allTeamInfo) {
put(teamInfo.getTeamId(),teamInfo);
}
//平台console打印
ConsolePrinter.info("[" + SDK.getAppAPI().getAppContext(Constant.APP_ID).getNameI18N() + "]Cache加载pal 小组用户角色权限信息 [" + (( allTeamInfo == null) ? 0 : allTeamInfo.size()) + "个]");
ConsolePrinter.info("[" + SDK.getAppAPI().getAppContext(CoEConstant.APP_ID).getNameI18N() + "]Cache加载pal 小组用户角色权限信息 [" + (( allTeamInfo == null) ? 0 : allTeamInfo.size()) + "个]");
}
@ -129,9 +131,15 @@ public class CooperationCache extends Cache<String, TeamInfo> {
Set<String> appPermission = userInfo.getAppPermission();
if (appPermission.contains("all")){
Set<String> set = new HashSet<>();
List<CooperationAppProfile> appProfiles = CooperationAppManager.getList();
for (CooperationAppProfile profile : appProfiles) {
set.add(profile.getId());
// aslp服务地址
String aslp = "aslp://com.actionsoft.apps.coe.pal.cooperation/listApps";
//列出已注册的流程团队扩展App
ResponseObject ro = SDK.getAppAPI().callASLP(SDK.getAppAPI().getAppContext(CoEConstant.APP_ID), aslp, new HashMap<String, Object>());
if (ro.isOk()) {
JSONArray appArr = (JSONArray)((Map)ro.getData()).get("apps");
for (int i = 0; i < appArr.size(); i++) {
set.add(appArr.getJSONObject(i).getString("id"));
}
}
return set;
}

View File

@ -14,6 +14,7 @@ import com.actionsoft.apps.coe.pal.aslp.MethodAPI.QueryMethodListByMethod;
import com.actionsoft.apps.coe.pal.aslp.PermAPI.*;
import com.actionsoft.apps.coe.pal.aslp.PublishAPI.PublishPALRepository;
import com.actionsoft.apps.coe.pal.aslp.RepositoryAPI.*;
import com.actionsoft.apps.coe.pal.cooperation.cache.CooperationCache;
import com.actionsoft.apps.coe.pal.pal.home.aslp.RegisterExtendsApp;
import com.actionsoft.apps.coe.pal.pal.method.aslp.RegisterMethodApp;
import com.actionsoft.apps.coe.pal.pal.repository.addons.RepositoryDiagramExistMark;
@ -165,6 +166,9 @@ public class Plugins implements PluginListener {
list.add(new ASLPPluginProfile("queryAllPublishedPALRepositoryModelsByPid", QueryAllPublishedPALRepositoryModelsByPid.class.getName(), "获取流程资产库下所有已发布的子流程请直接调用SDK.getPALRepositoryQueryAPI.getAllPublishedPalRepositoryModelsByPid()方法", new HttpASLP(HttpASLP.AUTH_AWS_SID, null)));
list.add(new AddOnsPluginProfile(RepositoryDiagramExistMark.class.getName(), "PAL初始化模型图标记", null));
//小组用户权限信息cache
list.add(new CachePluginProfile(CooperationCache.class));
return list;
}