@openinc/parse-server-opendash 4.24.0 → 4.25.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/dist/features/config/helper/getConfig.js +2 -1
- package/dist/features/config/types/ConfigKeys.d.ts +1 -0
- package/dist/features/config/types/ConfigKeys.js +10 -25
- package/dist/features/openservice/alarms/tenantForSecret.js +3 -1
- package/dist/features/openservice/alarms/ticket/AlarmTicketTypes.d.ts +0 -4
- package/dist/features/openservice/alarms/ticket/AlarmTicketTypes.js +1 -5
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +10 -6
- package/dist/features/openservice/init.d.ts +12 -6
- package/dist/features/openservice/init.js +29 -21
- package/dist/features/openservice/tickets/ticketAccess.d.ts +40 -0
- package/dist/features/openservice/tickets/ticketAccess.js +105 -0
- package/dist/features/openservice/tickets/ticketCleanup.d.ts +25 -0
- package/dist/features/openservice/tickets/ticketCleanup.js +65 -0
- package/dist/features/openservice/tickets/ticketNotifications.d.ts +2 -0
- package/dist/features/openservice/tickets/ticketNotifications.js +242 -0
- package/dist/features/openservice/tickets/ticketNumber.d.ts +12 -0
- package/dist/features/openservice/tickets/ticketNumber.js +75 -0
- package/dist/features/openservice/tickets/ticketReferences.d.ts +61 -0
- package/dist/features/openservice/tickets/ticketReferences.js +229 -0
- 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/permissions/types/Permissions.d.ts +1 -0
- package/dist/features/permissions/types/Permissions.js +5 -2
- package/dist/features/schema/indexes.js +24 -0
- package/dist/features/schema/services/beforeSaveHook.js +54 -0
- package/dist/functions/openinc-backfill-ticket-sort-keys.d.ts +3 -2
- package/dist/functions/openinc-backfill-ticket-sort-keys.js +3 -2
- 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 +15 -0
- package/dist/helper/getUserLanguage.js +28 -4
- package/dist/helper/roleNames.d.ts +7 -0
- package/dist/helper/roleNames.js +21 -0
- package/dist/helper/ticketSortKeys.d.ts +8 -9
- package/dist/helper/ticketSortKeys.js +21 -23
- package/dist/helper/updateWithoutTriggers.d.ts +22 -0
- package/dist/helper/updateWithoutTriggers.js +57 -0
- package/dist/hooks/Chat_Message.js +119 -41
- package/dist/hooks/Config_open_service.js +30 -4
- package/dist/hooks/Meta_Entry.js +75 -14
- package/dist/hooks/Service_Equipment.js +6 -6
- package/dist/hooks/Service_FormConfig.js +19 -7
- package/dist/hooks/Service_Project.js +15 -1
- package/dist/hooks/Service_Status.js +51 -2
- package/dist/hooks/Service_Tag.js +51 -11
- package/dist/hooks/Service_Ticket.js +57 -626
- package/dist/index.js +7 -2
- package/dist/scripts/migration/lib/ptr.d.ts +1 -1
- package/dist/scripts/migration/lib/ptr.js +3 -5
- package/dist/scripts/migration/lib/ticket.js +3 -2
- package/dist/scripts/repair-ticket-acl.d.ts +1 -0
- package/dist/scripts/repair-ticket-acl.js +135 -0
- package/package.json +4 -1
- package/dist/helper/pointerIds.d.ts +0 -17
- package/dist/helper/pointerIds.js +0 -45
|
@@ -16,8 +16,9 @@ async function getConfig(key) {
|
|
|
16
16
|
const result = await new node_1.default.Query(index_js_1.Config).equalTo("key", key).first({
|
|
17
17
|
useMasterKey: true,
|
|
18
18
|
});
|
|
19
|
+
// Deliberately not logged: this runs on every push notification and alarm
|
|
20
|
+
// call, and several keys hold secrets (alarm secrets, Outlook credentials).
|
|
19
21
|
const value = result?.get("value");
|
|
20
|
-
console.log("[@openinc/parse-server-opendash][Config]", key, value);
|
|
21
22
|
return value || "";
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
@@ -84,6 +84,7 @@ export declare const ConfigKeys: {
|
|
|
84
84
|
readonly scheduleMetaFields: "OPENSERVICE_SCHEDULE_META_FIELDS";
|
|
85
85
|
readonly outlookIntegration: "OPENSERVICE_MICROSOFT_OUTLOOK_INTEGRATION";
|
|
86
86
|
readonly ticketArchiveAfterDays: "OPENSERVICE_TICKET_ARCHIVE_AFTER_DAYS";
|
|
87
|
+
readonly ticketDueNotifications: "OPENSERVICE_TICKET_DUE_NOTIFICATIONS";
|
|
87
88
|
readonly v2NotificationWatermark: "OPENSERVICE_V2_NOTIFICATION_WATERMARK";
|
|
88
89
|
};
|
|
89
90
|
};
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Every `OD3_Config` key this server knows, with what it is for and what it
|
|
4
|
-
* should hold when nobody has said otherwise.
|
|
5
|
-
*
|
|
6
|
-
* **Why a catalogue and not just string constants.** Setting an installation up
|
|
7
|
-
* used to mean creating rows by hand in the Parse dashboard, from a list that
|
|
8
|
-
* existed only in people's heads: the keys were spelled out inline at their
|
|
9
|
-
* point of use, some of them in three different files. A key nobody documented
|
|
10
|
-
* is a key somebody forgets, and a forgotten key is an endpoint that refuses
|
|
11
|
-
* every call for a reason nobody can see.
|
|
12
|
-
*
|
|
13
|
-
* Entries with a `defaultValue` (or `generate`) are created automatically at
|
|
14
|
-
* boot by `ensureConfigs()`. The rest need a human because they need data only
|
|
15
|
-
* the customer has — those are listed too, so a setup page can show what is
|
|
16
|
-
* still missing instead of leaving it to be discovered in production.
|
|
17
|
-
*
|
|
18
|
-
* **Never overwritten.** The bootstrap only ever creates; an existing value is
|
|
19
|
-
* left exactly as it is, including an empty one somebody set deliberately.
|
|
20
|
-
*/
|
|
21
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
3
|
exports.ConfigKeys = exports.ALL_CONFIG_KEYS = exports.OPENSERVICE_CONFIG_KEYS = void 0;
|
|
23
4
|
exports.configKeyDefinition = configKeyDefinition;
|
|
5
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
24
6
|
/**
|
|
25
7
|
* The open.SERVICE keys.
|
|
26
8
|
*
|
|
@@ -46,7 +28,7 @@ exports.OPENSERVICE_CONFIG_KEYS = [
|
|
|
46
28
|
required: true,
|
|
47
29
|
},
|
|
48
30
|
{
|
|
49
|
-
key:
|
|
31
|
+
key: openservice_shared_1.TICKET_CONFIG_KEYS.assignmentNotifications,
|
|
50
32
|
description: "Conditional rules for who is notified about a ticket beyond its assignees. JSON array, edited in the ticket admin.",
|
|
51
33
|
scope: "tenant",
|
|
52
34
|
defaultValue: "[]",
|
|
@@ -68,7 +50,7 @@ exports.OPENSERVICE_CONFIG_KEYS = [
|
|
|
68
50
|
},
|
|
69
51
|
{
|
|
70
52
|
// Read by the scheduler's `archiveIdleTickets` job.
|
|
71
|
-
key:
|
|
53
|
+
key: openservice_shared_1.TICKET_CONFIG_KEYS.ticketArchiveAfterDays,
|
|
72
54
|
description: 'Days a finished ticket (status category done or cancelled) may go without a change, chat message, file or meta entry before it is archived. "0" switches it off.',
|
|
73
55
|
scope: "tenant",
|
|
74
56
|
defaultValue: "30",
|
|
@@ -86,7 +68,7 @@ exports.OPENSERVICE_CONFIG_KEYS = [
|
|
|
86
68
|
scope: "tenant",
|
|
87
69
|
},
|
|
88
70
|
{
|
|
89
|
-
key:
|
|
71
|
+
key: openservice_shared_1.TICKET_CONFIG_KEYS.v2NotificationWatermark,
|
|
90
72
|
description: "How far the notification worker has got. Written by the scheduler; removing it re-sends or skips reminders.",
|
|
91
73
|
scope: "global",
|
|
92
74
|
runtimeState: true,
|
|
@@ -111,12 +93,15 @@ exports.ConfigKeys = {
|
|
|
111
93
|
OpenService: {
|
|
112
94
|
alarmScheduleSecret: "OPENSERVICE_ALARM_SCHEDULE_SECRET",
|
|
113
95
|
alarmTicketSecret: "OPENSERVICE_ALARM_TICKET_SECRET",
|
|
114
|
-
assignmentNotifications:
|
|
96
|
+
assignmentNotifications: openservice_shared_1.TICKET_CONFIG_KEYS.assignmentNotifications,
|
|
115
97
|
closedTicketsLifetime: "OPENSERVICE_CLOSED_TICKET_LIFETIME",
|
|
116
98
|
createTicketOnSchedule: "OPENSERVICE_CREATE_TICKET_ON_SCHEDULE",
|
|
117
99
|
scheduleMetaFields: "OPENSERVICE_SCHEDULE_META_FIELDS",
|
|
118
100
|
outlookIntegration: "OPENSERVICE_MICROSOFT_OUTLOOK_INTEGRATION",
|
|
119
|
-
ticketArchiveAfterDays:
|
|
120
|
-
|
|
101
|
+
ticketArchiveAfterDays: openservice_shared_1.TICKET_CONFIG_KEYS.ticketArchiveAfterDays,
|
|
102
|
+
// Written by the ticket admin page, read by the scheduler. Not catalogued:
|
|
103
|
+
// an empty rule list is the default, so there is nothing to seed.
|
|
104
|
+
ticketDueNotifications: openservice_shared_1.TICKET_CONFIG_KEYS.ticketDueNotifications,
|
|
105
|
+
v2NotificationWatermark: openservice_shared_1.TICKET_CONFIG_KEYS.v2NotificationWatermark,
|
|
121
106
|
},
|
|
122
107
|
};
|
|
@@ -20,10 +20,12 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
20
20
|
async function tenantForSecret(configKey, secret) {
|
|
21
21
|
if (!secret)
|
|
22
22
|
return undefined;
|
|
23
|
+
// `findAll`: a plain `find` stops at the server's default limit (100), and
|
|
24
|
+
// every tenant past it would have its valid secret silently refused.
|
|
23
25
|
const configs = await new node_1.default.Query(index_js_1.Config)
|
|
24
26
|
.equalTo("key", configKey)
|
|
25
27
|
.include("tenant")
|
|
26
|
-
.
|
|
28
|
+
.findAll({ useMasterKey: true });
|
|
27
29
|
const match = configs.find((config) => {
|
|
28
30
|
const value = config.get("value");
|
|
29
31
|
return typeof value === "string" && constantTimeEqual(value.trim(), secret);
|
|
@@ -19,10 +19,6 @@ export declare const ALARM_TICKET_ACTION_ID = "openservice-create-ticket";
|
|
|
19
19
|
* only answers to the master key.
|
|
20
20
|
*/
|
|
21
21
|
export declare const ALARM_TICKET_SECRET_CONFIG_KEY = "OPENSERVICE_ALARM_TICKET_SECRET";
|
|
22
|
-
/** Status category a fresh ticket lands in — mirrors the ticket plugin's port. */
|
|
23
|
-
export declare const DEFAULT_STATUS_CATEGORY = "inbox";
|
|
24
|
-
/** Categories in which a ticket counts as finished (mirrors core's `DONE_CATEGORIES`). */
|
|
25
|
-
export declare const DONE_STATUS_CATEGORIES: string[];
|
|
26
22
|
/**
|
|
27
23
|
* What the person configuring the alarm filled into the action's form
|
|
28
24
|
* (`OD3_AlarmAction.formFields`).
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* into an `OD3_Service_Ticket`.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
13
|
+
exports.ALARM_TICKET_SECRET_CONFIG_KEY = exports.ALARM_TICKET_ACTION_ID = void 0;
|
|
14
14
|
/** Id of the action row, and the marker in a ticket's `origin`. */
|
|
15
15
|
exports.ALARM_TICKET_ACTION_ID = "openservice-create-ticket";
|
|
16
16
|
/**
|
|
@@ -22,7 +22,3 @@ exports.ALARM_TICKET_ACTION_ID = "openservice-create-ticket";
|
|
|
22
22
|
* only answers to the master key.
|
|
23
23
|
*/
|
|
24
24
|
exports.ALARM_TICKET_SECRET_CONFIG_KEY = "OPENSERVICE_ALARM_TICKET_SECRET";
|
|
25
|
-
/** Status category a fresh ticket lands in — mirrors the ticket plugin's port. */
|
|
26
|
-
exports.DEFAULT_STATUS_CATEGORY = "inbox";
|
|
27
|
-
/** Categories in which a ticket counts as finished (mirrors core's `DONE_CATEGORIES`). */
|
|
28
|
-
exports.DONE_STATUS_CATEGORIES = ["done", "cancelled"];
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createAlarmTicket = createAlarmTicket;
|
|
7
7
|
exports.tenantForAlarmTicket = tenantForAlarmTicket;
|
|
8
8
|
const node_1 = __importDefault(require("parse/node"));
|
|
9
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
9
10
|
const index_js_1 = require("../../../../types/index.js");
|
|
10
11
|
const actionParams_js_1 = require("../actionParams.js");
|
|
11
12
|
const alarmIdentity_js_1 = require("../alarmIdentity.js");
|
|
@@ -52,7 +53,7 @@ async function createAlarmTicket(tenant, event, rawParams = {}) {
|
|
|
52
53
|
}
|
|
53
54
|
const status = await resolveDefaultStatus(tenant);
|
|
54
55
|
if (!status) {
|
|
55
|
-
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `No "${
|
|
56
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `No "${openservice_shared_1.DEFAULT_STATUS_CATEGORY}" status configured for this tenant — cannot create a ticket.`);
|
|
56
57
|
}
|
|
57
58
|
const equipment = await (0, resolveEquipment_js_1.resolveEquipment)(tenant, event, params.equipmentId, `[${AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID}]`);
|
|
58
59
|
const ticket = new index_js_1.Service_Ticket();
|
|
@@ -74,8 +75,8 @@ async function createAlarmTicket(tenant, event, rawParams = {}) {
|
|
|
74
75
|
project.id = params.projectId;
|
|
75
76
|
ticket.set("project", project);
|
|
76
77
|
}
|
|
77
|
-
// Assignment arrays hold plain ids in this schema (see
|
|
78
|
-
//
|
|
78
|
+
// Assignment arrays hold plain ids in this schema (see `refIds` in
|
|
79
|
+
// `@opendash/openservice-shared`, which reads both).
|
|
79
80
|
if (params.assignedUserIds?.length) {
|
|
80
81
|
ticket.set("assignedUsers", params.assignedUserIds);
|
|
81
82
|
}
|
|
@@ -110,15 +111,18 @@ async function findOpenTicket(tenant, origin) {
|
|
|
110
111
|
.find({ useMasterKey: true });
|
|
111
112
|
return tickets.find((ticket) => {
|
|
112
113
|
const category = ticket.get("status")?.get("category");
|
|
113
|
-
return !
|
|
114
|
+
return !(0, openservice_shared_1.isDoneCategory)(category);
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
117
|
/** The tenant's inbox status, else a global one — never another tenant's. */
|
|
117
118
|
async function resolveDefaultStatus(tenant) {
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
// Only this tenant's and the global ones: across all tenants a plain `find`
|
|
120
|
+
// stopped at the default limit (100) and could miss the tenant's own inbox.
|
|
121
|
+
const statuses = await node_1.default.Query.or(new node_1.default.Query(index_js_1.Service_Status).equalTo("tenant", tenant), new node_1.default.Query(index_js_1.Service_Status).doesNotExist("tenant"))
|
|
122
|
+
.equalTo("category", openservice_shared_1.DEFAULT_STATUS_CATEGORY)
|
|
120
123
|
.equalTo("deleted", false)
|
|
121
124
|
.ascending("order")
|
|
125
|
+
.limit(1000)
|
|
122
126
|
.find({ useMasterKey: true });
|
|
123
127
|
return (statuses.find((status) => status.get("tenant")?.id === tenant.id) ?? statuses.find((status) => !status.get("tenant")));
|
|
124
128
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bring the open.SERVICE feature up.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* `Maintenance_*` classes, v2 the `Service_*` ones
|
|
6
|
-
* (
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Each generation behind its own feature flag: the v1 bootstraps seed and
|
|
5
|
+
* migrate the `Maintenance_*` classes (`MAINTENANCE`), v2 the `Service_*` ones
|
|
6
|
+
* (`SERVICE`). Both used to hang on `MAINTENANCE` alone, so an installation
|
|
7
|
+
* running only v2 got none of its own setup — no config rows (archive period,
|
|
8
|
+
* alarm secrets), no alarm actions. The v1 half is deprecated (each function
|
|
9
|
+
* says what replaces it) but must keep running as long as installations hold
|
|
10
|
+
* v1 data — dropping it would strand their tickets and plans, not just their
|
|
11
|
+
* code.
|
|
9
12
|
*/
|
|
10
|
-
export declare function init(
|
|
13
|
+
export declare function init(generations: {
|
|
14
|
+
v1: boolean;
|
|
15
|
+
v2: boolean;
|
|
16
|
+
}): Promise<void>;
|
|
@@ -14,32 +14,40 @@ const initTicket_js_1 = require("./ticket/initTicket.js");
|
|
|
14
14
|
/**
|
|
15
15
|
* Bring the open.SERVICE feature up.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
* `Maintenance_*` classes, v2 the `Service_*` ones
|
|
19
|
-
* (
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
* Each generation behind its own feature flag: the v1 bootstraps seed and
|
|
18
|
+
* migrate the `Maintenance_*` classes (`MAINTENANCE`), v2 the `Service_*` ones
|
|
19
|
+
* (`SERVICE`). Both used to hang on `MAINTENANCE` alone, so an installation
|
|
20
|
+
* running only v2 got none of its own setup — no config rows (archive period,
|
|
21
|
+
* alarm secrets), no alarm actions. The v1 half is deprecated (each function
|
|
22
|
+
* says what replaces it) but must keep running as long as installations hold
|
|
23
|
+
* v1 data — dropping it would strand their tickets and plans, not just their
|
|
24
|
+
* code.
|
|
22
25
|
*/
|
|
23
|
-
async function init() {
|
|
26
|
+
async function init(generations) {
|
|
24
27
|
console.log("Initializing open.SERVICE feature...");
|
|
25
28
|
// --- v1 (`Maintenance_*`), deprecated ------------------------------------
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
if (generations.v1) {
|
|
30
|
+
await (0, initKanbanStates_js_1.initKanbanStates)();
|
|
31
|
+
await (0, initIssuecategory_js_1.initIssuecategory)();
|
|
32
|
+
await (0, initMessages_js_1.initializeMessages)();
|
|
33
|
+
await (0, initKanbanStates_js_1.initCurrentTicketStates)();
|
|
34
|
+
await (0, initTicket_js_1.updateTicketDescription)();
|
|
35
|
+
await (0, initKanbanStates_js_1.initEnabledFlag)();
|
|
36
|
+
await (0, initTicket_js_1.initTicketClass)();
|
|
37
|
+
await (0, reassignScheduleExecutions_js_1.reassignScheduleExecutions)();
|
|
38
|
+
await (0, checkStatus_js_1.checkStatus)();
|
|
39
|
+
await (0, initSchedulesFeature_js_1.initSchedulesFeature)();
|
|
40
|
+
}
|
|
36
41
|
// --- v2 (`Service_*`) ----------------------------------------------------
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
if (generations.v2) {
|
|
43
|
+
await (0, initServiceSchedulesFeature_js_1.initServiceSchedulesFeature)();
|
|
44
|
+
await (0, index_js_2.ensureAlarmTicketAction)();
|
|
45
|
+
await (0, index_js_2.ensureAlarmScheduleAction)();
|
|
46
|
+
await (0, index_js_2.ensureAlarmScheduleWebhook)();
|
|
47
|
+
}
|
|
41
48
|
// Last, so the rows it reports as missing are the ones a human still has to
|
|
42
|
-
// supply rather than ones a later bootstrap would have created anyway.
|
|
49
|
+
// supply rather than ones a later bootstrap would have created anyway. The
|
|
50
|
+
// catalogue holds keys of both generations.
|
|
43
51
|
await (0, index_js_1.ensureConfigs)();
|
|
44
52
|
console.log("open.SERVICE feature initialized.");
|
|
45
53
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rejects assigned roles that reach beyond the ticket's tenant.
|
|
3
|
+
*
|
|
4
|
+
* An assigned role gets read/write on the ticket (`setTicketACL`) and every
|
|
5
|
+
* member a mail (`notifyNewAssignees`), and nothing else stopped a writer —
|
|
6
|
+
* or an alarm caller passing `assignedRoleIds` — from assigning another
|
|
7
|
+
* tenant's user role, `od-admin`, or `od-user`, which every user belongs to.
|
|
8
|
+
*
|
|
9
|
+
* `_Role` has no tenant column; a role's tenant lives in its name. So:
|
|
10
|
+
*
|
|
11
|
+
* - **`od-` roles** are the platform's. Only the ticket tenant's own are
|
|
12
|
+
* assignable (`od-tenant-user-<tenant>` and its siblings, see
|
|
13
|
+
* `isAssignableRoleName` in `@opendash/openservice-shared` — the frontend's
|
|
14
|
+
* role picker applies the same rule); the global ones (`od-admin`, `od-user`,
|
|
15
|
+
* `od-tenant-verified`, …) and other tenants' are refused.
|
|
16
|
+
* - **Any other name** is a role somebody created for their organisation
|
|
17
|
+
* ("Elektrik", "Schicht A"). Its tenant cannot be told from the name, so it
|
|
18
|
+
* stays assignable.
|
|
19
|
+
*
|
|
20
|
+
* Judged only when `assignedRoles` changes, like the other reference guards,
|
|
21
|
+
* so a ticket that already carries a bad role stays saveable until somebody
|
|
22
|
+
* edits its roles. Not skipped for the master key: the alarm endpoint writes
|
|
23
|
+
* with it on behalf of an outside caller.
|
|
24
|
+
*/
|
|
25
|
+
export declare function assertAssignableRoles(object: Parse.Object): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the ticket ACL from `createdBy`, `assignedUsers` and `assignedRoles` —
|
|
28
|
+
* each gets read/write. `assignedUsers`/`assignedRoles` are arrays of Parse
|
|
29
|
+
* pointers, so we iterate the entries (by object id) rather than the array
|
|
30
|
+
* indices. Parse ACL role grants require the role *name*, not its id, so the
|
|
31
|
+
* assigned role pointers are resolved to names first.
|
|
32
|
+
*
|
|
33
|
+
* This is the authority on who may write a ticket. It builds on the fresh
|
|
34
|
+
* default ACL `defaultAclHandler` has just set (od-admin, the tenant's admins,
|
|
35
|
+
* tenant-wide read), so everything granted here is derived from the ticket's
|
|
36
|
+
* current fields and nothing survives from an earlier save — taking someone
|
|
37
|
+
* off a ticket takes their access with them. The tenant-user write is denied
|
|
38
|
+
* explicitly all the same, to keep the decision readable in one place.
|
|
39
|
+
*/
|
|
40
|
+
export declare function setTicketACL(object: Parse.Object): Promise<void>;
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
exports.assertAssignableRoles = assertAssignableRoles;
|
|
7
|
+
exports.setTicketACL = setTicketACL;
|
|
8
|
+
// Who a ticket belongs to: the roles it may be assigned to, and its ACL.
|
|
9
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
10
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
11
|
+
/**
|
|
12
|
+
* Rejects assigned roles that reach beyond the ticket's tenant.
|
|
13
|
+
*
|
|
14
|
+
* An assigned role gets read/write on the ticket (`setTicketACL`) and every
|
|
15
|
+
* member a mail (`notifyNewAssignees`), and nothing else stopped a writer —
|
|
16
|
+
* or an alarm caller passing `assignedRoleIds` — from assigning another
|
|
17
|
+
* tenant's user role, `od-admin`, or `od-user`, which every user belongs to.
|
|
18
|
+
*
|
|
19
|
+
* `_Role` has no tenant column; a role's tenant lives in its name. So:
|
|
20
|
+
*
|
|
21
|
+
* - **`od-` roles** are the platform's. Only the ticket tenant's own are
|
|
22
|
+
* assignable (`od-tenant-user-<tenant>` and its siblings, see
|
|
23
|
+
* `isAssignableRoleName` in `@opendash/openservice-shared` — the frontend's
|
|
24
|
+
* role picker applies the same rule); the global ones (`od-admin`, `od-user`,
|
|
25
|
+
* `od-tenant-verified`, …) and other tenants' are refused.
|
|
26
|
+
* - **Any other name** is a role somebody created for their organisation
|
|
27
|
+
* ("Elektrik", "Schicht A"). Its tenant cannot be told from the name, so it
|
|
28
|
+
* stays assignable.
|
|
29
|
+
*
|
|
30
|
+
* Judged only when `assignedRoles` changes, like the other reference guards,
|
|
31
|
+
* so a ticket that already carries a bad role stays saveable until somebody
|
|
32
|
+
* edits its roles. Not skipped for the master key: the alarm endpoint writes
|
|
33
|
+
* with it on behalf of an outside caller.
|
|
34
|
+
*/
|
|
35
|
+
async function assertAssignableRoles(object) {
|
|
36
|
+
if (!object.dirty("assignedRoles"))
|
|
37
|
+
return;
|
|
38
|
+
const roleIds = (0, openservice_shared_1.refIds)(object.get("assignedRoles"));
|
|
39
|
+
if (roleIds.length === 0)
|
|
40
|
+
return;
|
|
41
|
+
const tenantId = object.get("tenant")?.id;
|
|
42
|
+
const roles = await new node_1.default.Query(node_1.default.Role)
|
|
43
|
+
.containedIn("objectId", roleIds)
|
|
44
|
+
.select("name")
|
|
45
|
+
.limit(roleIds.length)
|
|
46
|
+
.find({ useMasterKey: true });
|
|
47
|
+
for (const role of roles) {
|
|
48
|
+
const name = role.getName() ?? "";
|
|
49
|
+
if ((0, openservice_shared_1.isAssignableRoleName)(name, tenantId))
|
|
50
|
+
continue;
|
|
51
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `Cannot assign role ${name} to a ticket of tenant ${tenantId}.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets the ticket ACL from `createdBy`, `assignedUsers` and `assignedRoles` —
|
|
56
|
+
* each gets read/write. `assignedUsers`/`assignedRoles` are arrays of Parse
|
|
57
|
+
* pointers, so we iterate the entries (by object id) rather than the array
|
|
58
|
+
* indices. Parse ACL role grants require the role *name*, not its id, so the
|
|
59
|
+
* assigned role pointers are resolved to names first.
|
|
60
|
+
*
|
|
61
|
+
* This is the authority on who may write a ticket. It builds on the fresh
|
|
62
|
+
* default ACL `defaultAclHandler` has just set (od-admin, the tenant's admins,
|
|
63
|
+
* tenant-wide read), so everything granted here is derived from the ticket's
|
|
64
|
+
* current fields and nothing survives from an earlier save — taking someone
|
|
65
|
+
* off a ticket takes their access with them. The tenant-user write is denied
|
|
66
|
+
* explicitly all the same, to keep the decision readable in one place.
|
|
67
|
+
*/
|
|
68
|
+
async function setTicketACL(object) {
|
|
69
|
+
const acl = object.getACL() ?? new node_1.default.ACL();
|
|
70
|
+
// deny global read / write
|
|
71
|
+
acl.setPublicReadAccess(false);
|
|
72
|
+
acl.setPublicWriteAccess(false);
|
|
73
|
+
// the tenant reads every ticket, but writes only its own / assigned ones
|
|
74
|
+
const tenantId = object.get("tenant")?.id;
|
|
75
|
+
if (tenantId) {
|
|
76
|
+
acl.setRoleReadAccess(`od-tenant-user-${tenantId}`, true);
|
|
77
|
+
acl.setRoleWriteAccess(`od-tenant-user-${tenantId}`, false);
|
|
78
|
+
}
|
|
79
|
+
// creator read/write
|
|
80
|
+
const creatorId = object.get("createdBy")?.id;
|
|
81
|
+
if (creatorId) {
|
|
82
|
+
acl.setReadAccess(creatorId, true);
|
|
83
|
+
acl.setWriteAccess(creatorId, true);
|
|
84
|
+
}
|
|
85
|
+
// assigned users read/write
|
|
86
|
+
for (const userId of (0, openservice_shared_1.refIds)(object.get("assignedUsers"))) {
|
|
87
|
+
acl.setReadAccess(userId, true);
|
|
88
|
+
acl.setWriteAccess(userId, true);
|
|
89
|
+
}
|
|
90
|
+
// assigned roles read/write (resolve pointer ids → role names)
|
|
91
|
+
const roleIds = (0, openservice_shared_1.refIds)(object.get("assignedRoles"));
|
|
92
|
+
if (roleIds.length > 0) {
|
|
93
|
+
const roles = await new node_1.default.Query(node_1.default.Role)
|
|
94
|
+
.containedIn("objectId", roleIds)
|
|
95
|
+
.find({ useMasterKey: true });
|
|
96
|
+
for (const role of roles) {
|
|
97
|
+
const name = role.getName();
|
|
98
|
+
if (name) {
|
|
99
|
+
acl.setRoleReadAccess(name, true);
|
|
100
|
+
acl.setRoleWriteAccess(name, true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
object.setACL(acl);
|
|
105
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes everything attached to a ticket after it is deleted for good — the
|
|
3
|
+
* archive's "delete permanently" promises that nothing of it is left.
|
|
4
|
+
*
|
|
5
|
+
* Parse cannot cascade these on its own: meta head-data ({@link Meta_Entry})
|
|
6
|
+
* and chat messages ({@link Chat_Message}) link to the ticket by a plain string
|
|
7
|
+
* key rather than a pointer, and notifications reference it inside their JSON
|
|
8
|
+
* `data` blob. The ticket's files ({@link Assets}) — its file library and the
|
|
9
|
+
* attachments of its comments — share the chat's context; destroying an asset
|
|
10
|
+
* row also removes its stored file (see the `Assets` hook).
|
|
11
|
+
*
|
|
12
|
+
* **The history goes too**: every {@link Changelog} entry of the ticket — the
|
|
13
|
+
* delete entry the changelog's `beforeDelete` just wrote included — and of each
|
|
14
|
+
* row removed here. The rows are destroyed with `skipChangelog`, or each would
|
|
15
|
+
* write a delete entry holding its content straight back into the history.
|
|
16
|
+
*
|
|
17
|
+
* Left alone: child tickets (their `parent` pointer dangles; they are tickets
|
|
18
|
+
* of their own) and sent mails (`Core_Email` keeps a log of what went out,
|
|
19
|
+
* with no reference to the ticket that could be matched).
|
|
20
|
+
*
|
|
21
|
+
* This is the single cleanup path for both single deletes and the dev
|
|
22
|
+
* "delete all" command, so the frontend no longer needs to delete related data
|
|
23
|
+
* itself.
|
|
24
|
+
*/
|
|
25
|
+
export declare function cleanupTicketRelations(ticketId: string): Promise<void>;
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
exports.cleanupTicketRelations = cleanupTicketRelations;
|
|
7
|
+
// The cascade that removes everything attached to a ticket deleted for good.
|
|
8
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
9
|
+
const index_js_1 = require("../../../types/index.js");
|
|
10
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
11
|
+
/**
|
|
12
|
+
* Removes everything attached to a ticket after it is deleted for good — the
|
|
13
|
+
* archive's "delete permanently" promises that nothing of it is left.
|
|
14
|
+
*
|
|
15
|
+
* Parse cannot cascade these on its own: meta head-data ({@link Meta_Entry})
|
|
16
|
+
* and chat messages ({@link Chat_Message}) link to the ticket by a plain string
|
|
17
|
+
* key rather than a pointer, and notifications reference it inside their JSON
|
|
18
|
+
* `data` blob. The ticket's files ({@link Assets}) — its file library and the
|
|
19
|
+
* attachments of its comments — share the chat's context; destroying an asset
|
|
20
|
+
* row also removes its stored file (see the `Assets` hook).
|
|
21
|
+
*
|
|
22
|
+
* **The history goes too**: every {@link Changelog} entry of the ticket — the
|
|
23
|
+
* delete entry the changelog's `beforeDelete` just wrote included — and of each
|
|
24
|
+
* row removed here. The rows are destroyed with `skipChangelog`, or each would
|
|
25
|
+
* write a delete entry holding its content straight back into the history.
|
|
26
|
+
*
|
|
27
|
+
* Left alone: child tickets (their `parent` pointer dangles; they are tickets
|
|
28
|
+
* of their own) and sent mails (`Core_Email` keeps a log of what went out,
|
|
29
|
+
* with no reference to the ticket that could be matched).
|
|
30
|
+
*
|
|
31
|
+
* This is the single cleanup path for both single deletes and the dev
|
|
32
|
+
* "delete all" command, so the frontend no longer needs to delete related data
|
|
33
|
+
* itself.
|
|
34
|
+
*/
|
|
35
|
+
async function cleanupTicketRelations(ticketId) {
|
|
36
|
+
const context = (0, openservice_shared_1.ticketContextKey)(ticketId);
|
|
37
|
+
const [metaEntries, chatMessages, assets, notifications] = await Promise.all([
|
|
38
|
+
new node_1.default.Query(index_js_1.Meta_Entry)
|
|
39
|
+
.equalTo("entryClassName", index_js_1.Service_Ticket.className)
|
|
40
|
+
.equalTo("entryObjectId", ticketId)
|
|
41
|
+
.findAll({ useMasterKey: true }),
|
|
42
|
+
new node_1.default.Query(index_js_1.Chat_Message)
|
|
43
|
+
.equalTo("context", context)
|
|
44
|
+
.findAll({ useMasterKey: true }),
|
|
45
|
+
new node_1.default.Query(index_js_1.Assets)
|
|
46
|
+
.equalTo("context", context)
|
|
47
|
+
.findAll({ useMasterKey: true }),
|
|
48
|
+
// `data` is a JSON Object column; Parse supports dot-notation into it. Query
|
|
49
|
+
// by class name (untyped) so the `data.ticketId` path key is accepted.
|
|
50
|
+
new node_1.default.Query(index_js_1.Notification.className)
|
|
51
|
+
.equalTo("data.ticketId", ticketId)
|
|
52
|
+
.findAll({ useMasterKey: true }),
|
|
53
|
+
]);
|
|
54
|
+
// Both steps run even if one fails: a chat message that could not be removed
|
|
55
|
+
// is no reason to keep the ticket's whole history.
|
|
56
|
+
const failures = [];
|
|
57
|
+
await node_1.default.Object.destroyAll([...metaEntries, ...chatMessages, ...assets, ...notifications], { useMasterKey: true, context: { skipChangelog: true } }).catch((error) => failures.push(error));
|
|
58
|
+
const historyOf = (className, rows) => new node_1.default.Query(index_js_1.Changelog).equalTo("nameOfClass", className).containedIn("changedObject", rows.map((row) => row.id));
|
|
59
|
+
const history = await node_1.default.Query.or(new node_1.default.Query(index_js_1.Changelog)
|
|
60
|
+
.equalTo("nameOfClass", index_js_1.Service_Ticket.className)
|
|
61
|
+
.equalTo("changedObject", ticketId), historyOf(index_js_1.Meta_Entry.className, metaEntries), historyOf(index_js_1.Chat_Message.className, chatMessages), historyOf(index_js_1.Assets.className, assets), historyOf(index_js_1.Notification.className, notifications)).findAll({ useMasterKey: true });
|
|
62
|
+
await node_1.default.Object.destroyAll(history, { useMasterKey: true }).catch((error) => failures.push(error));
|
|
63
|
+
if (failures.length > 0)
|
|
64
|
+
throw failures[0];
|
|
65
|
+
}
|