@crombolo/data 0.63.0 → 0.65.1
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/audit.ts +31 -1
- package/src/change-report.ts +1 -1
- package/src/cluster.ts +10 -4
- package/src/content-query.ts +2 -3
- package/src/index.ts +1 -0
- package/src/repositories/users.ts +8 -4
- package/src/schema/plan.ts +2 -0
- package/src/schema/session-view-as.ts +24 -0
- package/src/tables.gen.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@crombolo/core": "0.
|
|
32
|
+
"@crombolo/core": "0.65.1",
|
|
33
33
|
"kysely": "0.29.6"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/audit.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The audit log: who did what, when and from where. Entries are only ever
|
|
3
3
|
* added, read and aged out; nothing edits one. docs/audit-log.md.
|
|
4
4
|
*/
|
|
5
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
5
6
|
import { normaliseUuid } from '@crombolo/core'
|
|
6
7
|
import type { Expression, ExpressionBuilder, SqlBool } from 'kysely'
|
|
7
8
|
import type { Db } from './database.ts'
|
|
@@ -173,6 +174,35 @@ function toEntry(row: Record<string, unknown>): AuditEntry {
|
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
|
|
177
|
+
/**
|
|
178
|
+
* What a request's entries say about how it was made, filled in once the caller
|
|
179
|
+
* is known: an administrator viewing as groups (story 314) has every entry they
|
|
180
|
+
* write say so.
|
|
181
|
+
*/
|
|
182
|
+
export interface AuditContext {
|
|
183
|
+
viewing?: { userKey: string; groups: string }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const contexts = new AsyncLocalStorage<AuditContext>()
|
|
187
|
+
|
|
188
|
+
/** Runs `work` with an audit context of its own, which it fills in as it learns who is asking. */
|
|
189
|
+
export const withAuditContext = <T>(work: () => T): T => contexts.run({}, work)
|
|
190
|
+
|
|
191
|
+
/** The context of the request being answered; undefined outside one. */
|
|
192
|
+
export const currentAuditContext = (): AuditContext | undefined => contexts.getStore()
|
|
193
|
+
|
|
194
|
+
/** The detail an entry is written with: "while viewing as Editors" added to the viewer's own. */
|
|
195
|
+
export function detailInContext(
|
|
196
|
+
entry: Pick<AuditEntryInput, 'userKey' | 'detail'>,
|
|
197
|
+
context = currentAuditContext(),
|
|
198
|
+
): string | null | undefined {
|
|
199
|
+
const viewing = context?.viewing
|
|
200
|
+
if (!viewing || !entry.userKey || !UUID.test(entry.userKey)) return entry.detail
|
|
201
|
+
if (normaliseUuid(entry.userKey) !== viewing.userKey) return entry.detail
|
|
202
|
+
const note = `while viewing as ${viewing.groups}`
|
|
203
|
+
return entry.detail ? `${entry.detail}, ${note}` : `${note[0]?.toUpperCase()}${note.slice(1)}`
|
|
204
|
+
}
|
|
205
|
+
|
|
176
206
|
export class AuditLog {
|
|
177
207
|
#db: Db
|
|
178
208
|
|
|
@@ -203,7 +233,7 @@ export class AuditLog {
|
|
|
203
233
|
source: entry.source,
|
|
204
234
|
ip_address: clip(entry.ipAddress, LIMITS.ipAddress),
|
|
205
235
|
forwarded_for: clip(entry.forwardedFor, LIMITS.forwardedFor),
|
|
206
|
-
detail: clip(entry
|
|
236
|
+
detail: clip(detailInContext(entry), LIMITS.detail),
|
|
207
237
|
})
|
|
208
238
|
.execute()
|
|
209
239
|
}
|
package/src/change-report.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { DbDate } from './dialect.ts'
|
|
|
14
14
|
export type FindingKind = 'auto' | 'person' | 'blocking'
|
|
15
15
|
|
|
16
16
|
/** Who a run of findings belongs to. Scopes the resolve sweep. */
|
|
17
|
-
export type FindingSource = 'upgrade' | 'transfer'
|
|
17
|
+
export type FindingSource = 'upgrade' | 'transfer' | 'import'
|
|
18
18
|
|
|
19
19
|
export interface Finding {
|
|
20
20
|
kind: FindingKind
|
package/src/cluster.ts
CHANGED
|
@@ -12,13 +12,19 @@ import { sql } from './query.ts'
|
|
|
12
12
|
* node has to look at its views tree again. `schema` and `content` invalidate
|
|
13
13
|
* the published cache; this one makes a node take a new snapshot. `public-files`
|
|
14
14
|
* is a site's `public/` folder changed by something a watcher cannot see, so a
|
|
15
|
-
* node lists it again (story 285).
|
|
15
|
+
* node lists it again (story 285). `extensions` is an extension granted, turned
|
|
16
|
+
* on or off, or removed: each node starts or stops it to match (story 346).
|
|
16
17
|
*/
|
|
17
|
-
export type CacheInstructionKind =
|
|
18
|
+
export type CacheInstructionKind =
|
|
19
|
+
| 'schema'
|
|
20
|
+
| 'content'
|
|
21
|
+
| 'components'
|
|
22
|
+
| 'public-files'
|
|
23
|
+
| 'extensions'
|
|
18
24
|
|
|
19
|
-
/** Kinds about a site's files, not published content: they move no checkpoint. */
|
|
25
|
+
/** Kinds about a site's files or code, not published content: they move no checkpoint. */
|
|
20
26
|
const isFileChange = (kind: CacheInstructionKind) =>
|
|
21
|
-
kind === 'components' || kind === 'public-files'
|
|
27
|
+
kind === 'components' || kind === 'public-files' || kind === 'extensions'
|
|
22
28
|
|
|
23
29
|
export interface CacheInstruction {
|
|
24
30
|
id: number
|
package/src/content-query.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* properties".
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
|
+
BLOCK_EDITORS,
|
|
10
11
|
dateFromText,
|
|
11
12
|
ObjectTypes,
|
|
12
13
|
STORAGE_COLUMN,
|
|
@@ -254,9 +255,7 @@ export class ContentQueryRefused extends Error {}
|
|
|
254
255
|
|
|
255
256
|
/** Editors whose value is JSON or markup: only `exists` and `empty` apply; `text` searches them. */
|
|
256
257
|
const STRUCTURED_EDITORS = new Set([
|
|
257
|
-
|
|
258
|
-
'Umbraco.BlockGrid',
|
|
259
|
-
'Umbraco.RichText',
|
|
258
|
+
...BLOCK_EDITORS,
|
|
260
259
|
'Umbraco.MediaPicker3',
|
|
261
260
|
'Umbraco.MultiUrlPicker',
|
|
262
261
|
'Umbraco.MultiNodeTreePicker',
|
package/src/index.ts
CHANGED
|
@@ -118,6 +118,7 @@ export * from './schema/rich-text-ui.ts'
|
|
|
118
118
|
export * from './schema/search-index.ts'
|
|
119
119
|
export * from './schema/search-removals.ts'
|
|
120
120
|
export * from './schema/seed.ts'
|
|
121
|
+
export * from './schema/session-view-as.ts'
|
|
121
122
|
export * from './schema/since-version.ts'
|
|
122
123
|
export * from './schema/site-search.ts'
|
|
123
124
|
export * from './schema/site-settings-types.ts'
|
|
@@ -582,10 +582,14 @@ export class UserRepository {
|
|
|
582
582
|
.execute()
|
|
583
583
|
}
|
|
584
584
|
|
|
585
|
-
/**
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
585
|
+
/**
|
|
586
|
+
* The user's groups' grants, languages and start node positions, for access
|
|
587
|
+
* checks; the given groups' instead, when they are given (story 314).
|
|
588
|
+
*/
|
|
589
|
+
async access(userId: number, groupKeys?: readonly string[]): Promise<UserAccessData> {
|
|
590
|
+
const groups = await new UserGroupRepository(this.#db).byKeys(
|
|
591
|
+
groupKeys ?? (await this.byId(userId))?.groupKeys ?? [],
|
|
592
|
+
)
|
|
589
593
|
const nodeIds: Record<string, number> = {}
|
|
590
594
|
for (const group of groups)
|
|
591
595
|
for (const tree of TREES) {
|
package/src/schema/plan.ts
CHANGED
|
@@ -73,6 +73,7 @@ import { richTextUiMigration } from './rich-text-ui.ts'
|
|
|
73
73
|
import { searchIndexMigration } from './search-index.ts'
|
|
74
74
|
import { searchRemovalsMigration } from './search-removals.ts'
|
|
75
75
|
import { serverRoleMigration } from './server-role.ts'
|
|
76
|
+
import { sessionViewAsMigration } from './session-view-as.ts'
|
|
76
77
|
import { sinceVersionMigration } from './since-version.ts'
|
|
77
78
|
import { siteSearchMigration } from './site-search.ts'
|
|
78
79
|
import { siteSettingsTypesMigration } from './site-settings-types.ts'
|
|
@@ -167,4 +168,5 @@ export const cromboloPlan = new MigrationPlan([
|
|
|
167
168
|
userGroupOwnersMigration,
|
|
168
169
|
prunedPermissionsMigration,
|
|
169
170
|
userStartNodesDroppedMigration,
|
|
171
|
+
sessionViewAsMigration,
|
|
170
172
|
])
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 077 — a back-office session viewing as user groups (story 314):
|
|
3
|
+
* the groups' keys, as JSON, and when the view ends. Both null when the
|
|
4
|
+
* session is its user's own.
|
|
5
|
+
*/
|
|
6
|
+
import type { Db } from '../database.ts'
|
|
7
|
+
import type { Migration } from '../migrations.ts'
|
|
8
|
+
import { schemaOps } from '../schema-ops.ts'
|
|
9
|
+
import { STATE_USER_START_NODES_DROPPED } from './user-start-nodes-dropped.ts'
|
|
10
|
+
|
|
11
|
+
export const STATE_SESSION_VIEW_AS = '{7b1d4e62-0077-4a39-9c85-2f6e0d3a0077}'
|
|
12
|
+
|
|
13
|
+
export const sessionViewAsMigration: Migration = {
|
|
14
|
+
from: STATE_USER_START_NODES_DROPPED,
|
|
15
|
+
to: STATE_SESSION_VIEW_AS,
|
|
16
|
+
name: 'AddSessionViewAs',
|
|
17
|
+
kind: 'expand',
|
|
18
|
+
release: '0.65.1',
|
|
19
|
+
async up(db: Db) {
|
|
20
|
+
const t = db.dialect.types
|
|
21
|
+
await schemaOps(db).addColumn('user_login_session', 'view_as_groups', t.text)
|
|
22
|
+
await schemaOps(db).addColumn('user_login_session', 'view_as_until', t.timestamp)
|
|
23
|
+
},
|
|
24
|
+
}
|
package/src/tables.gen.ts
CHANGED