All files / src/components RoleGate.vue

0% Statements 0/11
100% Branches 1/1
100% Functions 1/1
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                                                   
<script setup lang="ts">
import { computed } from "vue"
import { useRole } from "@/composables/useRole"
 
/**
 * Conditional slot wrapper for permission-gated template content.
 *
 *   <RoleGate admin>…</RoleGate>          – nur Admins sehen den Slot
 *   <RoleGate staff>…</RoleGate>          – Teacher + Admin
 *   <RoleGate :can="canEditApp(app)">…</RoleGate>
 *
 * The capability checks (``can``) are evaluated by the parent and
 * passed in as a plain boolean — the gate component itself stays
 * thin and does not know about specific resources.
 */
const props = defineProps<{
  admin?: boolean
  staff?: boolean
  can?: boolean
}>()
 
const { isAdmin, isStaff } = useRole()
const allow = computed(() => {
  if (props.admin) return isAdmin.value
  if (props.staff) return isStaff.value
  if (props.can !== undefined) return props.can
  return true
})
</script>
 
<template>
  <slot v-if="allow" />
</template>