编辑组织成员角色
This commit is contained in:
parent
17679bb9f7
commit
44743620d4
|
@ -0,0 +1,8 @@
|
|||
package io.metersphere.base.mapper.ext;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface ExtOrganizationMapper {
|
||||
|
||||
int checkOrgRole(@Param("orgId") String orgId,@Param("userId") String userId,@Param("roleId") String roleId);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!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 count(id)
|
||||
from user_role ur
|
||||
where ur.user_id = #{userId}
|
||||
and ur.source_id = #{orgId}
|
||||
and ur.role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -22,5 +22,7 @@ public interface ExtUserRoleMapper {
|
|||
|
||||
List<Role> getOrganizationMemberRoles(@Param("orgId") String orgId, @Param("userId") String userId);
|
||||
|
||||
List<User> getBesideOrgMemberList(@Param("orgId") String orgId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -71,6 +71,15 @@
|
|||
where o.id = #{orgId} and ur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="getBesideOrgMemberList" parameterType="java.lang.String" resultType="io.metersphere.base.domain.User">
|
||||
select *
|
||||
from `user`
|
||||
where `user`.id not in (select distinct u.id
|
||||
from `user` u
|
||||
join user_role ur on u.id = ur.user_id
|
||||
where ur.source_id = #{orgId})
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
|
@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
|
|||
import io.metersphere.base.domain.Organization;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.dto.OrganizationMemberDTO;
|
||||
import io.metersphere.service.OrganizationService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
|
@ -39,4 +40,9 @@ public class OrganizationController {
|
|||
public List<Organization> getOrganizationListByUserId(@PathVariable String userId) {
|
||||
return organizationService.getOrganizationListByUserId(userId);
|
||||
}
|
||||
|
||||
@PostMapping("/member/update")
|
||||
public void updateOrgMember(@RequestBody OrganizationMemberDTO memberDTO) {
|
||||
organizationService.updateOrgMember(memberDTO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,4 +149,12 @@ public class UserController {
|
|||
return PageUtils.setPageInfo(page, userService.getOrganizationMemberDTO(request));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@GetMapping("/besideorg/list/{orgId}")
|
||||
public List<User> getBesideOrgMemberList(@PathVariable String orgId) {
|
||||
return userService.getBesideOrgMemberList(orgId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,14 +22,24 @@ public class OrganizationMemberDTO {
|
|||
|
||||
private String language;
|
||||
|
||||
private List<Role> roles = new ArrayList<>();
|
||||
private String organizationId;
|
||||
|
||||
public List<Role> getRoles() {
|
||||
return roles;
|
||||
public String getOrganizationId() {
|
||||
return organizationId;
|
||||
}
|
||||
|
||||
public void setRoles(List<Role> roles) {
|
||||
this.roles = roles;
|
||||
public void setOrganizationId(String organizationId) {
|
||||
this.organizationId = organizationId;
|
||||
}
|
||||
|
||||
private List<String> roleIds = new ArrayList<>();
|
||||
|
||||
public List<String> getRoleIds() {
|
||||
return roleIds;
|
||||
}
|
||||
|
||||
public void setRoleIds(List<String> roleIds) {
|
||||
this.roleIds = roleIds;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package io.metersphere.service;
|
||||
|
||||
import io.metersphere.base.domain.Organization;
|
||||
import io.metersphere.base.domain.OrganizationExample;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.OrganizationMapper;
|
||||
import io.metersphere.base.mapper.UserMapper;
|
||||
import io.metersphere.base.mapper.UserRoleMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
|
||||
import io.metersphere.dto.OrganizationMemberDTO;
|
||||
import io.metersphere.dto.UserRoleHelpDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -14,6 +17,7 @@ import javax.annotation.Resource;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
@ -25,6 +29,10 @@ public class OrganizationService {
|
|||
private UserRoleMapper userRoleMapper;
|
||||
@Resource
|
||||
private ExtUserRoleMapper extUserRoleMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ExtOrganizationMapper extOrganizationMapper;
|
||||
|
||||
public Organization addOrganization(Organization organization) {
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
|
@ -62,4 +70,45 @@ public class OrganizationService {
|
|||
organizationExample.createCriteria().andIdIn(list);
|
||||
return organizationMapper.selectByExample(organizationExample);
|
||||
}
|
||||
|
||||
public void updateOrgMember(OrganizationMemberDTO memberDTO) {
|
||||
User user = new User();
|
||||
BeanUtils.copyProperties(memberDTO, user);
|
||||
userMapper.updateByPrimaryKeySelective(user);
|
||||
//
|
||||
String orgId = memberDTO.getOrganizationId();
|
||||
String userId = user.getId();
|
||||
// 已有角色
|
||||
List<Role> memberRoles = extUserRoleMapper.getOrganizationMemberRoles(orgId, 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 (checkOrgRole(orgId, userId, roles.get(i)) == 0) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setUserId(userId);
|
||||
userRole.setRoleId(roles.get(i));
|
||||
userRole.setSourceId(orgId);
|
||||
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(orgId)
|
||||
.andRoleIdIn(allRoleIds);
|
||||
userRoleMapper.deleteByExample(userRoleExample);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查组织成员是否有某一角色
|
||||
public Integer checkOrgRole(String orgId, String userId, String roleId) {
|
||||
return extOrganizationMapper.checkOrgRole(orgId, userId, roleId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -274,7 +274,6 @@ public class UserService {
|
|||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||
for (String userId : request.getUserIds()) {
|
||||
for (String roleId : request.getRoleIds()) {
|
||||
// todo 判断用户是否有该角色
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setRoleId(roleId);
|
||||
|
@ -313,4 +312,11 @@ public class UserService {
|
|||
public List<OrganizationMemberDTO> getOrganizationMemberDTO(QueryOrgMemberRequest request) {
|
||||
return extUserRoleMapper.getOrganizationMemberDTO(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询该组织外的其他用户列表
|
||||
*/
|
||||
public List<User> getBesideOrgMemberList(String orgId) {
|
||||
return extUserRoleMapper.getBesideOrgMemberList(orgId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,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>
|
||||
|
@ -58,6 +59,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>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
@ -76,6 +79,36 @@
|
|||
<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" @remove-tag="checkTag" >
|
||||
<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="updateOrgMember('updateUserForm')" size="medium">保存</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -94,6 +127,7 @@
|
|||
result: {},
|
||||
btnTips: "添加组织成员",
|
||||
createVisible: false,
|
||||
updateVisible: false,
|
||||
form: {},
|
||||
queryPath: "/user/orgmember/list",
|
||||
condition: "",
|
||||
|
@ -143,6 +177,7 @@
|
|||
},
|
||||
closeFunc() {
|
||||
this.form = {};
|
||||
this.initTableData();
|
||||
},
|
||||
handleSizeChange(size) {
|
||||
this.pageSize = size;
|
||||
|
@ -152,6 +187,37 @@
|
|||
this.currentPage = current;
|
||||
this.initTableData();
|
||||
},
|
||||
edit(row) {
|
||||
this.updateVisible = true;
|
||||
this.form = row;
|
||||
let roleIds = this.form.roles.map(r => r.id);
|
||||
this.result = this.$get('/role/list/org', response => {
|
||||
this.$set(this.form, "allroles", response.data);
|
||||
})
|
||||
// 编辑使填充角色信息
|
||||
this.$set(this.form, 'roleIds', roleIds);
|
||||
},
|
||||
updateOrgMember() {
|
||||
let param = {
|
||||
id: this.form.id,
|
||||
name: this.form.name,
|
||||
email: this.form.email,
|
||||
phone: this.form.phone,
|
||||
roleIds: this.form.roleIds,
|
||||
organizationId: this.currentUser().lastOrganizationId
|
||||
}
|
||||
this.result = this.$post("/organization/member/update", param,() => {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '修改成功!'
|
||||
});
|
||||
this.updateVisible = false;
|
||||
this.initTableData();
|
||||
});
|
||||
},
|
||||
checkTag() {
|
||||
// todo 修改成员信息时必须保留一个组织级角色
|
||||
},
|
||||
del(row) {
|
||||
this.$confirm('是否删除用户 ' + row.name + ' ?', '', {
|
||||
confirmButtonText: '确定',
|
||||
|
@ -174,7 +240,7 @@
|
|||
},
|
||||
create() {
|
||||
this.form = {};
|
||||
this.result = this.$get('/user/list', response => {
|
||||
this.result = this.$get('/user/besideorg/list/' + this.currentUser().lastOrganizationId, response => {
|
||||
this.createVisible = true;
|
||||
this.$set(this.form, "userList", response.data);
|
||||
});
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<el-form-item :label="$t('commons.description')">
|
||||
<el-input type="textarea" v-model="form.description"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('workspace.organization_name')" prop="userIds">
|
||||
<el-form-item :label="$t('workspace.organization_name')" prop="orgIds">
|
||||
<el-select v-model="form.organizationId" placeholder="请选择组织" class="select-width">
|
||||
<el-option
|
||||
v-for="item in form.orgList"
|
||||
|
@ -168,6 +168,9 @@
|
|||
name: [
|
||||
{required: true, message: this.$t('workspace.input_name'), trigger: 'blur'},
|
||||
{min: 2, max: 50, message: this.$t('commons.input_limit', [2, 50]), trigger: 'blur'}
|
||||
],
|
||||
orgIds: [
|
||||
{required: true, message: '请选择组织', trigger: ['blur']}
|
||||
]
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue