diff --git a/backend/src/main/java/io/metersphere/commons/constants/RoleConstants.java b/backend/src/main/java/io/metersphere/commons/constants/RoleConstants.java index 19d254b23c..abd8a70f22 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/RoleConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/RoleConstants.java @@ -3,6 +3,8 @@ package io.metersphere.commons.constants; public class RoleConstants { public final static String ADMIN = "admin"; public final static String ORG_ADMIN = "org_admin"; + // 组织内其它角色 + public final static String ORG_OTHER = "org_other"; public final static String TEST_VIEWER = "test_viewer"; public final static String TEST_MANAGER = "test_manager"; public final static String TEST_USER = "test_user"; diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index 735d326dbe..07ea025080 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -8,6 +8,7 @@ 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.controller.request.organization.AddOrgMemberRequest; import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserRoleDTO; import io.metersphere.service.UserService; @@ -98,4 +99,20 @@ public class UserController { userService.deleteMember(workspaceId, userId); } + /** + * 添加组织成员 + */ + @PostMapping("/orgmember/add") + public void addOrganizationMember(@RequestBody AddOrgMemberRequest request) { + userService.addOrganizationMember(request); + } + + /** + * 删除组织成员 + */ + @GetMapping("/orgmember/delete/{organizationId}/{userId}") + public void delOrganizationMember(@PathVariable String organizationId, @PathVariable String userId) { + userService.delOrganizationMember(organizationId, userId); + } + } diff --git a/backend/src/main/java/io/metersphere/controller/request/organization/AddOrgMemberRequest.java b/backend/src/main/java/io/metersphere/controller/request/organization/AddOrgMemberRequest.java new file mode 100644 index 0000000000..5cc36523f2 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/organization/AddOrgMemberRequest.java @@ -0,0 +1,25 @@ +package io.metersphere.controller.request.organization; + +import java.util.List; + +public class AddOrgMemberRequest { + + private String organizationId; + private List userIds; + + public String getOrganizationId() { + return organizationId; + } + + public void setOrganizationId(String organizationId) { + this.organizationId = organizationId; + } + + public List getUserIds() { + return userIds; + } + + public void setUserIds(List userIds) { + this.userIds = userIds; + } +} diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 51e1637675..66f7d24bcb 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -10,6 +10,7 @@ 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.controller.request.organization.AddOrgMemberRequest; import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserRoleDTO; import io.metersphere.dto.UserRoleHelpDTO; @@ -258,4 +259,26 @@ public class UserService { .andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId); userRoleMapper.deleteByExample(example); } + + public void addOrganizationMember(AddOrgMemberRequest request) { + if (!CollectionUtils.isEmpty(request.getUserIds())) { + for (String userId : request.getUserIds()) { + UserRole userRole = new UserRole(); + userRole.setId(UUID.randomUUID().toString()); + userRole.setRoleId(RoleConstants.ORG_OTHER); + userRole.setSourceId(request.getOrganizationId()); + userRole.setUserId(userId); + userRole.setUpdateTime(System.currentTimeMillis()); + userRole.setCreateTime(System.currentTimeMillis()); + userRoleMapper.insertSelective(userRole); + } + } + } + + public void delOrganizationMember(String organizationId, String userId) { + UserRoleExample userRoleExample = new UserRoleExample(); + userRoleExample.createCriteria().andRoleIdEqualTo(RoleConstants.ORG_OTHER) + .andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId); + userRoleMapper.deleteByExample(userRoleExample); + } }