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

--bug=1015604 --user=李玉号 【系统设置】用户仅有项目权限时不占工作空间配额
https://www.tapd.cn/55049933/s/1218365
This commit is contained in:
shiziyuan9527 2022-08-03 15:00:39 +08:00 committed by shiziyuan9527
parent 1f22fc0e78
commit 32a2c4f506
3 changed files with 15 additions and 14 deletions

View File

@ -430,7 +430,7 @@ public class GroupService {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
UserGroupMapper mapper = sqlSession.getMapper(UserGroupMapper.class);
checkQuota(quotaService, type, sourceIds, 1);
checkQuota(quotaService, type, sourceIds, Collections.singletonList(userId));
for (String sourceId : sourceIds) {
UserGroup userGroup = new UserGroup();
userGroup.setId(UUID.randomUUID().toString());
@ -448,9 +448,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

@ -143,7 +143,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) {
@ -165,9 +165,9 @@ public class UserService {
}
}
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);
}
}
@ -462,7 +462,7 @@ public class UserService {
if (!CollectionUtils.isEmpty(request.getUserIds())) {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
if (CollectionUtils.isNotEmpty(request.getUserIds())) {
checkQuota(quotaService, "WORKSPACE", Collections.singletonList(request.getWorkspaceId()), request.getUserIds().size());
checkQuota(quotaService, "WORKSPACE", Collections.singletonList(request.getWorkspaceId()), request.getUserIds());
}
for (String userId : request.getUserIds()) {
UserGroupExample userGroupExample = new UserGroupExample();
@ -881,7 +881,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();
@ -953,7 +953,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) {
@ -997,7 +997,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();
@ -1204,7 +1204,7 @@ public class UserService {
}
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
if (CollectionUtils.isNotEmpty(request.getUserIds())) {
checkQuota(quotaService, "PROJECT", Collections.singletonList(request.getProjectId()), request.getUserIds().size());
checkQuota(quotaService, "PROJECT", Collections.singletonList(request.getProjectId()), request.getUserIds());
}
for (String userId : request.getUserIds()) {
UserGroupExample userGroupExample = new UserGroupExample();
@ -1333,7 +1333,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) {