@kernhq/module-quire 0.16.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kernhq/module-quire",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"description": "Kern Quire: collaborative documents, spaces and page trees",
|
|
5
5
|
"homepage": "https://github.com/KernAIO/module-quire#readme",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"@changesets/cli": "^2.27.0",
|
|
72
72
|
"@kernhq/contracts": "^0.7.0",
|
|
73
73
|
"@kernhq/kernel": "^0.9.0",
|
|
74
|
+
"@kernhq/testing": "^0.1.12",
|
|
74
75
|
"@kernhq/tsconfig": "^0.1.0",
|
|
75
76
|
"@kernhq/ui": "^0.14.0",
|
|
76
77
|
"@tanstack/svelte-query": "^6.1.0",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Quire permission matrix, blessed rather than assumed.
|
|
3
|
+
*
|
|
4
|
+
* Defaults are declared one permission at a time, which makes the whole picture — which built-in
|
|
5
|
+
* role ends up holding what — impossible to read from any single line. This writes it out in full
|
|
6
|
+
* and compares it against what the module declares. Rows list the *effective* grants, cascade
|
|
7
|
+
* included: the kernel expands declared `defaultRoles` upward through guest ⊆ member ⊆ admin ⊆
|
|
8
|
+
* owner, and `permissionMatrixDiff` applies the same expansion.
|
|
9
|
+
*
|
|
10
|
+
* Changing a default is meant to be deliberate: edit `defaultRoles` → this fails naming every row
|
|
11
|
+
* that moved → confirm that is what you meant → update `BLESSED` in the same commit.
|
|
12
|
+
*/
|
|
13
|
+
import { permissionMatrixDiff } from '@kernhq/testing'
|
|
14
|
+
import { describe, expect, it } from 'vitest'
|
|
15
|
+
import { quirePermissions } from './permissions.js'
|
|
16
|
+
|
|
17
|
+
/** Every built-in role that holds the permission by default, lowest role first. */
|
|
18
|
+
const BLESSED: Record<string, readonly string[]> = {
|
|
19
|
+
'quire.space.view': ['guest', 'member', 'admin', 'owner'],
|
|
20
|
+
'quire.space.manage': ['admin', 'owner'],
|
|
21
|
+
'quire.page.view': ['guest', 'member', 'admin', 'owner'],
|
|
22
|
+
'quire.page.create': ['member', 'admin', 'owner'],
|
|
23
|
+
'quire.page.edit': ['member', 'admin', 'owner'],
|
|
24
|
+
'quire.page.comment': ['guest', 'member', 'admin', 'owner'],
|
|
25
|
+
'quire.page.publish': ['member', 'admin', 'owner'],
|
|
26
|
+
'quire.page.export': ['member', 'admin', 'owner'],
|
|
27
|
+
'quire.page.import': ['admin', 'owner'],
|
|
28
|
+
'quire.page.delete': ['admin', 'owner'],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Permissions whose misuse costs data: an import overwrites, a delete removes. */
|
|
32
|
+
const DANGEROUS = ['quire.page.import', 'quire.page.delete']
|
|
33
|
+
|
|
34
|
+
describe('quire permissions', () => {
|
|
35
|
+
it('grants each permission to exactly the blessed roles', () => {
|
|
36
|
+
expect(permissionMatrixDiff(quirePermissions, BLESSED)).toEqual([])
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('namespaces every key under the module id and declares it once', () => {
|
|
40
|
+
const keys = quirePermissions.map((p) => p.key)
|
|
41
|
+
expect(keys.filter((key) => !key.startsWith('quire.'))).toEqual([])
|
|
42
|
+
expect(keys.filter((key, i) => keys.indexOf(key) !== i)).toEqual([])
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('marks exactly the destructive permissions dangerous', () => {
|
|
46
|
+
const flagged = quirePermissions.filter((p) => p.dangerous).map((p) => p.key)
|
|
47
|
+
expect(flagged.toSorted()).toEqual(DANGEROUS.toSorted())
|
|
48
|
+
})
|
|
49
|
+
})
|