@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
|
@@ -6,9 +6,10 @@ import { SessionTokenType } from "../../schema/index.js";
|
|
|
6
6
|
* @param request - The request object containing the user's session token and masterkey status.
|
|
7
7
|
* @param key - The permission key required for the operation.
|
|
8
8
|
* @param message - The error message to be thrown if the user does not have the required permission.
|
|
9
|
+
* @param tenant - The tenant the operation concerns — only a permission held there counts (see {@link hasPermission}).
|
|
9
10
|
* @returns A Promise that resolves if the user has the required permission, or throws an error if not.
|
|
10
11
|
*/
|
|
11
12
|
export declare function requirePermission(request: {
|
|
12
13
|
master?: boolean;
|
|
13
14
|
sessionToken: SessionTokenType;
|
|
14
|
-
}, key: string | null, message: string): Promise<void>;
|
|
15
|
+
}, key: string | null, message: string, tenant?: Parse.Object | null): Promise<void>;
|
|
@@ -13,9 +13,10 @@ const index_js_1 = require("../index.js");
|
|
|
13
13
|
* @param request - The request object containing the user's session token and masterkey status.
|
|
14
14
|
* @param key - The permission key required for the operation.
|
|
15
15
|
* @param message - The error message to be thrown if the user does not have the required permission.
|
|
16
|
+
* @param tenant - The tenant the operation concerns — only a permission held there counts (see {@link hasPermission}).
|
|
16
17
|
* @returns A Promise that resolves if the user has the required permission, or throws an error if not.
|
|
17
18
|
*/
|
|
18
|
-
async function requirePermission(request, key, message) {
|
|
19
|
+
async function requirePermission(request, key, message, tenant) {
|
|
19
20
|
if (request.master) {
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
@@ -25,7 +26,7 @@ async function requirePermission(request, key, message) {
|
|
|
25
26
|
if (!request.sessionToken) {
|
|
26
27
|
throw new node_1.default.Error(119, "Missing Permission (2): " + (message || key || "Master Key Only"));
|
|
27
28
|
}
|
|
28
|
-
const p = await (0, index_js_1.hasPermission)(request.sessionToken, key);
|
|
29
|
+
const p = await (0, index_js_1.hasPermission)(request.sessionToken, key, tenant);
|
|
29
30
|
if (!p) {
|
|
30
31
|
throw new node_1.default.Error(119, "Missing Permission (3): " + (message || key || "Master Key Only"));
|
|
31
32
|
}
|
|
@@ -25,6 +25,7 @@ export declare namespace Permissions {
|
|
|
25
25
|
ticket_access = "openservice-ticket:can-access-ticket-plugin",
|
|
26
26
|
ticket_create = "openservice-ticket:can-create-ticket",
|
|
27
27
|
ticket_delete = "openservice-ticket:can-delete-ticket",
|
|
28
|
+
ticket_purge = "openservice-ticket:can-purge-ticket",
|
|
28
29
|
ticket_analytics_view = "openservice-ticket:can-view-analytics",
|
|
29
30
|
schedule_access = "openservice-schedule:can-access-schedule-plugin",
|
|
30
31
|
schedule_create = "openservice-schedule:can-create-schedule",
|
|
@@ -49,11 +49,14 @@ var Permissions;
|
|
|
49
49
|
//
|
|
50
50
|
// No `read`, `edit` or `assign`: the ticket's ACL decides those per
|
|
51
51
|
// record. `create` has no record yet whose ACL could be asked. `delete`
|
|
52
|
-
// covers archiving, which
|
|
53
|
-
// assigned to the ticket.
|
|
52
|
+
// covers archiving and restoring, which are updates the ACL would grant to
|
|
53
|
+
// everybody assigned to the ticket. `purge` is the hard delete from the
|
|
54
|
+
// archive: it destroys the ticket with everything attached, its history
|
|
55
|
+
// included, and cannot be undone — so it is granted separately.
|
|
54
56
|
SERVICE["ticket_access"] = "openservice-ticket:can-access-ticket-plugin";
|
|
55
57
|
SERVICE["ticket_create"] = "openservice-ticket:can-create-ticket";
|
|
56
58
|
SERVICE["ticket_delete"] = "openservice-ticket:can-delete-ticket";
|
|
59
|
+
SERVICE["ticket_purge"] = "openservice-ticket:can-purge-ticket";
|
|
57
60
|
// The ticket evaluations page. Its own key rather than the schedule
|
|
58
61
|
// plugin's `analytics_view`: a tenant may well want its shift leads to see
|
|
59
62
|
// ticket throughput without opening up maintenance compliance, and the two
|
|
@@ -113,6 +113,24 @@ exports.INDEXES = [
|
|
|
113
113
|
// little here.
|
|
114
114
|
defineIndexes(index_js_1.Service_Ticket, {
|
|
115
115
|
od_tenant_deleted_dueDate: ["tenant", "deleted", "dueDate"],
|
|
116
|
+
// The archive page (`deleted = true`, latest change first) and the
|
|
117
|
+
// scheduler's auto-archive (`deleted = false`, idle since a cutoff). The
|
|
118
|
+
// archived side is the one that keeps growing, so it must not be sorted in
|
|
119
|
+
// memory.
|
|
120
|
+
od_tenant_deleted_updatedAt: ["tenant", "deleted", "updatedAt"],
|
|
121
|
+
// Sorting the dashboard table by status, project or equipment: a pointer
|
|
122
|
+
// sorts by its shadow column (`statusOrder`, `projectSortKey`,
|
|
123
|
+
// `equipmentSortKey`), and without these Mongo sorted every live ticket of
|
|
124
|
+
// the tenant in memory for each page. By number: the default "Nr." column
|
|
125
|
+
// and the archive's `#123` lookup.
|
|
126
|
+
od_tenant_deleted_statusOrder: ["tenant", "deleted", "statusOrder"],
|
|
127
|
+
od_tenant_deleted_projectSortKey: ["tenant", "deleted", "projectSortKey"],
|
|
128
|
+
od_tenant_deleted_equipmentSortKey: [
|
|
129
|
+
"tenant",
|
|
130
|
+
"deleted",
|
|
131
|
+
"equipmentSortKey",
|
|
132
|
+
],
|
|
133
|
+
od_tenant_deleted_number: ["tenant", "deleted", "number"],
|
|
116
134
|
od_status_dueDate: ["status", "dueDate"],
|
|
117
135
|
od_equipment_dueDate: ["equipment", "dueDate"],
|
|
118
136
|
od_project_dueDate: ["project", "dueDate"],
|
|
@@ -122,6 +140,12 @@ exports.INDEXES = [
|
|
|
122
140
|
od_tags: ["tags"],
|
|
123
141
|
// Tickets of a schedule or alarm, and the alarm webhook's dedupe.
|
|
124
142
|
od_origin_createdAt: ["origin", "createdAt"],
|
|
143
|
+
// The analytics windows (created / closed in the last 90 days). They read
|
|
144
|
+
// archived tickets too — finished ones are archived automatically — so
|
|
145
|
+
// the `tenant` + `deleted` prefix above would walk every ticket the
|
|
146
|
+
// tenant ever had.
|
|
147
|
+
od_tenant_createdAt: ["tenant", "createdAt"],
|
|
148
|
+
od_tenant_closedAt: ["tenant", "closedAt"],
|
|
125
149
|
}),
|
|
126
150
|
// The header equipment picker on every /service route; alarm machine
|
|
127
151
|
// resolution; tag re-parenting.
|
|
@@ -41,6 +41,7 @@ function beforeSaveHook(target, callback) {
|
|
|
41
41
|
if (!beforeSaveHooks[className]) {
|
|
42
42
|
beforeSaveHooks[className] = [];
|
|
43
43
|
node_1.default.Cloud.beforeSave(className, async function beforeSaveHookFunction(request) {
|
|
44
|
+
assertFilesHaveUrl(request.object);
|
|
44
45
|
const sessionToken = request.user?.getSessionToken();
|
|
45
46
|
const newRequest = {
|
|
46
47
|
...request,
|
|
@@ -53,3 +54,56 @@ function beforeSaveHook(target, callback) {
|
|
|
53
54
|
}
|
|
54
55
|
beforeSaveHooks[className].push(callback);
|
|
55
56
|
}
|
|
57
|
+
/** How deep {@link assertFilesHaveUrl} looks into arrays and objects. */
|
|
58
|
+
const FILE_SEARCH_DEPTH = 3;
|
|
59
|
+
/**
|
|
60
|
+
* Refuses a save that references a file without a URL.
|
|
61
|
+
*
|
|
62
|
+
* A REST client may name a file by `name` alone. Parse Server turns that into
|
|
63
|
+
* a `Parse.File` without a URL, and once a beforeSave trigger has run it
|
|
64
|
+
* encodes the object again — on success to build the save (`_getSaveJSON`), on
|
|
65
|
+
* failure to log it (`toJSON`). Either throws "Tried to encode an unsaved file"
|
|
66
|
+
* outside any promise chain and takes the whole process down. Every class with
|
|
67
|
+
* a beforeSave registered here and a file column (assets, chat attachments,
|
|
68
|
+
* tenant logos, …) was affected: one request from any logged-in user crashed
|
|
69
|
+
* the server.
|
|
70
|
+
*
|
|
71
|
+
* Throwing alone is not enough, since the failure path encodes the object as
|
|
72
|
+
* well. The offending field is taken off the object first, so what Parse logs
|
|
73
|
+
* is encodable, and the caller gets an ordinary error response.
|
|
74
|
+
*
|
|
75
|
+
* Nobody loses a working call: the SDKs always send the URL, and a request
|
|
76
|
+
* without one never got past the crash.
|
|
77
|
+
*/
|
|
78
|
+
function assertFilesHaveUrl(object) {
|
|
79
|
+
for (const key of object.dirtyKeys()) {
|
|
80
|
+
if (hasFileWithoutUrl(object.get(key), 0)) {
|
|
81
|
+
object.unset(key);
|
|
82
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `${key}: the file has no URL — upload it first and send its url along with its name.`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function hasFileWithoutUrl(value, depth) {
|
|
87
|
+
if (isParseFile(value))
|
|
88
|
+
return !value.url();
|
|
89
|
+
if (depth >= FILE_SEARCH_DEPTH || !value || typeof value !== "object") {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
// A pointer is not followed: its fields are not part of this save.
|
|
93
|
+
if (value instanceof node_1.default.Object)
|
|
94
|
+
return false;
|
|
95
|
+
const children = Array.isArray(value) ? value : Object.values(value);
|
|
96
|
+
return children.some((child) => hasFileWithoutUrl(child, depth + 1));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Duck-typed as well as `instanceof`: the trigger's objects come from Parse
|
|
100
|
+
* Server's own copy of the SDK, which need not be the module imported here.
|
|
101
|
+
*/
|
|
102
|
+
function isParseFile(value) {
|
|
103
|
+
if (value instanceof node_1.default.File)
|
|
104
|
+
return true;
|
|
105
|
+
const candidate = value;
|
|
106
|
+
return (!!candidate &&
|
|
107
|
+
typeof candidate.url === "function" &&
|
|
108
|
+
typeof candidate.getData === "function");
|
|
109
|
+
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Fills the sort shadow columns of one ticket — a Parse Dashboard script, run
|
|
3
3
|
* from "Run script on selected row" in the data browser.
|
|
4
4
|
*
|
|
5
|
-
* `statusOrder`, `projectSortKey` and `equipmentSortKey` are derived
|
|
6
|
-
* `
|
|
5
|
+
* `statusOrder`, `projectSortKey` and `equipmentSortKey` are derived by the
|
|
6
|
+
* ticket's `beforeSave` (`applySortKeys` in
|
|
7
|
+
* `features/openservice/tickets/ticketReferences.ts`) when a ticket is saved, so every ticket written
|
|
7
8
|
* before those columns existed sorts as empty until it is touched once.
|
|
8
9
|
*
|
|
9
10
|
* All this does is re-save the row. The hook fills a missing key even when the
|
|
@@ -10,8 +10,9 @@ const index_js_1 = require("../types/index.js");
|
|
|
10
10
|
* Fills the sort shadow columns of one ticket — a Parse Dashboard script, run
|
|
11
11
|
* from "Run script on selected row" in the data browser.
|
|
12
12
|
*
|
|
13
|
-
* `statusOrder`, `projectSortKey` and `equipmentSortKey` are derived
|
|
14
|
-
* `
|
|
13
|
+
* `statusOrder`, `projectSortKey` and `equipmentSortKey` are derived by the
|
|
14
|
+
* ticket's `beforeSave` (`applySortKeys` in
|
|
15
|
+
* `features/openservice/tickets/ticketReferences.ts`) when a ticket is saved, so every ticket written
|
|
15
16
|
* before those columns existed sorts as empty until it is touched once.
|
|
16
17
|
*
|
|
17
18
|
* All this does is re-save the row. The hook fills a missing key even when the
|
|
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
8
|
const index_js_1 = require("../features/config/index.js");
|
|
9
|
+
const aclAccess_js_1 = require("../helper/aclAccess.js");
|
|
9
10
|
const index_js_2 = require("../types/index.js");
|
|
10
11
|
async function init(name) {
|
|
11
12
|
node_1.default.Cloud.define(name, async (request) => {
|
|
12
13
|
const userId = request.user?.id;
|
|
13
14
|
let roles = [];
|
|
14
15
|
if (request.user) {
|
|
15
|
-
roles = await
|
|
16
|
+
roles = await (0, aclAccess_js_1.userRoleNames)(request.user);
|
|
16
17
|
}
|
|
17
18
|
const parseSchema = await node_1.default.Schema.all();
|
|
18
19
|
const schema = parseSchema
|
|
@@ -44,27 +45,6 @@ async function init(name) {
|
|
|
44
45
|
};
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
|
-
// Returns all role names the user belongs to, including transitive parent roles.
|
|
48
|
-
// In Parse, roles can contain other roles via the "roles" relation, so a user in
|
|
49
|
-
// role "staff" also inherits permissions from "admin" if "staff" is a child of "admin".
|
|
50
|
-
async function getUserRoles(user) {
|
|
51
|
-
// visited prevents infinite loops in case of cyclic role definitions
|
|
52
|
-
const visited = new Set();
|
|
53
|
-
async function collect(roleQuery) {
|
|
54
|
-
const found = await roleQuery.find({ useMasterKey: true });
|
|
55
|
-
for (const role of found) {
|
|
56
|
-
const name = role.getName();
|
|
57
|
-
if (name && !visited.has(name)) {
|
|
58
|
-
visited.add(name);
|
|
59
|
-
// Find parent roles that contain this role as a child and continue upward
|
|
60
|
-
await collect(new node_1.default.Query(node_1.default.Role).equalTo("roles", role));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// Entry point: direct roles of the user
|
|
65
|
-
await collect(new node_1.default.Query(node_1.default.Role).equalTo("users", user));
|
|
66
|
-
return [...visited];
|
|
67
|
-
}
|
|
68
48
|
async function getTenants() {
|
|
69
49
|
try {
|
|
70
50
|
const tenants = await new node_1.default.Query(index_js_2.Tenant)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every role name `user` holds, inherited ones included.
|
|
3
|
+
*
|
|
4
|
+
* In Parse a role's `roles` relation lists the roles whose users inherit it, so
|
|
5
|
+
* a user in "staff" also holds "admin" when "staff" is listed under "admin".
|
|
6
|
+
* Walked upwards from the user's direct roles; `visited` guards against cyclic
|
|
7
|
+
* role definitions.
|
|
8
|
+
*/
|
|
9
|
+
export declare function userRoleNames(user: Parse.User): Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Whether `user` passes `object`'s ACL for `access` — the check Parse makes on
|
|
12
|
+
* a client request, for hook code that reads a *related* object with the
|
|
13
|
+
* master key and has to decide on the caller's behalf (may this user write
|
|
14
|
+
* header data about that ticket?).
|
|
15
|
+
*
|
|
16
|
+
* No ACL, or a public grant, lets everybody through; otherwise the user's own
|
|
17
|
+
* grant or one of their roles' (inherited ones included) has to.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasAclAccess(object: Parse.Object, user: Parse.User | undefined, access: "read" | "write"): Promise<boolean>;
|
|
@@ -0,0 +1,57 @@
|
|
|
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.userRoleNames = userRoleNames;
|
|
7
|
+
exports.hasAclAccess = hasAclAccess;
|
|
8
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
9
|
+
/**
|
|
10
|
+
* Every role name `user` holds, inherited ones included.
|
|
11
|
+
*
|
|
12
|
+
* In Parse a role's `roles` relation lists the roles whose users inherit it, so
|
|
13
|
+
* a user in "staff" also holds "admin" when "staff" is listed under "admin".
|
|
14
|
+
* Walked upwards from the user's direct roles; `visited` guards against cyclic
|
|
15
|
+
* role definitions.
|
|
16
|
+
*/
|
|
17
|
+
async function userRoleNames(user) {
|
|
18
|
+
const visited = new Set();
|
|
19
|
+
async function collect(roleQuery) {
|
|
20
|
+
const found = await roleQuery.find({ useMasterKey: true });
|
|
21
|
+
for (const role of found) {
|
|
22
|
+
const name = role.getName();
|
|
23
|
+
if (name && !visited.has(name)) {
|
|
24
|
+
visited.add(name);
|
|
25
|
+
// The roles that list this one as a child — continue upward.
|
|
26
|
+
await collect(new node_1.default.Query(node_1.default.Role).equalTo("roles", role));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
await collect(new node_1.default.Query(node_1.default.Role).equalTo("users", user));
|
|
31
|
+
return [...visited];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether `user` passes `object`'s ACL for `access` — the check Parse makes on
|
|
35
|
+
* a client request, for hook code that reads a *related* object with the
|
|
36
|
+
* master key and has to decide on the caller's behalf (may this user write
|
|
37
|
+
* header data about that ticket?).
|
|
38
|
+
*
|
|
39
|
+
* No ACL, or a public grant, lets everybody through; otherwise the user's own
|
|
40
|
+
* grant or one of their roles' (inherited ones included) has to.
|
|
41
|
+
*/
|
|
42
|
+
async function hasAclAccess(object, user, access) {
|
|
43
|
+
const acl = object.getACL();
|
|
44
|
+
if (!acl)
|
|
45
|
+
return true;
|
|
46
|
+
const read = access === "read";
|
|
47
|
+
if (read ? acl.getPublicReadAccess() : acl.getPublicWriteAccess()) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (!user?.id)
|
|
51
|
+
return false;
|
|
52
|
+
if (read ? acl.getReadAccess(user.id) : acl.getWriteAccess(user.id)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const roles = await userRoleNames(user);
|
|
56
|
+
return roles.some((name) => read ? acl.getRoleReadAccess(name) : acl.getRoleWriteAccess(name));
|
|
57
|
+
}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
import { _User } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The language to write to `recipient` in, as the server's translations are
|
|
4
|
+
* keyed: `"de-DE"` or `"en-US"` (see `initTranslation`).
|
|
5
|
+
*
|
|
6
|
+
* Two things made every recipient get the default before:
|
|
7
|
+
*
|
|
8
|
+
* - **Unfetched settings.** Recipients come out of role and user queries
|
|
9
|
+
* without `include("settings")`, so `settings` is a bare pointer and reading
|
|
10
|
+
* `preferred_language` off it yields `undefined`. The row is fetched here
|
|
11
|
+
* when its data is missing.
|
|
12
|
+
* - **Code format.** The settings store ISO 639-2 codes (`"deu"`, the default
|
|
13
|
+
* `ensureSettings` writes; `"eng"`), not the server's locale names. How a code
|
|
14
|
+
* maps is `toServerLanguage` in `@opendash/openservice-shared`, which the
|
|
15
|
+
* scheduler's reminders use as well.
|
|
16
|
+
*/
|
|
2
17
|
export declare function getUserLanguage(recipient: _User): Promise<string>;
|
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getUserLanguage = getUserLanguage;
|
|
4
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
5
|
+
/**
|
|
6
|
+
* The language to write to `recipient` in, as the server's translations are
|
|
7
|
+
* keyed: `"de-DE"` or `"en-US"` (see `initTranslation`).
|
|
8
|
+
*
|
|
9
|
+
* Two things made every recipient get the default before:
|
|
10
|
+
*
|
|
11
|
+
* - **Unfetched settings.** Recipients come out of role and user queries
|
|
12
|
+
* without `include("settings")`, so `settings` is a bare pointer and reading
|
|
13
|
+
* `preferred_language` off it yields `undefined`. The row is fetched here
|
|
14
|
+
* when its data is missing.
|
|
15
|
+
* - **Code format.** The settings store ISO 639-2 codes (`"deu"`, the default
|
|
16
|
+
* `ensureSettings` writes; `"eng"`), not the server's locale names. How a code
|
|
17
|
+
* maps is `toServerLanguage` in `@opendash/openservice-shared`, which the
|
|
18
|
+
* scheduler's reminders use as well.
|
|
19
|
+
*/
|
|
4
20
|
async function getUserLanguage(recipient) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
21
|
+
let settings = recipient.get("settings");
|
|
22
|
+
if (!settings)
|
|
23
|
+
return openservice_shared_1.DEFAULT_SERVER_LANGUAGE;
|
|
24
|
+
if (!settings.isDataAvailable()) {
|
|
25
|
+
try {
|
|
26
|
+
settings = await settings.fetch({ useMasterKey: true });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return openservice_shared_1.DEFAULT_SERVER_LANGUAGE;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return (0, openservice_shared_1.toServerLanguage)(settings.get("preferred_language"));
|
|
9
33
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role **names** for an array-of-ref field holding role pointers.
|
|
3
|
+
*
|
|
4
|
+
* `Parse.ACL` grants roles by name, never by id, so a role reference has to be
|
|
5
|
+
* resolved before it can be written into an ACL.
|
|
6
|
+
*/
|
|
7
|
+
export declare function roleNames(Parse: typeof import("parse/node").default, value: unknown): Promise<string[]>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.roleNames = roleNames;
|
|
4
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
5
|
+
/**
|
|
6
|
+
* Role **names** for an array-of-ref field holding role pointers.
|
|
7
|
+
*
|
|
8
|
+
* `Parse.ACL` grants roles by name, never by id, so a role reference has to be
|
|
9
|
+
* resolved before it can be written into an ACL.
|
|
10
|
+
*/
|
|
11
|
+
async function roleNames(Parse, value) {
|
|
12
|
+
const ids = (0, openservice_shared_1.refIds)(value);
|
|
13
|
+
if (ids.length === 0)
|
|
14
|
+
return [];
|
|
15
|
+
const roles = await new Parse.Query(Parse.Role)
|
|
16
|
+
.containedIn("objectId", ids)
|
|
17
|
+
.find({ useMasterKey: true });
|
|
18
|
+
return roles
|
|
19
|
+
.map((role) => role.getName())
|
|
20
|
+
.filter((name) => !!name);
|
|
21
|
+
}
|
|
@@ -10,16 +10,10 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Same shape as the tag closure reconciliation in `Service_Tag`: an invariant
|
|
12
12
|
* that has to hold for every write path, which only a backend trigger can
|
|
13
|
-
* guarantee.
|
|
13
|
+
* guarantee. The label keys come from `sortKeyOf` in
|
|
14
|
+
* `@opendash/openservice-shared`, the same function the ticket's own
|
|
15
|
+
* `beforeSave` uses.
|
|
14
16
|
*/
|
|
15
|
-
/**
|
|
16
|
-
* Comparable form of a label — identical to the one in `hooks/Service_Ticket`.
|
|
17
|
-
*
|
|
18
|
-
* MongoDB compares strings byte by byte, so "Ökowerk" would sort behind
|
|
19
|
-
* "Zementwerk". Folding the diacritics puts it at "O", which is what German
|
|
20
|
-
* readers expect (DIN 5007-1).
|
|
21
|
-
*/
|
|
22
|
-
export declare function sortKeyOf(label: unknown): string | undefined;
|
|
23
17
|
/**
|
|
24
18
|
* Writes `value` into `targetField` on every live ticket pointing at `row`.
|
|
25
19
|
*
|
|
@@ -32,6 +26,11 @@ export declare function sortKeyOf(label: unknown): string | undefined;
|
|
|
32
26
|
* every key then. They are also what grows without bound: finished tickets are
|
|
33
27
|
* archived automatically, so reordering "Done" would otherwise rewrite every
|
|
34
28
|
* ticket ever finished.
|
|
29
|
+
*
|
|
30
|
+
* One database update for all of them, without triggers, changelog entries or
|
|
31
|
+
* a new `updatedAt` — see {@link updateWithoutTriggers}. Saving each ticket
|
|
32
|
+
* instead (the fallback) also told the auto-archive they had just been worked
|
|
33
|
+
* on.
|
|
35
34
|
*/
|
|
36
35
|
export declare function pushSortKeyToTickets(pointerField: "status" | "project" | "equipment", targetField: "statusOrder" | "projectSortKey" | "equipmentSortKey", row: Parse.Object, value: number | string | undefined): Promise<number>;
|
|
37
36
|
/**
|
|
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sortKeyOf = sortKeyOf;
|
|
7
6
|
exports.pushSortKeyToTickets = pushSortKeyToTickets;
|
|
8
7
|
exports.derivedValueChanged = derivedValueChanged;
|
|
9
8
|
const node_1 = __importDefault(require("parse/node"));
|
|
10
9
|
const index_js_1 = require("../types/index.js");
|
|
10
|
+
const updateWithoutTriggers_js_1 = require("./updateWithoutTriggers.js");
|
|
11
11
|
/**
|
|
12
12
|
* Keeps the tickets' sort shadow columns in step when the referenced master
|
|
13
13
|
* data is renamed or reordered.
|
|
@@ -20,27 +20,10 @@ const index_js_1 = require("../types/index.js");
|
|
|
20
20
|
*
|
|
21
21
|
* Same shape as the tag closure reconciliation in `Service_Tag`: an invariant
|
|
22
22
|
* that has to hold for every write path, which only a backend trigger can
|
|
23
|
-
* guarantee.
|
|
23
|
+
* guarantee. The label keys come from `sortKeyOf` in
|
|
24
|
+
* `@opendash/openservice-shared`, the same function the ticket's own
|
|
25
|
+
* `beforeSave` uses.
|
|
24
26
|
*/
|
|
25
|
-
/**
|
|
26
|
-
* Comparable form of a label — identical to the one in `hooks/Service_Ticket`.
|
|
27
|
-
*
|
|
28
|
-
* MongoDB compares strings byte by byte, so "Ökowerk" would sort behind
|
|
29
|
-
* "Zementwerk". Folding the diacritics puts it at "O", which is what German
|
|
30
|
-
* readers expect (DIN 5007-1).
|
|
31
|
-
*/
|
|
32
|
-
function sortKeyOf(label) {
|
|
33
|
-
if (typeof label !== "string")
|
|
34
|
-
return undefined;
|
|
35
|
-
const trimmed = label.trim();
|
|
36
|
-
if (!trimmed)
|
|
37
|
-
return undefined;
|
|
38
|
-
return trimmed
|
|
39
|
-
.normalize("NFD")
|
|
40
|
-
.replace(/\p{Diacritic}/gu, "")
|
|
41
|
-
.replace(/ß/g, "ss")
|
|
42
|
-
.toLowerCase();
|
|
43
|
-
}
|
|
44
27
|
/**
|
|
45
28
|
* Writes `value` into `targetField` on every live ticket pointing at `row`.
|
|
46
29
|
*
|
|
@@ -53,12 +36,24 @@ function sortKeyOf(label) {
|
|
|
53
36
|
* every key then. They are also what grows without bound: finished tickets are
|
|
54
37
|
* archived automatically, so reordering "Done" would otherwise rewrite every
|
|
55
38
|
* ticket ever finished.
|
|
39
|
+
*
|
|
40
|
+
* One database update for all of them, without triggers, changelog entries or
|
|
41
|
+
* a new `updatedAt` — see {@link updateWithoutTriggers}. Saving each ticket
|
|
42
|
+
* instead (the fallback) also told the auto-archive they had just been worked
|
|
43
|
+
* on.
|
|
56
44
|
*/
|
|
57
45
|
async function pushSortKeyToTickets(pointerField, targetField, row, value) {
|
|
46
|
+
const tenant = row.get("tenant");
|
|
47
|
+
const changed = await (0, updateWithoutTriggers_js_1.updateWithoutTriggers)(index_js_1.Service_Ticket.className, {
|
|
48
|
+
[pointerField]: (0, updateWithoutTriggers_js_1.restPointer)(row),
|
|
49
|
+
deleted: { $ne: true },
|
|
50
|
+
...(tenant ? { tenant: (0, updateWithoutTriggers_js_1.restPointer)(tenant) } : {}),
|
|
51
|
+
}, { [targetField]: value === undefined ? { __op: "Delete" } : value });
|
|
52
|
+
if (changed !== undefined)
|
|
53
|
+
return changed;
|
|
58
54
|
const query = new node_1.default.Query(index_js_1.Service_Ticket)
|
|
59
55
|
.equalTo(pointerField, row)
|
|
60
56
|
.notEqualTo("deleted", true);
|
|
61
|
-
const tenant = row.get("tenant");
|
|
62
57
|
if (tenant)
|
|
63
58
|
query.equalTo("tenant", tenant);
|
|
64
59
|
const affected = await query.findAll({ useMasterKey: true });
|
|
@@ -70,7 +65,10 @@ async function pushSortKeyToTickets(pointerField, targetField, row, value) {
|
|
|
70
65
|
else
|
|
71
66
|
ticket.set(targetField, value);
|
|
72
67
|
}
|
|
73
|
-
await node_1.default.Object.saveAll(affected, {
|
|
68
|
+
await node_1.default.Object.saveAll(affected, {
|
|
69
|
+
useMasterKey: true,
|
|
70
|
+
context: { skipChangelog: true },
|
|
71
|
+
});
|
|
74
72
|
return affected.length;
|
|
75
73
|
}
|
|
76
74
|
/**
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes derived, denormalised columns straight to the database — every row
|
|
3
|
+
* matching `where` at once, with no triggers, no changelog entry and no new
|
|
4
|
+
* `updatedAt`. `where` and `update` are in REST format: pointers as
|
|
5
|
+
* `{ __type: "Pointer", … }`, `{ __op: "Delete" }` to unset a column.
|
|
6
|
+
*
|
|
7
|
+
* For values that only mirror another row: a ticket's sort keys mirror its
|
|
8
|
+
* status, project and equipment, its tag closure mirrors the tag tree. Saving
|
|
9
|
+
* each affected row did three things that are wrong for such a value:
|
|
10
|
+
*
|
|
11
|
+
* - every ticket hook ran once per row, for thousands of rows;
|
|
12
|
+
* - every row got a changelog entry for a change nobody made to it;
|
|
13
|
+
* - every row got a new `updatedAt`, which the auto-archive reads as
|
|
14
|
+
* activity — reordering "Done" postponed the archiving of every finished
|
|
15
|
+
* ticket by a whole period.
|
|
16
|
+
*
|
|
17
|
+
* Returns the number of rows changed, or `undefined` when the database is out
|
|
18
|
+
* of reach; the caller then saves the rows instead.
|
|
19
|
+
*/
|
|
20
|
+
export declare function updateWithoutTriggers(className: string, where: Record<string, unknown>, update: Record<string, unknown>): Promise<number | undefined>;
|
|
21
|
+
/** A pointer in the REST format `updateWithoutTriggers` takes. */
|
|
22
|
+
export declare function restPointer(object: Parse.Object): Record<string, string>;
|
|
@@ -0,0 +1,57 @@
|
|
|
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.updateWithoutTriggers = updateWithoutTriggers;
|
|
7
|
+
exports.restPointer = restPointer;
|
|
8
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
9
|
+
/**
|
|
10
|
+
* The DatabaseController of the running Parse Server, or `undefined` when it
|
|
11
|
+
* is out of reach (a second copy of `parse-server`, whose config cache is
|
|
12
|
+
* empty). Same reach as `ensureIndexes`.
|
|
13
|
+
*/
|
|
14
|
+
function database() {
|
|
15
|
+
try {
|
|
16
|
+
const Config = require("parse-server/lib/Config");
|
|
17
|
+
const db = Config.get(node_1.default.applicationId)?.database;
|
|
18
|
+
return typeof db?.update === "function" ? db : undefined;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Writes derived, denormalised columns straight to the database — every row
|
|
26
|
+
* matching `where` at once, with no triggers, no changelog entry and no new
|
|
27
|
+
* `updatedAt`. `where` and `update` are in REST format: pointers as
|
|
28
|
+
* `{ __type: "Pointer", … }`, `{ __op: "Delete" }` to unset a column.
|
|
29
|
+
*
|
|
30
|
+
* For values that only mirror another row: a ticket's sort keys mirror its
|
|
31
|
+
* status, project and equipment, its tag closure mirrors the tag tree. Saving
|
|
32
|
+
* each affected row did three things that are wrong for such a value:
|
|
33
|
+
*
|
|
34
|
+
* - every ticket hook ran once per row, for thousands of rows;
|
|
35
|
+
* - every row got a changelog entry for a change nobody made to it;
|
|
36
|
+
* - every row got a new `updatedAt`, which the auto-archive reads as
|
|
37
|
+
* activity — reordering "Done" postponed the archiving of every finished
|
|
38
|
+
* ticket by a whole period.
|
|
39
|
+
*
|
|
40
|
+
* Returns the number of rows changed, or `undefined` when the database is out
|
|
41
|
+
* of reach; the caller then saves the rows instead.
|
|
42
|
+
*/
|
|
43
|
+
async function updateWithoutTriggers(className, where, update) {
|
|
44
|
+
const db = database();
|
|
45
|
+
if (!db)
|
|
46
|
+
return undefined;
|
|
47
|
+
const result = await db.update(className, where, update, { many: true });
|
|
48
|
+
return result?.modifiedCount ?? 0;
|
|
49
|
+
}
|
|
50
|
+
/** A pointer in the REST format `updateWithoutTriggers` takes. */
|
|
51
|
+
function restPointer(object) {
|
|
52
|
+
return {
|
|
53
|
+
__type: "Pointer",
|
|
54
|
+
className: object.className,
|
|
55
|
+
objectId: object.id,
|
|
56
|
+
};
|
|
57
|
+
}
|