Merge branch 'dev' of github.com:fit2cloudrd/metersphere-server into dev

This commit is contained in:
Captain.B 2020-02-27 18:26:11 +08:00
commit 963c17b5b9
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 `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">
AND `user`.name like CONCAT('%', #{orgMember.name},'%')
</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 List<String> userIds;
private List<String> roleIds;
public String getOrganizationId() {
return organizationId;
@ -22,4 +23,12 @@ public class AddOrgMemberRequest {
public void setUserIds(List<String> 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;
import io.metersphere.commons.constants.RoleConstants;
public class QueryOrgMemberRequest {
private String name;
private String organizationId;
private String roleId = RoleConstants.ORG_ADMIN;
public String getName() {
return name;
@ -23,12 +21,4 @@ public class QueryOrgMemberRequest {
public void setOrganizationId(String 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) {
if (!CollectionUtils.isEmpty(request.getUserIds())) {
for (String userId : request.getUserIds()) {
UserRole userRole = new UserRole();
userRole.setId(UUID.randomUUID().toString());
userRole.setRoleId(RoleConstants.ORG_ADMIN);
userRole.setSourceId(request.getOrganizationId());
userRole.setUserId(userId);
userRole.setUpdateTime(System.currentTimeMillis());
userRole.setCreateTime(System.currentTimeMillis());
userRoleMapper.insertSelective(userRole);
for (String roleId : request.getRoleIds()) {
// todo 判断用户是否有该角色
UserRole userRole = new UserRole();
userRole.setId(UUID.randomUUID().toString());
userRole.setRoleId(roleId);
userRole.setSourceId(request.getOrganizationId());
userRole.setUserId(userId);
userRole.setUpdateTime(System.currentTimeMillis());
userRole.setCreateTime(System.currentTimeMillis());
userRoleMapper.insertSelective(userRole);
}
}
}
}
public void delOrganizationMember(String organizationId, String userId) {
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andRoleIdEqualTo(RoleConstants.ORG_ADMIN)
.andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId);
userRoleExample.createCriteria().andRoleIdLike("%org%").andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId);
userRoleMapper.deleteByExample(userRoleExample);
}

View File

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