feat: wire global runtime injection and playground
This commit is contained in:
80
test/fixtures/basic/app.vue
vendored
80
test/fixtures/basic/app.vue
vendored
@@ -1,6 +1,82 @@
|
||||
<template>
|
||||
<div>basic</div>
|
||||
<main>
|
||||
<h1>basic</h1>
|
||||
|
||||
<section>
|
||||
<button
|
||||
id="can-view"
|
||||
v-can="canProxy.employee.view"
|
||||
>
|
||||
Voir
|
||||
</button>
|
||||
|
||||
<button
|
||||
v-if="isReady"
|
||||
id="can-edit"
|
||||
v-can="canProxy.employee.edit"
|
||||
>
|
||||
Editer
|
||||
</button>
|
||||
<p
|
||||
id="cannot-edit"
|
||||
v-cannot
|
||||
>
|
||||
Refus
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<template v-if="showContracts">
|
||||
<p v-can="canProxy.contract.create">
|
||||
Creation contrat
|
||||
</p>
|
||||
<p v-cannot>
|
||||
Pas de creation
|
||||
</p>
|
||||
</template>
|
||||
<p v-else>
|
||||
Section contrats masquee, aucune directive appliquee.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Suppression</h2>
|
||||
<button
|
||||
id="can-delete"
|
||||
v-can="canProxy.employee.delete"
|
||||
>
|
||||
Supprimer
|
||||
</button>
|
||||
<p
|
||||
id="cannot-delete"
|
||||
v-cannot
|
||||
>
|
||||
Suppression interdite
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<p id="path-display">
|
||||
{{ String(canProxy.employee.view) }}
|
||||
</p>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<script setup lang="ts">
|
||||
const isReady = true
|
||||
const showContracts = true
|
||||
interface FixturePermissions {
|
||||
employee: {
|
||||
view: boolean
|
||||
edit: boolean
|
||||
delete: boolean
|
||||
}
|
||||
contract: {
|
||||
create: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const nuxtApp = useNuxtApp()
|
||||
const canProxy = nuxtApp.$can as unknown as FixturePermissions
|
||||
</script>
|
||||
|
||||
11
test/fixtures/basic/nuxt.config.ts
vendored
11
test/fixtures/basic/nuxt.config.ts
vendored
@@ -1,7 +1,14 @@
|
||||
import MyModule from '../../../src/module'
|
||||
import NuxtCan from '../../../src/module'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
modules: [
|
||||
MyModule,
|
||||
NuxtCan,
|
||||
],
|
||||
nuxtCan: {
|
||||
permissions: {
|
||||
employee: ['view', 'edit', 'delete'],
|
||||
contract: ['create'],
|
||||
},
|
||||
canFunctionImport: '~/permissions/__can__',
|
||||
},
|
||||
})
|
||||
|
||||
10
test/fixtures/basic/permissions/__can__.ts
vendored
Normal file
10
test/fixtures/basic/permissions/__can__.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
const granted = new Set([
|
||||
'employee.view',
|
||||
'employee.edit',
|
||||
'contract.create',
|
||||
])
|
||||
|
||||
export function __can__(path: string[]) {
|
||||
const key = Array.isArray(path) ? path.join('.') : String(path)
|
||||
return granted.has(key)
|
||||
}
|
||||
Reference in New Issue
Block a user