refactor(系统设置): 超级用户组权限
This commit is contained in:
parent
19205a7879
commit
eef046300b
|
@ -24,6 +24,7 @@ export const ROLE_ORG_ADMIN = 'org_admin';
|
||||||
export const ROLE_TEST_MANAGER = 'test_manager';
|
export const ROLE_TEST_MANAGER = 'test_manager';
|
||||||
export const ROLE_TEST_USER = 'test_user';
|
export const ROLE_TEST_USER = 'test_user';
|
||||||
export const ROLE_TEST_VIEWER = 'test_viewer';
|
export const ROLE_TEST_VIEWER = 'test_viewer';
|
||||||
|
export const SUPER_GROUP = 'super_group';
|
||||||
|
|
||||||
export const ORGANIZATION_ID = 'organization_id';
|
export const ORGANIZATION_ID = 'organization_id';
|
||||||
export const WORKSPACE_ID = 'workspace_id';
|
export const WORKSPACE_ID = 'workspace_id';
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
import {LicenseKey} from "./constants";
|
import {LicenseKey, SUPER_GROUP} from "./constants";
|
||||||
import {getCurrentProjectID, getCurrentUser, getCurrentWorkspaceId} from "./token";
|
import {getCurrentProjectID, getCurrentUser, getCurrentWorkspaceId} from "./token";
|
||||||
|
|
||||||
export function hasPermission(permission) {
|
export function hasPermission(permission) {
|
||||||
let user = getCurrentUser();
|
let user = getCurrentUser();
|
||||||
|
let index = user.groups.findIndex(g => g.id === SUPER_GROUP);
|
||||||
|
if (index !== -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
user.userGroups.forEach(ug => {
|
user.userGroups.forEach(ug => {
|
||||||
user.groupPermissions.forEach(gp => {
|
user.groupPermissions.forEach(gp => {
|
||||||
|
@ -13,20 +17,6 @@ export function hasPermission(permission) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let superGroupPermissions = user.userGroups.filter(ug => ug.group && ug.group.id === 'super_group')
|
|
||||||
.flatMap(ug => ug.userGroupPermissions)
|
|
||||||
.map(g => g.permissionId)
|
|
||||||
.reduce((total, current) => {
|
|
||||||
total.add(current);
|
|
||||||
return total;
|
|
||||||
}, new Set);
|
|
||||||
|
|
||||||
for (const p of superGroupPermissions) {
|
|
||||||
if (p === permission) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo 权限验证
|
// todo 权限验证
|
||||||
let currentProjectPermissions = user.userGroups.filter(ug => ug.group && ug.group.type === 'PROJECT')
|
let currentProjectPermissions = user.userGroups.filter(ug => ug.group && ug.group.type === 'PROJECT')
|
||||||
.filter(ug => ug.sourceId === getCurrentProjectID())
|
.filter(ug => ug.sourceId === getCurrentProjectID())
|
||||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.commons.utils;
|
||||||
|
|
||||||
import io.metersphere.base.domain.Group;
|
import io.metersphere.base.domain.Group;
|
||||||
import io.metersphere.base.domain.UserGroupPermission;
|
import io.metersphere.base.domain.UserGroupPermission;
|
||||||
|
import io.metersphere.commons.constants.UserGroupConstants;
|
||||||
import io.metersphere.commons.user.SessionUser;
|
import io.metersphere.commons.user.SessionUser;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -141,6 +142,15 @@ public class SessionUtils {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
long count = user.getGroups()
|
||||||
|
.stream()
|
||||||
|
.filter(g -> StringUtils.equals(g.getId(), UserGroupConstants.SUPER_GROUP))
|
||||||
|
.count();
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Set<String> currentProjectPermissions = getCurrentProjectPermissions(userGroupPermissions, projectId, group, user);
|
Set<String> currentProjectPermissions = getCurrentProjectPermissions(userGroupPermissions, projectId, group, user);
|
||||||
if (currentProjectPermissions.contains(permission)) {
|
if (currentProjectPermissions.contains(permission)) {
|
||||||
|
|
|
@ -70,8 +70,6 @@ public class GroupService {
|
||||||
@Resource
|
@Resource
|
||||||
private BaseUserService baseUserService;
|
private BaseUserService baseUserService;
|
||||||
private static final String GLOBAL = "global";
|
private static final String GLOBAL = "global";
|
||||||
private static final String SUPER_GROUP = "super_group";
|
|
||||||
|
|
||||||
|
|
||||||
// 服务权限拼装顺序
|
// 服务权限拼装顺序
|
||||||
private static final String[] servicePermissionLoadOrder = {MicroServiceName.PROJECT_MANAGEMENT,
|
private static final String[] servicePermissionLoadOrder = {MicroServiceName.PROJECT_MANAGEMENT,
|
||||||
|
@ -225,7 +223,7 @@ public class GroupService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editGroupPermission(EditGroupRequest request) {
|
public void editGroupPermission(EditGroupRequest request) {
|
||||||
if (StringUtils.equals(request.getUserGroupId(), SUPER_GROUP)) {
|
if (StringUtils.equals(request.getUserGroupId(), UserGroupConstants.SUPER_GROUP)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<GroupPermission> permissions = request.getPermissions();
|
List<GroupPermission> permissions = request.getPermissions();
|
||||||
|
|
|
@ -68,7 +68,6 @@ public class GroupService {
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
|
|
||||||
private static final String GLOBAL = "global";
|
private static final String GLOBAL = "global";
|
||||||
private static final String SUPER_GROUP = "super_group";
|
|
||||||
private static final String PERSONAL_PREFIX = "PERSONAL";
|
private static final String PERSONAL_PREFIX = "PERSONAL";
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,7 +235,7 @@ public class GroupService {
|
||||||
|
|
||||||
public void editGroupPermission(EditGroupRequest request) {
|
public void editGroupPermission(EditGroupRequest request) {
|
||||||
// 超级用户组禁止修改权限
|
// 超级用户组禁止修改权限
|
||||||
if (StringUtils.equals(request.getUserGroupId(), SUPER_GROUP)) {
|
if (StringUtils.equals(request.getUserGroupId(), UserGroupConstants.SUPER_GROUP)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<GroupPermission> permissions = request.getPermissions();
|
List<GroupPermission> permissions = request.getPermissions();
|
||||||
|
@ -331,19 +330,21 @@ public class GroupService {
|
||||||
private List<GroupResourceDTO> getResourcePermission(List<GroupResource> resources, List<GroupPermission> permissions, Group group, List<String> permissionList) {
|
private List<GroupResourceDTO> getResourcePermission(List<GroupResource> resources, List<GroupPermission> permissions, Group group, List<String> permissionList) {
|
||||||
List<GroupResourceDTO> dto = new ArrayList<>();
|
List<GroupResourceDTO> dto = new ArrayList<>();
|
||||||
List<GroupResource> grs;
|
List<GroupResource> grs;
|
||||||
if (StringUtils.equals(group.getId(), SUPER_GROUP)) {
|
if (StringUtils.equals(group.getId(), UserGroupConstants.SUPER_GROUP)) {
|
||||||
grs = resources;
|
grs = resources;
|
||||||
|
permissions.forEach(p -> p.setChecked(true));
|
||||||
} else {
|
} else {
|
||||||
grs = resources
|
grs = resources
|
||||||
.stream()
|
.stream()
|
||||||
.filter(g -> g.getId().startsWith(group.getType()) || g.getId().startsWith(PERSONAL_PREFIX))
|
.filter(g -> g.getId().startsWith(group.getType()) || g.getId().startsWith(PERSONAL_PREFIX))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
|
||||||
permissions.forEach(p -> {
|
permissions.forEach(p -> {
|
||||||
if (permissionList.contains(p.getId())) {
|
if (permissionList.contains(p.getId())) {
|
||||||
p.setChecked(true);
|
p.setChecked(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (GroupResource r : grs) {
|
for (GroupResource r : grs) {
|
||||||
GroupResourceDTO resourceDTO = new GroupResourceDTO();
|
GroupResourceDTO resourceDTO = new GroupResourceDTO();
|
||||||
resourceDTO.setResource(r);
|
resourceDTO.setResource(r);
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
import GroupPermission from "./GroupPermission";
|
import GroupPermission from "./GroupPermission";
|
||||||
import {PROJECT_GROUP_SCOPE, USER_GROUP_SCOPE} from "metersphere-frontend/src/utils/table-constants";
|
import {PROJECT_GROUP_SCOPE, USER_GROUP_SCOPE} from "metersphere-frontend/src/utils/table-constants";
|
||||||
import {hasLicense} from "metersphere-frontend/src/utils/permission";
|
import {hasLicense} from "metersphere-frontend/src/utils/permission";
|
||||||
import {GROUP_TYPE} from 'metersphere-frontend/src/utils/constants'
|
import {GROUP_TYPE, SUPER_GROUP} from 'metersphere-frontend/src/utils/constants'
|
||||||
import {getUserGroupPermission, modifyUserGroupPermission} from "../../../api/user-group";
|
import {getUserGroupPermission, modifyUserGroupPermission} from "../../../api/user-group";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -99,7 +99,7 @@ export default {
|
||||||
},
|
},
|
||||||
isReadOnly() {
|
isReadOnly() {
|
||||||
return function (data) {
|
return function (data) {
|
||||||
if (this.group.id === 'super_group') {
|
if (this.group.id === SUPER_GROUP) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const isDefaultSystemGroup = this.group.id === 'admin' && data.resource.id === 'SYSTEM_GROUP';
|
const isDefaultSystemGroup = this.group.id === 'admin' && data.resource.id === 'SYSTEM_GROUP';
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {SUPER_GROUP} from 'metersphere-frontend/src/utils/constants';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "GroupPermission",
|
name: "GroupPermission",
|
||||||
props: {
|
props: {
|
||||||
|
@ -45,7 +47,7 @@ export default {
|
||||||
isReadOnly() {
|
isReadOnly() {
|
||||||
return function (permission) {
|
return function (permission) {
|
||||||
// 禁止取消系统管理员用户组权限
|
// 禁止取消系统管理员用户组权限
|
||||||
if (this.group.id === 'super_group') {
|
if (this.group.id === SUPER_GROUP) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// 禁止取消系统管理员用户组和超级管理员用户组的读取和设置权限
|
// 禁止取消系统管理员用户组和超级管理员用户组的读取和设置权限
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
<el-table-column prop="description" :label="$t('group.description')" show-overflow-tooltip/>
|
<el-table-column prop="description" :label="$t('group.description')" show-overflow-tooltip/>
|
||||||
<el-table-column :label="$t('commons.operating')" min-width="120">
|
<el-table-column :label="$t('commons.operating')" min-width="120">
|
||||||
<template v-slot="scope">
|
<template v-slot="scope">
|
||||||
<div v-if="scope.row.id === 'super_group'">
|
<div v-if="scope.row.id === SUPER_GROUP">
|
||||||
<ms-table-operator
|
<ms-table-operator
|
||||||
:is-show="true"
|
:is-show="true"
|
||||||
@editClick="edit(scope.row)" @deleteClick="del(scope.row)">
|
@editClick="edit(scope.row)" @deleteClick="del(scope.row)">
|
||||||
|
@ -101,6 +101,8 @@ import {_sort} from "metersphere-frontend/src/utils/tableUtils";
|
||||||
import GroupMember from "./GroupMember";
|
import GroupMember from "./GroupMember";
|
||||||
import {hasPermission} from "metersphere-frontend/src/utils/permission";
|
import {hasPermission} from "metersphere-frontend/src/utils/permission";
|
||||||
import {delUserGroupById, getUserGroupListByPage} from "../../../api/user-group";
|
import {delUserGroupById, getUserGroupListByPage} from "../../../api/user-group";
|
||||||
|
import {SUPER_GROUP} from 'metersphere-frontend/src/utils/constants'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "UserGroup",
|
name: "UserGroup",
|
||||||
|
@ -123,6 +125,7 @@ export default {
|
||||||
total: 0,
|
total: 0,
|
||||||
screenHeight: 'calc(100vh - 160px)',
|
screenHeight: 'calc(100vh - 160px)',
|
||||||
groups: [],
|
groups: [],
|
||||||
|
SUPER_GROUP
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
activated() {
|
activated() {
|
||||||
|
|
Loading…
Reference in New Issue