@openinc/parse-server-opendash 4.25.0 → 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.
- package/dist/features/openservice/tickets/ticketArchive.d.ts +54 -0
- package/dist/features/openservice/tickets/ticketArchive.js +112 -0
- package/dist/features/openservice/tickets/ticketFormConfig.d.ts +20 -0
- package/dist/features/openservice/tickets/ticketFormConfig.js +74 -0
- package/dist/features/openservice/tickets/ticketPriority.d.ts +47 -0
- package/dist/features/openservice/tickets/ticketPriority.js +103 -0
- package/dist/features/openservice/tickets/ticketReferences.d.ts +4 -4
- package/dist/features/openservice/tickets/ticketReferences.js +12 -6
- package/dist/features/schema/indexes.js +9 -2
- package/dist/features/schema/services/ensureIndexes.js +11 -2
- package/dist/functions/openinc-openservice-form-config.d.ts +20 -0
- package/dist/functions/openinc-openservice-form-config.js +51 -0
- package/dist/hooks/Service_Ticket.js +23 -1
- package/dist/types/Service_Ticket.d.ts +6 -0
- package/dist/types/Service_Ticket.js +12 -0
- package/package.json +1 -1
- package/schema/Service_Ticket.json +6 -0
|
@@ -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,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>;
|
|
@@ -0,0 +1,74 @@
|
|
|
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.applicableFormConfig = applicableFormConfig;
|
|
7
|
+
// Which ticket form config applies to a user. The frontend asks this through
|
|
8
|
+
// `openinc-openservice-form-config`, and the ticket hook reads the priority
|
|
9
|
+
// formula out of the same answer, so both always work with the same config.
|
|
10
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
11
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
12
|
+
const index_js_1 = require("../../../types/index.js");
|
|
13
|
+
const aclAccess_js_1 = require("../../../helper/aclAccess.js");
|
|
14
|
+
/** More configs per tenant would not be a form any more but a mistake. */
|
|
15
|
+
const MAX_CONFIGS = 1000;
|
|
16
|
+
/**
|
|
17
|
+
* The form config that applies to `user` in `tenant`, or `undefined` when
|
|
18
|
+
* none does — the frontend then uses its built-in form.
|
|
19
|
+
*
|
|
20
|
+
* Highest `priority` first, and in that order:
|
|
21
|
+
* 1. a config naming the user,
|
|
22
|
+
* 2. a config naming one of the user's roles, inherited ones included,
|
|
23
|
+
* 3. the tenant's global default (a config naming nobody).
|
|
24
|
+
*
|
|
25
|
+
* Read with the master key. The browser cannot do the role step itself: it
|
|
26
|
+
* knows its roles by name, a config names them by id, and a role the user may
|
|
27
|
+
* not read cannot be looked up — comparing the two never matched, so a config
|
|
28
|
+
* for a role silently never applied. Without a user (a master-key write) only
|
|
29
|
+
* the global default can apply.
|
|
30
|
+
*
|
|
31
|
+
* Without a tenant only configs without one are considered: with the master
|
|
32
|
+
* key, "all configs" would be every tenant's.
|
|
33
|
+
*/
|
|
34
|
+
async function applicableFormConfig(tenant, user) {
|
|
35
|
+
const query = new node_1.default.Query(index_js_1.Service_FormConfig).limit(MAX_CONFIGS);
|
|
36
|
+
if (tenant)
|
|
37
|
+
query.equalTo("tenant", tenant);
|
|
38
|
+
else
|
|
39
|
+
query.doesNotExist("tenant");
|
|
40
|
+
// Stable on equal priority: the older config wins, on every call alike.
|
|
41
|
+
const configs = (await query.ascending("createdAt").find({
|
|
42
|
+
useMasterKey: true,
|
|
43
|
+
})).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
44
|
+
if (configs.length === 0)
|
|
45
|
+
return undefined;
|
|
46
|
+
const userId = user?.id;
|
|
47
|
+
if (user && userId) {
|
|
48
|
+
const userMatch = configs.find((c) => (0, openservice_shared_1.refIds)(c.users).includes(userId));
|
|
49
|
+
if (userMatch)
|
|
50
|
+
return userMatch;
|
|
51
|
+
const roleMatch = await findRoleMatch(configs, user);
|
|
52
|
+
if (roleMatch)
|
|
53
|
+
return roleMatch;
|
|
54
|
+
}
|
|
55
|
+
return configs.find((c) => (0, openservice_shared_1.refIds)(c.users).length === 0 && (0, openservice_shared_1.refIds)(c.roles).length === 0);
|
|
56
|
+
}
|
|
57
|
+
/** The first config naming one of the user's roles (see `userRoleNames`). */
|
|
58
|
+
async function findRoleMatch(configs, user) {
|
|
59
|
+
const roleIds = [...new Set(configs.flatMap((c) => (0, openservice_shared_1.refIds)(c.roles)))];
|
|
60
|
+
if (roleIds.length === 0)
|
|
61
|
+
return undefined;
|
|
62
|
+
const [held, roles] = await Promise.all([
|
|
63
|
+
(0, aclAccess_js_1.userRoleNames)(user),
|
|
64
|
+
new node_1.default.Query(node_1.default.Role)
|
|
65
|
+
.containedIn("objectId", roleIds)
|
|
66
|
+
.limit(roleIds.length)
|
|
67
|
+
.find({ useMasterKey: true }),
|
|
68
|
+
]);
|
|
69
|
+
const heldNames = new Set(held);
|
|
70
|
+
const heldIds = new Set(roles
|
|
71
|
+
.filter((role) => heldNames.has(role.getName() ?? ""))
|
|
72
|
+
.map((role) => role.id));
|
|
73
|
+
return configs.find((c) => (0, openservice_shared_1.refIds)(c.roles).some((id) => heldIds.has(id)));
|
|
74
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { FormulaNode } from "@opendash/ruleset-core";
|
|
2
|
+
import type { Service_FormConfig } from "../../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* The fields a priority formula may read, e.g.
|
|
5
|
+
* `max(downtime, restriction) * 0.7 + frequency * 0.3`. Mirrors
|
|
6
|
+
* `SCALE_FIELD_KEYS` in `@opendash/plugin-openservice-ticket`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PRIORITY_FORMULA_INPUTS: readonly ["downtime", "restriction", "frequency"];
|
|
9
|
+
interface PriorityFormula {
|
|
10
|
+
expression: FormulaNode;
|
|
11
|
+
names: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The formula a config's priority entry asks for, or `undefined` when the
|
|
15
|
+
* priority is entered by hand — or when the stored formula does not parse: the
|
|
16
|
+
* editor refuses to save one, and a broken formula must not block saving
|
|
17
|
+
* tickets. Mirrors `compilePriorityFormula` of the frontend.
|
|
18
|
+
*/
|
|
19
|
+
export declare function priorityFormulaOf(config: Service_FormConfig | undefined): PriorityFormula | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The priority for a ticket's values, or `undefined` when there is nothing to
|
|
22
|
+
* compute from. Mirrors `computePriority` of the frontend:
|
|
23
|
+
*
|
|
24
|
+
* - None of the inputs the formula reads is set: `undefined`, so a ticket
|
|
25
|
+
* nobody has assessed keeps its priority.
|
|
26
|
+
* - Some are set: the rest count as 0, the lowest level.
|
|
27
|
+
* - Clamped to 0–100 and rounded; no number at all (division by zero) is
|
|
28
|
+
* `undefined` as well.
|
|
29
|
+
*/
|
|
30
|
+
export declare function computePriority(formula: PriorityFormula, values: (key: string) => unknown): number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Sets the computed priority on a ticket being saved, under the form config
|
|
33
|
+
* that applies to the user saving it (see `applicableFormConfig`).
|
|
34
|
+
*
|
|
35
|
+
* Only when this save changes one of the inputs — a ticket the save does not
|
|
36
|
+
* reassess keeps its priority, also when the formula has changed since — and
|
|
37
|
+
* only when the caller does not set the priority itself in the same save:
|
|
38
|
+
* the ticket forms send the value they computed and showed, and an import
|
|
39
|
+
* keeps the priority its file states.
|
|
40
|
+
*
|
|
41
|
+
* "Changes" and "sets" are judged against `original`. The admin table sends
|
|
42
|
+
* every field of its form, the unchanged priority included; counting that as
|
|
43
|
+
* set by hand would leave the old priority after every factor edit there —
|
|
44
|
+
* which is the case this exists for.
|
|
45
|
+
*/
|
|
46
|
+
export declare function applyComputedPriority(object: Parse.Object, original: Parse.Object | undefined, user: Parse.User | undefined): Promise<void>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PRIORITY_FORMULA_INPUTS = void 0;
|
|
4
|
+
exports.priorityFormulaOf = priorityFormulaOf;
|
|
5
|
+
exports.computePriority = computePriority;
|
|
6
|
+
exports.applyComputedPriority = applyComputedPriority;
|
|
7
|
+
const ruleset_core_1 = require("@opendash/ruleset-core");
|
|
8
|
+
const ticketFormConfig_js_1 = require("./ticketFormConfig.js");
|
|
9
|
+
/**
|
|
10
|
+
* The fields a priority formula may read, e.g.
|
|
11
|
+
* `max(downtime, restriction) * 0.7 + frequency * 0.3`. Mirrors
|
|
12
|
+
* `SCALE_FIELD_KEYS` in `@opendash/plugin-openservice-ticket`.
|
|
13
|
+
*/
|
|
14
|
+
exports.PRIORITY_FORMULA_INPUTS = [
|
|
15
|
+
"downtime",
|
|
16
|
+
"restriction",
|
|
17
|
+
"frequency",
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* The formula a config's priority entry asks for, or `undefined` when the
|
|
21
|
+
* priority is entered by hand — or when the stored formula does not parse: the
|
|
22
|
+
* editor refuses to save one, and a broken formula must not block saving
|
|
23
|
+
* tickets. Mirrors `compilePriorityFormula` of the frontend.
|
|
24
|
+
*/
|
|
25
|
+
function priorityFormulaOf(config) {
|
|
26
|
+
let entries;
|
|
27
|
+
try {
|
|
28
|
+
entries = JSON.parse(config?.fields ?? "[]");
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (!Array.isArray(entries))
|
|
34
|
+
return undefined;
|
|
35
|
+
const entry = entries.find((e) => !!e && typeof e === "object" && e.key === "priority");
|
|
36
|
+
if (entry?.computed !== true || typeof entry.formula !== "string")
|
|
37
|
+
return undefined;
|
|
38
|
+
const result = (0, ruleset_core_1.validateFormula)(entry.formula, [...exports.PRIORITY_FORMULA_INPUTS]);
|
|
39
|
+
if (result.ok === false)
|
|
40
|
+
return undefined;
|
|
41
|
+
return { expression: result.expression, names: result.names };
|
|
42
|
+
}
|
|
43
|
+
function asNumber(value) {
|
|
44
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
45
|
+
? value
|
|
46
|
+
: undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The priority for a ticket's values, or `undefined` when there is nothing to
|
|
50
|
+
* compute from. Mirrors `computePriority` of the frontend:
|
|
51
|
+
*
|
|
52
|
+
* - None of the inputs the formula reads is set: `undefined`, so a ticket
|
|
53
|
+
* nobody has assessed keeps its priority.
|
|
54
|
+
* - Some are set: the rest count as 0, the lowest level.
|
|
55
|
+
* - Clamped to 0–100 and rounded; no number at all (division by zero) is
|
|
56
|
+
* `undefined` as well.
|
|
57
|
+
*/
|
|
58
|
+
function computePriority(formula, values) {
|
|
59
|
+
const scope = {};
|
|
60
|
+
let anySet = false;
|
|
61
|
+
for (const name of formula.names) {
|
|
62
|
+
const value = asNumber(values(name));
|
|
63
|
+
if (value !== undefined)
|
|
64
|
+
anySet = true;
|
|
65
|
+
scope[name] = value ?? 0;
|
|
66
|
+
}
|
|
67
|
+
if (!anySet)
|
|
68
|
+
return undefined;
|
|
69
|
+
const result = (0, ruleset_core_1.evaluateFormula)(formula.expression, scope);
|
|
70
|
+
if (Number.isNaN(result))
|
|
71
|
+
return undefined;
|
|
72
|
+
return Math.round(Math.min(100, Math.max(0, result)));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sets the computed priority on a ticket being saved, under the form config
|
|
76
|
+
* that applies to the user saving it (see `applicableFormConfig`).
|
|
77
|
+
*
|
|
78
|
+
* Only when this save changes one of the inputs — a ticket the save does not
|
|
79
|
+
* reassess keeps its priority, also when the formula has changed since — and
|
|
80
|
+
* only when the caller does not set the priority itself in the same save:
|
|
81
|
+
* the ticket forms send the value they computed and showed, and an import
|
|
82
|
+
* keeps the priority its file states.
|
|
83
|
+
*
|
|
84
|
+
* "Changes" and "sets" are judged against `original`. The admin table sends
|
|
85
|
+
* every field of its form, the unchanged priority included; counting that as
|
|
86
|
+
* set by hand would leave the old priority after every factor edit there —
|
|
87
|
+
* which is the case this exists for.
|
|
88
|
+
*/
|
|
89
|
+
async function applyComputedPriority(object, original, user) {
|
|
90
|
+
const before = (key) => original?.get(key);
|
|
91
|
+
const changes = (key) => object.isNew() ? object.get(key) != null : object.get(key) !== before(key);
|
|
92
|
+
if (!exports.PRIORITY_FORMULA_INPUTS.some(changes))
|
|
93
|
+
return;
|
|
94
|
+
if (changes("priority"))
|
|
95
|
+
return;
|
|
96
|
+
const tenant = object.get("tenant");
|
|
97
|
+
const formula = priorityFormulaOf(await (0, ticketFormConfig_js_1.applicableFormConfig)(tenant, user));
|
|
98
|
+
if (!formula)
|
|
99
|
+
return;
|
|
100
|
+
const priority = computePriority(formula, (key) => object.get(key));
|
|
101
|
+
if (priority !== undefined)
|
|
102
|
+
object.set("priority", priority);
|
|
103
|
+
}
|
|
@@ -53,9 +53,9 @@ export declare function applySortKeys(object: Parse.Object, rows: Map<string, Pa
|
|
|
53
53
|
* not closed, and leaving the old date would quietly count it as finished in
|
|
54
54
|
* every evaluation while it is being worked on again.
|
|
55
55
|
*
|
|
56
|
-
* **A value the caller sent wins.** `
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
56
|
+
* **A value the caller sent wins.** A `closedAt` named in this same save — the
|
|
57
|
+
* migration replaying history, an import, a correction in the admin table — is
|
|
58
|
+
* kept; overwriting it with `now` would be this function deciding it knows
|
|
59
|
+
* better.
|
|
60
60
|
*/
|
|
61
61
|
export declare function applyClosedAt(object: Parse.Object, rows: Map<string, Parse.Object>): void;
|
|
@@ -197,18 +197,24 @@ function applySortKeys(object, rows, refresh = false) {
|
|
|
197
197
|
* not closed, and leaving the old date would quietly count it as finished in
|
|
198
198
|
* every evaluation while it is being worked on again.
|
|
199
199
|
*
|
|
200
|
-
* **A value the caller sent wins.** `
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
200
|
+
* **A value the caller sent wins.** A `closedAt` named in this same save — the
|
|
201
|
+
* migration replaying history, an import, a correction in the admin table — is
|
|
202
|
+
* kept; overwriting it with `now` would be this function deciding it knows
|
|
203
|
+
* better.
|
|
204
204
|
*/
|
|
205
205
|
function applyClosedAt(object, rows) {
|
|
206
206
|
// Nothing to react to: the status is unchanged. A ticket whose status stayed
|
|
207
207
|
// put keeps whatever stamp it has, including none.
|
|
208
208
|
if (!object.dirty("status"))
|
|
209
209
|
return;
|
|
210
|
-
// Explicitly set in this save — see the note above.
|
|
211
|
-
|
|
210
|
+
// Explicitly set in this save — see the note above. A new object is dirty in
|
|
211
|
+
// every attribute (the Parse SDK answers `dirty()` with `true` while there is
|
|
212
|
+
// no id), so on create only a value counts as sent: asking `dirty` there left
|
|
213
|
+
// every ticket created in a finished status without a `closedAt`.
|
|
214
|
+
const sent = object.isNew()
|
|
215
|
+
? object.get("closedAt") != null
|
|
216
|
+
: object.dirty("closedAt");
|
|
217
|
+
if (sent)
|
|
212
218
|
return;
|
|
213
219
|
const status = object.get("status");
|
|
214
220
|
const row = status?.id ? rows.get(status.id) : undefined;
|
|
@@ -6,7 +6,9 @@ const index_js_1 = require("../../types/index.js");
|
|
|
6
6
|
* Declares indexes of `type`, by name. Field names are checked against the
|
|
7
7
|
* generated class, so renaming a field breaks the build instead of leaving an
|
|
8
8
|
* index on a column nobody writes. A pointer is indexed by its name — the
|
|
9
|
-
* adapter turns it into `_p_<field>`, `createdAt` into `_created_at`.
|
|
9
|
+
* adapter turns it into `_p_<field>`, `createdAt` into `_created_at`. A key
|
|
10
|
+
* inside an `Object` column is indexed by its dotted path, which Mongo indexes
|
|
11
|
+
* as it is.
|
|
10
12
|
*
|
|
11
13
|
* Parse's own classes have no generated class, only a type: pass their fixed
|
|
12
14
|
* name and the attributes type, `defineIndexes<_SessionAttributes>("_Session", …)`.
|
|
@@ -67,9 +69,14 @@ exports.INDEXES = [
|
|
|
67
69
|
defineIndexes(index_js_1.UserData, {
|
|
68
70
|
od_user_key: ["user", "key"],
|
|
69
71
|
}),
|
|
70
|
-
// Notification drawer and unread badge.
|
|
72
|
+
// Notification drawer and unread badge. By ticket: deleting a ticket for
|
|
73
|
+
// good removes its notifications, and the scheduler's due reminders look up
|
|
74
|
+
// what they already sent every 5 minutes (`data.ruleId` + `data.ticketId`
|
|
75
|
+
// `$in`). Without it both read every notification ever sent — measured
|
|
76
|
+
// locally at 500 000 rows: ~170 ms per ticket scanning, under 1 ms indexed.
|
|
71
77
|
defineIndexes(index_js_1.Notification, {
|
|
72
78
|
od_user_read_createdAt: ["user", "read", "createdAt"],
|
|
79
|
+
od_data_ticketId: ["data.ticketId"],
|
|
73
80
|
}),
|
|
74
81
|
// Open chats poll every 5 s.
|
|
75
82
|
defineIndexes(index_js_1.Chat_Message, {
|
|
@@ -44,13 +44,22 @@ function storageAdapter() {
|
|
|
44
44
|
* a column nobody writes. Two array fields in one index are worse: Mongo
|
|
45
45
|
* builds it, then refuses every save of a row that has both arrays set
|
|
46
46
|
* ("cannot index parallel arrays").
|
|
47
|
+
*
|
|
48
|
+
* A dotted field (`data.ticketId`) is a key inside an `Object` column: the
|
|
49
|
+
* column has to exist and be one. What the key holds is up to the writers —
|
|
50
|
+
* the schema does not describe it.
|
|
47
51
|
*/
|
|
48
52
|
function invalidReason(schema, fields) {
|
|
49
|
-
const
|
|
53
|
+
const column = (field) => field.split(".")[0];
|
|
54
|
+
const missing = fields.filter((field) => !schema.fields[column(field)]);
|
|
50
55
|
if (missing.length > 0) {
|
|
51
56
|
return `unknown field(s) ${missing.join(", ")}`;
|
|
52
57
|
}
|
|
53
|
-
const
|
|
58
|
+
const notObjects = fields.filter((field) => field.includes(".") && schema.fields[column(field)].type !== "Object");
|
|
59
|
+
if (notObjects.length > 0) {
|
|
60
|
+
return `path into a column that is not an Object (${notObjects.join(", ")})`;
|
|
61
|
+
}
|
|
62
|
+
const arrays = fields.filter((field) => schema.fields[column(field)].type === "Array");
|
|
54
63
|
if (arrays.length > 1) {
|
|
55
64
|
return `more than one array field (${arrays.join(", ")})`;
|
|
56
65
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ticket form config that applies to the caller — for the create form,
|
|
3
|
+
* the detail edit and the import of `@opendash/plugin-openservice-ticket`.
|
|
4
|
+
*
|
|
5
|
+
* Params: `{ tenant?: string }`, the active tenant (default: the caller's
|
|
6
|
+
* own). Returns `{ id: string | null }`; `null` means the built-in form.
|
|
7
|
+
*
|
|
8
|
+
* **Why a function.** Resolution goes by the caller's roles, inherited ones
|
|
9
|
+
* included, and the browser cannot resolve them: it knows its roles by name, a
|
|
10
|
+
* config names them by id, and a role the caller may not read cannot be looked
|
|
11
|
+
* up. The ticket hook takes the priority formula from the same resolution
|
|
12
|
+
* (`applicableFormConfig`), so the form and the server never pick different
|
|
13
|
+
* configs.
|
|
14
|
+
*
|
|
15
|
+
* Only an id comes back, and only one of a config the caller can read — its
|
|
16
|
+
* audience ACL grants that to the users and roles it names — so the answer
|
|
17
|
+
* reveals nothing the caller could not list anyway. The browser reads the
|
|
18
|
+
* config itself with its own session.
|
|
19
|
+
*/
|
|
20
|
+
export declare function init(name: string): Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
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.init = init;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const ticketFormConfig_js_1 = require("../features/openservice/tickets/ticketFormConfig.js");
|
|
9
|
+
const index_js_1 = require("../types/index.js");
|
|
10
|
+
/**
|
|
11
|
+
* The ticket form config that applies to the caller — for the create form,
|
|
12
|
+
* the detail edit and the import of `@opendash/plugin-openservice-ticket`.
|
|
13
|
+
*
|
|
14
|
+
* Params: `{ tenant?: string }`, the active tenant (default: the caller's
|
|
15
|
+
* own). Returns `{ id: string | null }`; `null` means the built-in form.
|
|
16
|
+
*
|
|
17
|
+
* **Why a function.** Resolution goes by the caller's roles, inherited ones
|
|
18
|
+
* included, and the browser cannot resolve them: it knows its roles by name, a
|
|
19
|
+
* config names them by id, and a role the caller may not read cannot be looked
|
|
20
|
+
* up. The ticket hook takes the priority formula from the same resolution
|
|
21
|
+
* (`applicableFormConfig`), so the form and the server never pick different
|
|
22
|
+
* configs.
|
|
23
|
+
*
|
|
24
|
+
* Only an id comes back, and only one of a config the caller can read — its
|
|
25
|
+
* audience ACL grants that to the users and roles it names — so the answer
|
|
26
|
+
* reveals nothing the caller could not list anyway. The browser reads the
|
|
27
|
+
* config itself with its own session.
|
|
28
|
+
*/
|
|
29
|
+
async function init(name) {
|
|
30
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
31
|
+
const user = request.user;
|
|
32
|
+
const sessionToken = user?.getSessionToken();
|
|
33
|
+
if (!user || !sessionToken) {
|
|
34
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_SESSION_TOKEN, `${name} requires a logged-in user`);
|
|
35
|
+
}
|
|
36
|
+
const requested = request.params?.tenant;
|
|
37
|
+
if (requested !== undefined && typeof requested !== "string") {
|
|
38
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name}: tenant must be an object id`);
|
|
39
|
+
}
|
|
40
|
+
const tenant = requested
|
|
41
|
+
? index_js_1.Tenant.createWithoutData(requested)
|
|
42
|
+
: user.get("tenant");
|
|
43
|
+
const config = await (0, ticketFormConfig_js_1.applicableFormConfig)(tenant, user);
|
|
44
|
+
if (!config?.id)
|
|
45
|
+
return { id: null };
|
|
46
|
+
const readable = await new node_1.default.Query(index_js_1.Service_FormConfig)
|
|
47
|
+
.equalTo("objectId", config.id)
|
|
48
|
+
.first({ sessionToken });
|
|
49
|
+
return { id: readable?.id ?? null };
|
|
50
|
+
}, { requireUser: true });
|
|
51
|
+
}
|
|
@@ -10,6 +10,8 @@ const ticketNumber_js_1 = require("../features/openservice/tickets/ticketNumber.
|
|
|
10
10
|
const ticketReferences_js_1 = require("../features/openservice/tickets/ticketReferences.js");
|
|
11
11
|
const ticketAccess_js_1 = require("../features/openservice/tickets/ticketAccess.js");
|
|
12
12
|
const ticketNotifications_js_1 = require("../features/openservice/tickets/ticketNotifications.js");
|
|
13
|
+
const ticketArchive_js_1 = require("../features/openservice/tickets/ticketArchive.js");
|
|
14
|
+
const ticketPriority_js_1 = require("../features/openservice/tickets/ticketPriority.js");
|
|
13
15
|
async function init() {
|
|
14
16
|
// Soft delete: a ticket is referenced by chat messages, meta entries,
|
|
15
17
|
// notifications and child tickets, so the frontend archives instead of
|
|
@@ -35,6 +37,12 @@ async function init() {
|
|
|
35
37
|
Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
|
|
36
38
|
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_delete, "archive a ticket", original.get("tenant"));
|
|
37
39
|
}
|
|
40
|
+
// Whether an archived ticket still feeds the similar-case search is archive
|
|
41
|
+
// management as well (the archive page's switch), so it takes the same
|
|
42
|
+
// capability. Set while archiving, it is covered by the check above.
|
|
43
|
+
if (!(0, index_js_1.isMigrationMode)() && (0, ticketArchive_js_1.changesSimilarCaseUse)(object, original)) {
|
|
44
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_delete, "change whether an archived ticket is used for similar cases", original.get("tenant"));
|
|
45
|
+
}
|
|
38
46
|
if (isNew && !object.get("createdBy") && user)
|
|
39
47
|
object.set("createdBy", user);
|
|
40
48
|
await (0, index_js_1.defaultHandler)(request);
|
|
@@ -71,6 +79,14 @@ async function init() {
|
|
|
71
79
|
(0, ticketReferences_js_1.assertSameTenantReferences)(object, referenced);
|
|
72
80
|
(0, ticketReferences_js_1.applySortKeys)(object, referenced, restored);
|
|
73
81
|
(0, ticketReferences_js_1.applyClosedAt)(object, referenced);
|
|
82
|
+
(0, ticketArchive_js_1.applyArchiveReason)(object, original, !!request.master);
|
|
83
|
+
(0, ticketArchive_js_1.applySimilarCaseUse)(object, original);
|
|
84
|
+
// The priority a form config derives from downtime, restriction and
|
|
85
|
+
// frequency. The ticket forms compute it as well, to show it while the
|
|
86
|
+
// user types — here it holds for every other write path (the admin table,
|
|
87
|
+
// the REST API). A migration replays the stored priority as it was.
|
|
88
|
+
if (!(0, index_js_1.isMigrationMode)())
|
|
89
|
+
await (0, ticketPriority_js_1.applyComputedPriority)(object, original, user);
|
|
74
90
|
// Assign a sequential ticket number on creation. Done here (backend) rather
|
|
75
91
|
// than in the frontend because every write path — the create form, the
|
|
76
92
|
// cross-plugin service, and the generic entity admin — funnels through this
|
|
@@ -81,7 +97,13 @@ async function init() {
|
|
|
81
97
|
// move could collide with an existing number in the new project. Drawing a
|
|
82
98
|
// fresh number from the destination keeps each project's sequence unique
|
|
83
99
|
// (the source sequence simply gains a gap, which is fine).
|
|
84
|
-
|
|
100
|
+
//
|
|
101
|
+
// Compared against `original`, not taken from `dirty()`: a field the save
|
|
102
|
+
// merely resends counts as dirty, and the admin table resends every field
|
|
103
|
+
// of its form — each edit there used to give the ticket a new number.
|
|
104
|
+
const projectId = (value) => value?.id;
|
|
105
|
+
const projectChanged = !isNew &&
|
|
106
|
+
projectId(object.get("project")) !== projectId(original?.get("project"));
|
|
85
107
|
// The number is the server's. The REST API and the generic admin let a
|
|
86
108
|
// client send one, and a caller-chosen number collides with — or poses as
|
|
87
109
|
// — another ticket's. Master-key writes (alarm tickets) are the server's
|
|
@@ -11,6 +11,7 @@ export interface Service_TicketAttributes {
|
|
|
11
11
|
createdAt: Date;
|
|
12
12
|
updatedAt: Date;
|
|
13
13
|
actualDuration?: number | undefined;
|
|
14
|
+
archiveReason?: string | undefined;
|
|
14
15
|
assignedRoles?: any[] | undefined;
|
|
15
16
|
assignedUsers?: any[] | undefined;
|
|
16
17
|
checklist?: any[] | undefined;
|
|
@@ -38,12 +39,15 @@ export interface Service_TicketAttributes {
|
|
|
38
39
|
tags?: any[] | undefined;
|
|
39
40
|
tenant: Tenant;
|
|
40
41
|
title: string;
|
|
42
|
+
useForSimilarCases?: boolean | undefined;
|
|
41
43
|
}
|
|
42
44
|
export declare class Service_Ticket extends Parse.Object<Service_TicketAttributes> {
|
|
43
45
|
static className: string;
|
|
44
46
|
constructor(data?: Partial<Service_TicketAttributes>);
|
|
45
47
|
get actualDuration(): number | undefined;
|
|
46
48
|
set actualDuration(value: number | undefined);
|
|
49
|
+
get archiveReason(): string | undefined;
|
|
50
|
+
set archiveReason(value: string | undefined);
|
|
47
51
|
get assignedRoles(): any[] | undefined;
|
|
48
52
|
set assignedRoles(value: any[] | undefined);
|
|
49
53
|
get assignedUsers(): any[] | undefined;
|
|
@@ -98,4 +102,6 @@ export declare class Service_Ticket extends Parse.Object<Service_TicketAttribute
|
|
|
98
102
|
set tenant(value: Tenant);
|
|
99
103
|
get title(): string;
|
|
100
104
|
set title(value: string);
|
|
105
|
+
get useForSimilarCases(): boolean | undefined;
|
|
106
|
+
set useForSimilarCases(value: boolean | undefined);
|
|
101
107
|
}
|
|
@@ -16,6 +16,12 @@ class Service_Ticket extends node_1.default.Object {
|
|
|
16
16
|
set actualDuration(value) {
|
|
17
17
|
super.set("actualDuration", value);
|
|
18
18
|
}
|
|
19
|
+
get archiveReason() {
|
|
20
|
+
return super.get("archiveReason");
|
|
21
|
+
}
|
|
22
|
+
set archiveReason(value) {
|
|
23
|
+
super.set("archiveReason", value);
|
|
24
|
+
}
|
|
19
25
|
get assignedRoles() {
|
|
20
26
|
return super.get("assignedRoles");
|
|
21
27
|
}
|
|
@@ -178,6 +184,12 @@ class Service_Ticket extends node_1.default.Object {
|
|
|
178
184
|
set title(value) {
|
|
179
185
|
super.set("title", value);
|
|
180
186
|
}
|
|
187
|
+
get useForSimilarCases() {
|
|
188
|
+
return super.get("useForSimilarCases");
|
|
189
|
+
}
|
|
190
|
+
set useForSimilarCases(value) {
|
|
191
|
+
super.set("useForSimilarCases", value);
|
|
192
|
+
}
|
|
181
193
|
}
|
|
182
194
|
exports.Service_Ticket = Service_Ticket;
|
|
183
195
|
node_1.default.Object.registerSubclass("OD3_Service_Ticket", Service_Ticket);
|
package/package.json
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
"actualDuration": {
|
|
4
4
|
"type": "Number"
|
|
5
5
|
},
|
|
6
|
+
"archiveReason": {
|
|
7
|
+
"type": "String"
|
|
8
|
+
},
|
|
6
9
|
"assignedRoles": {
|
|
7
10
|
"type": "Array"
|
|
8
11
|
},
|
|
@@ -97,6 +100,9 @@
|
|
|
97
100
|
"title": {
|
|
98
101
|
"type": "String",
|
|
99
102
|
"required": true
|
|
103
|
+
},
|
|
104
|
+
"useForSimilarCases": {
|
|
105
|
+
"type": "Boolean"
|
|
100
106
|
}
|
|
101
107
|
},
|
|
102
108
|
"classLevelPermissions": {
|