feat: mirror v-can guard chains
This commit is contained in:
4
test/fixtures/basic/permissions/__can__.ts
vendored
4
test/fixtures/basic/permissions/__can__.ts
vendored
@@ -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
31
test/fixtures/chains/app.vue
vendored
Normal 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
12
test/fixtures/chains/nuxt.config.ts
vendored
Normal 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
5
test/fixtures/chains/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "chains",
|
||||
"type": "module"
|
||||
}
|
||||
6
test/fixtures/chains/permissions/__can__.ts
vendored
Normal file
6
test/fixtures/chains/permissions/__can__.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
const granted = new Set<string>([])
|
||||
|
||||
export function __can__(...path: string[]) {
|
||||
const key = path.join('.')
|
||||
return granted.has(key)
|
||||
}
|
||||
Reference in New Issue
Block a user