@crombolo/data 0.20.0 → 0.21.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 +2 -2
- package/src/index.ts +1 -0
- package/src/repositories/documents.ts +25 -0
- package/src/repositories/users.ts +16 -1
- package/src/schema/media-permissions.ts +40 -0
- package/src/schema/plan.ts +2 -0
- package/src/schema/seed.ts +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
31
|
+
"@crombolo/core": "0.21.0"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -65,6 +65,7 @@ export * from './schema/form-permission-prefix.ts'
|
|
|
65
65
|
export * from './schema/group-permissions.ts'
|
|
66
66
|
export * from './schema/identity.ts'
|
|
67
67
|
export * from './schema/log-viewer.ts'
|
|
68
|
+
export * from './schema/media-permissions.ts'
|
|
68
69
|
export * from './schema/member-property-type.ts'
|
|
69
70
|
export * from './schema/members.ts'
|
|
70
71
|
export * from './schema/plan.ts'
|
|
@@ -1767,6 +1767,31 @@ export class DocumentRepository {
|
|
|
1767
1767
|
return (await this.#propertyTypes(contentTypeNodeId)).map((p) => p.alias)
|
|
1768
1768
|
}
|
|
1769
1769
|
|
|
1770
|
+
/** A document's property types — alias, key and name — compositions included; undefined when there is no document. */
|
|
1771
|
+
async propertyTypeKeys(
|
|
1772
|
+
key: string,
|
|
1773
|
+
): Promise<Array<{ alias: string; key: string; name: string }> | undefined> {
|
|
1774
|
+
const node = await this.#nodes.byKey(key)
|
|
1775
|
+
if (!node) return undefined
|
|
1776
|
+
const contentTypeNodeId = await this.#contentTypeNodeId(node.id)
|
|
1777
|
+
if (!contentTypeNodeId) return undefined
|
|
1778
|
+
const rows = await this.#db.query<{ alias: string; unique_id: string; name: string }>(
|
|
1779
|
+
`WITH RECURSIVE ancestry(id) AS (
|
|
1780
|
+
SELECT ?
|
|
1781
|
+
UNION
|
|
1782
|
+
SELECT c.parent_content_type_id FROM content_type_composition c JOIN ancestry a ON a.id = c.child_content_type_id
|
|
1783
|
+
)
|
|
1784
|
+
SELECT p.alias, p.unique_id, p.name FROM property_type p
|
|
1785
|
+
WHERE p.content_type_id IN (SELECT id FROM ancestry) AND p.retired_at IS NULL`,
|
|
1786
|
+
[contentTypeNodeId],
|
|
1787
|
+
)
|
|
1788
|
+
return rows.map((row) => ({
|
|
1789
|
+
alias: String(row.alias),
|
|
1790
|
+
key: normaliseUuid(String(row.unique_id)),
|
|
1791
|
+
name: String(row.name),
|
|
1792
|
+
}))
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1770
1795
|
/** Property types of a content type, including everything it composes; retired ones excluded. */
|
|
1771
1796
|
async #propertyTypes(contentTypeNodeId: number): Promise<PropertyTypeRow[]> {
|
|
1772
1797
|
const rows = await this.#db.query(
|
|
@@ -596,13 +596,28 @@ export class UserRepository {
|
|
|
596
596
|
return {
|
|
597
597
|
groups: groups.map((group) => {
|
|
598
598
|
const granular = new Map<string, string[]>()
|
|
599
|
+
const properties = new Map<string, string[]>()
|
|
599
600
|
for (const row of group.granular)
|
|
600
601
|
if (row.context === 'Document' && row.key) {
|
|
601
602
|
const verbs = granular.get(row.key) ?? []
|
|
602
603
|
if (row.permission) verbs.push(row.permission)
|
|
603
604
|
granular.set(row.key, verbs)
|
|
605
|
+
} else if (row.context === 'DocumentTypeProperty' && row.key) {
|
|
606
|
+
// `<property type key>|<verb>`; an empty verb is an explicit "nothing"
|
|
607
|
+
const [propertyType, verb = ''] = row.permission.split('|')
|
|
608
|
+
if (!propertyType) continue
|
|
609
|
+
const key = propertyType.toLowerCase()
|
|
610
|
+
const verbs = properties.get(key) ?? []
|
|
611
|
+
if (verb) verbs.push(verb)
|
|
612
|
+
properties.set(key, verbs)
|
|
604
613
|
}
|
|
605
|
-
return {
|
|
614
|
+
return {
|
|
615
|
+
key: group.key,
|
|
616
|
+
alias: group.alias,
|
|
617
|
+
defaults: group.permissions,
|
|
618
|
+
granular,
|
|
619
|
+
properties,
|
|
620
|
+
}
|
|
606
621
|
}),
|
|
607
622
|
languages: languageRows.map((l) => String(l.iso_code)),
|
|
608
623
|
hasAccessToAllLanguages: groups.some((g) => g.hasAccessToAllLanguages),
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 045 — the media verbs, `Crombolo.Media.Read` and
|
|
3
|
+
* `Crombolo.Media.Update` (story 088). docs/backoffice-hosting.md, "Authorization".
|
|
4
|
+
*
|
|
5
|
+
* Before them the Media section alone let a group change every item in it, so
|
|
6
|
+
* every group that has the section — built-in or made on the site — is given
|
|
7
|
+
* both, and keeps exactly the access it had. The built-in groups are also given
|
|
8
|
+
* whatever else the seed grants that they lack, element verbs included.
|
|
9
|
+
* Idempotent, and it never takes a verb away.
|
|
10
|
+
*/
|
|
11
|
+
import { MediaPermissions } from '@crombolo/core'
|
|
12
|
+
import type { Db } from '../database.ts'
|
|
13
|
+
import type { Migration } from '../migrations.ts'
|
|
14
|
+
import { STATE_APPROVAL_SCHEDULES } from './approval-schedules.ts'
|
|
15
|
+
import { grantBuiltInPermissions } from './seed.ts'
|
|
16
|
+
|
|
17
|
+
export const STATE_MEDIA_PERMISSIONS = '{8d4f2b61-0045-4c3e-9a17-5e2b7c9d1f45}'
|
|
18
|
+
|
|
19
|
+
export const mediaPermissionsMigration: Migration = {
|
|
20
|
+
from: STATE_APPROVAL_SCHEDULES,
|
|
21
|
+
to: STATE_MEDIA_PERMISSIONS,
|
|
22
|
+
name: 'GrantMediaPermissions',
|
|
23
|
+
kind: 'expand',
|
|
24
|
+
release: '0.21.0',
|
|
25
|
+
async up(db: Db) {
|
|
26
|
+
await grantBuiltInPermissions(db)
|
|
27
|
+
for (const permission of Object.values(MediaPermissions))
|
|
28
|
+
await db.exec(
|
|
29
|
+
`INSERT INTO user_group_permission (user_group_key, permission)
|
|
30
|
+
SELECT g.key, ? FROM user_group g
|
|
31
|
+
WHERE EXISTS (
|
|
32
|
+
SELECT 1 FROM user_group_section s
|
|
33
|
+
WHERE s.user_group_id = g.id AND LOWER(s.app_alias) IN ('media', 'umb.section.media')
|
|
34
|
+
) AND NOT EXISTS (
|
|
35
|
+
SELECT 1 FROM user_group_permission p WHERE p.user_group_key = g.key AND p.permission = ?
|
|
36
|
+
)`,
|
|
37
|
+
[permission, permission],
|
|
38
|
+
)
|
|
39
|
+
},
|
|
40
|
+
}
|
package/src/schema/plan.ts
CHANGED
|
@@ -36,6 +36,7 @@ import { formsMigration } from './forms.ts'
|
|
|
36
36
|
import { groupPermissionsMigration } from './group-permissions.ts'
|
|
37
37
|
import { identityMigration } from './identity.ts'
|
|
38
38
|
import { logViewerMigration } from './log-viewer.ts'
|
|
39
|
+
import { mediaPermissionsMigration } from './media-permissions.ts'
|
|
39
40
|
import { memberPropertyTypeMigration } from './member-property-type.ts'
|
|
40
41
|
import { membersMigration } from './members.ts'
|
|
41
42
|
import { propertySearchableMigration } from './property-searchable.ts'
|
|
@@ -103,4 +104,5 @@ export const cromboloPlan = new MigrationPlan([
|
|
|
103
104
|
trashedDateMigration,
|
|
104
105
|
contentNotificationsMigration,
|
|
105
106
|
approvalSchedulesMigration,
|
|
107
|
+
mediaPermissionsMigration,
|
|
106
108
|
])
|
package/src/schema/seed.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Password hashing is injected rather than imported so this package stays free of
|
|
5
5
|
* a dependency on @crombolo/auth.
|
|
6
6
|
*/
|
|
7
|
-
import { RemotePermissions } from '@crombolo/core'
|
|
7
|
+
import { MediaPermissions, RemotePermissions } from '@crombolo/core'
|
|
8
8
|
import type { Db } from '../database.ts'
|
|
9
9
|
import { DbDate } from '../dialect.ts'
|
|
10
10
|
|
|
@@ -41,6 +41,9 @@ const FORM_FULL = [
|
|
|
41
41
|
'Crombolo.FormEntry.Sensitive',
|
|
42
42
|
] as const
|
|
43
43
|
|
|
44
|
+
/** Browsing and changing media (story 088): every built-in group with the Media section. */
|
|
45
|
+
const MEDIA_FULL = Object.values(MediaPermissions)
|
|
46
|
+
|
|
44
47
|
export const BUILT_IN_GROUP_PERMISSIONS: Record<string, readonly string[]> = {
|
|
45
48
|
admin: [
|
|
46
49
|
'Umb.Document.Create',
|
|
@@ -67,6 +70,7 @@ export const BUILT_IN_GROUP_PERMISSIONS: Record<string, readonly string[]> = {
|
|
|
67
70
|
...FORM_FULL,
|
|
68
71
|
...ELEMENT_EDIT,
|
|
69
72
|
...Object.values(RemotePermissions),
|
|
73
|
+
...MEDIA_FULL,
|
|
70
74
|
],
|
|
71
75
|
editor: [
|
|
72
76
|
'Umb.Document.Create',
|
|
@@ -93,6 +97,7 @@ export const BUILT_IN_GROUP_PERMISSIONS: Record<string, readonly string[]> = {
|
|
|
93
97
|
'Crombolo.FormEntry.Read',
|
|
94
98
|
'Crombolo.FormEntry.Manage',
|
|
95
99
|
...ELEMENT_EDIT,
|
|
100
|
+
...MEDIA_FULL,
|
|
96
101
|
],
|
|
97
102
|
writer: [
|
|
98
103
|
'Umb.Document.Create',
|