@contember/engine-content-api 1.2.0-alpha.1 → 1.2.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/VariableInjector.d.ts.map +1 -1
- package/dist/src/acl/VariableInjector.js +9 -7
- package/dist/src/acl/VariableInjector.js.map +1 -1
- package/dist/src/acl/VariableUtils.d.ts.map +1 -1
- package/dist/src/acl/VariableUtils.js +18 -12
- package/dist/src/acl/VariableUtils.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js +6 -1
- package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/acl/setField.test.js +12 -2
- package/dist/tests/cases/integration/graphQlRequests/insert/acl/setField.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/aclInsert.test.js +6 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/aclInsert.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.js +24 -4
- package/dist/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.js +6 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js +24 -4
- package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js.map +1 -1
- package/dist/tests/cases/unit/aclVariablesFactory.test.js +8 -6
- package/dist/tests/cases/unit/aclVariablesFactory.test.js.map +1 -1
- package/dist/tests/cases/unit/predicatesInjector.test.js +12 -6
- package/dist/tests/cases/unit/predicatesInjector.test.js.map +1 -1
- package/dist/tests/cases/unit/variableInjector.test.js +15 -3
- package/dist/tests/cases/unit/variableInjector.test.js.map +1 -1
- package/dist/tests/src/testGraphql.d.ts.map +1 -1
- package/dist/tests/src/testGraphql.js +4 -1
- package/dist/tests/src/testGraphql.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/acl/VariableInjector.ts +10 -8
- package/src/acl/VariableUtils.ts +18 -13
- package/tests/cases/integration/graphQlRequests/delete/aclDelete.test.ts +7 -2
- package/tests/cases/integration/graphQlRequests/insert/acl/setField.test.ts +13 -3
- package/tests/cases/integration/graphQlRequests/insert/aclInsert.test.ts +7 -2
- package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +24 -4
- package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +6 -1
- package/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.ts +25 -5
- package/tests/cases/unit/aclVariablesFactory.test.ts +8 -6
- package/tests/cases/unit/predicatesInjector.test.ts +12 -6
- package/tests/cases/unit/variableInjector.test.ts +17 -5
- package/tests/src/testGraphql.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-content-api",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src/index.d.ts",
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"test": "vitest --no-threads"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@contember/database": "^1.2.0-alpha.
|
|
14
|
-
"@contember/dic": "^1.2.0-alpha.
|
|
15
|
-
"@contember/engine-common": "^1.2.0-alpha.
|
|
16
|
-
"@contember/graphql-utils": "^1.2.0-alpha.
|
|
17
|
-
"@contember/schema": "^1.2.0-alpha.
|
|
18
|
-
"@contember/schema-utils": "^1.2.0-alpha.
|
|
13
|
+
"@contember/database": "^1.2.0-alpha.2",
|
|
14
|
+
"@contember/dic": "^1.2.0-alpha.2",
|
|
15
|
+
"@contember/engine-common": "^1.2.0-alpha.2",
|
|
16
|
+
"@contember/graphql-utils": "^1.2.0-alpha.2",
|
|
17
|
+
"@contember/schema": "^1.2.0-alpha.2",
|
|
18
|
+
"@contember/schema-utils": "^1.2.0-alpha.2",
|
|
19
19
|
"@graphql-tools/schema": "^8.3.5",
|
|
20
20
|
"graphql-tag": "^2.12.5"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@contember/database-tester": "^1.2.0-alpha.
|
|
24
|
-
"@contember/engine-api-tester": "^1.2.0-alpha.
|
|
25
|
-
"@contember/schema-definition": "^1.2.0-alpha.
|
|
23
|
+
"@contember/database-tester": "^1.2.0-alpha.2",
|
|
24
|
+
"@contember/engine-api-tester": "^1.2.0-alpha.2",
|
|
25
|
+
"@contember/schema-definition": "^1.2.0-alpha.2",
|
|
26
26
|
"@graphql-codegen/cli": "^1.15.2",
|
|
27
27
|
"@graphql-codegen/typescript": "^1.15.2",
|
|
28
28
|
"@graphql-codegen/typescript-operations": "^1.15.2",
|
|
@@ -23,16 +23,18 @@ export class VariableInjector {
|
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
private createCondition(variable: Acl.
|
|
27
|
-
if (variable === undefined) {
|
|
26
|
+
private createCondition(variable: Acl.VariableMapEntry | undefined): Input.Condition {
|
|
27
|
+
if (variable === undefined || variable.value.length === 0) {
|
|
28
28
|
return { never: true }
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
|
|
31
|
+
const { value, definition } = variable
|
|
32
|
+
if (definition.type === Acl.VariableType.condition) {
|
|
33
|
+
if (value.length === 1) {
|
|
34
|
+
return value[0] as Input.Condition
|
|
35
|
+
}
|
|
36
|
+
return { or: value as Input.Condition[] }
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
return { in: value as (string | number)[] }
|
|
37
39
|
}
|
|
38
40
|
}
|
package/src/acl/VariableUtils.ts
CHANGED
|
@@ -17,20 +17,25 @@ export const createAclVariables = (
|
|
|
17
17
|
const roleVariables = getRoleVariables(membership.role, aclSchema)
|
|
18
18
|
const membershipVariablesMap = Object.fromEntries(membership.variables.map(it => [it.name, it.values]))
|
|
19
19
|
|
|
20
|
-
return Object.entries(roleVariables).map(([name, def]) => {
|
|
20
|
+
return Object.entries(roleVariables).map(([name, def]): [string, Acl.VariableMapEntry] => {
|
|
21
21
|
const prefixed = prefixVariable(membership.role, name)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
const value = (() => {
|
|
23
|
+
switch (def.type) {
|
|
24
|
+
case Acl.VariableType.entity:
|
|
25
|
+
return membershipVariablesMap[name] ?? []
|
|
26
|
+
case Acl.VariableType.predefined:
|
|
27
|
+
switch (def.value) {
|
|
28
|
+
case 'identityID':
|
|
29
|
+
return [identity.identityId]
|
|
30
|
+
case 'personID':
|
|
31
|
+
return identity.personId ? [identity.personId] : []
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Unknown predefined variable ${def.value}`)
|
|
34
|
+
case Acl.VariableType.condition:
|
|
35
|
+
return (membershipVariablesMap[name] ?? []).map(it => JSON.parse(it))
|
|
36
|
+
}
|
|
37
|
+
})()
|
|
38
|
+
return [prefixed, { value: value, definition: def }]
|
|
34
39
|
})
|
|
35
40
|
},
|
|
36
41
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test } from 'vitest'
|
|
2
2
|
import { execute, sqlDeferred, sqlTransaction } from '../../../../src/test'
|
|
3
3
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
4
|
-
import { Model } from '@contember/schema'
|
|
4
|
+
import { Acl, Model } from '@contember/schema'
|
|
5
5
|
import { GQL, SQL } from '../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../src/testUuid'
|
|
7
7
|
|
|
@@ -32,7 +32,12 @@ test('delete post with acl', async () => {
|
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
34
|
variables: {
|
|
35
|
-
locale_variable:
|
|
35
|
+
locale_variable: {
|
|
36
|
+
definition: {
|
|
37
|
+
type: Acl.VariableType.condition,
|
|
38
|
+
},
|
|
39
|
+
value: [{ in: ['cs'] }],
|
|
40
|
+
},
|
|
36
41
|
},
|
|
37
42
|
executes: [
|
|
38
43
|
...sqlTransaction([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test } from 'vitest'
|
|
2
2
|
import { execute, failedTransaction, sqlTransaction } from '../../../../../src/test'
|
|
3
3
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
4
|
-
import { Model } from '@contember/schema'
|
|
4
|
+
import { Acl, Model } from '@contember/schema'
|
|
5
5
|
import { GQL, SQL } from '../../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../../src/testUuid'
|
|
7
7
|
|
|
@@ -34,7 +34,12 @@ test('set a name - allowed', async () => {
|
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
variables: {
|
|
37
|
-
name_variable:
|
|
37
|
+
name_variable: {
|
|
38
|
+
definition: {
|
|
39
|
+
type: Acl.VariableType.condition,
|
|
40
|
+
},
|
|
41
|
+
value: [{ in: ['John', 'Jack'] }],
|
|
42
|
+
},
|
|
38
43
|
},
|
|
39
44
|
executes: [
|
|
40
45
|
...sqlTransaction([
|
|
@@ -89,7 +94,12 @@ test('set a name - denied', async () => {
|
|
|
89
94
|
},
|
|
90
95
|
},
|
|
91
96
|
variables: {
|
|
92
|
-
name_variable:
|
|
97
|
+
name_variable: {
|
|
98
|
+
definition: {
|
|
99
|
+
type: Acl.VariableType.condition,
|
|
100
|
+
},
|
|
101
|
+
value: [{ in: ['John', 'Jack'] }],
|
|
102
|
+
},
|
|
93
103
|
},
|
|
94
104
|
executes: [
|
|
95
105
|
...failedTransaction([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test } from 'vitest'
|
|
2
2
|
import { execute, sqlTransaction } from '../../../../src/test'
|
|
3
3
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
4
|
-
import { Model } from '@contember/schema'
|
|
4
|
+
import { Acl, Model } from '@contember/schema'
|
|
5
5
|
import { GQL, SQL } from '../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../src/testUuid'
|
|
7
7
|
|
|
@@ -27,7 +27,12 @@ test('insert author (with acl)', async () => {
|
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
29
|
variables: {
|
|
30
|
-
name_variable:
|
|
30
|
+
name_variable: {
|
|
31
|
+
definition: {
|
|
32
|
+
type: Acl.VariableType.condition,
|
|
33
|
+
},
|
|
34
|
+
value: [{ in: ['John', 'Jack'] }],
|
|
35
|
+
},
|
|
31
36
|
},
|
|
32
37
|
query: GQL`
|
|
33
38
|
mutation {
|
|
@@ -45,7 +45,12 @@ test('querying id and title', async () => {
|
|
|
45
45
|
schema: schema,
|
|
46
46
|
permissions: permissions,
|
|
47
47
|
variables: {
|
|
48
|
-
localeVariable:
|
|
48
|
+
localeVariable: {
|
|
49
|
+
definition: {
|
|
50
|
+
type: Acl.VariableType.condition,
|
|
51
|
+
},
|
|
52
|
+
value: [{ in: ['cs'] }],
|
|
53
|
+
},
|
|
49
54
|
},
|
|
50
55
|
query: GQL`
|
|
51
56
|
query {
|
|
@@ -121,7 +126,12 @@ test('querying with extra where', async () => {
|
|
|
121
126
|
schema: schema,
|
|
122
127
|
permissions: permissions,
|
|
123
128
|
variables: {
|
|
124
|
-
localeVariable:
|
|
129
|
+
localeVariable: {
|
|
130
|
+
definition: {
|
|
131
|
+
type: Acl.VariableType.condition,
|
|
132
|
+
},
|
|
133
|
+
value: [{ in: ['cs'] }],
|
|
134
|
+
},
|
|
125
135
|
},
|
|
126
136
|
query: GQL`
|
|
127
137
|
query {
|
|
@@ -167,7 +177,12 @@ test('querying only id', async () => {
|
|
|
167
177
|
schema: schema,
|
|
168
178
|
permissions: permissions,
|
|
169
179
|
variables: {
|
|
170
|
-
localeVariable:
|
|
180
|
+
localeVariable: {
|
|
181
|
+
definition: {
|
|
182
|
+
type: Acl.VariableType.condition,
|
|
183
|
+
},
|
|
184
|
+
value: [{ in: ['cs'] }],
|
|
185
|
+
},
|
|
171
186
|
},
|
|
172
187
|
query: GQL`
|
|
173
188
|
query {
|
|
@@ -239,7 +254,12 @@ test('querying on nested field', async () => {
|
|
|
239
254
|
schema: schema,
|
|
240
255
|
permissions: permissions,
|
|
241
256
|
variables: {
|
|
242
|
-
localeVariable:
|
|
257
|
+
localeVariable: {
|
|
258
|
+
definition: {
|
|
259
|
+
type: Acl.VariableType.condition,
|
|
260
|
+
},
|
|
261
|
+
value: [{ in: ['cs'] }],
|
|
262
|
+
},
|
|
243
263
|
},
|
|
244
264
|
query: GQL`
|
|
245
265
|
query {
|
|
@@ -58,7 +58,12 @@ test('querying post + author name', async () => {
|
|
|
58
58
|
schema: schema,
|
|
59
59
|
permissions: permissions,
|
|
60
60
|
variables: {
|
|
61
|
-
countryVariable:
|
|
61
|
+
countryVariable: {
|
|
62
|
+
definition: {
|
|
63
|
+
type: Acl.VariableType.condition,
|
|
64
|
+
},
|
|
65
|
+
value: [{ in: ['Czechia'] }],
|
|
66
|
+
},
|
|
62
67
|
},
|
|
63
68
|
query: GQL`
|
|
64
69
|
query {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test } from 'vitest'
|
|
2
2
|
import { execute, failedTransaction, sqlTransaction } from '../../../../../src/test'
|
|
3
3
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
4
|
-
import { Model } from '@contember/schema'
|
|
4
|
+
import { Acl, Model } from '@contember/schema'
|
|
5
5
|
import { GQL, SQL } from '../../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../../src/testUuid'
|
|
7
7
|
|
|
@@ -35,7 +35,12 @@ test('update name', async () => {
|
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
variables: {
|
|
38
|
-
name_variable:
|
|
38
|
+
name_variable: {
|
|
39
|
+
definition: {
|
|
40
|
+
type: Acl.VariableType.condition,
|
|
41
|
+
},
|
|
42
|
+
value: [{ in: ['John', 'Jack'] }],
|
|
43
|
+
},
|
|
39
44
|
},
|
|
40
45
|
executes: [
|
|
41
46
|
...sqlTransaction([
|
|
@@ -98,7 +103,12 @@ test('update name - denied', async () => {
|
|
|
98
103
|
},
|
|
99
104
|
},
|
|
100
105
|
variables: {
|
|
101
|
-
name_variable:
|
|
106
|
+
name_variable: {
|
|
107
|
+
definition: {
|
|
108
|
+
type: Acl.VariableType.condition,
|
|
109
|
+
},
|
|
110
|
+
value: [{ in: ['John', 'Jack'] }],
|
|
111
|
+
},
|
|
102
112
|
},
|
|
103
113
|
executes: [
|
|
104
114
|
...failedTransaction([
|
|
@@ -176,8 +186,18 @@ test('update m:n', async () => {
|
|
|
176
186
|
},
|
|
177
187
|
},
|
|
178
188
|
variables: {
|
|
179
|
-
post_name_variable:
|
|
180
|
-
|
|
189
|
+
post_name_variable: {
|
|
190
|
+
definition: {
|
|
191
|
+
type: Acl.VariableType.condition,
|
|
192
|
+
},
|
|
193
|
+
value: [{ in: ['Lorem ipsum', 'Dolor sit'] }],
|
|
194
|
+
},
|
|
195
|
+
category_name_variable: {
|
|
196
|
+
definition: {
|
|
197
|
+
type: Acl.VariableType.condition,
|
|
198
|
+
},
|
|
199
|
+
value: [{ in: ['foo', 'bar'] }],
|
|
200
|
+
},
|
|
181
201
|
},
|
|
182
202
|
query: GQL`mutation {
|
|
183
203
|
updatePost(by: {id: "${testUuid(1)}"}, data: {categories: [
|
|
@@ -5,13 +5,14 @@ import { testUuid } from '@contember/engine-api-tester'
|
|
|
5
5
|
|
|
6
6
|
describe('create acl variables', () => {
|
|
7
7
|
|
|
8
|
+
const definition: Acl.EntityVariable = { type: Acl.VariableType.entity, entityName: 'Author' }
|
|
8
9
|
it('prefix from memberships', () => {
|
|
9
10
|
assert.deepStrictEqual(createAclVariables({
|
|
10
11
|
roles: {
|
|
11
12
|
author: {
|
|
12
13
|
stages: '*',
|
|
13
14
|
variables: {
|
|
14
|
-
authorID:
|
|
15
|
+
authorID: definition,
|
|
15
16
|
},
|
|
16
17
|
entities: {
|
|
17
18
|
},
|
|
@@ -22,7 +23,7 @@ describe('create acl variables', () => {
|
|
|
22
23
|
personId: null,
|
|
23
24
|
memberships: [{ role: 'author', variables: [{ name: 'authorID', values: [testUuid(2)] }] }],
|
|
24
25
|
}), {
|
|
25
|
-
author__authorID: [testUuid(2)],
|
|
26
|
+
author__authorID: { definition, value: [testUuid(2)] },
|
|
26
27
|
})
|
|
27
28
|
})
|
|
28
29
|
|
|
@@ -33,7 +34,7 @@ describe('create acl variables', () => {
|
|
|
33
34
|
author: {
|
|
34
35
|
stages: '*',
|
|
35
36
|
variables: {
|
|
36
|
-
authorID:
|
|
37
|
+
authorID: definition,
|
|
37
38
|
},
|
|
38
39
|
entities: {},
|
|
39
40
|
},
|
|
@@ -43,18 +44,19 @@ describe('create acl variables', () => {
|
|
|
43
44
|
personId: null,
|
|
44
45
|
memberships: [{ role: 'author', variables: [] }],
|
|
45
46
|
}), {
|
|
46
|
-
author__authorID: [],
|
|
47
|
+
author__authorID: { definition, value: [] },
|
|
47
48
|
})
|
|
48
49
|
})
|
|
49
50
|
|
|
50
51
|
|
|
51
52
|
it('predefined', () => {
|
|
53
|
+
const definition: Acl.PredefinedVariable = { type: Acl.VariableType.predefined, value: 'identityID' }
|
|
52
54
|
assert.deepStrictEqual(createAclVariables({
|
|
53
55
|
roles: {
|
|
54
56
|
author: {
|
|
55
57
|
stages: '*',
|
|
56
58
|
variables: {
|
|
57
|
-
authorIdentity:
|
|
59
|
+
authorIdentity: definition,
|
|
58
60
|
},
|
|
59
61
|
entities: {},
|
|
60
62
|
},
|
|
@@ -64,7 +66,7 @@ describe('create acl variables', () => {
|
|
|
64
66
|
personId: null,
|
|
65
67
|
memberships: [{ role: 'author', variables: [] }],
|
|
66
68
|
}), {
|
|
67
|
-
author__authorIdentity: [testUuid(1)],
|
|
69
|
+
author__authorIdentity: { definition, value: [testUuid(1)] },
|
|
68
70
|
})
|
|
69
71
|
})
|
|
70
72
|
})
|
|
@@ -44,10 +44,18 @@ const permissions: Acl.Permissions = {
|
|
|
44
44
|
|
|
45
45
|
describe('Predicates injector', () => {
|
|
46
46
|
|
|
47
|
+
const variables: Acl.VariablesMap = {
|
|
48
|
+
localeVariable: {
|
|
49
|
+
definition: {
|
|
50
|
+
type: Acl.VariableType.condition,
|
|
51
|
+
},
|
|
52
|
+
value: [{ in: ['cs'] }],
|
|
53
|
+
},
|
|
54
|
+
}
|
|
47
55
|
it('injects predicate', () => {
|
|
48
56
|
const injector = new PredicatesInjector(
|
|
49
57
|
schema,
|
|
50
|
-
new PredicateFactory(permissions, new VariableInjector(schema,
|
|
58
|
+
new PredicateFactory(permissions, new VariableInjector(schema, variables)),
|
|
51
59
|
)
|
|
52
60
|
const result = injector.inject(schema.entities['PostLocale'], {})
|
|
53
61
|
|
|
@@ -59,7 +67,7 @@ describe('Predicates injector', () => {
|
|
|
59
67
|
it('merges predicate with explicit where', () => {
|
|
60
68
|
const injector = new PredicatesInjector(
|
|
61
69
|
schema,
|
|
62
|
-
new PredicateFactory(permissions, new VariableInjector(schema,
|
|
70
|
+
new PredicateFactory(permissions, new VariableInjector(schema, variables)),
|
|
63
71
|
)
|
|
64
72
|
const result = injector.inject(schema.entities['PostLocale'], { id: { in: [1, 2] } })
|
|
65
73
|
|
|
@@ -71,9 +79,7 @@ describe('Predicates injector', () => {
|
|
|
71
79
|
id: { in: [1, 2] },
|
|
72
80
|
},
|
|
73
81
|
{
|
|
74
|
-
locale: {
|
|
75
|
-
in: ['cs'],
|
|
76
|
-
},
|
|
82
|
+
locale: { in: ['cs'] },
|
|
77
83
|
},
|
|
78
84
|
],
|
|
79
85
|
},
|
|
@@ -87,7 +93,7 @@ describe('Predicates injector', () => {
|
|
|
87
93
|
it('injects predicate to where', () => {
|
|
88
94
|
const injector = new PredicatesInjector(
|
|
89
95
|
schema,
|
|
90
|
-
new PredicateFactory(permissions, new VariableInjector(schema,
|
|
96
|
+
new PredicateFactory(permissions, new VariableInjector(schema, variables)),
|
|
91
97
|
)
|
|
92
98
|
|
|
93
99
|
const result = injector.inject(schema.entities['PostLocale'], { title: { eq: 'abc' } })
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { VariableInjector } from '../../../src/acl'
|
|
2
2
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
3
|
-
import { Model } from '@contember/schema'
|
|
4
|
-
import { describe, it
|
|
3
|
+
import { Acl, Model } from '@contember/schema'
|
|
4
|
+
import { assert, describe, it } from 'vitest'
|
|
5
5
|
|
|
6
6
|
describe('Variable injector', () => {
|
|
7
7
|
|
|
@@ -17,9 +17,21 @@ describe('Variable injector', () => {
|
|
|
17
17
|
)
|
|
18
18
|
.buildSchema()
|
|
19
19
|
|
|
20
|
+
const ids = ['91528a5c-839b-4114-9952-d661914a607f', '1e2f3937-a0b1-4105-8aae-6da8ac9fc146']
|
|
20
21
|
const injector = new VariableInjector(schema, {
|
|
21
|
-
site:
|
|
22
|
-
|
|
22
|
+
site: {
|
|
23
|
+
definition: {
|
|
24
|
+
type: Acl.VariableType.entity,
|
|
25
|
+
entityName: 'Site',
|
|
26
|
+
},
|
|
27
|
+
value: ids,
|
|
28
|
+
},
|
|
29
|
+
locale: {
|
|
30
|
+
definition: {
|
|
31
|
+
type: Acl.VariableType.condition,
|
|
32
|
+
},
|
|
33
|
+
value: [{ eq: 'cs' }],
|
|
34
|
+
},
|
|
23
35
|
})
|
|
24
36
|
const result = injector.inject(schema.entities['PostLocale'], {
|
|
25
37
|
or: [
|
|
@@ -53,7 +65,7 @@ describe('Variable injector', () => {
|
|
|
53
65
|
and: [
|
|
54
66
|
{
|
|
55
67
|
post: {
|
|
56
|
-
site: { id: { in:
|
|
68
|
+
site: { id: { in: ids } },
|
|
57
69
|
},
|
|
58
70
|
},
|
|
59
71
|
{
|
package/tests/src/testGraphql.ts
CHANGED
|
@@ -13,7 +13,9 @@ export const executeGraphQlTest = async (test: Test) => {
|
|
|
13
13
|
const rawResponse = await graphql(test.schema, test.query, null, test.context, test.queryVariables)
|
|
14
14
|
const response = JSON.parse(JSON.stringify(rawResponse))
|
|
15
15
|
if ('errors' in rawResponse) {
|
|
16
|
-
|
|
16
|
+
if (rawResponse.errors?.length === 1 && 'originalError' in (rawResponse.errors as any)[0]) {
|
|
17
|
+
throw (rawResponse.errors as any)[0].originalError
|
|
18
|
+
}
|
|
17
19
|
rawResponse.errors = (rawResponse.errors as any).map(({ message }: any) => ({ message }))
|
|
18
20
|
}
|
|
19
21
|
assert.deepStrictEqual(response, test.return)
|