工作空间下成员信息可修改

This commit is contained in:
shiziyuan9527 2020-02-28 16:51:08 +08:00
parent f5a315ffcd
commit db8cd75665
13 changed files with 279 additions and 57 deletions

View File

@ -4,5 +4,5 @@ import org.apache.ibatis.annotations.Param;
public interface ExtOrganizationMapper { 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);
} }

View File

@ -2,11 +2,11 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtOrganizationMapper"> <mapper namespace="io.metersphere.base.mapper.ext.ExtOrganizationMapper">
<select id="checkOrgRole" resultType="Integer"> <select id="checkSourceRole" resultType="Integer">
select count(id) select count(id)
from user_role ur from user_role ur
where ur.user_id = #{userId} where ur.user_id = #{userId}
and ur.source_id = #{orgId} and ur.source_id = #{sourceId}
and ur.role_id = #{roleId} and ur.role_id = #{roleId}
</select> </select>

View File

@ -38,8 +38,8 @@
</select> </select>
<select id="getMemberList" resultType="io.metersphere.base.domain.User"> <select id="getMemberList" resultType="io.metersphere.base.domain.User">
SELECT `user`.* FROM user_role JOIN `user` ON user_role.user_id = `user`.id SELECT distinct `user`.* FROM user_role JOIN `user` ON user_role.user_id = `user`.id
WHERE user_role.source_id = #{member.workspaceId} AND user_role.role_id = #{member.roleId} WHERE user_role.source_id = #{member.workspaceId}
<if test="member.name != null"> <if test="member.name != null">
AND `user`.name like CONCAT('%', #{member.name},'%') AND `user`.name like CONCAT('%', #{member.name},'%')
</if> </if>

View File

@ -7,7 +7,9 @@ import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.WorkspaceRequest; import io.metersphere.controller.request.WorkspaceRequest;
import io.metersphere.dto.OrganizationMemberDTO;
import io.metersphere.dto.WorkspaceDTO; import io.metersphere.dto.WorkspaceDTO;
import io.metersphere.dto.WorkspaceMemberDTO;
import io.metersphere.service.WorkspaceService; import io.metersphere.service.WorkspaceService;
import io.metersphere.user.SessionUtils; import io.metersphere.user.SessionUtils;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
@ -67,4 +69,9 @@ public class WorkspaceController {
String currentOrganizationId = SessionUtils.getCurrentOrganizationId(); String currentOrganizationId = SessionUtils.getCurrentOrganizationId();
return workspaceService.getWorkspaceListByOrgIdAndUserId(currentOrganizationId); return workspaceService.getWorkspaceListByOrgIdAndUserId(currentOrganizationId);
} }
@PostMapping("/member/update")
public void updateOrgMember(@RequestBody WorkspaceMemberDTO memberDTO) {
workspaceService.updateWorkspaceMember(memberDTO);
}
} }

View File

@ -5,8 +5,16 @@ import java.util.List;
public class AddMemberRequest { public class AddMemberRequest {
private String workspaceId; private String workspaceId;
private List<String> userIds; private List<String> userIds;
private List<String> roleIds;
public List<String> getRoleIds() {
return roleIds;
}
public void setRoleIds(List<String> roleIds) {
this.roleIds = roleIds;
}
public String getWorkspaceId() { public String getWorkspaceId() {
return workspaceId; return workspaceId;

View File

@ -1,11 +1,9 @@
package io.metersphere.controller.request.member; package io.metersphere.controller.request.member;
import io.metersphere.commons.constants.RoleConstants;
public class QueryMemberRequest { public class QueryMemberRequest {
private String name; private String name;
private String workspaceId; private String workspaceId;
private String roleId = RoleConstants.TEST_MANAGER;
public String getName() { public String getName() {
return name; return name;
@ -15,14 +13,6 @@ public class QueryMemberRequest {
this.name = name; this.name = name;
} }
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getWorkspaceId() { public String getWorkspaceId() {
return workspaceId; return workspaceId;
} }

View File

@ -1,7 +1,5 @@
package io.metersphere.dto; package io.metersphere.dto;
import io.metersphere.base.domain.Role;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -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<String> 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<String> getRoleIds() {
return roleIds;
}
public void setRoleIds(List<String> roleIds) {
this.roleIds = roleIds;
}
}

View File

@ -86,7 +86,7 @@ public class OrganizationService {
// 更新用户时添加了角色 // 更新用户时添加了角色
if (roles.size() > allRoleIds.size()) { if (roles.size() > allRoleIds.size()) {
for (int i = 0; i < roles.size(); i++) { 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 userRole = new UserRole();
userRole.setId(UUID.randomUUID().toString()); userRole.setId(UUID.randomUUID().toString());
userRole.setUserId(userId); userRole.setUserId(userId);
@ -107,8 +107,7 @@ public class OrganizationService {
} }
} }
// 检查组织成员是否有某一角色 public Integer checkSourceRole(String orgId, String userId, String roleId) {
public Integer checkOrgRole(String orgId, String userId, String roleId) { return extOrganizationMapper.checkSourceRole(orgId, userId, roleId);
return extOrganizationMapper.checkOrgRole(orgId, userId, roleId);
} }
} }

View File

@ -251,21 +251,23 @@ public class UserService {
public void addMember(AddMemberRequest request) { public void addMember(AddMemberRequest request) {
if (!CollectionUtils.isEmpty(request.getUserIds())) { if (!CollectionUtils.isEmpty(request.getUserIds())) {
for (String userId : request.getUserIds()) { for (String userId : request.getUserIds()) {
UserRole userRole = new UserRole(); for (String roleId : request.getRoleIds()) {
userRole.setRoleId(RoleConstants.TEST_MANAGER); UserRole userRole = new UserRole();
userRole.setSourceId(request.getWorkspaceId()); userRole.setRoleId(roleId);
userRole.setUserId(userId); userRole.setSourceId(request.getWorkspaceId());
userRole.setId(UUID.randomUUID().toString()); userRole.setUserId(userId);
userRole.setUpdateTime(System.currentTimeMillis()); userRole.setId(UUID.randomUUID().toString());
userRole.setCreateTime(System.currentTimeMillis()); userRole.setUpdateTime(System.currentTimeMillis());
userRoleMapper.insertSelective(userRole); userRole.setCreateTime(System.currentTimeMillis());
userRoleMapper.insertSelective(userRole);
}
} }
} }
} }
public void deleteMember(String workspaceId, String userId) { public void deleteMember(String workspaceId, String userId) {
UserRoleExample example = new UserRoleExample(); UserRoleExample example = new UserRoleExample();
example.createCriteria().andRoleIdEqualTo(RoleConstants.TEST_MANAGER) example.createCriteria().andRoleIdLike("%test%")
.andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId); .andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId);
userRoleMapper.deleteByExample(example); userRoleMapper.deleteByExample(example);
} }

View File

@ -1,8 +1,10 @@
package io.metersphere.service; package io.metersphere.service;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.UserRoleMapper; import io.metersphere.base.mapper.UserRoleMapper;
import io.metersphere.base.mapper.WorkspaceMapper; 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.ExtUserRoleMapper;
import io.metersphere.base.mapper.ext.ExtWorkspaceMapper; import io.metersphere.base.mapper.ext.ExtWorkspaceMapper;
import io.metersphere.commons.constants.RoleConstants; 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.controller.request.WorkspaceRequest;
import io.metersphere.dto.UserRoleHelpDTO; import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.dto.WorkspaceDTO; import io.metersphere.dto.WorkspaceDTO;
import io.metersphere.dto.WorkspaceMemberDTO;
import io.metersphere.user.SessionUser; import io.metersphere.user.SessionUser;
import io.metersphere.user.SessionUtils; import io.metersphere.user.SessionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -33,6 +37,10 @@ public class WorkspaceService {
private ExtUserRoleMapper extUserRoleMapper; private ExtUserRoleMapper extUserRoleMapper;
@Resource @Resource
private UserRoleMapper userRoleMapper; private UserRoleMapper userRoleMapper;
@Resource
private UserMapper userMapper;
@Resource
private ExtOrganizationMapper extOrganizationMapper;
public Workspace saveWorkspace(Workspace workspace) { public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) { if (StringUtils.isBlank(workspace.getName())) {
@ -130,4 +138,43 @@ public class WorkspaceService {
return resultWorkspaceList; 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<Role> memberRoles = extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId);
// 修改后的角色
List<String> roles = memberDTO.getRoleIds();
List<String> 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);
}
} }

View File

@ -16,7 +16,7 @@
<el-table-column prop="name" label="用户名"/> <el-table-column prop="name" label="用户名"/>
<el-table-column prop="email" label="邮箱"/> <el-table-column prop="email" label="邮箱"/>
<el-table-column prop="phone" label="电话"/> <el-table-column prop="phone" label="电话"/>
<el-table-column prop="roles" label="角色" width="140"> <el-table-column prop="roles" label="角色" width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag v-for="(role, index) in scope.row.roles" :key="index" size="mini" effect="dark" type="success"> <el-tag v-for="(role, index) in scope.row.roles" :key="index" size="mini" effect="dark" type="success">
{{ role.name }} {{ role.name }}
@ -25,6 +25,7 @@
</el-table-column> </el-table-column>
<el-table-column> <el-table-column>
<template slot-scope="scope"> <template slot-scope="scope">
<el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit" size="mini" circle/>
<el-button @click="del(scope.row)" type="danger" icon="el-icon-delete" size="mini" circle/> <el-button @click="del(scope.row)" type="danger" icon="el-icon-delete" size="mini" circle/>
</template> </template>
</el-table-column> </el-table-column>
@ -57,6 +58,8 @@
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.id"> :value="item.id">
<span class="workspace-member-name">{{ item.name }}</span>
<span class="workspace-member-email">{{ item.email }}</span>
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -75,6 +78,37 @@
<el-button type="primary" @click="submitForm('form')" size="medium">保存</el-button> <el-button type="primary" @click="submitForm('form')" size="medium">保存</el-button>
</span> </span>
</el-dialog> </el-dialog>
<el-dialog title="修改成员" :visible.sync="updateVisible" width="30%" :destroy-on-close="true" @close="closeFunc">
<el-form :model="form" label-position="left" label-width="100px" size="small" ref="updateUserForm">
<el-form-item label="ID" prop="id">
<el-input v-model="form.id" autocomplete="off" :disabled="true"/>
</el-form-item>
<el-form-item label="用户名" prop="name">
<el-input v-model="form.name" autocomplete="off"/>
</el-form-item>
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" autocomplete="off"/>
</el-form-item>
<el-form-item label="电话" prop="phone">
<el-input v-model="form.phone" autocomplete="off"/>
</el-form-item>
<el-form-item label="角色" prop="roleIds">
<el-select v-model="form.roleIds" multiple placeholder="请选择角色" class="select-width">
<el-option
v-for="item in form.allroles"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="updateWorkspaceMember('updateUserForm')" size="medium">保存</el-button>
</span>
</el-dialog>
</div> </div>
</template> </template>
@ -90,17 +124,18 @@
return { return {
result: {}, result: {},
form: {}, form: {},
btnTips: "添加成员", btnTips: "添加工作空间成员",
createVisible: false, createVisible: false,
updateVisible: false,
queryPath: "/user/member/list", queryPath: "/user/member/list",
condition: "", condition: "",
tableData: [], tableData: [],
rules: { rules: {
userIds: [ userIds: [
{required: true, message: '请选择成员', trigger: ['blur', 'change']} {required: true, message: '请选择成员', trigger: ['blur']}
], ],
roleIds: [ roleIds: [
{required: true, message: '请选择角色', trigger: ['blur', 'change']} {required: true, message: '请选择角色', trigger: ['blur']}
] ]
}, },
multipleSelection: [], multipleSelection: [],
@ -180,23 +215,40 @@
}); });
}); });
}, },
create() { edit(row) {
this.loading = true; this.updateVisible = true;
this.$get('/user/list').then(response => { this.form = row;
if (response.data.success) { let roleIds = this.form.roles.map(r => r.id);
this.createVisible = true; this.result = this.$get('/role/list/test', response => {
this.form = {userList: response.data.data}; this.$set(this.form, "allroles", response.data);
} else { })
this.$message.error(response.message); // 使
} this.$set(this.form, 'roleIds', roleIds);
this.loading = false; },
}).catch(() => { updateWorkspaceMember() {
this.loading = false; 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({ this.$message({
type: 'error', type: 'success',
message: '获取用户列表失败' message: '修改成功!'
}); });
this.updateVisible = false;
this.initTableData();
}); });
},
create() {
this.form = {};
this.$get('/user/list',response => {
this.createVisible = true;
this.$set(this.form, "userList", response.data);
})
this.result = this.$get('/role/list/test', response => { this.result = this.$get('/role/list/test', response => {
this.$set(this.form, "roles", response.data); this.$set(this.form, "roles", response.data);
}) })
@ -207,17 +259,13 @@
if (valid) { if (valid) {
let param = { let param = {
userIds: this.form.userIds, userIds: this.form.userIds,
roleIds: this.form.roleIds,
workspaceId: this.currentUser().lastWorkspaceId workspaceId: this.currentUser().lastWorkspaceId
}; };
this.$post("user/member/add", param).then(() => { this.$post("user/member/add", param, () => {
this.initTableData(); this.initTableData();
this.createVisible = false; this.createVisible = false;
this.loading = false;
}).catch(() => {
this.loading = false;
}) })
} else {
return false;
} }
}); });
} }
@ -243,4 +291,15 @@
.select-width { .select-width {
width: 100%; width: 100%;
} }
.workspace-member-name {
float: left;
}
.workspace-member-email {
float: right;
color: #8492a6;
font-size: 13px;
}
</style> </style>

View File

@ -58,8 +58,8 @@
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.id"> :value="item.id">
<span style="float: left">{{ item.name }}</span> <span class="org-member-name">{{ item.name }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.email }}</span> <span class="org-member-email">{{ item.email }}</span>
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -272,4 +272,18 @@
margin-right: -9px; margin-right: -9px;
float: right; float: right;
} }
.org-member-name {
float: left;
}
.org-member-email {
float: right;
color: #8492a6;
font-size: 13px;
}
.select-width {
width: 100%;
}
</style> </style>