Files
FEDEO/composables/useRole.js

91 lines
1.9 KiB
JavaScript

export const useRole = () => {
const supabase = useSupabaseClient()
const dataStore = useDataStore()
const rights = ref({
projects: {
label: "Projekte"
},
"projects-viewAll": {
label: "Alle Projekte einsehen",
parent: "projects"
},
"projects-viewOwn": {
label: "Eigene Projekte einsehen",
parent: "projects"
},
"projects-create": {
label: "Projekte erstellen",
parent: "projects"
},
contracts: {
label: "Verträge"
},
objects: {
label: "Objekte"
},
checks: {
label: "Überprüfungen"
},
})
let role = dataStore.activeProfile.role
/*const checkRight = (right) => {
let rightsToCheck = [right]
if(rights.value[right].parent) {
rightsToCheck.push(rights.value[right].parent)
}
let hasAllNeccessaryRights = false
rightsToCheck.forEach(i => {
if(role.rights.includes(i)){
hasAllNeccessaryRights = true
} else {
hasAllNeccessaryRights = false
}
})
return hasAllNeccessaryRights
}*/
const checkRight = (right) => {
let rightsToCheck = [right]
//console.log(right.split("-"))
if(right.split("-").length > 1) {
rightsToCheck.push(right.split("-")[0])
}
//console.log(rightsToCheck)
let hasAllNeccessaryRights = true
//console.log(role.rights)
rightsToCheck.forEach(i => {
if(!role.rights.includes(i)){
hasAllNeccessaryRights = false
}
})
//console.log(hasAllNeccessaryRights)
return hasAllNeccessaryRights
}
return {
role,
checkRight
}
}