@crombolo/schema 0.62.0 → 0.63.0
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 +3 -3
- package/src/user-groups.ts +26 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Schema-as-code for crombolo: TOML document, media and member type definitions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
32
|
-
"@crombolo/data": "0.
|
|
31
|
+
"@crombolo/core": "0.63.0",
|
|
32
|
+
"@crombolo/data": "0.63.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/user-groups.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `schema/user-groups/*.toml` — user groups a site declares (story 228): what a
|
|
3
|
-
* group is (its name, sections, permission verbs and
|
|
4
|
-
* starts or who is in it, which each environment's Users section keeps. Strict
|
|
3
|
+
* group is (its name, sections, permission verbs, languages and owners), never
|
|
4
|
+
* where it starts or who is in it, which each environment's Users section keeps. Strict
|
|
5
5
|
* as the type parser is, and canonical on the way out, so
|
|
6
6
|
* `parseUserGroup(writeUserGroup(x))` equals `x`. `docs/schema-as-code.md`.
|
|
7
7
|
*/
|
|
8
8
|
import {
|
|
9
9
|
ADMIN_GROUP_ALIAS,
|
|
10
10
|
isExtensionSectionAlias,
|
|
11
|
+
isRemotePermission,
|
|
11
12
|
KNOWN_PERMISSIONS,
|
|
12
13
|
RETIRED_SECTIONS,
|
|
13
14
|
SECTION_ALIASES,
|
|
15
|
+
withoutPrunedPermissions,
|
|
14
16
|
} from '@crombolo/core'
|
|
15
17
|
import { type ParseResult, Reader, toml } from './reader.ts'
|
|
16
18
|
|
|
@@ -24,9 +26,20 @@ export interface SchemaUserGroup {
|
|
|
24
26
|
permissions: string[]
|
|
25
27
|
/** ISO codes, or every language. */
|
|
26
28
|
languages: string[] | 'all'
|
|
29
|
+
/** The aliases of the groups whose members choose who is in it (story 302). */
|
|
30
|
+
owners?: string[]
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
const KEYS = [
|
|
33
|
+
const KEYS = [
|
|
34
|
+
'alias',
|
|
35
|
+
'name',
|
|
36
|
+
'description',
|
|
37
|
+
'icon',
|
|
38
|
+
'sections',
|
|
39
|
+
'permissions',
|
|
40
|
+
'languages',
|
|
41
|
+
'owners',
|
|
42
|
+
]
|
|
30
43
|
|
|
31
44
|
export function parseUserGroup(file: string, source: string): ParseResult<SchemaUserGroup> {
|
|
32
45
|
const r = new Reader(file)
|
|
@@ -55,7 +68,8 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
55
68
|
`${path}.sections`,
|
|
56
69
|
`"${section}" is not a section: one of ${Object.keys(SECTION_ALIASES).join(', ')}, or an extension's section alias`,
|
|
57
70
|
)
|
|
58
|
-
|
|
71
|
+
// A verb story 338 took out is read as what replaced it, so a file written before still loads.
|
|
72
|
+
const permissions = withoutPrunedPermissions(r.strs(t, 'permissions', path))
|
|
59
73
|
for (const permission of permissions)
|
|
60
74
|
if (!KNOWN_PERMISSIONS.has(permission))
|
|
61
75
|
r.problem(
|
|
@@ -65,6 +79,12 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
65
79
|
let languages: string[] | 'all' = []
|
|
66
80
|
if (t.languages === 'all') languages = 'all'
|
|
67
81
|
else if (t.languages !== undefined) languages = r.strs(t, 'languages', path)
|
|
82
|
+
const owners = t.owners === undefined ? undefined : r.strs(t, 'owners', path)
|
|
83
|
+
if (owners?.length && permissions.some(isRemotePermission))
|
|
84
|
+
r.problem(
|
|
85
|
+
`${path}.owners`,
|
|
86
|
+
"a group that can move sites or install code is only an administrator's to fill, so it cannot have owners",
|
|
87
|
+
)
|
|
68
88
|
const description = r.str(t, 'description', path)
|
|
69
89
|
const icon = r.str(t, 'icon', path)
|
|
70
90
|
const value: SchemaUserGroup = {
|
|
@@ -75,6 +95,7 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
75
95
|
sections,
|
|
76
96
|
permissions,
|
|
77
97
|
languages,
|
|
98
|
+
...(owners !== undefined ? { owners } : {}),
|
|
78
99
|
}
|
|
79
100
|
return { value: r.problems.length === 0 ? value : undefined, problems: r.problems }
|
|
80
101
|
}
|
|
@@ -91,5 +112,6 @@ export function writeUserGroup(group: SchemaUserGroup): string {
|
|
|
91
112
|
`permissions = ${list(group.permissions)}`,
|
|
92
113
|
`languages = ${group.languages === 'all' ? '"all"' : list(group.languages)}`,
|
|
93
114
|
)
|
|
115
|
+
if (group.owners !== undefined) out.push(`owners = ${list(group.owners)}`)
|
|
94
116
|
return `${out.join('\n')}\n`
|
|
95
117
|
}
|