diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOrganizationMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOrganizationMapper.java index 6607777dfd..6d5209ad8a 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOrganizationMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOrganizationMapper.java @@ -4,5 +4,5 @@ import org.apache.ibatis.annotations.Param; public interface ExtOrganizationMapper { - int checkOrgRole(@Param("orgId") String orgId,@Param("userId") String userId,@Param("roleId") String roleId); + int checkSourceRole(@Param("sourceId") String sourceId,@Param("userId") String userId,@Param("roleId") String roleId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOrganizationMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOrganizationMapper.xml index ca1bf126b4..5dafb7ee75 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOrganizationMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtOrganizationMapper.xml @@ -2,11 +2,11 @@ - select count(id) from user_role ur where ur.user_id = #{userId} - and ur.source_id = #{orgId} + and ur.source_id = #{sourceId} and ur.role_id = #{roleId} 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 26ed6ec2de..4bc8eb87cc 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 @@ -22,6 +22,8 @@ public interface ExtUserRoleMapper { List getOrganizationMemberRoles(@Param("orgId") String orgId, @Param("userId") String userId); + List getWorkspaceMemberRoles(@Param("workspaceId") String workspaceId, @Param("userId") String userId); + List getBesideOrgMemberList(@Param("orgId") String orgId); 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 ef80fdc4a0..80606210b0 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 @@ -38,8 +38,8 @@ + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index e4bec90aab..8ba5bbcd2d 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -140,6 +140,14 @@ public class UserController { return PageUtils.setPageInfo(page, userService.getOrgMemberList(request)); } + /** + * 组织成员列表不分页 + */ + @PostMapping("/orgmember/list/all") + public List getOrgMemberList(@RequestBody QueryOrgMemberRequest request) { + return userService.getOrgMemberList(request); + } + /** * 查询组织成员列表 带角色信息 */ diff --git a/backend/src/main/java/io/metersphere/controller/UserRoleController.java b/backend/src/main/java/io/metersphere/controller/UserRoleController.java index ae0799abc5..a26d75eb4a 100644 --- a/backend/src/main/java/io/metersphere/controller/UserRoleController.java +++ b/backend/src/main/java/io/metersphere/controller/UserRoleController.java @@ -16,8 +16,13 @@ public class UserRoleController { @Resource private UserRoleService userRoleService; - @GetMapping("/list/{orgId}/{userId}") + @GetMapping("/list/org/{orgId}/{userId}") public List getOrganizationMemberRoles(@PathVariable String orgId, @PathVariable String userId) { return userRoleService.getOrganizationMemberRoles(orgId, userId); } + + @GetMapping("/list/ws/{workspaceId}/{userId}") + public List workspaceId(@PathVariable String workspaceId, @PathVariable String userId) { + return userRoleService.getWorkspaceMemberRoles(workspaceId, userId); + } } diff --git a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java index f2cb3287e0..2fded241cb 100644 --- a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java +++ b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java @@ -7,7 +7,9 @@ import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.controller.request.WorkspaceRequest; +import io.metersphere.dto.OrganizationMemberDTO; import io.metersphere.dto.WorkspaceDTO; +import io.metersphere.dto.WorkspaceMemberDTO; import io.metersphere.service.WorkspaceService; import io.metersphere.user.SessionUtils; import org.apache.shiro.authz.annotation.RequiresRoles; @@ -67,4 +69,9 @@ public class WorkspaceController { String currentOrganizationId = SessionUtils.getCurrentOrganizationId(); return workspaceService.getWorkspaceListByOrgIdAndUserId(currentOrganizationId); } + + @PostMapping("/member/update") + public void updateOrgMember(@RequestBody WorkspaceMemberDTO memberDTO) { + workspaceService.updateWorkspaceMember(memberDTO); + } } 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 index ce84c1a9ad..40513843de 100644 --- a/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java @@ -5,8 +5,16 @@ import java.util.List; public class AddMemberRequest { private String workspaceId; - private List userIds; + private List roleIds; + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } public String getWorkspaceId() { return workspaceId; 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 index c951665b77..0795c9b98a 100644 --- a/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java @@ -1,11 +1,9 @@ package io.metersphere.controller.request.member; -import io.metersphere.commons.constants.RoleConstants; public class QueryMemberRequest { private String name; private String workspaceId; - private String roleId = RoleConstants.TEST_MANAGER; public String getName() { return name; @@ -15,14 +13,6 @@ public class QueryMemberRequest { this.name = name; } - public String getRoleId() { - return roleId; - } - - public void setRoleId(String roleId) { - this.roleId = roleId; - } - public String getWorkspaceId() { return workspaceId; } diff --git a/backend/src/main/java/io/metersphere/dto/OrganizationMemberDTO.java b/backend/src/main/java/io/metersphere/dto/OrganizationMemberDTO.java index 7c65f98b95..479919e9f6 100644 --- a/backend/src/main/java/io/metersphere/dto/OrganizationMemberDTO.java +++ b/backend/src/main/java/io/metersphere/dto/OrganizationMemberDTO.java @@ -1,7 +1,5 @@ package io.metersphere.dto; -import io.metersphere.base.domain.Role; - import java.util.ArrayList; import java.util.List; diff --git a/backend/src/main/java/io/metersphere/dto/WorkspaceMemberDTO.java b/backend/src/main/java/io/metersphere/dto/WorkspaceMemberDTO.java new file mode 100644 index 0000000000..d21e3b196f --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/WorkspaceMemberDTO.java @@ -0,0 +1,98 @@ +package io.metersphere.dto; + +import java.util.ArrayList; +import java.util.List; + +public class WorkspaceMemberDTO { + + private String id; + private String name; + private String email; + private String phone; + private String status; + private Long createTime; + private Long updateTime; + private String language; + private String workspaceId; + private List roleIds = new ArrayList<>(); + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public Long getCreateTime() { + return createTime; + } + + public void setCreateTime(Long createTime) { + this.createTime = createTime; + } + + public Long getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Long updateTime) { + this.updateTime = updateTime; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getWorkspaceId() { + return workspaceId; + } + + public void setWorkspaceId(String workspaceId) { + this.workspaceId = workspaceId; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } +} diff --git a/backend/src/main/java/io/metersphere/service/OrganizationService.java b/backend/src/main/java/io/metersphere/service/OrganizationService.java index 17ef8c689e..c82c51fdbb 100644 --- a/backend/src/main/java/io/metersphere/service/OrganizationService.java +++ b/backend/src/main/java/io/metersphere/service/OrganizationService.java @@ -86,7 +86,7 @@ public class OrganizationService { // 更新用户时添加了角色 if (roles.size() > allRoleIds.size()) { for (int i = 0; i < roles.size(); i++) { - if (checkOrgRole(orgId, userId, roles.get(i)) == 0) { + if (checkSourceRole(orgId, userId, roles.get(i)) == 0) { UserRole userRole = new UserRole(); userRole.setId(UUID.randomUUID().toString()); userRole.setUserId(userId); @@ -107,8 +107,7 @@ public class OrganizationService { } } - // 检查组织成员是否有某一角色 - public Integer checkOrgRole(String orgId, String userId, String roleId) { - return extOrganizationMapper.checkOrgRole(orgId, userId, roleId); + public Integer checkSourceRole(String orgId, String userId, String roleId) { + return extOrganizationMapper.checkSourceRole(orgId, userId, roleId); } } diff --git a/backend/src/main/java/io/metersphere/service/UserRoleService.java b/backend/src/main/java/io/metersphere/service/UserRoleService.java index 6e347790a4..68cb9aaad0 100644 --- a/backend/src/main/java/io/metersphere/service/UserRoleService.java +++ b/backend/src/main/java/io/metersphere/service/UserRoleService.java @@ -19,4 +19,8 @@ public class UserRoleService { return extUserRoleMapper.getOrganizationMemberRoles(orgId, userId); } + public List getWorkspaceMemberRoles(String workspaceId, String userId) { + return extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId); + } + } diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 856443e7ec..192f17f61d 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -251,21 +251,23 @@ public class UserService { public void addMember(AddMemberRequest request) { if (!CollectionUtils.isEmpty(request.getUserIds())) { for (String userId : request.getUserIds()) { - UserRole userRole = new UserRole(); - userRole.setRoleId(RoleConstants.TEST_MANAGER); - userRole.setSourceId(request.getWorkspaceId()); - userRole.setUserId(userId); - userRole.setId(UUID.randomUUID().toString()); - userRole.setUpdateTime(System.currentTimeMillis()); - userRole.setCreateTime(System.currentTimeMillis()); - userRoleMapper.insertSelective(userRole); + for (String roleId : request.getRoleIds()) { + UserRole userRole = new UserRole(); + userRole.setRoleId(roleId); + 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.TEST_MANAGER) + example.createCriteria().andRoleIdLike("%test%") .andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId); userRoleMapper.deleteByExample(example); } diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 1ea50bde38..5a8a5b8f2f 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -1,8 +1,10 @@ package io.metersphere.service; import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.UserMapper; import io.metersphere.base.mapper.UserRoleMapper; import io.metersphere.base.mapper.WorkspaceMapper; +import io.metersphere.base.mapper.ext.ExtOrganizationMapper; import io.metersphere.base.mapper.ext.ExtUserRoleMapper; import io.metersphere.base.mapper.ext.ExtWorkspaceMapper; import io.metersphere.commons.constants.RoleConstants; @@ -10,9 +12,11 @@ import io.metersphere.commons.exception.MSException; import io.metersphere.controller.request.WorkspaceRequest; import io.metersphere.dto.UserRoleHelpDTO; import io.metersphere.dto.WorkspaceDTO; +import io.metersphere.dto.WorkspaceMemberDTO; import io.metersphere.user.SessionUser; import io.metersphere.user.SessionUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,6 +37,10 @@ public class WorkspaceService { private ExtUserRoleMapper extUserRoleMapper; @Resource private UserRoleMapper userRoleMapper; + @Resource + private UserMapper userMapper; + @Resource + private ExtOrganizationMapper extOrganizationMapper; public Workspace saveWorkspace(Workspace workspace) { if (StringUtils.isBlank(workspace.getName())) { @@ -130,4 +138,43 @@ public class WorkspaceService { return resultWorkspaceList; } + public void updateWorkspaceMember(WorkspaceMemberDTO memberDTO) { + User user = new User(); + BeanUtils.copyProperties(memberDTO, user); + userMapper.updateByPrimaryKeySelective(user); + // + String workspaceId = memberDTO.getWorkspaceId(); + String userId = user.getId(); + // 已有角色 + List memberRoles = extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId); + // 修改后的角色 + List roles = memberDTO.getRoleIds(); + List allRoleIds = memberRoles.stream().map(Role::getId).collect(Collectors.toList()); + // 更新用户时添加了角色 + if (roles.size() > allRoleIds.size()) { + for (int i = 0; i < roles.size(); i++) { + if (checkSourceRole(workspaceId, userId, roles.get(i)) == 0) { + UserRole userRole = new UserRole(); + userRole.setId(UUID.randomUUID().toString()); + userRole.setUserId(userId); + userRole.setRoleId(roles.get(i)); + userRole.setSourceId(workspaceId); + userRole.setCreateTime(System.currentTimeMillis()); + userRole.setUpdateTime(System.currentTimeMillis()); + userRoleMapper.insertSelective(userRole); + } + } + } else if (roles.size() < allRoleIds.size()){ + allRoleIds.removeAll(roles); + UserRoleExample userRoleExample = new UserRoleExample(); + userRoleExample.createCriteria().andUserIdEqualTo(userId) + .andSourceIdEqualTo(workspaceId) + .andRoleIdIn(allRoleIds); + userRoleMapper.deleteByExample(userRoleExample); + } + } + + public Integer checkSourceRole(String orgId, String userId, String roleId) { + return extOrganizationMapper.checkSourceRole(orgId, userId, roleId); + } } diff --git a/frontend/src/performance/components/settings/Member.vue b/frontend/src/performance/components/settings/Member.vue index 0c41823e9e..16cdb25d16 100644 --- a/frontend/src/performance/components/settings/Member.vue +++ b/frontend/src/performance/components/settings/Member.vue @@ -1,5 +1,5 @@ @@ -71,16 +122,20 @@ components: {MsCreateBox}, data() { return { - loading: false, + result: {}, form: {}, - btnTips: "添加成员", + btnTips: "添加工作空间成员", createVisible: false, + updateVisible: false, queryPath: "/user/member/list", condition: "", tableData: [], rules: { userIds: [ - {required: true, message: '请选择成员', trigger: ['blur', 'change']} + {required: true, message: '请选择成员', trigger: ['blur']} + ], + roleIds: [ + {required: true, message: '请选择角色', trigger: ['blur']} ] }, multipleSelection: [], @@ -107,15 +162,17 @@ workspaceId: this.currentUser().lastWorkspaceId }; - this.$post(this.buildPagePath(this.queryPath), param).then(response => { - if (response.data.success) { - let data = response.data.data; - this.total = data.itemCount; - this.tableData = data.listObject; - } else { - this.$message.error(response.message); + this.result = this.$post(this.buildPagePath(this.queryPath), param, response => { + let data = response.data; + this.tableData = data.listObject; + let url = "/userrole/list/ws/" + this.currentUser().lastWorkspaceId; + for (let i = 0; i < this.tableData.length; i++) { + this.$get(url + "/" + this.tableData[i].id, response => { + let roles = response.data; + this.$set(this.tableData[i], "roles", roles); + }) } - this.loading = false; + this.total = data.itemCount; }) }, @@ -131,6 +188,10 @@ handleCurrentChange(current) { this.currentPage = current; }, + closeFunc() { + this.form = {}; + this.initTableData(); + }, del(row) { this.$confirm('移除该成员, 是否继续?', '提示', { confirmButtonText: '确定', @@ -154,41 +215,69 @@ }); }); }, - create() { - this.loading = true; - this.$get('/user/list').then(response => { - if (response.data.success) { - this.createVisible = true; - this.form = {userList: response.data.data}; - } else { - this.$message.error(response.message); - } - this.loading = false; - }).catch(() => { - this.loading = false; + edit(row) { + this.updateVisible = true; + this.form = row; + let roleIds = this.form.roles.map(r => r.id); + this.result = this.$get('/role/list/test', response => { + this.$set(this.form, "allroles", response.data); + }) + // 编辑使填充角色信息 + this.$set(this.form, 'roleIds', roleIds); + }, + updateWorkspaceMember() { + let param = { + id: this.form.id, + name: this.form.name, + email: this.form.email, + phone: this.form.phone, + roleIds: this.form.roleIds, + workspaceId: this.currentUser().lastWorkspaceId + } + this.result = this.$post("/workspace/member/update", param,() => { this.$message({ - type: 'error', - message: '获取用户列表失败' + type: 'success', + message: '修改成功!' }); + this.updateVisible = false; + this.initTableData(); }); }, + create() { + this.form = {}; + let param = { + name: this.condition, + organizationId: this.currentUser().lastOrganizationId + }; + let wsId = this.currentUser().lastWorkspaceId; + if (typeof wsId == "undefined" || wsId == null || wsId == "") { + this.$message({ + message:'请先选择工作空间!', + type: 'warning' + }); + return false; + } + this.$post('/user/orgmember/list/all', param,response => { + this.createVisible = true; + this.$set(this.form, "userList", response.data); + }) + this.result = this.$get('/role/list/test', response => { + this.$set(this.form, "roles", response.data); + }) + }, submitForm(formName) { this.loading = true; this.$refs[formName].validate((valid) => { if (valid) { let param = { userIds: this.form.userIds, + roleIds: this.form.roleIds, workspaceId: this.currentUser().lastWorkspaceId }; - this.$post("user/member/add", param).then(() => { + this.$post("user/member/add", param, () => { this.initTableData(); this.createVisible = false; - this.loading = false; - }).catch(() => { - this.loading = false; }) - } else { - return false; } }); } @@ -214,4 +303,15 @@ .select-width { width: 100%; } + + .workspace-member-name { + float: left; + } + + .workspace-member-email { + float: right; + color: #8492a6; + font-size: 13px; + } + diff --git a/frontend/src/performance/components/settings/OrganizationMember.vue b/frontend/src/performance/components/settings/OrganizationMember.vue index c55757a5c4..42a8d29058 100644 --- a/frontend/src/performance/components/settings/OrganizationMember.vue +++ b/frontend/src/performance/components/settings/OrganizationMember.vue @@ -22,7 +22,6 @@ {{ role.name }} -