@openinc/parse-server-opendash 4.24.1 → 4.26.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.
Files changed (55) hide show
  1. package/dist/features/config/helper/getConfig.js +2 -1
  2. package/dist/features/config/types/ConfigKeys.js +8 -26
  3. package/dist/features/openservice/alarms/ticket/AlarmTicketTypes.d.ts +0 -4
  4. package/dist/features/openservice/alarms/ticket/AlarmTicketTypes.js +1 -5
  5. package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +6 -5
  6. package/dist/features/openservice/tickets/ticketAccess.d.ts +40 -0
  7. package/dist/features/openservice/tickets/ticketAccess.js +105 -0
  8. package/dist/features/openservice/tickets/ticketArchive.d.ts +54 -0
  9. package/dist/features/openservice/tickets/ticketArchive.js +112 -0
  10. package/dist/features/openservice/tickets/ticketCleanup.d.ts +25 -0
  11. package/dist/features/openservice/tickets/ticketCleanup.js +65 -0
  12. package/dist/features/openservice/tickets/ticketFormConfig.d.ts +20 -0
  13. package/dist/features/openservice/tickets/ticketFormConfig.js +74 -0
  14. package/dist/features/openservice/tickets/ticketNotifications.d.ts +2 -0
  15. package/dist/features/openservice/tickets/ticketNotifications.js +242 -0
  16. package/dist/features/openservice/tickets/ticketNumber.d.ts +12 -0
  17. package/dist/features/openservice/tickets/ticketNumber.js +75 -0
  18. package/dist/features/openservice/tickets/ticketPriority.d.ts +47 -0
  19. package/dist/features/openservice/tickets/ticketPriority.js +103 -0
  20. package/dist/features/openservice/tickets/ticketReferences.d.ts +61 -0
  21. package/dist/features/openservice/tickets/ticketReferences.js +235 -0
  22. package/dist/features/permissions/types/Permissions.d.ts +1 -0
  23. package/dist/features/permissions/types/Permissions.js +5 -2
  24. package/dist/features/schema/indexes.js +22 -2
  25. package/dist/features/schema/services/ensureIndexes.js +11 -2
  26. package/dist/functions/openinc-backfill-ticket-sort-keys.d.ts +3 -2
  27. package/dist/functions/openinc-backfill-ticket-sort-keys.js +3 -2
  28. package/dist/functions/openinc-openservice-form-config.d.ts +20 -0
  29. package/dist/functions/openinc-openservice-form-config.js +51 -0
  30. package/dist/helper/getUserLanguage.d.ts +3 -5
  31. package/dist/helper/getUserLanguage.js +7 -16
  32. package/dist/helper/roleNames.d.ts +7 -0
  33. package/dist/helper/roleNames.js +21 -0
  34. package/dist/helper/ticketSortKeys.d.ts +8 -9
  35. package/dist/helper/ticketSortKeys.js +21 -23
  36. package/dist/helper/updateWithoutTriggers.d.ts +22 -0
  37. package/dist/helper/updateWithoutTriggers.js +57 -0
  38. package/dist/hooks/Chat_Message.js +7 -30
  39. package/dist/hooks/Meta_Entry.js +6 -1
  40. package/dist/hooks/Service_Equipment.js +2 -1
  41. package/dist/hooks/Service_FormConfig.js +6 -5
  42. package/dist/hooks/Service_Project.js +2 -1
  43. package/dist/hooks/Service_Status.js +3 -6
  44. package/dist/hooks/Service_Tag.js +51 -11
  45. package/dist/hooks/Service_Ticket.js +45 -702
  46. package/dist/scripts/migration/lib/ptr.d.ts +1 -1
  47. package/dist/scripts/migration/lib/ptr.js +3 -5
  48. package/dist/scripts/migration/lib/ticket.js +3 -2
  49. package/dist/scripts/repair-ticket-acl.js +3 -3
  50. package/dist/types/Service_Ticket.d.ts +6 -0
  51. package/dist/types/Service_Ticket.js +12 -0
  52. package/package.json +3 -1
  53. package/schema/Service_Ticket.json +6 -0
  54. package/dist/helper/pointerIds.d.ts +0 -17
  55. 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
  /**
@@ -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: "OPENSERVICE_ASSIGNMENT_NOTIFICATIONS",
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: "OPENSERVICE_TICKET_ARCHIVE_AFTER_DAYS",
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: "OPENSERVICE_V2_NOTIFICATION_WATERMARK",
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,15 +93,15 @@ exports.ConfigKeys = {
111
93
  OpenService: {
112
94
  alarmScheduleSecret: "OPENSERVICE_ALARM_SCHEDULE_SECRET",
113
95
  alarmTicketSecret: "OPENSERVICE_ALARM_TICKET_SECRET",
114
- assignmentNotifications: "OPENSERVICE_ASSIGNMENT_NOTIFICATIONS",
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: "OPENSERVICE_TICKET_ARCHIVE_AFTER_DAYS",
101
+ ticketArchiveAfterDays: openservice_shared_1.TICKET_CONFIG_KEYS.ticketArchiveAfterDays,
120
102
  // Written by the ticket admin page, read by the scheduler. Not catalogued:
121
103
  // an empty rule list is the default, so there is nothing to seed.
122
- ticketDueNotifications: "OPENSERVICE_TICKET_DUE_NOTIFICATIONS",
123
- v2NotificationWatermark: "OPENSERVICE_V2_NOTIFICATION_WATERMARK",
104
+ ticketDueNotifications: openservice_shared_1.TICKET_CONFIG_KEYS.ticketDueNotifications,
105
+ v2NotificationWatermark: openservice_shared_1.TICKET_CONFIG_KEYS.v2NotificationWatermark,
124
106
  },
125
107
  };
@@ -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.DONE_STATUS_CATEGORIES = exports.DEFAULT_STATUS_CATEGORY = exports.ALARM_TICKET_SECRET_CONFIG_KEY = exports.ALARM_TICKET_ACTION_ID = void 0;
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 "${AlarmTicketTypes_js_1.DEFAULT_STATUS_CATEGORY}" status configured for this tenant — cannot create a ticket.`);
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 the `pointerIds`
78
- // helper in the ticket hook, which accepts both).
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,7 +111,7 @@ 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 !AlarmTicketTypes_js_1.DONE_STATUS_CATEGORIES.includes(category);
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. */
@@ -118,7 +119,7 @@ async function resolveDefaultStatus(tenant) {
118
119
  // Only this tenant's and the global ones: across all tenants a plain `find`
119
120
  // stopped at the default limit (100) and could miss the tenant's own inbox.
120
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"))
121
- .equalTo("category", AlarmTicketTypes_js_1.DEFAULT_STATUS_CATEGORY)
122
+ .equalTo("category", openservice_shared_1.DEFAULT_STATUS_CATEGORY)
122
123
  .equalTo("deleted", false)
123
124
  .ascending("order")
124
125
  .limit(1000)
@@ -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,54 @@
1
+ /**
2
+ * The values of `archiveReason`. Mirrors `TICKET_ARCHIVE_REASONS` in
3
+ * `@opendash/openservice-shared`; import it from there once the installed
4
+ * nightly carries it (it arrived after `0.2.0-nightly.0`).
5
+ */
6
+ export declare const ARCHIVE_REASON: {
7
+ /** The scheduler's `archiveIdleTickets`: finished and idle for a period. */
8
+ readonly auto: "auto";
9
+ /** Everything else — the archive button, the admin table, the REST API. */
10
+ readonly manual: "manual";
11
+ };
12
+ /**
13
+ * Stamps `archiveReason` when a ticket is archived and clears it on restore.
14
+ *
15
+ * What it is for: the archive page shows who archived a ticket — the scheduler
16
+ * or somebody's hand. It decides nothing; whether a ticket feeds the
17
+ * similar-case search is `useForSimilarCases` (see {@link applySimilarCaseUse}).
18
+ *
19
+ * **Only the master key can say "auto".** The scheduler archives with the
20
+ * master key and sends `auto`. A client sending it is overruled. A master-key
21
+ * write without a reason (or with one that is not a known value) counts as
22
+ * `manual`.
23
+ *
24
+ * **Set once, at the moment of archiving.** A later save of an archived ticket
25
+ * keeps the stored reason, whatever it sends. Restoring clears it: a live
26
+ * ticket has no reason to be archived, and the next archive sets a fresh one.
27
+ */
28
+ export declare function applyArchiveReason(object: Parse.Object, original: Parse.Object | undefined, master: boolean): void;
29
+ /**
30
+ * Whether this save changes `useForSimilarCases` of a ticket that was archived
31
+ * before and stays archived — the archive page's switch. That is archive
32
+ * management, so the hook asks for the archiving capability.
33
+ */
34
+ export declare function changesSimilarCaseUse(object: Parse.Object, original: Parse.Object | undefined): boolean;
35
+ /**
36
+ * Keeps `useForSimilarCases` — whether an archived ticket still feeds "Ähnliche
37
+ * Tickets" — to archived tickets.
38
+ *
39
+ * **Why a column of its own.** The similar-case search should find solved
40
+ * problems, and many of them get archived: by the scheduler once they sat idle,
41
+ * by hand when somebody clears the board early. Some archived tickets are
42
+ * noise, though — duplicates, mistakes, tests. Who archived a ticket says
43
+ * nothing about which kind it is, so the person archiving decides (the archive
44
+ * dialog asks, ticked by default), and the archive page can change it later.
45
+ * The RAG source keeps every ticket where it is not `false`.
46
+ *
47
+ * - **Archiving** keeps a boolean the caller sent and sets `true` otherwise —
48
+ * the scheduler, the admin table and the REST API do not ask.
49
+ * - **While archived** a sent boolean is kept (the archive page's switch; the
50
+ * hook checks the capability), anything else is reverted.
51
+ * - **Live** tickets do not carry it: restoring clears it, and a value sent
52
+ * for a live ticket is dropped. A live ticket always feeds the search.
53
+ */
54
+ export declare function applySimilarCaseUse(object: Parse.Object, original: Parse.Object | undefined): void;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ARCHIVE_REASON = void 0;
4
+ exports.applyArchiveReason = applyArchiveReason;
5
+ exports.changesSimilarCaseUse = changesSimilarCaseUse;
6
+ exports.applySimilarCaseUse = applySimilarCaseUse;
7
+ /**
8
+ * The values of `archiveReason`. Mirrors `TICKET_ARCHIVE_REASONS` in
9
+ * `@opendash/openservice-shared`; import it from there once the installed
10
+ * nightly carries it (it arrived after `0.2.0-nightly.0`).
11
+ */
12
+ exports.ARCHIVE_REASON = {
13
+ /** The scheduler's `archiveIdleTickets`: finished and idle for a period. */
14
+ auto: "auto",
15
+ /** Everything else — the archive button, the admin table, the REST API. */
16
+ manual: "manual",
17
+ };
18
+ /**
19
+ * Stamps `archiveReason` when a ticket is archived and clears it on restore.
20
+ *
21
+ * What it is for: the archive page shows who archived a ticket — the scheduler
22
+ * or somebody's hand. It decides nothing; whether a ticket feeds the
23
+ * similar-case search is `useForSimilarCases` (see {@link applySimilarCaseUse}).
24
+ *
25
+ * **Only the master key can say "auto".** The scheduler archives with the
26
+ * master key and sends `auto`. A client sending it is overruled. A master-key
27
+ * write without a reason (or with one that is not a known value) counts as
28
+ * `manual`.
29
+ *
30
+ * **Set once, at the moment of archiving.** A later save of an archived ticket
31
+ * keeps the stored reason, whatever it sends. Restoring clears it: a live
32
+ * ticket has no reason to be archived, and the next archive sets a fresh one.
33
+ */
34
+ function applyArchiveReason(object, original, master) {
35
+ const archived = Boolean(object.get("deleted"));
36
+ const wasArchived = Boolean(original?.get("deleted"));
37
+ if (!archived) {
38
+ if (object.get("archiveReason") != null)
39
+ object.unset("archiveReason");
40
+ return;
41
+ }
42
+ if (wasArchived) {
43
+ if (!object.dirty("archiveReason"))
44
+ return;
45
+ const stored = original?.get("archiveReason");
46
+ if (stored != null)
47
+ object.set("archiveReason", stored);
48
+ else
49
+ object.unset("archiveReason");
50
+ return;
51
+ }
52
+ const sent = object.get("archiveReason");
53
+ object.set("archiveReason", master && sent === exports.ARCHIVE_REASON.auto
54
+ ? exports.ARCHIVE_REASON.auto
55
+ : exports.ARCHIVE_REASON.manual);
56
+ }
57
+ /**
58
+ * Whether this save changes `useForSimilarCases` of a ticket that was archived
59
+ * before and stays archived — the archive page's switch. That is archive
60
+ * management, so the hook asks for the archiving capability.
61
+ */
62
+ function changesSimilarCaseUse(object, original) {
63
+ return (!!original?.get("deleted") &&
64
+ !!object.get("deleted") &&
65
+ object.dirty("useForSimilarCases") &&
66
+ object.get("useForSimilarCases") !== original.get("useForSimilarCases"));
67
+ }
68
+ /**
69
+ * Keeps `useForSimilarCases` — whether an archived ticket still feeds "Ähnliche
70
+ * Tickets" — to archived tickets.
71
+ *
72
+ * **Why a column of its own.** The similar-case search should find solved
73
+ * problems, and many of them get archived: by the scheduler once they sat idle,
74
+ * by hand when somebody clears the board early. Some archived tickets are
75
+ * noise, though — duplicates, mistakes, tests. Who archived a ticket says
76
+ * nothing about which kind it is, so the person archiving decides (the archive
77
+ * dialog asks, ticked by default), and the archive page can change it later.
78
+ * The RAG source keeps every ticket where it is not `false`.
79
+ *
80
+ * - **Archiving** keeps a boolean the caller sent and sets `true` otherwise —
81
+ * the scheduler, the admin table and the REST API do not ask.
82
+ * - **While archived** a sent boolean is kept (the archive page's switch; the
83
+ * hook checks the capability), anything else is reverted.
84
+ * - **Live** tickets do not carry it: restoring clears it, and a value sent
85
+ * for a live ticket is dropped. A live ticket always feeds the search.
86
+ */
87
+ function applySimilarCaseUse(object, original) {
88
+ const archived = Boolean(object.get("deleted"));
89
+ const wasArchived = Boolean(original?.get("deleted"));
90
+ const value = object.get("useForSimilarCases");
91
+ if (!archived) {
92
+ if (value != null)
93
+ object.unset("useForSimilarCases");
94
+ return;
95
+ }
96
+ // On create the Parse SDK reports every attribute as dirty, so only a value
97
+ // counts as sent there.
98
+ const sent = object.isNew()
99
+ ? value != null
100
+ : object.dirty("useForSimilarCases");
101
+ if (wasArchived) {
102
+ if (!sent || typeof value === "boolean")
103
+ return;
104
+ const stored = original?.get("useForSimilarCases");
105
+ if (stored != null)
106
+ object.set("useForSimilarCases", stored);
107
+ else
108
+ object.unset("useForSimilarCases");
109
+ return;
110
+ }
111
+ object.set("useForSimilarCases", sent && value === false ? false : true);
112
+ }
@@ -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
+ }
@@ -0,0 +1,20 @@
1
+ import { Service_FormConfig, type Tenant } from "../../../types/index.js";
2
+ /**
3
+ * The form config that applies to `user` in `tenant`, or `undefined` when
4
+ * none does — the frontend then uses its built-in form.
5
+ *
6
+ * Highest `priority` first, and in that order:
7
+ * 1. a config naming the user,
8
+ * 2. a config naming one of the user's roles, inherited ones included,
9
+ * 3. the tenant's global default (a config naming nobody).
10
+ *
11
+ * Read with the master key. The browser cannot do the role step itself: it
12
+ * knows its roles by name, a config names them by id, and a role the user may
13
+ * not read cannot be looked up — comparing the two never matched, so a config
14
+ * for a role silently never applied. Without a user (a master-key write) only
15
+ * the global default can apply.
16
+ *
17
+ * Without a tenant only configs without one are considered: with the master
18
+ * key, "all configs" would be every tenant's.
19
+ */
20
+ export declare function applicableFormConfig(tenant: Tenant | undefined, user: Parse.User | undefined): Promise<Service_FormConfig | undefined>;