工作空间下成员信息可修改
This commit is contained in:
parent
f5a315ffcd
commit
db8cd75665
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<!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">
|
||||
|
||||
<select id="checkOrgRole" resultType="Integer">
|
||||
<select id="checkSourceRole" resultType="Integer">
|
||||
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}
|
||||
</select>
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
</select>
|
||||
|
||||
<select id="getMemberList" resultType="io.metersphere.base.domain.User">
|
||||
SELECT `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}
|
||||
SELECT distinct `user`.* FROM user_role JOIN `user` ON user_role.user_id = `user`.id
|
||||
WHERE user_role.source_id = #{member.workspaceId}
|
||||
<if test="member.name != null">
|
||||
AND `user`.name like CONCAT('%', #{member.name},'%')
|
||||
</if>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,16 @@ import java.util.List;
|
|||
public class AddMemberRequest {
|
||||
|
||||
private String workspaceId;
|
||||
|
||||
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() {
|
||||
return workspaceId;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package io.metersphere.dto;
|
||||
|
||||
import io.metersphere.base.domain.Role;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -251,8 +251,9 @@ public class UserService {
|
|||
public void addMember(AddMemberRequest request) {
|
||||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||
for (String userId : request.getUserIds()) {
|
||||
for (String roleId : request.getRoleIds()) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setRoleId(RoleConstants.TEST_MANAGER);
|
||||
userRole.setRoleId(roleId);
|
||||
userRole.setSourceId(request.getWorkspaceId());
|
||||
userRole.setUserId(userId);
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
|
@ -262,10 +263,11 @@ public class UserService {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<el-table-column prop="name" label="用户名"/>
|
||||
<el-table-column prop="email" 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">
|
||||
<el-tag v-for="(role, index) in scope.row.roles" :key="index" size="mini" effect="dark" type="success">
|
||||
{{ role.name }}
|
||||
|
@ -25,6 +25,7 @@
|
|||
</el-table-column>
|
||||
<el-table-column>
|
||||
<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/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
@ -57,6 +58,8 @@
|
|||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
<span class="workspace-member-name">{{ item.name }}</span>
|
||||
<span class="workspace-member-email">{{ item.email }}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
@ -75,6 +78,37 @@
|
|||
<el-button type="primary" @click="submitForm('form')" size="medium">保存</el-button>
|
||||
</span>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
|
@ -90,17 +124,18 @@
|
|||
return {
|
||||
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', 'change']}
|
||||
{required: true, message: '请选择角色', trigger: ['blur']}
|
||||
]
|
||||
},
|
||||
multipleSelection: [],
|
||||
|
@ -180,23 +215,40 @@
|
|||
});
|
||||
});
|
||||
},
|
||||
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);
|
||||
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.loading = false;
|
||||
}).catch(() => {
|
||||
this.loading = false;
|
||||
this.result = this.$post("/workspace/member/update", param,() => {
|
||||
this.$message({
|
||||
type: 'error',
|
||||
message: '获取用户列表失败'
|
||||
type: 'success',
|
||||
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.$set(this.form, "roles", response.data);
|
||||
})
|
||||
|
@ -207,17 +259,13 @@
|
|||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -243,4 +291,15 @@
|
|||
.select-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.workspace-member-name {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.workspace-member-email {
|
||||
float: right;
|
||||
color: #8492a6;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
|
@ -58,8 +58,8 @@
|
|||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
<span style="float: left">{{ item.name }}</span>
|
||||
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.email }}</span>
|
||||
<span class="org-member-name">{{ item.name }}</span>
|
||||
<span class="org-member-email">{{ item.email }}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
@ -272,4 +272,18 @@
|
|||
margin-right: -9px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.org-member-name {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.org-member-email {
|
||||
float: right;
|
||||
color: #8492a6;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.select-width {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue