From e23883c4faf7c71890dc13edbd3a66794d0b339a Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 3 Aug 2022 14:30:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BB=85=E6=9C=89=E9=A1=B9=E7=9B=AE=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=97=B6=E4=B8=8D=E5=8D=A0=E5=B7=A5=E4=BD=9C=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E9=85=8D=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1015604 --user=李玉号 【系统设置】用户仅有项目权限时不占工作空间配额 https://www.tapd.cn/55049933/s/1218365 --- .../io/metersphere/service/GroupService.java | 6 +++--- .../io/metersphere/service/QuotaService.java | 5 +++-- .../java/io/metersphere/service/UserService.java | 16 ++++++++-------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/GroupService.java b/backend/src/main/java/io/metersphere/service/GroupService.java index a18d8a7d6f..7fa4c8da48 100644 --- a/backend/src/main/java/io/metersphere/service/GroupService.java +++ b/backend/src/main/java/io/metersphere/service/GroupService.java @@ -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 sourceIds, int size) { + private void checkQuota(QuotaService quotaService, String type, List sourceIds, List userIds) { if (quotaService != null) { - Map addMemberMap = sourceIds.stream().collect(Collectors.toMap( id -> id, id -> size)); + Map> addMemberMap = sourceIds.stream().collect(Collectors.toMap( id -> id, id -> userIds)); quotaService.checkMemberCount(addMemberMap, type); } } diff --git a/backend/src/main/java/io/metersphere/service/QuotaService.java b/backend/src/main/java/io/metersphere/service/QuotaService.java index 1de2e9bc21..c500035007 100644 --- a/backend/src/main/java/io/metersphere/service/QuotaService.java +++ b/backend/src/main/java/io/metersphere/service/QuotaService.java @@ -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 map, String type); + void checkMemberCount(Map> map, String type); /** * 更新VumUsed配额 diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 4043357c76..c4030fcee9 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -140,7 +140,7 @@ public class UserService { } else { List ids = (List) 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 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 sourceIds = userGroups.stream().map(UserGroup::getSourceId).collect(Collectors.toList()); List 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 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 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 sourceIds, int size) { + private void checkQuota(QuotaService quotaService, String type, List sourceIds, List userIds) { if (quotaService != null) { - Map addMemberMap = sourceIds.stream().collect(Collectors.toMap(id -> id, id -> size)); + Map> addMemberMap = sourceIds.stream().collect(Collectors.toMap(id -> id, id -> userIds)); quotaService.checkMemberCount(addMemberMap, type); } } @@ -1346,7 +1346,7 @@ public class UserService { } else { List ids = (List) 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) {