组织增加成员时添加角色信息

This commit is contained in:
shiziyuan9527 2020-02-27 18:09:39 +08:00
parent fb215cd2e6
commit 8383b67948
9 changed files with 107 additions and 22 deletions

View File

@ -0,0 +1,11 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.Role;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtRoleMapper {
List<Role> getRoleList(@Param("sign") String sign);
}

View File

@ -0,0 +1,9 @@
<?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.ExtRoleMapper">
<select id="getRoleList" resultType="io.metersphere.base.domain.Role">
select * from role where id like CONCAT('%', #{sign},'%')
</select>
</mapper>

View File

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

View File

@ -0,0 +1,25 @@
package io.metersphere.controller;
import io.metersphere.base.domain.Role;
import io.metersphere.service.RoleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RequestMapping("role")
@RestController
public class RoleController {
@Resource
private RoleService roleService;
@GetMapping("/list/{sign}")
public List<Role> getRoleList(@PathVariable String sign) {
return roleService.getRoleList(sign);
}
}

View File

@ -6,6 +6,7 @@ public class AddOrgMemberRequest {
private String organizationId; private String organizationId;
private List<String> userIds; private List<String> userIds;
private List<String> roleIds;
public String getOrganizationId() { public String getOrganizationId() {
return organizationId; return organizationId;
@ -22,4 +23,12 @@ public class AddOrgMemberRequest {
public void setUserIds(List<String> userIds) { public void setUserIds(List<String> userIds) {
this.userIds = userIds; this.userIds = userIds;
} }
public List<String> getRoleIds() {
return roleIds;
}
public void setRoleIds(List<String> roleIds) {
this.roleIds = roleIds;
}
} }

View File

@ -1,12 +1,10 @@
package io.metersphere.controller.request.organization; package io.metersphere.controller.request.organization;
import io.metersphere.commons.constants.RoleConstants;
public class QueryOrgMemberRequest { public class QueryOrgMemberRequest {
private String name; private String name;
private String organizationId; private String organizationId;
private String roleId = RoleConstants.ORG_ADMIN;
public String getName() { public String getName() {
return name; return name;
@ -23,12 +21,4 @@ public class QueryOrgMemberRequest {
public void setOrganizationId(String organizationId) { public void setOrganizationId(String organizationId) {
this.organizationId = organizationId; this.organizationId = organizationId;
} }
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
} }

View File

@ -0,0 +1,20 @@
package io.metersphere.service;
import io.metersphere.base.domain.Role;
import io.metersphere.base.mapper.ext.ExtRoleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class RoleService {
@Resource
private ExtRoleMapper extRoleMapper;
public List<Role> getRoleList(String sign) {
return extRoleMapper.getRoleList(sign);
}
}

View File

@ -273,22 +273,24 @@ public class UserService {
public void addOrganizationMember(AddOrgMemberRequest request) { public void addOrganizationMember(AddOrgMemberRequest 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.setId(UUID.randomUUID().toString()); // todo 判断用户是否有该角色
userRole.setRoleId(RoleConstants.ORG_ADMIN); UserRole userRole = new UserRole();
userRole.setSourceId(request.getOrganizationId()); userRole.setId(UUID.randomUUID().toString());
userRole.setUserId(userId); userRole.setRoleId(roleId);
userRole.setUpdateTime(System.currentTimeMillis()); userRole.setSourceId(request.getOrganizationId());
userRole.setCreateTime(System.currentTimeMillis()); userRole.setUserId(userId);
userRoleMapper.insertSelective(userRole); userRole.setUpdateTime(System.currentTimeMillis());
userRole.setCreateTime(System.currentTimeMillis());
userRoleMapper.insertSelective(userRole);
}
} }
} }
} }
public void delOrganizationMember(String organizationId, String userId) { public void delOrganizationMember(String organizationId, String userId) {
UserRoleExample userRoleExample = new UserRoleExample(); UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andRoleIdEqualTo(RoleConstants.ORG_ADMIN) userRoleExample.createCriteria().andRoleIdLike("%org%").andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId);
.andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId);
userRoleMapper.deleteByExample(userRoleExample); userRoleMapper.deleteByExample(userRoleExample);
} }

View File

@ -61,6 +61,16 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </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.roles"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm('form')" size="medium">保存</el-button> <el-button type="primary" @click="submitForm('form')" size="medium">保存</el-button>
@ -91,6 +101,9 @@
rules: { rules: {
userIds: [ userIds: [
{required: true, message: '请选择成员', trigger: ['blur', 'change']} {required: true, message: '请选择成员', trigger: ['blur', 'change']}
],
roleIds: [
{required: true, message: '请选择角色', trigger: ['blur', 'change']}
] ]
}, },
multipleSelection: [], multipleSelection: [],
@ -130,9 +143,11 @@
}, },
handleSizeChange(size) { handleSizeChange(size) {
this.pageSize = size; this.pageSize = size;
this.initTableData();
}, },
handleCurrentChange(current) { handleCurrentChange(current) {
this.currentPage = current; this.currentPage = current;
this.initTableData();
}, },
del(row) { del(row) {
this.$confirm('是否删除用户 ' + row.name + ' ?', '', { this.$confirm('是否删除用户 ' + row.name + ' ?', '', {
@ -157,7 +172,10 @@
create() { create() {
this.result = this.$get('/user/list', response => { this.result = this.$get('/user/list', response => {
this.createVisible = true; this.createVisible = true;
this.form = {userList: response.data}; this.$set(this.form, "userList", response.data);
});
this.result = this.$get('/role/list/org', response => {
this.$set(this.form, "roles", response.data);
}) })
}, },
submitForm(formName) { submitForm(formName) {
@ -166,6 +184,7 @@
if (valid) { if (valid) {
let param = { let param = {
userIds: this.form.userIds, userIds: this.form.userIds,
roleIds: this.form.roleIds,
organizationId: this.currentUser().lastOrganizationId organizationId: this.currentUser().lastOrganizationId
}; };
this.result = this.$post("user/orgmember/add", param,() => { this.result = this.$post("user/orgmember/add", param,() => {