《优化需求23.5.29反馈-6.6更新》中小组权限问题相关代码优化

This commit is contained in:
qinoy 2023-07-13 14:53:54 +08:00
parent 21330baac3
commit e9a2274016
5 changed files with 133 additions and 8 deletions

View File

@ -283,10 +283,22 @@ public class CooperationWeb extends ActionWeb {
msg = "保存小组管理员信息";
if (isOk && repositoryVerIds.size() > 0) {
// 创建权限信息
Set<String> toBeInsertPermIds = new HashSet<>();
List<CoeCooperationTeamPermModel> perms = new ArrayList<>();
for (int i = 0; i < repositoryVerIds.size(); i++) {
CoeCooperationTeamPermModel perm = new CoeCooperationTeamPermModel(UUIDGener.getUUID(), teamId, repositoryVerIds.getString(i));
perms.add(perm);
// 将当前数据的所有直接父级也加权限
PALRepositoryModel repositoryModel = PALRepositoryCache.getCache().get(repositoryVerIds.getString(i));
if (repositoryModel == null) continue;
String parentId = repositoryModel.getParentId();
recursionLookUp(parentId, toBeInsertPermIds);
}
for (String permId : toBeInsertPermIds) {
CoeCooperationTeamPermModel perm = new CoeCooperationTeamPermModel(UUIDGener.getUUID(), teamId, permId);
perms.add(perm);
}
isOk = api.createCooperationTeamPerms(perms);
msg = "保存小组数据权限信息";
@ -377,11 +389,24 @@ public class CooperationWeb extends ActionWeb {
if (repositoryVerIds.size() > 0) {
// 创建权限信息
Set<String> toBeInsertPermIds = new HashSet<>();
List<CoeCooperationTeamPermModel> perms = new ArrayList<>();
for (int i = 0; i < repositoryVerIds.size(); i++) {
CoeCooperationTeamPermModel perm = new CoeCooperationTeamPermModel(UUIDGener.getUUID(), teamId, repositoryVerIds.getString(i));
perms.add(perm);
// 将当前数据的所有直接父级也加权限
PALRepositoryModel repositoryModel = PALRepositoryCache.getCache().get(repositoryVerIds.getString(i));
if (repositoryModel == null) continue;
String parentId = repositoryModel.getParentId();
recursionLookUp(parentId, toBeInsertPermIds);
}
for (String permId : toBeInsertPermIds) {
CoeCooperationTeamPermModel perm = new CoeCooperationTeamPermModel(UUIDGener.getUUID(), teamId, permId);
perms.add(perm);
}
isOk = api.createCooperationTeamPerms(perms);
msg = "更新小组数据权限信息";
@ -412,11 +437,22 @@ public class CooperationWeb extends ActionWeb {
* @param toBeInsertPermIds
*/
private void recursionLookUp(String targetId, Set<String> toBeInsertPermIds){
if (targetId.length() < 36) return;
if (targetId == null || targetId.isEmpty()) {
return;
}
toBeInsertPermIds.add(targetId);
PALRepositoryModel targetModel = PALRepositoryCache.getCache().get(targetId);
String parentId = targetModel.getParentId();
recursionLookUp(parentId, toBeInsertPermIds);
while (targetId.length() == 36){
PALRepositoryModel targetModel = PALRepositoryCache.getCache().get(targetId);
if (targetModel == null) {
break;
}
String parentId = targetModel.getParentId();
if (parentId == null || parentId.isEmpty()) {
break;
}
toBeInsertPermIds.add(parentId);
targetId = parentId;
}
}
/**

View File

@ -588,6 +588,39 @@ public class CoeCooperationAPIManager {
return true;
}
/**
* 向小组及其下的非隐藏角色的权限数据中添加数据
* @param teamId
* @param palVersionId
*/
public void addRepositoryToTeamAndRolePerm(String teamId, String palVersionId){
// 1向小组权限中添加数据
List<String> teamPermList = queryCooperationTeamPermVerIds(teamId);
// 获取现有数据权限判断是否已存在
if (!teamPermList.contains(palVersionId)) {
// 添加
CoeCooperationTeamPermModel teamPerm = new CoeCooperationTeamPermModel(UUIDGener.getUUID(), teamId, palVersionId);
new CoeCooperationTeamPermDao().insert(teamPerm);
}
// 2获取小组下非隐藏角色用户权限的角色
List<CoeCooperationRoleModel> coeCooperationRoleModels = queryCooperationRoleList(teamId);
for (CoeCooperationRoleModel roleModel : coeCooperationRoleModels) {
// 判断是否设定的默认全部权限
if (!CoeCooperationConst.PERM_ALL.equals(roleModel.getDataPerm())) {
// 获取现有角色数据权限判断是否已存在
List<String> rolePermList = new CoeCooperationRolePermDao().getRolePermListByRole(teamId, roleModel.getId());
if (!rolePermList.contains(palVersionId)){
CoeCooperationRolePermModel rolePerm = new CoeCooperationRolePermModel(UUIDGener.getUUID(), teamId, roleModel.getId(), palVersionId);
new CoeCooperationRolePermDao().insert(rolePerm);
}
}
}
//更新用户权限缓存
CooperationCache.updateTeamInfo(teamId);
}
/**
* 查询用户在指定小组中的角色
* @param teamId

View File

@ -4,6 +4,7 @@ import com.actionsoft.apps.AppPlatformConfig;
import com.actionsoft.apps.AppsConst;
import com.actionsoft.apps.coe.pal.cooperation.CoeCooperationAPIManager;
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.constant.CoeCooperationConst;
import com.actionsoft.apps.coe.pal.cooperation.model.CoeCooperationMemberModel;
import com.actionsoft.apps.coe.pal.cooperation.model.CoeCooperationTeamModel;
@ -8357,6 +8358,17 @@ public class CoeProcessLevelWeb extends ActionWeb {
CoeCooperationAPIManager.getInstance().addRepositoryToTeamAndRolePerm(_uc, teamId, model.getVersionId(), true, true);
}
// 新增的架构或者文件夹 自动加权 遍历所有小组 判断父级文件夹/架构是否在该小组下是否有权限
if (UtilString.isNotEmpty(parentId) && parentId.length() == 36){
List<TeamInfo> allTeamInfo = CoeCooperationAPIManager.getInstance().getAllTeamInfo();
allTeamInfo.parallelStream().forEach(teamInfo -> {
boolean isPerm = teamInfo.getVersionIds().stream().anyMatch(teamPermId -> teamPermId.equals(parentId));
if (isPerm){
CoeCooperationAPIManager.getInstance().addRepositoryToTeamAndRolePerm(teamInfo.getTeamId(), model.getVersionId());
}
});
}
// 操作行为日志记录
if (SDK.getAppAPI().getPropertyBooleanValue(CoEConstant.APP_ID, "IS_RECORD_OP_LOG", false)) {
CoEOpLogAPI.auditOkOp(_uc, CoEOpLogConst.MODULE_CATEGORY_REPOSITORY, CoEOpLogConst.OP_CREATE, CoEOpLogConst.INFO_REPOSITORY_CREATE);
@ -8454,6 +8466,17 @@ public class CoeProcessLevelWeb extends ActionWeb {
CoeCooperationAPIManager.getInstance().addRepositoryToTeamAndRolePerm(_uc, teamId, model.getVersionId(), true, true);
}
// 新增的架构或者文件夹 自动加权 遍历所有小组 判断父级文件夹/架构是否在该小组下是否有权限
if (UtilString.isNotEmpty(parentId) && parentId.length() == 36){
List<TeamInfo> allTeamInfo = CoeCooperationAPIManager.getInstance().getAllTeamInfo();
allTeamInfo.parallelStream().forEach(teamInfo -> {
boolean isPerm = teamInfo.getVersionIds().stream().anyMatch(teamPermId -> teamPermId.equals(parentId));
if (isPerm){
CoeCooperationAPIManager.getInstance().addRepositoryToTeamAndRolePerm(teamInfo.getTeamId(), model.getVersionId());
}
});
}
ro.put("id", id);
// 操作行为日志记录
if (SDK.getAppAPI().getPropertyBooleanValue(CoEConstant.APP_ID, "IS_RECORD_OP_LOG", false)) {
@ -8600,6 +8623,17 @@ public class CoeProcessLevelWeb extends ActionWeb {
CoeCooperationAPIManager.getInstance().addRepositoryToTeamAndRolePerm(_uc, teamId, model.getVersionId(), true, true);
}
// 新增的架构或者文件夹 自动加权 遍历所有小组 判断父级文件夹/架构是否在该小组下是否有权限
if (UtilString.isNotEmpty(parentId) && parentId.length() == 36){
List<TeamInfo> allTeamInfo = CoeCooperationAPIManager.getInstance().getAllTeamInfo();
allTeamInfo.parallelStream().forEach(teamInfo -> {
boolean isPerm = teamInfo.getVersionIds().stream().anyMatch(teamPermId -> teamPermId.equals(parentId));
if (isPerm){
CoeCooperationAPIManager.getInstance().addRepositoryToTeamAndRolePerm(teamInfo.getTeamId(), model.getVersionId());
}
});
}
ro.put("id", id);
// 操作行为日志记录
if (SDK.getAppAPI().getPropertyBooleanValue(CoEConstant.APP_ID, "IS_RECORD_OP_LOG", false)) {
@ -11001,6 +11035,17 @@ public String deleteReply(String replyid, String messageid) {
CoEOpLogAPI.auditOkOp(_uc, CoEOpLogConst.MODULE_CATEGORY_REPOSITORY, CoEOpLogConst.OP_UPDATE, CoEOpLogConst.INFO_REPOSITORY_MOVE_UPDATE);
}
// 移动的文件/文件夹/架构 只要有一个在当前小组数据权限中 目标文件/文件夹/架构及所有直接父级都放入小组权限中
List<TeamInfo> allTeamInfo = CoeCooperationAPIManager.getInstance().getAllTeamInfo();
allTeamInfo.parallelStream().forEach(teamInfo -> {
boolean isPerm = teamInfo.getVersionIds().stream().anyMatch(verId -> sourceList.stream().anyMatch(palRepositoryModel -> palRepositoryModel.getVersionId().equals(verId)));
if (isPerm){
Set<String> toBeInsertPermIds = new HashSet<>();
recursionLookUp(targetId, toBeInsertPermIds);
toBeInsertPermIds.forEach(permId -> CoeCooperationAPIManager.getInstance().addRepositoryToTeamAndRolePerm(teamInfo.getTeamId(), permId));
}
});
/**
* by bzp
*/
@ -11015,11 +11060,22 @@ public String deleteReply(String replyid, String messageid) {
* @param toBeInsertPermIds
*/
private void recursionLookUp(String targetId, Set<String> toBeInsertPermIds){
if (targetId.length() < 36) return;
if (targetId == null || targetId.isEmpty()) {
return;
}
toBeInsertPermIds.add(targetId);
PALRepositoryModel targetModel = PALRepositoryCache.getCache().get(targetId);
String parentId = targetModel.getParentId();
recursionLookUp(parentId, toBeInsertPermIds);
while (targetId.length() == 36){
PALRepositoryModel targetModel = PALRepositoryCache.getCache().get(targetId);
if (targetModel == null) {
break;
}
String parentId = targetModel.getParentId();
if (parentId == null || parentId.isEmpty()) {
break;
}
toBeInsertPermIds.add(parentId);
targetId = parentId;
}
}
/**