@contember/cli 2.2.0-alpha.10 → 2.2.0-alpha.12
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/commands/project/ProjectPrintSchemaCommand.cjs +6 -7
- package/dist/development/src/commands/project/ProjectPrintSchemaCommand.cjs.map +1 -1
- package/dist/development/src/commands/project/ProjectPrintSchemaCommand.js +6 -7
- package/dist/development/src/commands/project/ProjectPrintSchemaCommand.js.map +1 -1
- package/dist/development/src/lib/project/docs/components/EntityInfo.cjs +27 -28
- package/dist/development/src/lib/project/docs/components/EntityInfo.cjs.map +1 -1
- package/dist/development/src/lib/project/docs/components/EntityInfo.js +28 -29
- package/dist/development/src/lib/project/docs/components/EntityInfo.js.map +1 -1
- package/dist/development/src/lib/project/docs/components/FieldPermissions.cjs +30 -10
- package/dist/development/src/lib/project/docs/components/FieldPermissions.cjs.map +1 -1
- package/dist/development/src/lib/project/docs/components/FieldPermissions.js +30 -10
- package/dist/development/src/lib/project/docs/components/FieldPermissions.js.map +1 -1
- package/dist/development/src/lib/project/docs/components/SinglePermission.cjs +23 -10
- package/dist/development/src/lib/project/docs/components/SinglePermission.cjs.map +1 -1
- package/dist/development/src/lib/project/docs/components/SinglePermission.js +23 -10
- package/dist/development/src/lib/project/docs/components/SinglePermission.js.map +1 -1
- package/dist/production/src/commands/project/ProjectPrintSchemaCommand.cjs +6 -7
- package/dist/production/src/commands/project/ProjectPrintSchemaCommand.cjs.map +1 -1
- package/dist/production/src/commands/project/ProjectPrintSchemaCommand.js +6 -7
- package/dist/production/src/commands/project/ProjectPrintSchemaCommand.js.map +1 -1
- package/dist/production/src/lib/project/docs/components/EntityInfo.cjs +1 -2
- package/dist/production/src/lib/project/docs/components/EntityInfo.cjs.map +1 -1
- package/dist/production/src/lib/project/docs/components/EntityInfo.js +2 -3
- package/dist/production/src/lib/project/docs/components/EntityInfo.js.map +1 -1
- package/dist/production/src/lib/project/docs/components/FieldPermissions.cjs +18 -6
- package/dist/production/src/lib/project/docs/components/FieldPermissions.cjs.map +1 -1
- package/dist/production/src/lib/project/docs/components/FieldPermissions.js +19 -7
- package/dist/production/src/lib/project/docs/components/FieldPermissions.js.map +1 -1
- package/dist/production/src/lib/project/docs/components/SinglePermission.cjs +12 -3
- package/dist/production/src/lib/project/docs/components/SinglePermission.cjs.map +1 -1
- package/dist/production/src/lib/project/docs/components/SinglePermission.js +12 -3
- package/dist/production/src/lib/project/docs/components/SinglePermission.js.map +1 -1
- package/dist/types/lib/project/docs/components/EntityInfo.d.ts.map +1 -1
- package/dist/types/lib/project/docs/components/FieldPermissions.d.ts +3 -0
- package/dist/types/lib/project/docs/components/FieldPermissions.d.ts.map +1 -1
- package/dist/types/lib/project/docs/components/SinglePermission.d.ts +2 -1
- package/dist/types/lib/project/docs/components/SinglePermission.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -14
- package/src/commands/project/ProjectPrintSchemaCommand.ts +7 -7
- package/src/lib/project/docs/components/EntityInfo.tsx +2 -3
- package/src/lib/project/docs/components/FieldPermissions.tsx +25 -6
- package/src/lib/project/docs/components/SinglePermission.tsx +17 -3
- package/tests/cases/unit/project.test.ts +53 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/cli",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.12",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"contember": "./dist/production/run.js"
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"tailwindcss": "^4.2.1"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@contember/cli-common": "2.2.0-alpha.
|
|
40
|
-
"@contember/config-loader": "2.2.0-alpha.
|
|
41
|
-
"@contember/database": "2.2.0-alpha.
|
|
42
|
-
"@contember/dic": "2.2.0-alpha.
|
|
43
|
-
"@contember/engine-common": "2.2.0-alpha.
|
|
44
|
-
"@contember/engine-content-api": "2.2.0-alpha.
|
|
45
|
-
"@contember/graphql-client": "2.2.0-alpha.
|
|
46
|
-
"@contember/graphql-client-tenant": "2.2.0-alpha.
|
|
47
|
-
"@contember/migrations-client": "2.2.0-alpha.
|
|
48
|
-
"@contember/schema": "2.2.0-alpha.
|
|
49
|
-
"@contember/schema-migrations": "2.2.0-alpha.
|
|
50
|
-
"@contember/schema-utils": "2.2.0-alpha.
|
|
51
|
-
"@contember/typesafe": "2.2.0-alpha.
|
|
39
|
+
"@contember/cli-common": "2.2.0-alpha.12",
|
|
40
|
+
"@contember/config-loader": "2.2.0-alpha.12",
|
|
41
|
+
"@contember/database": "2.2.0-alpha.12",
|
|
42
|
+
"@contember/dic": "2.2.0-alpha.12",
|
|
43
|
+
"@contember/engine-common": "2.2.0-alpha.12",
|
|
44
|
+
"@contember/engine-content-api": "2.2.0-alpha.12",
|
|
45
|
+
"@contember/graphql-client": "2.2.0-alpha.12",
|
|
46
|
+
"@contember/graphql-client-tenant": "2.2.0-alpha.12",
|
|
47
|
+
"@contember/migrations-client": "2.2.0-alpha.12",
|
|
48
|
+
"@contember/schema": "2.2.0-alpha.12",
|
|
49
|
+
"@contember/schema-migrations": "2.2.0-alpha.12",
|
|
50
|
+
"@contember/schema-utils": "2.2.0-alpha.12",
|
|
51
|
+
"@contember/typesafe": "2.2.0-alpha.12",
|
|
52
52
|
"@graphql-tools/schema": "^10.0.31",
|
|
53
53
|
"chalk": "^5.6.2",
|
|
54
54
|
"chalk-table": "^1.0.2",
|
|
@@ -69,13 +69,13 @@ export class ProjectPrintSchemaCommand extends Command<Args, Options> {
|
|
|
69
69
|
const permissionFactory = new PermissionFactory()
|
|
70
70
|
const inputRoles = input.getOption('role')
|
|
71
71
|
const schemaNormalized = input.getOption('normalize') ? normalizeSchema(filteredSchema) : filteredSchema
|
|
72
|
-
|
|
72
|
+
// Built the way the engine builds it: types and introspection from the nested set, root fields from the root set.
|
|
73
|
+
const { root: rootPermissions, all: permissions } = permissionFactory.createContextual(schemaNormalized, inputRoles || ['admin'])
|
|
73
74
|
const schemaBuilderFactory = new GraphQlSchemaBuilderFactory()
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
75
|
+
const customPrimary = schemaNormalized.acl.customPrimary ?? false
|
|
76
|
+
const refreshMaterializedView = Object.values(schemaNormalized.acl.roles).some(it => it.content?.refreshMaterializedView)
|
|
77
|
+
const authorizator = new Authorizator(permissions, customPrimary, refreshMaterializedView)
|
|
78
|
+
const rootAuthorizator = new Authorizator(rootPermissions, customPrimary, refreshMaterializedView)
|
|
79
79
|
const introspection = new IntrospectionSchemaFactory(
|
|
80
80
|
schemaNormalized.model,
|
|
81
81
|
new EntityRulesResolver(schemaNormalized.validation, schemaNormalized.model),
|
|
@@ -97,7 +97,7 @@ export class ProjectPrintSchemaCommand extends Command<Args, Options> {
|
|
|
97
97
|
quiet: value => JSON.stringify(value),
|
|
98
98
|
})
|
|
99
99
|
} else if (format === 'graphql') {
|
|
100
|
-
const contentSchema = schemaBuilderFactory.create(schemaNormalized.model, authorizator).build()
|
|
100
|
+
const contentSchema = schemaBuilderFactory.create(schemaNormalized.model, authorizator, rootAuthorizator).build()
|
|
101
101
|
const introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(introspection)
|
|
102
102
|
const introspectionSchema = introspectionSchemaFactory.create()
|
|
103
103
|
const gqlSchema = mergeSchemas({
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Model, Schema } from '@contember/schema'
|
|
2
2
|
import { ReferencesMap } from '../../../schema/collectReferences.js'
|
|
3
3
|
import { formatEntityAnchor, formatFieldAnchor } from './utils.js'
|
|
4
|
-
import { SinglePermission } from './SinglePermission.js'
|
|
5
4
|
import { FieldType } from './FieldType.js'
|
|
6
|
-
import { FieldPermissions } from './FieldPermissions.js'
|
|
5
|
+
import { DeletePermission, FieldPermissions } from './FieldPermissions.js'
|
|
7
6
|
import { OnDelete } from './OnDelete.js'
|
|
8
7
|
import { Fragment, h } from 'preact'
|
|
9
8
|
|
|
@@ -40,7 +39,7 @@ export const EntityInfo = ({ entity, schema, references }: EntityInfoProps) => (
|
|
|
40
39
|
<td></td>
|
|
41
40
|
{Object.entries(schema.acl.roles).map(([name, role]) => (
|
|
42
41
|
<td class={'px-2'} key={name}>
|
|
43
|
-
<
|
|
42
|
+
<DeletePermission entityPermissions={role.entities[entity.name]} />
|
|
44
43
|
</td>
|
|
45
44
|
))}
|
|
46
45
|
</tr>
|
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
import { Fragment, h } from 'preact'
|
|
2
2
|
import { Acl } from '@contember/schema'
|
|
3
|
+
import { splitEntityPermissions } from '@contember/schema-utils'
|
|
3
4
|
import { SinglePermission } from './SinglePermission.js'
|
|
4
5
|
|
|
6
|
+
type FieldOperation = Acl.Operation.create | Acl.Operation.read | Acl.Operation.update
|
|
7
|
+
|
|
8
|
+
const FieldPermission = ({ split, operation, field, value }: {
|
|
9
|
+
split?: ReturnType<typeof splitEntityPermissions>
|
|
10
|
+
operation: FieldOperation
|
|
11
|
+
field: string
|
|
12
|
+
value: string
|
|
13
|
+
}) => {
|
|
14
|
+
const rootPredicate = split?.root.operations[operation]?.[field]
|
|
15
|
+
const throughPredicate = split?.through.operations[operation]?.[field]
|
|
16
|
+
return <SinglePermission value={value} predicate={rootPredicate || throughPredicate} throughOnly={!rootPredicate && !!throughPredicate} />
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
export const FieldPermissions = ({ entityPermissions, field }: { entityPermissions?: Acl.EntityPermissions; field: string }) => {
|
|
6
|
-
const
|
|
7
|
-
const updatePermissions = entityPermissions?.operations.update?.[field]
|
|
8
|
-
const createPermissions = entityPermissions?.operations.create?.[field]
|
|
20
|
+
const split = entityPermissions ? splitEntityPermissions(entityPermissions) : undefined
|
|
9
21
|
return (
|
|
10
22
|
<Fragment>
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
<
|
|
23
|
+
<FieldPermission split={split} operation={Acl.Operation.create} field={field} value={'C'} />
|
|
24
|
+
<FieldPermission split={split} operation={Acl.Operation.read} field={field} value={'R'} />
|
|
25
|
+
<FieldPermission split={split} operation={Acl.Operation.update} field={field} value={'U'} />
|
|
14
26
|
</Fragment>
|
|
15
27
|
)
|
|
16
28
|
}
|
|
29
|
+
|
|
30
|
+
export const DeletePermission = ({ entityPermissions }: { entityPermissions?: Acl.EntityPermissions }) => {
|
|
31
|
+
const split = entityPermissions ? splitEntityPermissions(entityPermissions) : undefined
|
|
32
|
+
const rootPredicate = split?.root.operations.delete
|
|
33
|
+
const throughPredicate = split?.through.operations.delete
|
|
34
|
+
return <SinglePermission value={'D'} predicate={rootPredicate || throughPredicate} throughOnly={!rootPredicate && !!throughPredicate} />
|
|
35
|
+
}
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import { h } from 'preact'
|
|
2
2
|
import { Acl } from '@contember/schema'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const THROUGH_ONLY_TITLE = 'only through a relation'
|
|
5
|
+
|
|
6
|
+
export const SinglePermission = ({ predicate, value, throughOnly = false }: { predicate?: Acl.Predicate; value: string; throughOnly?: boolean }) => {
|
|
5
7
|
if (!predicate) {
|
|
6
8
|
return <span class={'bg-red-500 text-white font-semibold px-0.5'}>{value}</span>
|
|
7
9
|
}
|
|
10
|
+
const throughClass = throughOnly ? ' underline decoration-dotted' : ''
|
|
8
11
|
if (predicate === true) {
|
|
9
|
-
return
|
|
12
|
+
return (
|
|
13
|
+
<span class={'bg-green-600 text-white font-semibold px-0.5' + throughClass} title={throughOnly ? THROUGH_ONLY_TITLE : undefined}>
|
|
14
|
+
{value}
|
|
15
|
+
</span>
|
|
16
|
+
)
|
|
10
17
|
}
|
|
11
|
-
return
|
|
18
|
+
return (
|
|
19
|
+
<span
|
|
20
|
+
class={'bg-yellow-400 text-black font-semibold px-0.5' + throughClass}
|
|
21
|
+
title={throughOnly ? `${predicate}, ${THROUGH_ONLY_TITLE}` : predicate}
|
|
22
|
+
>
|
|
23
|
+
{value}
|
|
24
|
+
</span>
|
|
25
|
+
)
|
|
12
26
|
}
|
|
@@ -3,7 +3,7 @@ import * as fs from 'node:fs/promises'
|
|
|
3
3
|
import * as os from 'node:os'
|
|
4
4
|
import * as path from 'node:path'
|
|
5
5
|
import chalk from 'chalk'
|
|
6
|
-
import { Schema } from '@contember/schema'
|
|
6
|
+
import { Model, Schema } from '@contember/schema'
|
|
7
7
|
import { emptySchema } from '@contember/schema-utils'
|
|
8
8
|
import {
|
|
9
9
|
JsonLoader,
|
|
@@ -221,3 +221,55 @@ describe('project print-schema — --format and --json are orthogonal', () => {
|
|
|
221
221
|
expect(JSON.parse(stderr).error.code).toBe('UNKNOWN_FORMAT')
|
|
222
222
|
})
|
|
223
223
|
})
|
|
224
|
+
|
|
225
|
+
const uuidEntity = (name: string, tableName: string): Model.Entity => ({
|
|
226
|
+
name,
|
|
227
|
+
primary: 'id',
|
|
228
|
+
primaryColumn: 'id',
|
|
229
|
+
tableName,
|
|
230
|
+
fields: {
|
|
231
|
+
id: { name: 'id', columnName: 'id', type: Model.ColumnType.Uuid, columnType: 'uuid', nullable: false },
|
|
232
|
+
},
|
|
233
|
+
unique: [],
|
|
234
|
+
indexes: [],
|
|
235
|
+
eventLog: { enabled: true },
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
// `Tag` is readable only via a `through` grant, so it must not get root query fields.
|
|
239
|
+
const schemaWithThroughOnlyEntity: Schema = {
|
|
240
|
+
...emptySchema,
|
|
241
|
+
model: {
|
|
242
|
+
enums: {},
|
|
243
|
+
entities: {
|
|
244
|
+
Post: uuidEntity('Post', 'post'),
|
|
245
|
+
Tag: uuidEntity('Tag', 'tag'),
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
acl: {
|
|
249
|
+
roles: {
|
|
250
|
+
reader: {
|
|
251
|
+
variables: {},
|
|
252
|
+
stages: '*',
|
|
253
|
+
entities: {
|
|
254
|
+
Post: { predicates: {}, operations: { read: { id: true } } },
|
|
255
|
+
Tag: { predicates: {}, operations: { through: { read: { id: true } } } },
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
describe('project print-schema — root fields', () => {
|
|
263
|
+
test('--format graphql gates root fields on the root grants only', async () => {
|
|
264
|
+
const { printSchemaCommand } = await buildProjectCommands(schemaWithThroughOnlyEntity)
|
|
265
|
+
const { exitCode, stdout } = await runApplication(
|
|
266
|
+
['project', 'print-schema', '--role', 'reader'],
|
|
267
|
+
{ ['project print-schema']: () => printSchemaCommand },
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
expect(exitCode).toBe(ExitCode.Success)
|
|
271
|
+
expect(stdout).toContain('getPost(')
|
|
272
|
+
expect(stdout).not.toContain('getTag(')
|
|
273
|
+
expect(stdout).not.toContain('listTag(')
|
|
274
|
+
})
|
|
275
|
+
})
|