@contember/engine-content-api 2.1.0-rc.3 → 2.1.0-rc.5
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/development/src/acl/PermissionFactory.cjs +5 -2
- package/dist/development/src/acl/PermissionFactory.cjs.map +1 -1
- package/dist/development/src/acl/PermissionFactory.js +5 -2
- package/dist/development/src/acl/PermissionFactory.js.map +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.cjs +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.js +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +6 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +6 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/production/src/acl/PermissionFactory.cjs +5 -2
- package/dist/production/src/acl/PermissionFactory.cjs.map +1 -1
- package/dist/production/src/acl/PermissionFactory.js +5 -2
- package/dist/production/src/acl/PermissionFactory.js.map +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.cjs +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.js +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +6 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +6 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/tests/src/test.d.ts +2 -1
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/acl/PermissionFactory.d.ts.map +1 -1
- package/dist/types/mapper/select/RelationFetcher.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/acl/PermissionFactory.ts +6 -2
- package/src/mapper/select/RelationFetcher.ts +1 -3
- package/src/mapper/select/handlers/FieldsVisitor.ts +12 -1
- package/tests/cases/integration/graphQlRequests/query/formatting/dateFormat.test.ts +132 -1
- package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +48 -2
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +3 -3
- package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +1 -1
- package/tests/cases/unit/permissionMerger.test.ts +191 -0
- package/tests/src/test.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-content-api",
|
|
3
|
-
"version": "2.1.0-rc.
|
|
3
|
+
"version": "2.1.0-rc.5",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"generate": "gql-gen --config graphql.codegen.yml"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/database": "2.1.0-rc.
|
|
30
|
-
"@contember/dic": "2.1.0-rc.
|
|
31
|
-
"@contember/graphql-utils": "2.1.0-rc.
|
|
32
|
-
"@contember/logger": "2.1.0-rc.
|
|
33
|
-
"@contember/schema": "2.1.0-rc.
|
|
34
|
-
"@contember/schema-definition": "2.1.0-rc.
|
|
35
|
-
"@contember/schema-utils": "2.1.0-rc.
|
|
29
|
+
"@contember/database": "2.1.0-rc.5",
|
|
30
|
+
"@contember/dic": "2.1.0-rc.5",
|
|
31
|
+
"@contember/graphql-utils": "2.1.0-rc.5",
|
|
32
|
+
"@contember/logger": "2.1.0-rc.5",
|
|
33
|
+
"@contember/schema": "2.1.0-rc.5",
|
|
34
|
+
"@contember/schema-definition": "2.1.0-rc.5",
|
|
35
|
+
"@contember/schema-utils": "2.1.0-rc.5",
|
|
36
36
|
"fast-deep-equal": "^3.1.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@contember/database-tester": "2.1.0-rc.
|
|
39
|
+
"@contember/database-tester": "2.1.0-rc.5",
|
|
40
40
|
"@types/node": "^24.12.0",
|
|
41
41
|
"graphql": "^16.13.1",
|
|
42
42
|
"pg": "^8.20.0"
|
|
@@ -129,8 +129,12 @@ export class PermissionFactory {
|
|
|
129
129
|
private mergeEntityPermissions(left: Acl.EntityPermissions, right: Acl.EntityPermissions, includeThrough = false): Acl.EntityPermissions {
|
|
130
130
|
let predicates: Writable<Acl.PredicateMap> = {}
|
|
131
131
|
const operations: Writable<Acl.EntityOperations> = {}
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
// Three-state: unstated stays unstated so the role-level default still applies, an explicit `false` survives, and `true` wins across roles.
|
|
133
|
+
if (left.operations.customPrimary !== undefined || right.operations.customPrimary !== undefined) {
|
|
134
|
+
operations.customPrimary = (left.operations.customPrimary ?? false) || (right.operations.customPrimary ?? false)
|
|
135
|
+
}
|
|
136
|
+
if (left.operations.refreshMaterializedView !== undefined || right.operations.refreshMaterializedView !== undefined) {
|
|
137
|
+
operations.refreshMaterializedView = (left.operations.refreshMaterializedView ?? false) || (right.operations.refreshMaterializedView ?? false)
|
|
134
138
|
}
|
|
135
139
|
const noRoot: `${Acl.Operation}`[] = []
|
|
136
140
|
|
|
@@ -162,9 +162,7 @@ export class RelationFetcher {
|
|
|
162
162
|
|
|
163
163
|
const primaryField = new FieldNode(targetEntity.primary, targetEntity.primary, {})
|
|
164
164
|
const inverseJoiningColumn = joiningColumns.targetColumn.columnName
|
|
165
|
-
const inverseIds = junctionValues
|
|
166
|
-
.map(it => it[inverseJoiningColumn])
|
|
167
|
-
.filter((it, index, arr) => arr.indexOf(it) === index)
|
|
165
|
+
const inverseIds = [...new Set(junctionValues.map(it => it[inverseJoiningColumn]))]
|
|
168
166
|
|
|
169
167
|
const queryWithWhere = objectNode
|
|
170
168
|
.withArgs({
|
|
@@ -32,7 +32,18 @@ export class FieldsVisitor implements Model.RelationByTypeVisitor<void>, Model.C
|
|
|
32
32
|
selectFrom += '::text'
|
|
33
33
|
}
|
|
34
34
|
if (column.type === Model.ColumnType.DateTime && this.settings.fullDateTimeResponse) {
|
|
35
|
-
|
|
35
|
+
if (this.settings.dateTimeResponseFormat === 'iso8601') {
|
|
36
|
+
// Format SQL-side to a valid ISO 8601 string (with "T" separator and "Z" suffix)
|
|
37
|
+
// instead of relying on JS Date, which would lose sub-second precision.
|
|
38
|
+
const format = `'YYYY-MM-DD"T"HH24:MI:SS.US"Z"'`
|
|
39
|
+
selectFrom = column.list
|
|
40
|
+
? `(select array_agg(to_char(elem AT TIME ZONE 'UTC', ${format}) order by ord) from unnest(${selectFrom}) with ordinality as t(elem, ord))`
|
|
41
|
+
: `to_char(${selectFrom} AT TIME ZONE 'UTC', ${format})`
|
|
42
|
+
} else {
|
|
43
|
+
// Legacy (backward-compatible) format: emit the raw PostgreSQL text
|
|
44
|
+
// representation, e.g. "2024-01-01 11:22:33.444444+00".
|
|
45
|
+
selectFrom += '::text'
|
|
46
|
+
}
|
|
36
47
|
}
|
|
37
48
|
if (column.type === Model.ColumnType.Enum && column.list) {
|
|
38
49
|
selectFrom += '::text[]'
|
|
@@ -1,10 +1,141 @@
|
|
|
1
1
|
import { test } from 'bun:test'
|
|
2
2
|
import { execute } from '../../../../../src/test'
|
|
3
|
-
import { SchemaBuilder } from '@contember/schema-definition'
|
|
3
|
+
import { SchemaBuilder, SchemaDefinition } from '@contember/schema-definition'
|
|
4
4
|
import { Model } from '@contember/schema'
|
|
5
5
|
import { GQL, SQL } from '../../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../../src/testUuid'
|
|
7
7
|
|
|
8
|
+
namespace DateTimeListModel {
|
|
9
|
+
export class Post {
|
|
10
|
+
publishedAt = SchemaDefinition.dateTimeColumn().list()
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test('Format dateTime query with fullDateTimeResponse (legacy format, default)', async () => {
|
|
15
|
+
await execute({
|
|
16
|
+
schema: new SchemaBuilder()
|
|
17
|
+
.entity('Post', entity => entity.column('publishedAt', column => column.type(Model.ColumnType.DateTime)))
|
|
18
|
+
.buildSchema(),
|
|
19
|
+
settings: { content: { fullDateTimeResponse: true } },
|
|
20
|
+
query: GQL`
|
|
21
|
+
query {
|
|
22
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
23
|
+
publishedAt
|
|
24
|
+
}
|
|
25
|
+
}`,
|
|
26
|
+
executes: [
|
|
27
|
+
{
|
|
28
|
+
sql: SQL`select "root_"."published_at"::text as "root_publishedAt", "root_"."id" as "root_id"
|
|
29
|
+
from "public"."post" as "root_"
|
|
30
|
+
where "root_"."id" = ?`,
|
|
31
|
+
response: { rows: [{ root_id: testUuid(1), root_publishedAt: '2019-11-01 05:00:00.000000+00' }] },
|
|
32
|
+
parameters: [testUuid(1)],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
return: {
|
|
36
|
+
data: {
|
|
37
|
+
getPost: {
|
|
38
|
+
publishedAt: '2019-11-01 05:00:00.000000+00',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('Format dateTime query with fullDateTimeResponse (iso8601 format)', async () => {
|
|
46
|
+
await execute({
|
|
47
|
+
schema: new SchemaBuilder()
|
|
48
|
+
.entity('Post', entity => entity.column('publishedAt', column => column.type(Model.ColumnType.DateTime)))
|
|
49
|
+
.buildSchema(),
|
|
50
|
+
settings: { content: { fullDateTimeResponse: true, dateTimeResponseFormat: 'iso8601' } },
|
|
51
|
+
query: GQL`
|
|
52
|
+
query {
|
|
53
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
54
|
+
publishedAt
|
|
55
|
+
}
|
|
56
|
+
}`,
|
|
57
|
+
executes: [
|
|
58
|
+
{
|
|
59
|
+
sql:
|
|
60
|
+
SQL`select to_char("root_"."published_at" AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"') as "root_publishedAt", "root_"."id" as "root_id"
|
|
61
|
+
from "public"."post" as "root_"
|
|
62
|
+
where "root_"."id" = ?`,
|
|
63
|
+
response: { rows: [{ root_id: testUuid(1), root_publishedAt: '2019-11-01T05:00:00.000000Z' }] },
|
|
64
|
+
parameters: [testUuid(1)],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
return: {
|
|
68
|
+
data: {
|
|
69
|
+
getPost: {
|
|
70
|
+
publishedAt: '2019-11-01T05:00:00.000000Z',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('Format dateTime query with fullDateTimeResponse (iso8601, null value)', async () => {
|
|
78
|
+
await execute({
|
|
79
|
+
schema: new SchemaBuilder()
|
|
80
|
+
.entity('Post', entity => entity.column('publishedAt', column => column.type(Model.ColumnType.DateTime)))
|
|
81
|
+
.buildSchema(),
|
|
82
|
+
settings: { content: { fullDateTimeResponse: true, dateTimeResponseFormat: 'iso8601' } },
|
|
83
|
+
query: GQL`
|
|
84
|
+
query {
|
|
85
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
86
|
+
publishedAt
|
|
87
|
+
}
|
|
88
|
+
}`,
|
|
89
|
+
executes: [
|
|
90
|
+
{
|
|
91
|
+
sql:
|
|
92
|
+
SQL`select to_char("root_"."published_at" AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"') as "root_publishedAt", "root_"."id" as "root_id"
|
|
93
|
+
from "public"."post" as "root_"
|
|
94
|
+
where "root_"."id" = ?`,
|
|
95
|
+
response: { rows: [{ root_id: testUuid(1), root_publishedAt: null }] },
|
|
96
|
+
parameters: [testUuid(1)],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
return: {
|
|
100
|
+
data: {
|
|
101
|
+
getPost: {
|
|
102
|
+
publishedAt: null,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('Format dateTime[] query with fullDateTimeResponse (iso8601 list)', async () => {
|
|
110
|
+
await execute({
|
|
111
|
+
schema: SchemaDefinition.createModel(DateTimeListModel),
|
|
112
|
+
settings: { content: { fullDateTimeResponse: true, dateTimeResponseFormat: 'iso8601' } },
|
|
113
|
+
query: GQL`
|
|
114
|
+
query {
|
|
115
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
116
|
+
publishedAt
|
|
117
|
+
}
|
|
118
|
+
}`,
|
|
119
|
+
executes: [
|
|
120
|
+
{
|
|
121
|
+
sql:
|
|
122
|
+
SQL`select (select array_agg(to_char(elem AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"') order by ord) from unnest("root_"."published_at") with ordinality as t(elem, ord)) as "root_publishedAt", "root_"."id" as "root_id"
|
|
123
|
+
from "public"."post" as "root_"
|
|
124
|
+
where "root_"."id" = ?`,
|
|
125
|
+
response: { rows: [{ root_id: testUuid(1), root_publishedAt: ['2019-11-01T05:00:00.000000Z', '2020-01-15T08:30:00.000000Z'] }] },
|
|
126
|
+
parameters: [testUuid(1)],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
return: {
|
|
130
|
+
data: {
|
|
131
|
+
getPost: {
|
|
132
|
+
publishedAt: ['2019-11-01T05:00:00.000000Z', '2020-01-15T08:30:00.000000Z'],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
8
139
|
test('Format date query', async () => {
|
|
9
140
|
await execute({
|
|
10
141
|
schema: new SchemaBuilder()
|
|
@@ -55,7 +55,8 @@ test('many has many with where, limit and orderBy', async () => {
|
|
|
55
55
|
"data".*
|
|
56
56
|
from "data"
|
|
57
57
|
where
|
|
58
|
-
|
|
58
|
+
"data"."rowNumber_" > ? and "data"."rowNumber_" <= ?
|
|
59
|
+
order by "data"."rowNumber_" asc`,
|
|
59
60
|
parameters: [testUuid(1), testUuid(2), 'cs', 1, 3],
|
|
60
61
|
response: {
|
|
61
62
|
rows: [
|
|
@@ -173,7 +174,8 @@ test('one has many with where, limit and orderBy', async () => {
|
|
|
173
174
|
order by "root_"."title" asc, "root_"."id" asc)
|
|
174
175
|
select "data".*
|
|
175
176
|
from "data"
|
|
176
|
-
|
|
177
|
+
where "data"."rowNumber_" > ? and "data"."rowNumber_" <= ?
|
|
178
|
+
order by "data"."rowNumber_" asc`,
|
|
177
179
|
parameters: ['cs', testUuid(1), testUuid(2), 1, 3],
|
|
178
180
|
response: {
|
|
179
181
|
rows: [
|
|
@@ -216,3 +218,47 @@ test('one has many with where, limit and orderBy', async () => {
|
|
|
216
218
|
},
|
|
217
219
|
})
|
|
218
220
|
})
|
|
221
|
+
|
|
222
|
+
test('one has many with nulls first in a limited page', async () => {
|
|
223
|
+
await execute({
|
|
224
|
+
schema: new SchemaBuilder()
|
|
225
|
+
.entity('Author', entity => entity.oneHasMany('posts', relation => relation.target('Post', entity => entity.column('title')).ownedBy('author')))
|
|
226
|
+
.buildSchema(),
|
|
227
|
+
query: GQL`
|
|
228
|
+
query {
|
|
229
|
+
listAuthor {
|
|
230
|
+
posts(orderBy: [{title: ascNullsFirst}], limit: 1) {
|
|
231
|
+
id
|
|
232
|
+
title
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}`,
|
|
236
|
+
executes: [
|
|
237
|
+
{
|
|
238
|
+
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_id" from "public"."author" as "root_"`,
|
|
239
|
+
response: { rows: [{ root_id: testUuid(1) }] },
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
sql: SQL`with "data" as
|
|
243
|
+
(select "root_"."author_id" as "__grouping_key",
|
|
244
|
+
"root_"."id" as "root_id",
|
|
245
|
+
"root_"."title" as "root_title",
|
|
246
|
+
row_number() over(partition by "root_"."author_id"
|
|
247
|
+
order by "root_"."title" asc nulls first, "root_"."id" asc) as "rowNumber_"
|
|
248
|
+
from "public"."post" as "root_"
|
|
249
|
+
where "root_"."author_id" in (?)
|
|
250
|
+
order by "root_"."title" asc nulls first, "root_"."id" asc)
|
|
251
|
+
select "data".* from "data"
|
|
252
|
+
where "data"."rowNumber_" <= ?
|
|
253
|
+
order by "data"."rowNumber_" asc`,
|
|
254
|
+
parameters: [testUuid(1), 1],
|
|
255
|
+
response: { rows: [{ __grouping_key: testUuid(1), root_id: testUuid(2), root_title: null }] },
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
return: {
|
|
259
|
+
data: {
|
|
260
|
+
listAuthor: [{ posts: [{ id: testUuid(2), title: null }] }],
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
})
|
|
264
|
+
})
|
|
@@ -221,7 +221,7 @@ test('Posts with paginated comments (one has many)', async () => {
|
|
|
221
221
|
where "root_"."deleted_at" is null
|
|
222
222
|
and "root_"."post_id" in (?, ?)
|
|
223
223
|
order by "root_"."id" asc)
|
|
224
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
224
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
225
225
|
parameters: [testUuid(1), testUuid(2), 1],
|
|
226
226
|
response: {
|
|
227
227
|
rows: [
|
|
@@ -375,7 +375,7 @@ test('Posts with paginated comments without count (one has many)', async () => {
|
|
|
375
375
|
where "root_"."deleted_at" is null
|
|
376
376
|
and "root_"."post_id" in (?, ?)
|
|
377
377
|
order by "root_"."id" asc)
|
|
378
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
378
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
379
379
|
parameters: [testUuid(1), testUuid(2), 1],
|
|
380
380
|
response: {
|
|
381
381
|
rows: [
|
|
@@ -471,7 +471,7 @@ test('Posts with paginated comments (one has many)', async () => {
|
|
|
471
471
|
where "root_"."deleted_at" is null
|
|
472
472
|
and "root_"."post_id" in (?)
|
|
473
473
|
order by "root_"."id" asc)
|
|
474
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
474
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
475
475
|
parameters: [testUuid(1), 1],
|
|
476
476
|
response: {
|
|
477
477
|
rows: [
|
|
@@ -136,7 +136,7 @@ test('sorts posts by random on has many relation', async () => {
|
|
|
136
136
|
inner join "rand_seed" on true
|
|
137
137
|
where "junction_"."category_id" in (?, ?)
|
|
138
138
|
order by random() asc)
|
|
139
|
-
select "data".* from "data" where "data"."rownumber_" <=
|
|
139
|
+
select "data".* from "data" where "data"."rownumber_" <= ? order by "data"."rownumber_" asc`,
|
|
140
140
|
parameters: [4555 / Math.pow(2, 31), testUuid(1), testUuid(2), 1],
|
|
141
141
|
response: {
|
|
142
142
|
rows: [
|
|
@@ -1007,3 +1007,194 @@ describe('Contextual permission merger', () => {
|
|
|
1007
1007
|
})
|
|
1008
1008
|
})
|
|
1009
1009
|
})
|
|
1010
|
+
|
|
1011
|
+
describe('Contextual permission merger - entity flags', () => {
|
|
1012
|
+
it('two roles: refreshMaterializedView is granted if any role grants it', () => {
|
|
1013
|
+
const result: Acl.Permissions = {
|
|
1014
|
+
Entity1: {
|
|
1015
|
+
operations: {
|
|
1016
|
+
refreshMaterializedView: true,
|
|
1017
|
+
read: {
|
|
1018
|
+
title: true,
|
|
1019
|
+
description: true,
|
|
1020
|
+
id: true,
|
|
1021
|
+
},
|
|
1022
|
+
},
|
|
1023
|
+
predicates: {},
|
|
1024
|
+
},
|
|
1025
|
+
}
|
|
1026
|
+
executeContextual({
|
|
1027
|
+
acl: {
|
|
1028
|
+
roles: {
|
|
1029
|
+
viewRole: {
|
|
1030
|
+
variables: {},
|
|
1031
|
+
entities: {
|
|
1032
|
+
Entity1: {
|
|
1033
|
+
predicates: {},
|
|
1034
|
+
operations: {
|
|
1035
|
+
refreshMaterializedView: true,
|
|
1036
|
+
read: { title: true },
|
|
1037
|
+
},
|
|
1038
|
+
},
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
otherRole: {
|
|
1042
|
+
variables: {},
|
|
1043
|
+
entities: {
|
|
1044
|
+
Entity1: {
|
|
1045
|
+
predicates: {},
|
|
1046
|
+
operations: {
|
|
1047
|
+
read: { description: true },
|
|
1048
|
+
},
|
|
1049
|
+
},
|
|
1050
|
+
},
|
|
1051
|
+
},
|
|
1052
|
+
},
|
|
1053
|
+
},
|
|
1054
|
+
roles: ['viewRole', 'otherRole'],
|
|
1055
|
+
rootResult: result,
|
|
1056
|
+
allResult: result,
|
|
1057
|
+
})
|
|
1058
|
+
})
|
|
1059
|
+
|
|
1060
|
+
it('two roles: an explicit customPrimary and refreshMaterializedView denial survives the merge', () => {
|
|
1061
|
+
// A dropped `false` would not stay denied: Authorizator resolves the flags with `??`, so an absent
|
|
1062
|
+
// key falls back to the role-level default instead of denying.
|
|
1063
|
+
const result: Acl.Permissions = {
|
|
1064
|
+
Entity1: {
|
|
1065
|
+
operations: {
|
|
1066
|
+
customPrimary: false,
|
|
1067
|
+
refreshMaterializedView: false,
|
|
1068
|
+
read: {
|
|
1069
|
+
title: true,
|
|
1070
|
+
description: true,
|
|
1071
|
+
id: true,
|
|
1072
|
+
},
|
|
1073
|
+
},
|
|
1074
|
+
predicates: {},
|
|
1075
|
+
},
|
|
1076
|
+
}
|
|
1077
|
+
executeContextual({
|
|
1078
|
+
acl: {
|
|
1079
|
+
roles: {
|
|
1080
|
+
denyingRole: {
|
|
1081
|
+
variables: {},
|
|
1082
|
+
entities: {
|
|
1083
|
+
Entity1: {
|
|
1084
|
+
predicates: {},
|
|
1085
|
+
operations: {
|
|
1086
|
+
customPrimary: false,
|
|
1087
|
+
refreshMaterializedView: false,
|
|
1088
|
+
read: { title: true },
|
|
1089
|
+
},
|
|
1090
|
+
},
|
|
1091
|
+
},
|
|
1092
|
+
},
|
|
1093
|
+
otherRole: {
|
|
1094
|
+
variables: {},
|
|
1095
|
+
entities: {
|
|
1096
|
+
Entity1: {
|
|
1097
|
+
predicates: {},
|
|
1098
|
+
operations: {
|
|
1099
|
+
read: { description: true },
|
|
1100
|
+
},
|
|
1101
|
+
},
|
|
1102
|
+
},
|
|
1103
|
+
},
|
|
1104
|
+
},
|
|
1105
|
+
},
|
|
1106
|
+
roles: ['denyingRole', 'otherRole'],
|
|
1107
|
+
rootResult: result,
|
|
1108
|
+
allResult: result,
|
|
1109
|
+
})
|
|
1110
|
+
})
|
|
1111
|
+
|
|
1112
|
+
it('two roles: an explicit denial loses to another role granting the flag', () => {
|
|
1113
|
+
const result: Acl.Permissions = {
|
|
1114
|
+
Entity1: {
|
|
1115
|
+
operations: {
|
|
1116
|
+
customPrimary: true,
|
|
1117
|
+
refreshMaterializedView: true,
|
|
1118
|
+
read: {
|
|
1119
|
+
title: true,
|
|
1120
|
+
description: true,
|
|
1121
|
+
id: true,
|
|
1122
|
+
},
|
|
1123
|
+
},
|
|
1124
|
+
predicates: {},
|
|
1125
|
+
},
|
|
1126
|
+
}
|
|
1127
|
+
executeContextual({
|
|
1128
|
+
acl: {
|
|
1129
|
+
roles: {
|
|
1130
|
+
denyingRole: {
|
|
1131
|
+
variables: {},
|
|
1132
|
+
entities: {
|
|
1133
|
+
Entity1: {
|
|
1134
|
+
predicates: {},
|
|
1135
|
+
operations: {
|
|
1136
|
+
customPrimary: false,
|
|
1137
|
+
refreshMaterializedView: false,
|
|
1138
|
+
read: { title: true },
|
|
1139
|
+
},
|
|
1140
|
+
},
|
|
1141
|
+
},
|
|
1142
|
+
},
|
|
1143
|
+
grantingRole: {
|
|
1144
|
+
variables: {},
|
|
1145
|
+
entities: {
|
|
1146
|
+
Entity1: {
|
|
1147
|
+
predicates: {},
|
|
1148
|
+
operations: {
|
|
1149
|
+
customPrimary: true,
|
|
1150
|
+
refreshMaterializedView: true,
|
|
1151
|
+
read: { description: true },
|
|
1152
|
+
},
|
|
1153
|
+
},
|
|
1154
|
+
},
|
|
1155
|
+
},
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
roles: ['denyingRole', 'grantingRole'],
|
|
1159
|
+
rootResult: result,
|
|
1160
|
+
allResult: result,
|
|
1161
|
+
})
|
|
1162
|
+
})
|
|
1163
|
+
|
|
1164
|
+
it('flags no role states stay absent, leaving the role-level default in charge', () => {
|
|
1165
|
+
const model: Model.Schema = new SchemaBuilder()
|
|
1166
|
+
.entity('Entity1', e => e.column('lorem').column('bar'))
|
|
1167
|
+
.buildSchema()
|
|
1168
|
+
const acl: Acl.Schema = {
|
|
1169
|
+
roles: {
|
|
1170
|
+
role1: {
|
|
1171
|
+
variables: {},
|
|
1172
|
+
entities: {
|
|
1173
|
+
Entity1: {
|
|
1174
|
+
predicates: {},
|
|
1175
|
+
operations: {
|
|
1176
|
+
read: { title: true },
|
|
1177
|
+
},
|
|
1178
|
+
},
|
|
1179
|
+
},
|
|
1180
|
+
},
|
|
1181
|
+
role2: {
|
|
1182
|
+
variables: {},
|
|
1183
|
+
entities: {
|
|
1184
|
+
Entity1: {
|
|
1185
|
+
predicates: {},
|
|
1186
|
+
operations: {
|
|
1187
|
+
read: { description: true },
|
|
1188
|
+
},
|
|
1189
|
+
},
|
|
1190
|
+
},
|
|
1191
|
+
},
|
|
1192
|
+
},
|
|
1193
|
+
}
|
|
1194
|
+
const { root, all } = new PermissionFactory().createContextual({ ...emptySchema, model, acl }, ['role1', 'role2'])
|
|
1195
|
+
|
|
1196
|
+
// Asserted on the key list, because a `customPrimary: undefined` would compare equal to an absent one.
|
|
1197
|
+
assert.deepStrictEqual(Object.keys(root.Entity1.operations), ['read'])
|
|
1198
|
+
assert.deepStrictEqual(Object.keys(all.Entity1.operations), ['read'])
|
|
1199
|
+
})
|
|
1200
|
+
})
|
package/tests/src/test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Acl, Model, Schema, Validation } from '@contember/schema'
|
|
1
|
+
import { Acl, Model, Schema, Settings, Validation } from '@contember/schema'
|
|
2
2
|
import { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory } from '../../src'
|
|
3
3
|
import { AllowAllPermissionFactory, emptySchema } from '@contember/schema-utils'
|
|
4
4
|
import { executeGraphQlTest } from './testGraphql'
|
|
@@ -14,6 +14,7 @@ export interface SqlQuery {
|
|
|
14
14
|
|
|
15
15
|
export interface Test {
|
|
16
16
|
schema: Model.Schema
|
|
17
|
+
settings?: Settings.Schema
|
|
17
18
|
validation?: Validation.Schema
|
|
18
19
|
permissions?: Acl.Permissions
|
|
19
20
|
variables?: Acl.VariablesMap
|
|
@@ -82,7 +83,7 @@ export const execute = async (test: Test) => {
|
|
|
82
83
|
const connection = createConnectionMock(test.executes)
|
|
83
84
|
|
|
84
85
|
const db = new Client(connection, 'public', {})
|
|
85
|
-
const schema: Schema = { ...emptySchema, model: test.schema, validation: test.validation || {} }
|
|
86
|
+
const schema: Schema = { ...emptySchema, model: test.schema, validation: test.validation || {}, settings: test.settings || emptySchema.settings }
|
|
86
87
|
const providers = {
|
|
87
88
|
uuid: createUuidGenerator('a456', 0),
|
|
88
89
|
now: () => new Date('2019-09-04 12:00'),
|