@openinc/parse-server-opendash 4.24.0 → 4.24.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/dist/features/config/types/ConfigKeys.d.ts +1 -0
- package/dist/features/config/types/ConfigKeys.js +3 -0
- package/dist/features/openservice/alarms/tenantForSecret.js +3 -1
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +4 -1
- package/dist/features/openservice/init.d.ts +12 -6
- package/dist/features/openservice/init.js +29 -21
- package/dist/features/permissions/helper/hasPermission.d.ts +10 -1
- package/dist/features/permissions/helper/hasPermission.js +20 -3
- package/dist/features/permissions/helper/requirePermission.d.ts +2 -1
- package/dist/features/permissions/helper/requirePermission.js +3 -2
- package/dist/features/schema/indexes.js +11 -0
- package/dist/features/schema/services/beforeSaveHook.js +54 -0
- package/dist/functions/openinc-config.js +2 -22
- package/dist/helper/aclAccess.d.ts +19 -0
- package/dist/helper/aclAccess.js +57 -0
- package/dist/helper/getUserLanguage.d.ts +17 -0
- package/dist/helper/getUserLanguage.js +37 -4
- package/dist/hooks/Chat_Message.js +113 -12
- package/dist/hooks/Config_open_service.js +30 -4
- package/dist/hooks/Meta_Entry.js +69 -13
- package/dist/hooks/Service_Equipment.js +4 -5
- package/dist/hooks/Service_FormConfig.js +13 -2
- package/dist/hooks/Service_Project.js +13 -0
- package/dist/hooks/Service_Status.js +54 -2
- package/dist/hooks/Service_Ticket.js +158 -48
- package/dist/index.js +7 -2
- package/dist/scripts/repair-ticket-acl.d.ts +1 -0
- package/dist/scripts/repair-ticket-acl.js +135 -0
- package/package.json +2 -1
|
@@ -58,37 +58,49 @@ async function init() {
|
|
|
58
58
|
(0, index_js_1.beforeSaveHook)("OD3_Service_Ticket", async (request) => {
|
|
59
59
|
const { object, original, user } = request;
|
|
60
60
|
const isNew = object.isNew();
|
|
61
|
-
// Creating a ticket is a capability: there is no record yet whose ACL
|
|
62
|
-
// could be asked, and the class-level `create` is open to everybody. The
|
|
63
|
-
// frontend hides its create buttons without it; this is what makes it
|
|
64
|
-
// hold for every other write path. A migration replays history, and
|
|
65
|
-
// master-key writes (alarm tickets) are the server's own.
|
|
66
|
-
//
|
|
67
|
-
// Passes `request`, not `request.user`: `defaultHandler` below refetches
|
|
68
|
-
// the user in place, which drops its session token (see the execution
|
|
69
|
-
// hook for the details).
|
|
70
|
-
if (isNew && !(0, index_js_1.isMigrationMode)()) {
|
|
71
|
-
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_create, "create a ticket");
|
|
72
|
-
}
|
|
73
61
|
// Archiving sets `deleted` — an update, which `setTicketACL` grants to the
|
|
74
62
|
// creator and everybody assigned. Retiring a ticket is a decision of its
|
|
75
63
|
// own, and restoring one is the same decision. Compared against
|
|
76
64
|
// `original`, so a client that resends the unchanged flag is not refused.
|
|
65
|
+
//
|
|
66
|
+
// Held in the ticket's own tenant: a cross-tenant assignee may hold
|
|
67
|
+
// `ticket_delete` at home, which says nothing about this tenant's tickets.
|
|
68
|
+
// Passes `request`, not `request.user`: `defaultHandler` below refetches
|
|
69
|
+
// the user in place, which drops its session token (see the execution
|
|
70
|
+
// hook for the details); the request carries the token taken before.
|
|
77
71
|
if (original &&
|
|
78
72
|
!(0, index_js_1.isMigrationMode)() &&
|
|
79
73
|
Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
|
|
80
|
-
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_delete, "archive a ticket");
|
|
74
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_delete, "archive a ticket", original.get("tenant"));
|
|
81
75
|
}
|
|
82
76
|
if (isNew && !object.get("createdBy") && user)
|
|
83
77
|
object.set("createdBy", user);
|
|
84
78
|
await (0, index_js_1.defaultHandler)(request);
|
|
79
|
+
// Creating a ticket is a capability: there is no record yet whose ACL
|
|
80
|
+
// could be asked, and the class-level `create` is open to everybody. The
|
|
81
|
+
// frontend hides its create buttons without it; this is what makes it
|
|
82
|
+
// hold for every other write path. A migration replays history, and
|
|
83
|
+
// master-key writes (alarm tickets) are the server's own.
|
|
84
|
+
//
|
|
85
|
+
// After `defaultHandler`, which settles the tenant — a submitted one is
|
|
86
|
+
// only honoured for a cross-tenant caller — so the capability is asked of
|
|
87
|
+
// the tenant the ticket actually lands in.
|
|
88
|
+
if (isNew && !(0, index_js_1.isMigrationMode)()) {
|
|
89
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_create, "create a ticket", object.get("tenant"));
|
|
90
|
+
}
|
|
85
91
|
// No `allowTenantUserWrite`: who may edit a ticket is decided per record by
|
|
86
92
|
// `setTicketACL` below — creator, assigned users, assigned roles — and a
|
|
87
93
|
// blanket write grant for every user in the tenant would make that decision
|
|
88
94
|
// meaningless (it did: `entity.readonly` was never true for a tenant
|
|
89
95
|
// member). Read is still granted tenant-wide, so the list and board keep
|
|
90
96
|
// showing every ticket.
|
|
91
|
-
|
|
97
|
+
//
|
|
98
|
+
// No `allowCustomACL` either: the ACL is rebuilt from scratch on every save.
|
|
99
|
+
// Keeping the stored one meant grants only ever accumulated — a user taken
|
|
100
|
+
// off a ticket kept writing it, and so did any user or role a client had
|
|
101
|
+
// slipped into the ACL it sent along.
|
|
102
|
+
await (0, index_js_1.defaultAclHandler)(request);
|
|
103
|
+
await assertAssignableRoles(object);
|
|
92
104
|
await setTicketACL(object);
|
|
93
105
|
// Archived tickets miss the sort keys master data pushes down (see
|
|
94
106
|
// pushSortKeyToTickets), so restoring one re-derives all of them.
|
|
@@ -108,6 +120,16 @@ async function init() {
|
|
|
108
120
|
// fresh number from the destination keeps each project's sequence unique
|
|
109
121
|
// (the source sequence simply gains a gap, which is fine).
|
|
110
122
|
const projectChanged = !isNew && object.dirty("project");
|
|
123
|
+
// The number is the server's. The REST API and the generic admin let a
|
|
124
|
+
// client send one, and a caller-chosen number collides with — or poses as
|
|
125
|
+
// — another ticket's. Master-key writes (alarm tickets) are the server's
|
|
126
|
+
// own and keep what they set.
|
|
127
|
+
if (!request.master && object.dirty("number") && !projectChanged) {
|
|
128
|
+
if (isNew)
|
|
129
|
+
object.unset("number");
|
|
130
|
+
else
|
|
131
|
+
object.set("number", original?.get("number"));
|
|
132
|
+
}
|
|
111
133
|
if ((isNew && object.get("number") == null) || projectChanged) {
|
|
112
134
|
await assignTicketNumber(object);
|
|
113
135
|
}
|
|
@@ -118,7 +140,7 @@ async function init() {
|
|
|
118
140
|
(0, index_js_1.beforeDeleteHook)(index_js_3.Service_Ticket, async (request) => {
|
|
119
141
|
if ((0, index_js_1.isMigrationMode)())
|
|
120
142
|
return;
|
|
121
|
-
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_delete, "delete a ticket");
|
|
143
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_delete, "delete a ticket", request.object.get("tenant"));
|
|
122
144
|
});
|
|
123
145
|
(0, index_js_1.afterDeleteHook)(index_js_3.Service_Ticket, async ({ object }) => {
|
|
124
146
|
if (object.id)
|
|
@@ -159,6 +181,11 @@ const RELATED_DELETE_LIMIT = 10000;
|
|
|
159
181
|
* rather than a pointer, and notifications reference it inside their JSON `data`
|
|
160
182
|
* blob. Without this hook all three would be orphaned.
|
|
161
183
|
*
|
|
184
|
+
* So would the ticket's files ({@link Assets}): its file library and the
|
|
185
|
+
* attachments of its comments share the chat's context. Destroying an asset
|
|
186
|
+
* row also removes its stored file (see the `Assets` hook) — the archive's
|
|
187
|
+
* "delete for good" promises exactly that.
|
|
188
|
+
*
|
|
162
189
|
* Child tickets (the `parent` self-pointer) are intentionally left untouched.
|
|
163
190
|
*
|
|
164
191
|
* This is the single cleanup path for both single deletes and the dev
|
|
@@ -166,16 +193,21 @@ const RELATED_DELETE_LIMIT = 10000;
|
|
|
166
193
|
* itself.
|
|
167
194
|
*/
|
|
168
195
|
async function cleanupTicketRelations(ticketId) {
|
|
169
|
-
|
|
196
|
+
// Chat and files are addressed as `contextToString(["service","ticket",id])`,
|
|
197
|
+
// i.e. a JSON.stringify of the tuple — match it exactly.
|
|
198
|
+
const context = JSON.stringify(["service", "ticket", ticketId]);
|
|
199
|
+
const [metaEntries, chatMessages, assets, notifications] = await Promise.all([
|
|
170
200
|
new node_1.default.Query(index_js_3.Meta_Entry)
|
|
171
201
|
.equalTo("entryClassName", index_js_3.Service_Ticket.className)
|
|
172
202
|
.equalTo("entryObjectId", ticketId)
|
|
173
203
|
.limit(RELATED_DELETE_LIMIT)
|
|
174
204
|
.find({ useMasterKey: true }),
|
|
175
|
-
// Chat context is stored as `contextToString(["service","ticket",id])`,
|
|
176
|
-
// i.e. a JSON.stringify of the tuple — match it exactly.
|
|
177
205
|
new node_1.default.Query(index_js_3.Chat_Message)
|
|
178
|
-
.equalTo("context",
|
|
206
|
+
.equalTo("context", context)
|
|
207
|
+
.limit(RELATED_DELETE_LIMIT)
|
|
208
|
+
.find({ useMasterKey: true }),
|
|
209
|
+
new node_1.default.Query(index_js_3.Assets)
|
|
210
|
+
.equalTo("context", context)
|
|
179
211
|
.limit(RELATED_DELETE_LIMIT)
|
|
180
212
|
.find({ useMasterKey: true }),
|
|
181
213
|
// `data` is a JSON Object column; Parse supports dot-notation into it. Query
|
|
@@ -185,7 +217,7 @@ async function cleanupTicketRelations(ticketId) {
|
|
|
185
217
|
.limit(RELATED_DELETE_LIMIT)
|
|
186
218
|
.find({ useMasterKey: true }),
|
|
187
219
|
]);
|
|
188
|
-
await node_1.default.Object.destroyAll([...metaEntries, ...chatMessages, ...notifications], { useMasterKey: true });
|
|
220
|
+
await node_1.default.Object.destroyAll([...metaEntries, ...chatMessages, ...assets, ...notifications], { useMasterKey: true });
|
|
189
221
|
}
|
|
190
222
|
/**
|
|
191
223
|
* Assigns a sequential `number` to a new ticket.
|
|
@@ -221,8 +253,22 @@ async function assignTicketNumber(ticket) {
|
|
|
221
253
|
* this is the per-row half of it, and it also repairs rows written before either
|
|
222
254
|
* existed, which carried the Parse default of public read *and write*. A client
|
|
223
255
|
* that could set `value` could hand another tenant duplicate ticket numbers.
|
|
256
|
+
*
|
|
257
|
+
* Serialised per tenant: the increment is atomic, but the find-or-create is
|
|
258
|
+
* not — two first tickets of a tenant arriving together each found no counter,
|
|
259
|
+
* each created one, and both became #1. The lock only spans this process, which
|
|
260
|
+
* is what runs the hooks.
|
|
224
261
|
*/
|
|
225
|
-
|
|
262
|
+
function nextTenantTicketNumber(tenant) {
|
|
263
|
+
const key = tenant.id;
|
|
264
|
+
const run = (counterLocks.get(key) ?? Promise.resolve()).then(() => incrementTenantCounter(tenant));
|
|
265
|
+
// The chain must survive a failed increment, or every later one would fail.
|
|
266
|
+
counterLocks.set(key, run.catch(() => undefined));
|
|
267
|
+
return run;
|
|
268
|
+
}
|
|
269
|
+
/** Per-tenant tail of the counter chain, see {@link nextTenantTicketNumber}. */
|
|
270
|
+
const counterLocks = new Map();
|
|
271
|
+
async function incrementTenantCounter(tenant) {
|
|
226
272
|
const existing = await new node_1.default.Query("OD3_Service_TicketCounter")
|
|
227
273
|
.equalTo("tenant", tenant)
|
|
228
274
|
.first({ useMasterKey: true });
|
|
@@ -243,14 +289,30 @@ async function nextTenantTicketNumber(tenant) {
|
|
|
243
289
|
/** Pointer fields on a ticket that must belong to the ticket's own tenant. */
|
|
244
290
|
const TENANT_SCOPED_POINTERS = ["status", "project", "equipment"];
|
|
245
291
|
/**
|
|
246
|
-
* Pointer-array fields whose entries must belong to the ticket's own tenant
|
|
292
|
+
* Pointer-array fields whose entries must belong to the ticket's own tenant,
|
|
293
|
+
* with the class the entries point at.
|
|
294
|
+
*
|
|
295
|
+
* The class is spelled out because the entity adapter stores such arrays as
|
|
296
|
+
* plain id **strings** (see `pointerIds`) — there is no `className` to read
|
|
297
|
+
* off an entry. Reading `.id` off them, as this guard used to, judged nothing.
|
|
247
298
|
*
|
|
248
299
|
* Not `assignedUsers`: people work across tenants — a customer assigns the
|
|
249
300
|
* service provider's staff to its tickets — so an assignee of another tenant
|
|
250
301
|
* is legitimate. Who can be picked is what the assigner may read; the ticket
|
|
251
|
-
* ACL then grants the assignee access.
|
|
302
|
+
* ACL then grants the assignee access. `assignedRoles` has its own guard,
|
|
303
|
+
* {@link assertAssignableRoles}: a role's tenant lives in its name.
|
|
304
|
+
*/
|
|
305
|
+
const TENANT_SCOPED_POINTER_ARRAYS = {
|
|
306
|
+
tags: index_js_3.Service_Tag.className,
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Role-name prefixes that end in a tenant id (`od-tenant-user-<tenantId>`).
|
|
252
310
|
*/
|
|
253
|
-
const
|
|
311
|
+
const TENANT_ROLE_PREFIXES = [
|
|
312
|
+
"od-tenant-user-",
|
|
313
|
+
"od-tenant-admin-",
|
|
314
|
+
"od-service-provider-",
|
|
315
|
+
];
|
|
254
316
|
/**
|
|
255
317
|
* Shadow columns the ticket carries so the table can sort by a pointer.
|
|
256
318
|
*
|
|
@@ -307,21 +369,22 @@ async function loadReferencedRows(object, refreshSortKeys = false) {
|
|
|
307
369
|
if (object.dirty(field) || keyMissing || (refreshSortKeys && hasSortKey))
|
|
308
370
|
suspects.push(value);
|
|
309
371
|
}
|
|
310
|
-
for (const field of TENANT_SCOPED_POINTER_ARRAYS) {
|
|
311
|
-
if (!object.dirty(field))
|
|
312
|
-
continue;
|
|
313
|
-
const value = object.get(field);
|
|
314
|
-
if (Array.isArray(value))
|
|
315
|
-
suspects.push(...value.filter(Boolean));
|
|
316
|
-
}
|
|
317
372
|
const byClass = new Map();
|
|
373
|
+
const add = (className, id) => {
|
|
374
|
+
const ids = byClass.get(className) ?? new Set();
|
|
375
|
+
ids.add(id);
|
|
376
|
+
byClass.set(className, ids);
|
|
377
|
+
};
|
|
318
378
|
for (const suspect of suspects) {
|
|
319
379
|
// A pointer that has not been saved yet has no id — nothing to look up.
|
|
320
|
-
if (
|
|
380
|
+
if (suspect.id)
|
|
381
|
+
add(suspect.className, suspect.id);
|
|
382
|
+
}
|
|
383
|
+
for (const [field, className] of Object.entries(TENANT_SCOPED_POINTER_ARRAYS)) {
|
|
384
|
+
if (!object.dirty(field))
|
|
321
385
|
continue;
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
byClass.set(suspect.className, ids);
|
|
386
|
+
for (const id of (0, pointerIds_js_1.pointerIds)(object.get(field)))
|
|
387
|
+
add(className, id);
|
|
325
388
|
}
|
|
326
389
|
const rows = new Map();
|
|
327
390
|
for (const [className, ids] of byClass) {
|
|
@@ -369,12 +432,11 @@ function assertSameTenantReferences(object, rows) {
|
|
|
369
432
|
if (row)
|
|
370
433
|
judged.push(row);
|
|
371
434
|
}
|
|
372
|
-
for (const field of TENANT_SCOPED_POINTER_ARRAYS) {
|
|
435
|
+
for (const field of Object.keys(TENANT_SCOPED_POINTER_ARRAYS)) {
|
|
373
436
|
if (!object.dirty(field))
|
|
374
437
|
continue;
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
const row = entry?.id ? rows.get(entry.id) : undefined;
|
|
438
|
+
for (const id of (0, pointerIds_js_1.pointerIds)(object.get(field))) {
|
|
439
|
+
const row = rows.get(id);
|
|
378
440
|
if (row)
|
|
379
441
|
judged.push(row);
|
|
380
442
|
}
|
|
@@ -388,6 +450,51 @@ function assertSameTenantReferences(object, rows) {
|
|
|
388
450
|
`${refTenantId} on a ticket of tenant ${tenantId}.`);
|
|
389
451
|
}
|
|
390
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* Rejects assigned roles that reach beyond the ticket's tenant.
|
|
455
|
+
*
|
|
456
|
+
* An assigned role gets read/write on the ticket (`setTicketACL`) and every
|
|
457
|
+
* member a mail (`notifyNewAssignees`), and nothing else stopped a writer —
|
|
458
|
+
* or an alarm caller passing `assignedRoleIds` — from assigning another
|
|
459
|
+
* tenant's user role, `od-admin`, or `od-user`, which every user belongs to.
|
|
460
|
+
*
|
|
461
|
+
* `_Role` has no tenant column; a role's tenant lives in its name. So:
|
|
462
|
+
*
|
|
463
|
+
* - **`od-` roles** are the platform's. Only the ticket tenant's own are
|
|
464
|
+
* assignable (`od-tenant-user-<tenant>` and its siblings, see
|
|
465
|
+
* {@link TENANT_ROLE_PREFIXES}); the global ones (`od-admin`, `od-user`,
|
|
466
|
+
* `od-tenant-verified`, …) and other tenants' are refused.
|
|
467
|
+
* - **Any other name** is a role somebody created for their organisation
|
|
468
|
+
* ("Elektrik", "Schicht A"). Its tenant cannot be told from the name, so it
|
|
469
|
+
* stays assignable.
|
|
470
|
+
*
|
|
471
|
+
* Judged only when `assignedRoles` changes, like the other reference guards,
|
|
472
|
+
* so a ticket that already carries a bad role stays saveable until somebody
|
|
473
|
+
* edits its roles. Not skipped for the master key: the alarm endpoint writes
|
|
474
|
+
* with it on behalf of an outside caller.
|
|
475
|
+
*/
|
|
476
|
+
async function assertAssignableRoles(object) {
|
|
477
|
+
if (!object.dirty("assignedRoles"))
|
|
478
|
+
return;
|
|
479
|
+
const roleIds = (0, pointerIds_js_1.pointerIds)(object.get("assignedRoles"));
|
|
480
|
+
if (roleIds.length === 0)
|
|
481
|
+
return;
|
|
482
|
+
const tenantId = object.get("tenant")?.id;
|
|
483
|
+
const roles = await new node_1.default.Query(node_1.default.Role)
|
|
484
|
+
.containedIn("objectId", roleIds)
|
|
485
|
+
.select("name")
|
|
486
|
+
.limit(roleIds.length)
|
|
487
|
+
.find({ useMasterKey: true });
|
|
488
|
+
for (const role of roles) {
|
|
489
|
+
const name = role.getName() ?? "";
|
|
490
|
+
if (!name.startsWith("od-"))
|
|
491
|
+
continue;
|
|
492
|
+
const prefix = TENANT_ROLE_PREFIXES.find((p) => name.startsWith(p));
|
|
493
|
+
if (prefix && tenantId && name.slice(prefix.length) === tenantId)
|
|
494
|
+
continue;
|
|
495
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `Cannot assign role ${name} to a ticket of tenant ${tenantId}.`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
391
498
|
/**
|
|
392
499
|
* Keeps {@link SORT_KEY_FIELDS} in step with the pointers they shadow.
|
|
393
500
|
*
|
|
@@ -474,12 +581,12 @@ function applyClosedAt(object, rows) {
|
|
|
474
581
|
* indices. Parse ACL role grants require the role *name*, not its id, so the
|
|
475
582
|
* assigned role pointers are resolved to names first.
|
|
476
583
|
*
|
|
477
|
-
* This is the authority on who may write a ticket
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
584
|
+
* This is the authority on who may write a ticket. It builds on the fresh
|
|
585
|
+
* default ACL `defaultAclHandler` has just set (od-admin, the tenant's admins,
|
|
586
|
+
* tenant-wide read), so everything granted here is derived from the ticket's
|
|
587
|
+
* current fields and nothing survives from an earlier save — taking someone
|
|
588
|
+
* off a ticket takes their access with them. The tenant-user write is denied
|
|
589
|
+
* explicitly all the same, to keep the decision readable in one place.
|
|
483
590
|
*/
|
|
484
591
|
async function setTicketACL(object) {
|
|
485
592
|
const acl = object.getACL() ?? new node_1.default.ACL();
|
|
@@ -646,12 +753,15 @@ async function notifyRecipients(userIds, roleIds, notified, ticket, options) {
|
|
|
646
753
|
* recipient's tenant host — to the body.
|
|
647
754
|
*/
|
|
648
755
|
async function sendAssignmentNotification(user, ticket, options) {
|
|
649
|
-
|
|
756
|
+
// A translator fixed to the recipient's language rather than
|
|
757
|
+
// `i18next.changeLanguage`, which is global: two notifications in flight at
|
|
758
|
+
// once could each end up in the other's language.
|
|
759
|
+
const t = i18next_1.default.getFixedT(await (0, getUserLanguage_js_1.getUserLanguage)(user));
|
|
650
760
|
const base = `openservice:ticket.assignment.${options.variant}`;
|
|
651
761
|
const ticketName = ticket.get("title");
|
|
652
762
|
await new index_js_3.Notification({
|
|
653
|
-
title:
|
|
654
|
-
description:
|
|
763
|
+
title: t(`${base}.title`),
|
|
764
|
+
description: t(`${base}.description`, {
|
|
655
765
|
username: options.assignerName,
|
|
656
766
|
ticketName,
|
|
657
767
|
}),
|
package/dist/index.js
CHANGED
|
@@ -87,8 +87,13 @@ async function init() {
|
|
|
87
87
|
await (0, index_js_5.initPermissions)();
|
|
88
88
|
await (0, index_js_3.initNotifications)();
|
|
89
89
|
await (0, index_js_8.initUserSettings)();
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
const serviceGenerations = {
|
|
91
|
+
v1: (0, index_js_2.isFeatureEnabled)("MAINTENANCE"),
|
|
92
|
+
v2: (0, index_js_2.isFeatureEnabled)("SERVICE"),
|
|
93
|
+
};
|
|
94
|
+
if (serviceGenerations.v1 || serviceGenerations.v2) {
|
|
95
|
+
await (0, index_js_4.init)(serviceGenerations);
|
|
96
|
+
}
|
|
92
97
|
if ((0, index_js_2.isFeatureEnabled)("DOCUMENTATION"))
|
|
93
98
|
await (0, importDocs_js_1.importDocs)();
|
|
94
99
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
7
|
+
const pointerIds_js_1 = require("../helper/pointerIds.js");
|
|
8
|
+
const index_js_1 = require("../types/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* One-off repair for ticket ACLs written before the `Service_Ticket` hook
|
|
11
|
+
* rebuilt them on every save.
|
|
12
|
+
*
|
|
13
|
+
* The hook used to keep the stored ACL and only ever add to it, so a user taken
|
|
14
|
+
* off a ticket kept read and write, and so did anything a client had slipped
|
|
15
|
+
* into the ACL. Since the fix every save starts from scratch — but a ticket
|
|
16
|
+
* nobody touches keeps its old grants. This walks every ticket, archived ones
|
|
17
|
+
* included, and re-saves those whose ACL differs from what the hook grants
|
|
18
|
+
* today; the hook itself then writes the ACL, so this script only decides
|
|
19
|
+
* *which* tickets to touch.
|
|
20
|
+
*
|
|
21
|
+
* PARSE_URL=… PARSE_APP_ID=… PARSE_MASTER_KEY=… \
|
|
22
|
+
* node dist/scripts/repair-ticket-acl.js [--dry-run]
|
|
23
|
+
*
|
|
24
|
+
* A re-save stamps `updatedAt`, which the scheduler's auto-archive reads as
|
|
25
|
+
* activity: a repaired, finished ticket is archived one period later than it
|
|
26
|
+
* would have been. Tickets whose ACL is already right are not touched. The
|
|
27
|
+
* re-save writes no changelog entry (`skipChangelog`). Safe to re-run.
|
|
28
|
+
*/
|
|
29
|
+
const BATCH_SIZE = 200;
|
|
30
|
+
function requireEnv(name) {
|
|
31
|
+
const value = process.env[name];
|
|
32
|
+
if (!value) {
|
|
33
|
+
console.error(`Missing required environment variable ${name}.`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
/** An ACL as a sorted list of `key:r` / `key:w` entries, false grants dropped. */
|
|
39
|
+
function normalise(grants) {
|
|
40
|
+
return Object.entries(grants)
|
|
41
|
+
.flatMap(([key, permissions]) => [
|
|
42
|
+
...(permissions.read ? [`${key}:r`] : []),
|
|
43
|
+
...(permissions.write ? [`${key}:w`] : []),
|
|
44
|
+
])
|
|
45
|
+
.sort()
|
|
46
|
+
.join("|");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What the hook grants a ticket today — `defaultAclHandler` without a custom
|
|
50
|
+
* ACL plus `setTicketACL`. Only used to pick the tickets to re-save; the hook
|
|
51
|
+
* has the last word.
|
|
52
|
+
*/
|
|
53
|
+
function expectedGrants(ticket, roleNameById) {
|
|
54
|
+
const grants = {};
|
|
55
|
+
const grant = (key, read, write) => {
|
|
56
|
+
const current = grants[key] ?? {};
|
|
57
|
+
grants[key] = {
|
|
58
|
+
read: current.read || read,
|
|
59
|
+
write: current.write || write,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
grant("role:od-admin", true, true);
|
|
63
|
+
const tenantId = ticket.get("tenant")?.id;
|
|
64
|
+
if (tenantId) {
|
|
65
|
+
grant(`role:od-tenant-user-${tenantId}`, true, false);
|
|
66
|
+
grant(`role:od-tenant-admin-${tenantId}`, true, true);
|
|
67
|
+
}
|
|
68
|
+
const creatorId = ticket.get("createdBy")?.id;
|
|
69
|
+
if (creatorId)
|
|
70
|
+
grant(creatorId, true, true);
|
|
71
|
+
for (const userId of (0, pointerIds_js_1.pointerIds)(ticket.get("assignedUsers"))) {
|
|
72
|
+
grant(userId, true, true);
|
|
73
|
+
}
|
|
74
|
+
for (const roleId of (0, pointerIds_js_1.pointerIds)(ticket.get("assignedRoles"))) {
|
|
75
|
+
const name = roleNameById.get(roleId);
|
|
76
|
+
if (name)
|
|
77
|
+
grant(`role:${name}`, true, true);
|
|
78
|
+
}
|
|
79
|
+
return grants;
|
|
80
|
+
}
|
|
81
|
+
async function main() {
|
|
82
|
+
const dryRun = process.argv.includes("--dry-run");
|
|
83
|
+
node_1.default.initialize(requireEnv("PARSE_APP_ID"), undefined, requireEnv("PARSE_MASTER_KEY"));
|
|
84
|
+
node_1.default.serverURL =
|
|
85
|
+
process.env.PARSE_URL ?? "http://localhost:1337/parse";
|
|
86
|
+
const roles = await new node_1.default.Query(node_1.default.Role).findAll({
|
|
87
|
+
useMasterKey: true,
|
|
88
|
+
});
|
|
89
|
+
const roleNameById = new Map(roles.flatMap((role) => {
|
|
90
|
+
const name = role.getName();
|
|
91
|
+
return role.id && name ? [[role.id, name]] : [];
|
|
92
|
+
}));
|
|
93
|
+
let checked = 0;
|
|
94
|
+
let repaired = 0;
|
|
95
|
+
let failed = 0;
|
|
96
|
+
// The master key bypasses the soft-delete filter: archived tickets are
|
|
97
|
+
// reachable by link and need the repair as much as live ones.
|
|
98
|
+
await new node_1.default.Query(index_js_1.Service_Ticket).eachBatch(async (tickets) => {
|
|
99
|
+
const stale = [];
|
|
100
|
+
for (const ticket of tickets) {
|
|
101
|
+
const expected = expectedGrants(ticket, roleNameById);
|
|
102
|
+
const stored = (ticket.getACL()?.toJSON() ?? {});
|
|
103
|
+
if (normalise(stored) === normalise(expected))
|
|
104
|
+
continue;
|
|
105
|
+
// Gives the save something to send — an unchanged object may not be
|
|
106
|
+
// written at all. The hook rebuilds the ACL from scratch anyway.
|
|
107
|
+
ticket.setACL(new node_1.default.ACL(expected));
|
|
108
|
+
stale.push(ticket);
|
|
109
|
+
}
|
|
110
|
+
checked += tickets.length;
|
|
111
|
+
if (dryRun || stale.length === 0) {
|
|
112
|
+
repaired += stale.length;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
await node_1.default.Object.saveAll(stale, {
|
|
117
|
+
useMasterKey: true,
|
|
118
|
+
context: { skipChangelog: true },
|
|
119
|
+
});
|
|
120
|
+
repaired += stale.length;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
failed += stale.length;
|
|
124
|
+
console.error(`Could not repair ${stale.length} ticket(s):`, error);
|
|
125
|
+
}
|
|
126
|
+
}, { batchSize: BATCH_SIZE, useMasterKey: true });
|
|
127
|
+
console.log(`${dryRun ? "[dry run] " : ""}Checked ${checked} ticket(s), ` +
|
|
128
|
+
`${dryRun ? "would repair" : "repaired"} ${repaired}` +
|
|
129
|
+
(failed > 0 ? `, failed ${failed}` : "") +
|
|
130
|
+
".");
|
|
131
|
+
}
|
|
132
|
+
main().catch((error) => {
|
|
133
|
+
console.error(error);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openinc/parse-server-opendash",
|
|
3
|
-
"version": "4.24.
|
|
3
|
+
"version": "4.24.1",
|
|
4
4
|
"description": "Parse Server Cloud Code for open.INC Stack.",
|
|
5
5
|
"packageManager": "pnpm@12.8.1",
|
|
6
6
|
"keywords": [
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"migrate:verify": "node dist/scripts/migration/verify.js",
|
|
69
69
|
"backfill:meta-contexts": "node dist/scripts/backfill-meta-contexts.js",
|
|
70
70
|
"backfill:changelog-search": "node dist/scripts/backfill-changelog-search.js",
|
|
71
|
+
"repair:ticket-acl": "node dist/scripts/repair-ticket-acl.js",
|
|
71
72
|
"seed:v1": "node dist/scripts/seed-v1-testdata.js"
|
|
72
73
|
},
|
|
73
74
|
"dependencies": {
|