diff --git a/backend/src/main/java/io/metersphere/controller/GroupController.java b/backend/src/main/java/io/metersphere/controller/GroupController.java index 1776071d81..828275ed85 100644 --- a/backend/src/main/java/io/metersphere/controller/GroupController.java +++ b/backend/src/main/java/io/metersphere/controller/GroupController.java @@ -1,18 +1,14 @@ package io.metersphere.controller; import io.metersphere.base.domain.Group; -import io.metersphere.base.domain.Role; -import io.metersphere.commons.constants.RoleConstants; +import io.metersphere.base.domain.Organization; import io.metersphere.commons.utils.Pager; import io.metersphere.controller.request.GroupRequest; import io.metersphere.controller.request.group.EditGroupRequest; import io.metersphere.dto.GroupDTO; import io.metersphere.dto.GroupPermissionDTO; import io.metersphere.service.GroupService; -import org.apache.shiro.authz.annotation.Logical; -import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; - import javax.annotation.Resource; import java.util.List; import java.util.Map; @@ -78,10 +74,12 @@ public class GroupController { } @GetMapping("/list/ws/{workspaceId}/{userId}") - @RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR) public List getWorkspaceMemberGroups(@PathVariable String workspaceId, @PathVariable String userId) { return groupService.getWorkspaceMemberGroups(workspaceId, userId); } - + @GetMapping("/org/{userId}") + public List getOrganization(@PathVariable String userId) { + return groupService.getOrganization(userId); + } } diff --git a/backend/src/main/java/io/metersphere/service/GroupService.java b/backend/src/main/java/io/metersphere/service/GroupService.java index fdf2b6800d..b83f64c3f6 100644 --- a/backend/src/main/java/io/metersphere/service/GroupService.java +++ b/backend/src/main/java/io/metersphere/service/GroupService.java @@ -5,11 +5,13 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.GroupMapper; +import io.metersphere.base.mapper.OrganizationMapper; import io.metersphere.base.mapper.UserGroupMapper; import io.metersphere.base.mapper.UserGroupPermissionMapper; import io.metersphere.base.mapper.ext.ExtGroupMapper; import io.metersphere.base.mapper.ext.ExtUserGroupMapper; import io.metersphere.commons.constants.UserGroupType; +import io.metersphere.commons.exception.MSException; import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.PageUtils; @@ -52,6 +54,8 @@ public class GroupService { private UserGroupMapper userGroupMapper; @Resource private OrganizationService organizationService; + @Resource + private OrganizationMapper organizationMapper; private static final Map> map = new HashMap>(4){{ put(UserGroupType.SYSTEM, Arrays.asList(UserGroupType.SYSTEM, UserGroupType.ORGANIZATION, UserGroupType.WORKSPACE, UserGroupType.PROJECT)); @@ -69,6 +73,7 @@ public class GroupService { public Group addGroup(EditGroupRequest request) { Group group = new Group(); + checkGroupExist(request); group.setId(UUID.randomUUID().toString()); group.setName(request.getName()); group.setCreator(SessionUtils.getUserId()); @@ -86,7 +91,23 @@ public class GroupService { return group; } + private void checkGroupExist(EditGroupRequest request) { + String name = request.getName(); + String id = request.getId(); + GroupExample groupExample = new GroupExample(); + GroupExample.Criteria criteria = groupExample.createCriteria(); + criteria.andNameEqualTo(name); + if (StringUtils.isNotBlank(id)) { + criteria.andIdNotEqualTo(id); + } + List groups = groupMapper.selectByExample(groupExample); + if (CollectionUtils.isNotEmpty(groups)) { + MSException.throwException("用户组名称已存在!"); + } + } + public void editGroup(EditGroupRequest request) { + checkGroupExist(request); Group group = new Group(); request.setScopeId(null); BeanUtils.copyBean(group, request); @@ -280,4 +301,28 @@ public class GroupService { return PageUtils.setPageInfo(page, groups); } + public List getOrganization(String userId) { + List list = new ArrayList<>(); + GroupExample groupExample = new GroupExample(); + groupExample.createCriteria().andTypeEqualTo(UserGroupType.ORGANIZATION); + List groups = groupMapper.selectByExample(groupExample); + List groupIds = groups.stream().map(Group::getId).collect(Collectors.toList()); + + if (CollectionUtils.isEmpty(groups)) { + return list; + } + UserGroupExample userGroupExample = new UserGroupExample(); + userGroupExample.createCriteria().andUserIdEqualTo(userId).andGroupIdIn(groupIds); + List userGroups = userGroupMapper.selectByExample(userGroupExample); + List orgIds = userGroups.stream().map(UserGroup::getSourceId).collect(Collectors.toList()); + + if (CollectionUtils.isEmpty(orgIds)) { + return list; + } + + OrganizationExample organizationExample = new OrganizationExample(); + organizationExample.createCriteria().andIdIn(orgIds); + list = organizationMapper.selectByExample(organizationExample); + return list; + } } diff --git a/frontend/src/business/components/settings/system/group/EditUserGroup.vue b/frontend/src/business/components/settings/system/group/EditUserGroup.vue index 3e55fd0256..3ab855114d 100644 --- a/frontend/src/business/components/settings/system/group/EditUserGroup.vue +++ b/frontend/src/business/components/settings/system/group/EditUserGroup.vue @@ -5,13 +5,13 @@ - + - - + + @@ -20,19 +20,16 @@ - - - + - + - - - - + + + @@ -44,6 +41,9 @@