You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
788 B
40 lines
788 B
1 year ago
|
const {
|
||
|
ERROR
|
||
|
} = require('../common/error')
|
||
|
|
||
|
function hasRole (...roleList) {
|
||
|
const userRole = this.authInfo.role || []
|
||
|
if (userRole.includes('admin')) {
|
||
|
return
|
||
|
}
|
||
|
const isMatch = roleList.every(roleItem => {
|
||
|
return userRole.includes(roleItem)
|
||
|
})
|
||
|
if (!isMatch) {
|
||
|
throw {
|
||
|
errCode: ERROR.PERMISSION_ERROR
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function hasPermission (...permissionList) {
|
||
|
const userRole = this.authInfo.role || []
|
||
|
const userPermission = this.authInfo.permission || []
|
||
|
if (userRole.includes('admin')) {
|
||
|
return
|
||
|
}
|
||
|
const isMatch = permissionList.every(permissionItem => {
|
||
|
return userPermission.includes(permissionItem)
|
||
|
})
|
||
|
if (!isMatch) {
|
||
|
throw {
|
||
|
errCode: ERROR.PERMISSION_ERROR
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
hasRole,
|
||
|
hasPermission
|
||
|
}
|