refactor(用户组和权限): 优化
This commit is contained in:
parent
d0fc6de7df
commit
232e8d09f3
|
@ -1,8 +1,8 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public class UserGroupType {
|
||||
public static final String SYSTEM = "system";
|
||||
public static final String ORGANIZATION = "organization";
|
||||
public static final String WORKSPACE = "workspace";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String SYSTEM = "SYSTEM";
|
||||
public static final String ORGANIZATION = "ORGANIZATION";
|
||||
public static final String WORKSPACE = "WORKSPACE";
|
||||
public static final String PROJECT = "PROJECT";
|
||||
}
|
||||
|
|
|
@ -2,12 +2,10 @@ package io.metersphere.dto;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class GroupPermissionDTO {
|
||||
private List<GroupResourceDTO> system;
|
||||
private List<GroupResourceDTO> organization;
|
||||
private List<GroupResourceDTO> workspace;
|
||||
private List<GroupResourceDTO> project;
|
||||
private List<GroupResourceDTO> permissions = new ArrayList<>();
|
||||
}
|
||||
|
|
|
@ -47,6 +47,13 @@ public class GroupService {
|
|||
@Resource
|
||||
private UserGroupPermissionMapper userGroupPermissionMapper;
|
||||
|
||||
private static final Map<String, List<String>> map = new HashMap<String, List<String>>(4){{
|
||||
put(UserGroupType.SYSTEM, Arrays.asList(UserGroupType.SYSTEM, UserGroupType.ORGANIZATION, UserGroupType.WORKSPACE, UserGroupType.PROJECT));
|
||||
put(UserGroupType.ORGANIZATION, Arrays.asList(UserGroupType.ORGANIZATION, UserGroupType.WORKSPACE, UserGroupType.PROJECT));
|
||||
put(UserGroupType.WORKSPACE, Arrays.asList(UserGroupType.WORKSPACE, UserGroupType.PROJECT));
|
||||
put(UserGroupType.PROJECT, Collections.singletonList(UserGroupType.PROJECT));
|
||||
}};
|
||||
|
||||
public Pager<List<GroupDTO>> getGroupList(EditGroupRequest request) {
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
List<UserGroupDTO> userGroup = extUserGroupMapper.getUserGroup(user.getId());
|
||||
|
@ -105,7 +112,11 @@ public class GroupService {
|
|||
group = JSON.parseObject(permission, GroupJson.class);
|
||||
List<GroupResource> resource = group.getResource();
|
||||
List<GroupPermission> permissions = group.getPermissions();
|
||||
getPermission(resource, permissions, type, dto, permissionList);
|
||||
List<GroupResourceDTO> dtoPermissions = dto.getPermissions();
|
||||
List<String> groups = map.get(type);
|
||||
for (String gp : groups) {
|
||||
dtoPermissions.addAll(getResourcePermission(resource, permissions, gp, permissionList));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -141,12 +152,6 @@ public class GroupService {
|
|||
sqlSession.flushStatements();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private List<GroupResourceDTO> getResourcePermission(List<GroupResource> resource, List<GroupPermission> permissions, String type, List<String> permissionList) {
|
||||
List<GroupResourceDTO> dto = new ArrayList<>();
|
||||
List<GroupResource> resources = resource.stream().filter(g -> g.getId().startsWith(type)).collect(Collectors.toList());
|
||||
|
@ -188,58 +193,17 @@ public class GroupService {
|
|||
return new Pager<>();
|
||||
}
|
||||
|
||||
private void getPermission(List<GroupResource> resource, List<GroupPermission> permissions, String type, GroupPermissionDTO dto, List<String> permissionList) {
|
||||
dto.setSystem(getResourcePermission(resource, permissions, "SYSTEM", permissionList));
|
||||
dto.setOrganization(getResourcePermission(resource, permissions, "ORGANIZATION", permissionList));
|
||||
dto.setWorkspace(getResourcePermission(resource, permissions, "WORKSPACE", permissionList));
|
||||
dto.setProject(getResourcePermission(resource, permissions, "PROJECT", permissionList));
|
||||
switch (type) {
|
||||
case "SYSTEM":
|
||||
dto.setSystem(getResourcePermission(resource, permissions, "SYSTEM", permissionList));
|
||||
dto.setOrganization(getResourcePermission(resource, permissions, "ORGANIZATION", permissionList));
|
||||
dto.setWorkspace(getResourcePermission(resource, permissions, "WORKSPACE", permissionList));
|
||||
dto.setProject(getResourcePermission(resource, permissions, "PROJECT", permissionList));
|
||||
break;
|
||||
case "ORGANIZATION":
|
||||
dto.setOrganization(getResourcePermission(resource, permissions, "ORGANIZATION", permissionList));
|
||||
dto.setWorkspace(getResourcePermission(resource, permissions, "WORKSPACE", permissionList));
|
||||
dto.setProject(getResourcePermission(resource, permissions, "PROJECT", permissionList));
|
||||
break;
|
||||
case "WORKSPACE":
|
||||
dto.setWorkspace(getResourcePermission(resource, permissions, "WORKSPACE", permissionList));
|
||||
dto.setProject(getResourcePermission(resource, permissions, "PROJECT", permissionList));
|
||||
break;
|
||||
case "PROJECT":
|
||||
dto.setProject(getResourcePermission(resource, permissions, "PROJECT", permissionList));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Pager<List<GroupDTO>> getUserGroup(String groupType, EditGroupRequest request) {
|
||||
List<String> types = new ArrayList<>();
|
||||
List<String> types;
|
||||
String orgId = SessionUtils.getCurrentOrganizationId();
|
||||
List<String> scopes = Arrays.asList("global", orgId);
|
||||
int goPage = request.getGoPage();
|
||||
int pageSize = request.getPageSize();
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
switch (groupType) {
|
||||
case UserGroupType.SYSTEM:
|
||||
types = Arrays.asList(UserGroupType.SYSTEM,UserGroupType.ORGANIZATION, UserGroupType.WORKSPACE, UserGroupType.PROJECT);
|
||||
scopes = new ArrayList<>();
|
||||
break;
|
||||
case UserGroupType.ORGANIZATION:
|
||||
types = Arrays.asList(UserGroupType.ORGANIZATION, UserGroupType.WORKSPACE, UserGroupType.PROJECT);
|
||||
break;
|
||||
case UserGroupType.WORKSPACE:
|
||||
types = Arrays.asList(UserGroupType.WORKSPACE, UserGroupType.PROJECT);
|
||||
break;
|
||||
case UserGroupType.PROJECT:
|
||||
types.add(UserGroupType.PROJECT);
|
||||
break;
|
||||
default:
|
||||
if (StringUtils.equals(groupType, UserGroupType.SYSTEM)) {
|
||||
scopes = new ArrayList<>();
|
||||
}
|
||||
types = map.get(groupType);
|
||||
request.setTypes(types);
|
||||
request.setScopes(scopes);
|
||||
List<GroupDTO> groups = extGroupMapper.getGroupList(request);
|
||||
|
|
|
@ -52,16 +52,6 @@ export default {
|
|||
result: {}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
map() {
|
||||
return new Map([
|
||||
['system', ['system', 'organization', 'workspace', 'project']],
|
||||
['organization', ['organization', 'workspace', 'project']],
|
||||
['workspace', ['workspace', 'project']],
|
||||
['project', ['project']],
|
||||
])
|
||||
}
|
||||
},
|
||||
components: {
|
||||
GroupPermission,
|
||||
GroupOperator
|
||||
|
@ -71,26 +61,16 @@ export default {
|
|||
this.tableData = [];
|
||||
this.dialogVisible = true;
|
||||
this.group = Object.assign({}, row);
|
||||
this.getGroupJson(this.group.type);
|
||||
this.getGroupJson();
|
||||
},
|
||||
getGroupJson(type) {
|
||||
getGroupJson() {
|
||||
this.result = this.$post("/user/group/permission", this.group, result => {
|
||||
let data = result.data;
|
||||
if (data) {
|
||||
this.tableData = this._getGroupPermission(data, type);
|
||||
this.tableData = data.permissions;
|
||||
}
|
||||
})
|
||||
},
|
||||
_getGroupPermission(data, type) {
|
||||
let arr = [];
|
||||
let group = this.map.get(type);
|
||||
if (group) {
|
||||
group.forEach(g => {
|
||||
arr.push(...data[g]);
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
onSubmit() {
|
||||
let param = {};
|
||||
let permissions = [];
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
<el-col :span="11" :offset="2">
|
||||
<el-form-item label="所属类型">
|
||||
<el-select v-model="form.type" placeholder="请选择所属类型" style="width: 100%">
|
||||
<el-option label="系统" value="system"></el-option>
|
||||
<el-option label="组织" value="organization"></el-option>
|
||||
<el-option label="工作空间" value="workspace"></el-option>
|
||||
<el-option label="项目" value="project"></el-option>
|
||||
<el-option label="系统" value="SYSTEM"></el-option>
|
||||
<el-option label="组织" value="ORGANIZATION"></el-option>
|
||||
<el-option label="工作空间" value="WORKSPACE"></el-option>
|
||||
<el-option label="项目" value="PROJECT"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
<span v-for="(permission, index) in permissions" :key="index" style="margin-left: 25px;">
|
||||
<el-checkbox v-model="permission['checked']" @change="change($event, permission)">{{ permission.name }}</el-checkbox>
|
||||
<span v-for="(permission, index) in permissions" :key="index" style="margin-right: 25px;">
|
||||
<el-checkbox v-model="permission['checked']" @change="change($event, permission)">
|
||||
{{ permission.name }}
|
||||
</el-checkbox>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
@ -71,8 +71,8 @@ export const ISSUE_STATUS_MAP = {
|
|||
|
||||
export const USER_GROUP_SCOPE = {
|
||||
// todo i18n
|
||||
'system': '系统',
|
||||
'organization': '组织',
|
||||
'workspace': '工作空间',
|
||||
'project': '项目'
|
||||
'SYSTEM': '系统',
|
||||
'ORGANIZATION': '组织',
|
||||
'WORKSPACE': '工作空间',
|
||||
'PROJECT': '项目'
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue