feat: mirror v-can guard chains

This commit is contained in:
stanig2106
2025-11-14 19:23:18 +01:00
parent 2c4fe3f353
commit 7d823307fa
16 changed files with 573 additions and 138 deletions

View File

@@ -4,7 +4,7 @@ const granted = new Set([
'contract.create',
])
export function __can__(path: string[]) {
const key = Array.isArray(path) ? path.join('.') : String(path)
export function __can__(...path: string[]) {
const key = path.join('.')
return granted.has(key)
}

31
test/fixtures/chains/app.vue vendored Normal file
View File

@@ -0,0 +1,31 @@
<template>
<main>
<section>
<div id="branch-draft" v-if="phase === 'draft'" v-can="can.employee.view">
Draft
</div>
<div id="branch-pending" v-else-if="phase === 'pending'">
Pending
</div>
<div id="branch-fallback" v-else>
Fallback
</div>
<p id="branch-denied" v-cannot>
Permission missing
</p>
</section>
<section>
<button id="approve-action" v-can="can.contract.approve">
Approve
</button>
<p id="explicit-denied" v-cannot="can.contract.approve">
Need contract.approve
</p>
</section>
</main>
</template>
<script setup lang="ts">
const phase = 'pending'
</script>

12
test/fixtures/chains/nuxt.config.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
import NuxtCan from '../../../src/module'
export default defineNuxtConfig({
modules: [NuxtCan],
nuxtCan: {
permissions: {
employee: ['view'],
contract: ['approve'],
},
canFunctionImport: '~/permissions/__can__',
},
})

5
test/fixtures/chains/package.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"private": true,
"name": "chains",
"type": "module"
}

View File

@@ -0,0 +1,6 @@
const granted = new Set<string>([])
export function __can__(...path: string[]) {
const key = path.join('.')
return granted.has(key)
}