fix(项目设置): 用户组与权限存在的问题

--story=1007490 --user=李玉号 项目设置-用户组与权限存在的问题
https://www.tapd.cn/55049933/s/1154901
This commit is contained in:
shiziyuan9527 2022-05-09 18:06:07 +08:00 committed by 刘瑞斌
parent 818fa49eaf
commit 0c1d158d45
6 changed files with 45 additions and 8 deletions

View File

@ -5,8 +5,14 @@
<select id="getGroupList" resultType="io.metersphere.dto.GroupDTO">
select *,
(select count(distinct ug.user_id) from user_group ug join user on ug.user_id = user.id where ug.group_id =
temp.id) as memberSize
<if test="request.onlyQueryCurrentProject == true">
(select count(distinct ug.user_id) from user_group ug join user on ug.user_id = user.id where ug.group_id =
temp.id and ug.source_id = #{request.projectId}) as memberSize
</if>
<if test="request.onlyQueryCurrentProject == false">
(select count(distinct ug.user_id) from user_group ug join user on ug.user_id = user.id where ug.group_id =
temp.id) as memberSize
</if>
from (
select g.*, w.name as scopeName from `group` g, workspace w
<where>

View File

@ -60,6 +60,9 @@
<if test="request.name != null and request.name !=''">
and user.name like concat('%', #{request.name},'%')
</if>
<if test="request.onlyQueryCurrentProject == true">
and ug.source_id = #{request.projectId}
</if>
order by ug.update_time desc
</select>

View File

@ -10,6 +10,7 @@ import io.metersphere.commons.constants.OperLogModule;
import io.metersphere.commons.constants.PermissionConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.GroupRequest;
import io.metersphere.controller.request.group.EditGroupRequest;
import io.metersphere.controller.request.group.EditGroupUserRequest;
@ -17,6 +18,7 @@ import io.metersphere.dto.GroupDTO;
import io.metersphere.dto.GroupPermissionDTO;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.service.GroupService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
@ -35,13 +37,22 @@ public class GroupController {
private GroupService groupService;
@PostMapping("/get/{goPage}/{pageSize}")
@RequiresPermissions(value = {PermissionConstants.SYSTEM_GROUP_READ, PermissionConstants.PROJECT_GROUP_READ}, logical = Logical.OR)
@RequiresPermissions(value = {PermissionConstants.SYSTEM_GROUP_READ}, logical = Logical.OR)
public Pager<List<GroupDTO>> getGroupList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody EditGroupRequest request) {
request.setGoPage(goPage);
request.setPageSize(pageSize);
return groupService.getGroupList(request);
}
@PostMapping("/get/current/project/{goPage}/{pageSize}")
@RequiresPermissions(value = {PermissionConstants.PROJECT_GROUP_READ}, logical = Logical.OR)
public Pager<List<GroupDTO>> getCurrentProjectGroupList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody EditGroupRequest request) {
request.setOnlyQueryCurrentProject(true);
request.setGoPage(goPage);
request.setPageSize(pageSize);
return groupService.getGroupList(request);
}
@GetMapping("/get/all")
public List<GroupDTO> getAllGroup() {
return groupService.getAllGroup();
@ -117,11 +128,23 @@ public class GroupController {
}
@PostMapping("/user/{goPage}/{pageSize}")
@RequiresPermissions(value = {PermissionConstants.SYSTEM_GROUP_READ}, logical = Logical.OR)
public Pager<List<User>> getGroupUser(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody EditGroupRequest editGroupRequest) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, groupService.getGroupUser(editGroupRequest));
}
@PostMapping("/current/project/user/{goPage}/{pageSize}")
@RequiresPermissions(value = {PermissionConstants.PROJECT_GROUP_READ}, logical = Logical.OR)
public Pager<List<User>> getCurrentProjectGroupUser(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody EditGroupRequest editGroupRequest) {
editGroupRequest.setOnlyQueryCurrentProject(true);
if (StringUtils.isBlank(editGroupRequest.getProjectId())) {
editGroupRequest.setProjectId(SessionUtils.getCurrentProjectId());
}
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, groupService.getGroupUser(editGroupRequest));
}
@GetMapping("/rm/{userId}/{groupId}")
public void removeGroupMember(@PathVariable String userId, @PathVariable String groupId) {
groupService.removeGroupMember(userId, groupId);

View File

@ -27,4 +27,5 @@ public class EditGroupRequest extends Group {
private List<GroupPermission> permissions;
private String userGroupId;
private List<OrderRequest> orders;
private boolean onlyQueryCurrentProject = false;
}

View File

@ -146,7 +146,7 @@ export default {
initData() {
this.condition.projectId = this.projectId;
if (this.projectId) {
this.result = this.$post("/user/group/get/" + this.currentPage + "/" + this.pageSize, this.condition, res => {
this.result = this.$post("/user/group/get/current/project/" + this.currentPage + "/" + this.pageSize, this.condition, res => {
let data = res.data;
if (data) {
let {itemCount, listObject} = data;
@ -205,7 +205,7 @@ export default {
this.initData();
},
memberClick(row) {
this.$refs.groupMember.open(row);
this.$refs.groupMember.open(row, '/user/group/current/project/user/', 'user/ws/current/member/list');
}
}
};

View File

@ -129,6 +129,8 @@ export default {
title: '',
submitType: '',
userSelectDisable: false,
initUserGroupUrl: "/user/group/user/",
initUserUrl: "/user/list/",
rules: {
userIds: {required: true, message: this.$t('member.please_choose_member'), trigger: 'blur'},
sourceIds: {required: true, message: this.$t('group.select_belong_source'), trigger: 'blur'}
@ -153,7 +155,7 @@ export default {
methods: {
init() {
this.condition.userGroupId = this.group.id;
this.result = this.$post("/user/group/user/" + this.currentPage + "/" + this.pageSize, this.condition, res => {
this.result = this.$post(this.initUserGroupUrl + this.currentPage + "/" + this.pageSize, this.condition, res => {
let data = res.data;
if (data) {
let {itemCount, listObject} = data;
@ -162,7 +164,9 @@ export default {
}
})
},
open(group) {
open(group, initUserGroupUrl, initUserUrl) {
this.initUserGroupUrl = initUserGroupUrl ? initUserGroupUrl : "/user/group/user/";
this.initUserUrl = initUserUrl ? initUserUrl : "/user/list/";
this.visible = true;
this.group = group;
this.init();
@ -211,7 +215,7 @@ export default {
})
},
getUser() {
this.memberResult = this.$get('/user/list/', response => {
this.memberResult = this.$get(this.initUserUrl, response => {
this.users = response.data;
})
},