fix(系统设置): 用户仅有项目权限时不占工作空间配额

--bug=1015604 --user=李玉号 【系统设置】用户仅有项目权限时不占工作空间配额
https://www.tapd.cn/55049933/s/1218365
This commit is contained in:
shiziyuan9527 2022-08-03 14:30:59 +08:00 committed by f2c-ci-robot[bot]
parent cad3d298cc
commit 7cb8908a31
3 changed files with 14 additions and 13 deletions

View File

@ -443,7 +443,7 @@ public class GroupService {
if (user == null) {
continue;
}
checkQuota(quotaService, group.getType(), sourceIds, 1);
checkQuota(quotaService, group.getType(), sourceIds, Collections.singletonList(userId));
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
UserGroupMapper mapper = sqlSession.getMapper(UserGroupMapper.class);
UserGroupExample userGroupExample = new UserGroupExample();
@ -465,9 +465,9 @@ public class GroupService {
}
}
private void checkQuota(QuotaService quotaService, String type, List<String> sourceIds, int size) {
private void checkQuota(QuotaService quotaService, String type, List<String> sourceIds, List<String> userIds) {
if (quotaService != null) {
Map<String, Integer> addMemberMap = sourceIds.stream().collect(Collectors.toMap( id -> id, id -> size));
Map<String, List<String>> addMemberMap = sourceIds.stream().collect(Collectors.toMap( id -> id, id -> userIds));
quotaService.checkMemberCount(addMemberMap, type);
}
}

View File

@ -6,6 +6,7 @@ import io.metersphere.base.domain.Quota;
import io.metersphere.performance.request.TestPlanRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -62,10 +63,10 @@ public interface QuotaService {
/**
* 检查向某资源添加人员时是否超额
* @param map 资源ID:添加人数
* @param map 资源ID:添加用户ID列表
* @param type 检查类型 PROJECT/WORKSPACE
*/
void checkMemberCount(Map<String, Integer> map, String type);
void checkMemberCount(Map<String, List<String>> map, String type);
/**
* 更新VumUsed配额

View File

@ -140,7 +140,7 @@ public class UserService {
} else {
List<String> ids = (List<String>) map.get("ids");
Group group = groupMapper.selectByPrimaryKey(groupId);
checkQuota(quotaService, group.getType(), ids, 1);
checkQuota(quotaService, group.getType(), ids, Collections.singletonList(userId));
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
UserGroupMapper mapper = sqlSession.getMapper(UserGroupMapper.class);
for (String id : ids) {
@ -848,7 +848,7 @@ public class UserService {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
List<String> worksapceIds = request.getBatchProcessValue();
if (CollectionUtils.isNotEmpty(userIds)) {
checkQuota(quotaService, "WORKSPACE", worksapceIds, userIds.size());
checkQuota(quotaService, "WORKSPACE", worksapceIds, userIds);
}
for (String userId : userIds) {
UserGroupExample userGroupExample = new UserGroupExample();
@ -920,7 +920,7 @@ public class UserService {
List<String> sourceIds = userGroups.stream().map(UserGroup::getSourceId).collect(Collectors.toList());
List<String> list = sourceMap.get(group);
list.removeAll(sourceIds);
checkQuota(quotaService, gp.getType(), list, 1);
checkQuota(quotaService, gp.getType(), list, Collections.singletonList(userId));
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
UserGroupMapper mapper = sqlSession.getMapper(UserGroupMapper.class);
for (String sourceId : list) {
@ -964,7 +964,7 @@ public class UserService {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
List<String> projectIds = request.getBatchProcessValue();
if (CollectionUtils.isNotEmpty(userIds)) {
checkQuota(quotaService, "PROJECT", projectIds, userIds.size());
checkQuota(quotaService, "PROJECT", projectIds, userIds);
}
for (String userId : userIds) {
UserGroupExample userGroupExample = new UserGroupExample();
@ -1229,13 +1229,13 @@ public class UserService {
private void checkQuotaOfMemberSize(String type, String sourceId, List<String> userIds) {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
if (CollectionUtils.isNotEmpty(userIds)) {
checkQuota(quotaService, type, Collections.singletonList(sourceId), userIds.size());
checkQuota(quotaService, type, Collections.singletonList(sourceId), userIds);
}
}
private void checkQuota(QuotaService quotaService, String type, List<String> sourceIds, int size) {
private void checkQuota(QuotaService quotaService, String type, List<String> sourceIds, List<String> userIds) {
if (quotaService != null) {
Map<String, Integer> addMemberMap = sourceIds.stream().collect(Collectors.toMap(id -> id, id -> size));
Map<String, List<String>> addMemberMap = sourceIds.stream().collect(Collectors.toMap(id -> id, id -> userIds));
quotaService.checkMemberCount(addMemberMap, type);
}
}
@ -1346,7 +1346,7 @@ public class UserService {
} else {
List<String> ids = (List<String>) map.get("ids");
Group group = groupMapper.selectByPrimaryKey(groupId);
checkQuota(quotaService, group.getType(), ids, 1);
checkQuota(quotaService, group.getType(), ids, Collections.singletonList(userId));
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
UserGroupMapper mapper = sqlSession.getMapper(UserGroupMapper.class);
for (String id : ids) {