杂务:整理文档并收口 YumiNail 修复
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { permissionApi } from '@/api/permission'
|
||||
import { computed, ref } from 'vue'
|
||||
import { isBootstrapAdminUser, loadCachedAdminUserInfo } from '@/utils/admin-session'
|
||||
import { isAllowedForShoplessPlatformAdmin } from '@/utils/platform-admin-permissions'
|
||||
|
||||
const USER_PERMISSIONS_STORAGE_KEY = 'userPermissions'
|
||||
|
||||
@@ -22,6 +24,8 @@ const readPermissionsFromStorage = () => {
|
||||
const userPermissions = ref<string[]>(readPermissionsFromStorage() || [])
|
||||
const loadingPermissions = ref(false)
|
||||
|
||||
const isPlatformAdminUser = () => Number(loadCachedAdminUserInfo()?.type) === 4
|
||||
|
||||
export const getStoredUserPermissions = () => readPermissionsFromStorage()
|
||||
|
||||
export const setStoredUserPermissions = (permissions: string[]) => {
|
||||
@@ -51,14 +55,32 @@ export const fetchUserPermissionsStrict = async () => {
|
||||
|
||||
export const usePermission = () => {
|
||||
const hasPermission = (permissionCode: string) => {
|
||||
if (isBootstrapAdminUser(loadCachedAdminUserInfo())) {
|
||||
return isAllowedForShoplessPlatformAdmin(permissionCode)
|
||||
}
|
||||
if (isPlatformAdminUser() && isAllowedForShoplessPlatformAdmin(permissionCode)) {
|
||||
return isAllowedForShoplessPlatformAdmin(permissionCode)
|
||||
}
|
||||
return userPermissions.value.includes(permissionCode)
|
||||
}
|
||||
|
||||
const hasAnyPermission = (permissionCodes: string[]) => {
|
||||
if (isBootstrapAdminUser(loadCachedAdminUserInfo())) {
|
||||
return permissionCodes.some(isAllowedForShoplessPlatformAdmin)
|
||||
}
|
||||
if (isPlatformAdminUser() && permissionCodes.some(isAllowedForShoplessPlatformAdmin)) {
|
||||
return permissionCodes.some(isAllowedForShoplessPlatformAdmin)
|
||||
}
|
||||
return permissionCodes.some(code => userPermissions.value.includes(code))
|
||||
}
|
||||
|
||||
const hasAllPermissions = (permissionCodes: string[]) => {
|
||||
if (isBootstrapAdminUser(loadCachedAdminUserInfo())) {
|
||||
return permissionCodes.every(isAllowedForShoplessPlatformAdmin)
|
||||
}
|
||||
if (isPlatformAdminUser() && permissionCodes.every(isAllowedForShoplessPlatformAdmin)) {
|
||||
return permissionCodes.every(isAllowedForShoplessPlatformAdmin)
|
||||
}
|
||||
return permissionCodes.every(code => userPermissions.value.includes(code))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user