@contember/engine-content-api 1.0.0-alpha.1 → 1.0.0-alpha.2
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/dist/src/acl/VariableUtils.d.ts +5 -1
- package/dist/src/acl/VariableUtils.d.ts.map +1 -1
- package/dist/src/acl/VariableUtils.js +25 -7
- package/dist/src/acl/VariableUtils.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/cases/unit/aclVariablesFactory.test.d.ts +2 -0
- package/dist/tests/cases/unit/aclVariablesFactory.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/aclVariablesFactory.test.js +86 -0
- package/dist/tests/cases/unit/aclVariablesFactory.test.js.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/acl/VariableUtils.ts +34 -10
- package/tests/cases/unit/aclVariablesFactory.test.ts +73 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-content-api",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src/index.d.ts",
|
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
"test": "uvu dist/tests/cases/ \\.js$"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@contember/database": "^1.0.0-alpha.
|
|
13
|
-
"@contember/dic": "^1.0.0-alpha.
|
|
14
|
-
"@contember/engine-common": "^1.0.0-alpha.
|
|
15
|
-
"@contember/graphql-utils": "^1.0.0-alpha.
|
|
16
|
-
"@contember/schema": "^1.0.0-alpha.
|
|
17
|
-
"@contember/schema-utils": "^1.0.0-alpha.
|
|
12
|
+
"@contember/database": "^1.0.0-alpha.2",
|
|
13
|
+
"@contember/dic": "^1.0.0-alpha.2",
|
|
14
|
+
"@contember/engine-common": "^1.0.0-alpha.2",
|
|
15
|
+
"@contember/graphql-utils": "^1.0.0-alpha.2",
|
|
16
|
+
"@contember/schema": "^1.0.0-alpha.2",
|
|
17
|
+
"@contember/schema-utils": "^1.0.0-alpha.2",
|
|
18
18
|
"@graphql-tools/schema": "^7.1.5",
|
|
19
19
|
"graphql-tag": "^2.12.5"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@contember/database-tester": "^1.0.0-alpha.
|
|
23
|
-
"@contember/engine-api-tester": "^1.0.0-alpha.
|
|
24
|
-
"@contember/schema-definition": "^1.0.0-alpha.
|
|
22
|
+
"@contember/database-tester": "^1.0.0-alpha.2",
|
|
23
|
+
"@contember/engine-api-tester": "^1.0.0-alpha.2",
|
|
24
|
+
"@contember/schema-definition": "^1.0.0-alpha.2",
|
|
25
25
|
"@graphql-codegen/cli": "^1.15.2",
|
|
26
26
|
"@graphql-codegen/typescript": "^1.15.2",
|
|
27
27
|
"@graphql-codegen/typescript-operations": "^1.15.2",
|
package/src/acl/VariableUtils.ts
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import { Acl } from '@contember/schema'
|
|
2
|
+
import { getRoleVariables } from '@contember/schema-utils'
|
|
2
3
|
|
|
3
4
|
type Memberships = readonly { role: string; variables: readonly { name: string; values: readonly string[] }[] }[]
|
|
4
5
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
export const createAclVariables = (
|
|
7
|
+
aclSchema: Acl.Schema,
|
|
8
|
+
identity: {
|
|
9
|
+
identityId: string
|
|
10
|
+
personId: string | null
|
|
11
|
+
memberships: Memberships
|
|
12
|
+
},
|
|
13
|
+
): Acl.VariablesMap => {
|
|
14
|
+
|
|
15
|
+
const variablesEntries = identity.memberships.flatMap(
|
|
16
|
+
membership => {
|
|
17
|
+
const roleVariables = getRoleVariables(membership.role, aclSchema)
|
|
18
|
+
const membershipVariablesMap = Object.fromEntries(membership.variables.map(it => [it.name, it.values]))
|
|
19
|
+
|
|
20
|
+
return Object.entries(roleVariables).map(([name, def]) => {
|
|
21
|
+
const prefixed = prefixVariable(membership.role, name)
|
|
22
|
+
|
|
23
|
+
switch (def.type) {
|
|
24
|
+
case Acl.VariableType.entity:
|
|
25
|
+
return [prefixed, membershipVariablesMap[name] ?? []]
|
|
26
|
+
case Acl.VariableType.predefined:
|
|
27
|
+
switch (def.value) {
|
|
28
|
+
case 'identityID':
|
|
29
|
+
return [prefixed, [identity.identityId]]
|
|
30
|
+
case 'personID':
|
|
31
|
+
return [prefixed, identity.personId ? [identity.personId] : []]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
},
|
|
15
36
|
)
|
|
37
|
+
|
|
38
|
+
return Object.fromEntries(variablesEntries)
|
|
16
39
|
}
|
|
40
|
+
|
|
17
41
|
export const prefixVariable = (role: string, variableName: string) => `${role}__${variableName}`
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as assert from 'uvu/assert'
|
|
2
|
+
import { suite } from 'uvu'
|
|
3
|
+
import { createAclVariables } from '../../../src'
|
|
4
|
+
import { Acl } from '@contember/schema'
|
|
5
|
+
import { testUuid } from '@contember/engine-api-tester'
|
|
6
|
+
|
|
7
|
+
const createAclVariablesTest = suite('create acl variables')
|
|
8
|
+
|
|
9
|
+
createAclVariablesTest('prefix from memberships', () => {
|
|
10
|
+
assert.equal(createAclVariables({
|
|
11
|
+
roles: {
|
|
12
|
+
author: {
|
|
13
|
+
stages: '*',
|
|
14
|
+
variables: {
|
|
15
|
+
authorID: { type: Acl.VariableType.entity, entityName: 'Author' },
|
|
16
|
+
},
|
|
17
|
+
entities: {
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}, {
|
|
22
|
+
identityId: testUuid(1),
|
|
23
|
+
personId: null,
|
|
24
|
+
memberships: [{ role: 'author', variables: [{ name: 'authorID', values: [testUuid(2)] }] }],
|
|
25
|
+
}), {
|
|
26
|
+
author__authorID: [testUuid(2)],
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
createAclVariablesTest('undefined variable', () => {
|
|
32
|
+
assert.equal(createAclVariables({
|
|
33
|
+
roles: {
|
|
34
|
+
author: {
|
|
35
|
+
stages: '*',
|
|
36
|
+
variables: {
|
|
37
|
+
authorID: { type: Acl.VariableType.entity, entityName: 'Author' },
|
|
38
|
+
},
|
|
39
|
+
entities: {},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}, {
|
|
43
|
+
identityId: testUuid(1),
|
|
44
|
+
personId: null,
|
|
45
|
+
memberships: [{ role: 'author', variables: [] }],
|
|
46
|
+
}), {
|
|
47
|
+
author__authorID: [],
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
createAclVariablesTest('predefined', () => {
|
|
53
|
+
assert.equal(createAclVariables({
|
|
54
|
+
roles: {
|
|
55
|
+
author: {
|
|
56
|
+
stages: '*',
|
|
57
|
+
variables: {
|
|
58
|
+
authorIdentity: { type: Acl.VariableType.predefined, value: 'identityID' },
|
|
59
|
+
},
|
|
60
|
+
entities: {},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
}, {
|
|
64
|
+
identityId: testUuid(1),
|
|
65
|
+
personId: null,
|
|
66
|
+
memberships: [{ role: 'author', variables: [] }],
|
|
67
|
+
}), {
|
|
68
|
+
author__authorIdentity: [testUuid(1)],
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
createAclVariablesTest.run()
|