mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added permissions
core
This commit is contained in:
parent
7f144e8053
commit
e1ca4f5b31
@ -1,6 +1,7 @@
|
|||||||
import SettingsCore from "./settings"
|
import SettingsCore from "./settings"
|
||||||
import APICore from "./api"
|
import APICore from "./api"
|
||||||
import StyleCore from "./style"
|
import StyleCore from "./style"
|
||||||
|
import PermissionsCore from "./permissions"
|
||||||
|
|
||||||
import I18nCore from "./i18n"
|
import I18nCore from "./i18n"
|
||||||
import NotificationsCore from "./notifications"
|
import NotificationsCore from "./notifications"
|
||||||
@ -13,6 +14,7 @@ import mediaPlayer from "./mediaPlayer"
|
|||||||
export default [
|
export default [
|
||||||
SettingsCore,
|
SettingsCore,
|
||||||
APICore,
|
APICore,
|
||||||
|
PermissionsCore,
|
||||||
StyleCore,
|
StyleCore,
|
||||||
I18nCore,
|
I18nCore,
|
||||||
SoundCore,
|
SoundCore,
|
||||||
|
43
packages/app/src/cores/permissions/index.js
Normal file
43
packages/app/src/cores/permissions/index.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import Core from "evite/src/core"
|
||||||
|
import UserModel from "models/user"
|
||||||
|
|
||||||
|
export default class PermissionsCore extends Core {
|
||||||
|
publicMethods = {
|
||||||
|
permissions: this
|
||||||
|
}
|
||||||
|
|
||||||
|
isUserAdmin = "unchecked"
|
||||||
|
|
||||||
|
// this will works with a newer version of evite
|
||||||
|
async initializeBeforeRuntimeInit() {
|
||||||
|
this.isUserAdmin = await UserModel.hasAdmin()
|
||||||
|
}
|
||||||
|
|
||||||
|
hasAdmin = async () => {
|
||||||
|
return await UserModel.hasAdmin()
|
||||||
|
}
|
||||||
|
|
||||||
|
hasPermission = async (permission) => {
|
||||||
|
let query = []
|
||||||
|
|
||||||
|
if (Array.isArray(permission)) {
|
||||||
|
query = permission
|
||||||
|
} else {
|
||||||
|
query = [permission]
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a promise and check if the user has all the permission in the query
|
||||||
|
const result = await Promise.all(query.map(async (permission) => {
|
||||||
|
const hasPermission = await UserModel.hasRole(permission)
|
||||||
|
|
||||||
|
return hasPermission
|
||||||
|
}))
|
||||||
|
|
||||||
|
// if the user has all the permission in the query, return true
|
||||||
|
if (result.every((hasPermission) => hasPermission)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user