diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserRoleMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserRoleMapper.java index 3cbe99f3b0..10e360fecb 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserRoleMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserRoleMapper.java @@ -1,5 +1,7 @@ package io.metersphere.base.mapper.ext; +import io.metersphere.base.domain.User; +import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.dto.UserRoleHelpDTO; import org.apache.ibatis.annotations.Param; @@ -8,4 +10,6 @@ import java.util.List; public interface ExtUserRoleMapper { List getUserRoleHelpList(@Param("userId") String userId); + + List getMemberList(@Param("member") QueryMemberRequest request); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserRoleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserRoleMapper.xml index ed798731f7..5b50199586 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserRoleMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserRoleMapper.xml @@ -27,4 +27,9 @@ WHERE user_role.user_id = #{userId} + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/commons/constants/RoleConstants.java b/backend/src/main/java/io/metersphere/commons/constants/RoleConstants.java new file mode 100644 index 0000000000..e0d256f49c --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/constants/RoleConstants.java @@ -0,0 +1,14 @@ +package io.metersphere.commons.constants; + +public enum RoleConstants { + ADMIN("admin"), ORGADMIN("org_admin"), TESTUSER("test_user"), TESTVIEWER("test_viewer"), TESTMANAGER("test_manager"); + private String value; + + RoleConstants(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index 5eeed703bb..4865b2edd8 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -1,12 +1,19 @@ package io.metersphere.controller; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.Role; import io.metersphere.base.domain.User; +import io.metersphere.commons.utils.PageUtils; +import io.metersphere.commons.utils.Pager; +import io.metersphere.controller.request.member.AddMemberRequest; +import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserRoleDTO; import io.metersphere.service.UserService; import io.metersphere.user.SessionUtils; import org.springframework.web.bind.annotation.*; + import javax.annotation.Resource; import java.util.List; @@ -23,13 +30,19 @@ public class UserController { } @GetMapping("/list") - public List getUserList() { return userService.getUserList(); } + public List getUserList() { + return userService.getUserList(); + } @GetMapping("/delete/{userId}") - public void deleteUser(@PathVariable(value = "userId") String userId) { userService.deleteUser(userId); } + public void deleteUser(@PathVariable(value = "userId") String userId) { + userService.deleteUser(userId); + } @PostMapping("/update") - public void updateUser(@RequestBody User user) { userService.updateUser(user); } + public void updateUser(@RequestBody User user) { + userService.updateUser(user); + } @GetMapping("/role/list/{userId}") public List getUserRolesList(@PathVariable(value = "userId") String userId) { @@ -42,7 +55,7 @@ public class UserController { } @PostMapping("/switch/source/{sourceId}") - public void switchUserRole(@PathVariable (value = "sourceId") String sourceId) { + public void switchUserRole(@PathVariable(value = "sourceId") String sourceId) { UserDTO user = SessionUtils.getUser(); userService.switchUserRole(user, sourceId); } @@ -51,4 +64,30 @@ public class UserController { public User getUserInfo(@PathVariable(value = "userId") String userId) { return userService.getUserInfo(userId); } + + /** + * 获取成员用户 + */ + @PostMapping("/member/list/{goPage}/{pageSize}") + public Pager> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return PageUtils.setPageInfo(page, userService.getMemberList(request)); + } + + /** + * 添加成员 + */ + @PostMapping("/member/add") + public void addMember(@RequestBody AddMemberRequest request) { + userService.addMember(request); + } + + /** + * 删除成员 + */ + @GetMapping("/member/delete/{workspaceId}/{userId}") + public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) { + userService.deleteMember(workspaceId, userId); + } + } diff --git a/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java b/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java new file mode 100644 index 0000000000..ce84c1a9ad --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java @@ -0,0 +1,26 @@ +package io.metersphere.controller.request.member; + +import java.util.List; + +public class AddMemberRequest { + + private String workspaceId; + + private List userIds; + + public String getWorkspaceId() { + return workspaceId; + } + + public void setWorkspaceId(String workspaceId) { + this.workspaceId = workspaceId; + } + + public List getUserIds() { + return userIds; + } + + public void setUserIds(List userIds) { + this.userIds = userIds; + } +} diff --git a/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java b/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java new file mode 100644 index 0000000000..fc1afed366 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java @@ -0,0 +1,16 @@ +package io.metersphere.controller.request.member; + +import io.metersphere.commons.constants.RoleConstants; + +public class QueryMemberRequest { + private String workspaceId; + private String roleId = RoleConstants.TESTMANAGER.getValue(); + + public String getWorkspaceId() { + return workspaceId; + } + + public void setWorkspaceId(String workspaceId) { + this.workspaceId = workspaceId; + } +} diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 66b84ad20d..a95219dabc 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -6,9 +6,11 @@ import io.metersphere.base.mapper.RoleMapper; import io.metersphere.base.mapper.UserMapper; import io.metersphere.base.mapper.UserRoleMapper; import io.metersphere.base.mapper.ext.ExtUserRoleMapper; +import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.exception.MSException; +import io.metersphere.controller.request.member.AddMemberRequest; +import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.dto.UserDTO; -import io.metersphere.dto.UserOperateDTO; import io.metersphere.dto.UserRoleDTO; import io.metersphere.dto.UserRoleHelpDTO; import org.apache.commons.lang3.StringUtils; @@ -223,4 +225,31 @@ public class UserService { public User getUserInfo(String userId) { return userMapper.selectByPrimaryKey(userId); } + + public List getMemberList(QueryMemberRequest request) { + return extUserRoleMapper.getMemberList(request); + } + + @Transactional(rollbackFor = Exception.class) + public void addMember(AddMemberRequest request) { + if (!CollectionUtils.isEmpty(request.getUserIds())) { + for (String userId : request.getUserIds()) { + UserRole userRole = new UserRole(); + userRole.setRoleId(RoleConstants.TESTMANAGER.getValue()); + userRole.setSourceId(request.getWorkspaceId()); + userRole.setUserId(userId); + userRole.setId(UUID.randomUUID().toString()); + userRole.setUpdateTime(System.currentTimeMillis()); + userRole.setCreateTime(System.currentTimeMillis()); + userRoleMapper.insertSelective(userRole); + } + } + } + + public void deleteMember(String workspaceId, String userId) { + UserRoleExample example = new UserRoleExample(); + example.createCriteria().andRoleIdEqualTo(RoleConstants.TESTMANAGER.getValue()) + .andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId); + userRoleMapper.deleteByExample(example); + } }