mirror of
https://github.com/jumpserver/lina.git
synced 2026-01-25 14:34:46 +00:00
feat: 优化鉴权
This commit is contained in:
@@ -73,6 +73,18 @@ export function getAdminOrUserPageRole(allRoles, page) {
|
||||
return allRoles[1]
|
||||
}
|
||||
|
||||
export function hasPerm(source, target) {
|
||||
if (typeof source !== 'object') {
|
||||
source = [source]
|
||||
}
|
||||
if (typeof target !== 'object') {
|
||||
target = [target]
|
||||
}
|
||||
const totalSource = sumPerms(source)
|
||||
const totalTarget = sumPerms(target)
|
||||
return (totalTarget & totalSource) === totalTarget
|
||||
}
|
||||
|
||||
export function sumPerms(perms) {
|
||||
let sum = 0
|
||||
for (const perm of perms) {
|
||||
@@ -86,5 +98,5 @@ export default {
|
||||
SUPER_ADMIN, SUPER_AUDITOR, ORG_ADMIN, ORG_AUDITOR,
|
||||
USER, ANON,
|
||||
getRolesDisplay, getPermsToRolesDisplay, getAdminOrUserPageRole,
|
||||
parseUserRoles, sumPerms
|
||||
parseUserRoles, sumPerms, hasPerm
|
||||
}
|
||||
|
||||
@@ -106,15 +106,18 @@ function cleanCurrentRole(allRoles) {
|
||||
let currentRole = store.getters.currentRole
|
||||
// 没有的话就应该选择一个
|
||||
|
||||
console.log('Curernt ROle', currentRole)
|
||||
// console.log('Curernt Role', currentRole)
|
||||
if (!currentRole && typeof currentRole !== 'number') {
|
||||
currentRole = rolec.getAdminOrUserPageRole(allRoles)
|
||||
console.log('1')
|
||||
} else {
|
||||
console.log('2')
|
||||
if ((currentRole & rolec.sumPerms(allRoles)) !== currentRole) {
|
||||
currentRole = rolec.getAdminOrUserPageRole(allRoles)
|
||||
}
|
||||
}
|
||||
const hasAudit = rolec.hasPerm(currentRole, rolec.PERM_AUDIT)
|
||||
const hasAdmin = rolec.hasPerm(allRoles, rolec.PERM_ADMIN)
|
||||
// 这代表上次用户登录了auditor,这次切换了
|
||||
if (hasAudit && hasAdmin) {
|
||||
currentRole = rolec.getAdminOrUserPageRole(allRoles)
|
||||
}
|
||||
if (!rolec.hasPerm(allRoles, currentRole)) {
|
||||
currentRole = rolec.getAdminOrUserPageRole(allRoles)
|
||||
}
|
||||
store.dispatch('users/setCurrentRole', currentRole)
|
||||
return [currentRole]
|
||||
|
||||
Reference in New Issue
Block a user