@openinc/parse-server-opendash 4.29.0 → 4.31.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.
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gives every source without a tag one —
|
|
3
|
-
*
|
|
2
|
+
* Gives every source without a tag one — run from the "Missing tags" button
|
|
3
|
+
* in the source admin view (`MissingSourceTagsButton`, @opendash/plugin-parse).
|
|
4
4
|
*
|
|
5
|
-
* Some instances have `OD3_Source` rows whose `tag` was never set.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Some instances have `OD3_Source` rows whose `tag` was never set. They get
|
|
6
|
+
* `tenant-<tenant id>-<source id>`, which is unique by construction, so the
|
|
7
|
+
* duplicate check in `hooks/Source.ts` never has anything to object to. A
|
|
8
|
+
* source without a tenant is left alone: there is nothing to build the tag
|
|
9
|
+
* from.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* Params: `{ dryRun: true }` only lists the sources and the tag each would
|
|
12
|
+
* get; without it they are saved. Either way the answer is one row per source
|
|
13
|
+
* without a tag, so the admin view shows the same table before and after.
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* Gated on `opendash:can-admin-tenants` (`Permissions.CORE.tenant_admin`): it
|
|
16
|
+
* reaches into every tenant's sources. That permission is registered on
|
|
17
|
+
* startup and held by od-admin only. The source permission
|
|
18
|
+
* `opendash:source:write-tag-ignore-tenant-prefix` would describe the tag
|
|
19
|
+
* better, but it is never registered — on most instances nobody holds it.
|
|
16
20
|
*
|
|
17
|
-
*
|
|
21
|
+
* The sources are read with the caller's session, so a source whose ACL hides
|
|
22
|
+
* it from the caller is not touched. They are saved with the master key: the
|
|
23
|
+
* generated tag ignores the tenant's tag prefix, and with a session the Source
|
|
24
|
+
* beforeSave would demand exactly that unregistered permission. The afterSave
|
|
25
|
+
* creates the `AccessPermissions` row a tagged source gets, as for a tag
|
|
26
|
+
* entered in the form.
|
|
18
27
|
*
|
|
19
|
-
* @param name The
|
|
28
|
+
* @param name The function name, derived from the file name.
|
|
20
29
|
*/
|
|
21
30
|
export declare function init(name: string): Promise<void>;
|
|
@@ -5,81 +5,75 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
-
const index_js_1 = require("../
|
|
8
|
+
const index_js_1 = require("../features/permissions/index.js");
|
|
9
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
10
|
+
const index_js_2 = require("../types/index.js");
|
|
9
11
|
/**
|
|
10
|
-
* Gives every source without a tag one —
|
|
11
|
-
*
|
|
12
|
+
* Gives every source without a tag one — run from the "Missing tags" button
|
|
13
|
+
* in the source admin view (`MissingSourceTagsButton`, @opendash/plugin-parse).
|
|
12
14
|
*
|
|
13
|
-
* Some instances have `OD3_Source` rows whose `tag` was never set.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* Some instances have `OD3_Source` rows whose `tag` was never set. They get
|
|
16
|
+
* `tenant-<tenant id>-<source id>`, which is unique by construction, so the
|
|
17
|
+
* duplicate check in `hooks/Source.ts` never has anything to object to. A
|
|
18
|
+
* source without a tenant is left alone: there is nothing to build the tag
|
|
19
|
+
* from.
|
|
16
20
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
21
|
+
* Params: `{ dryRun: true }` only lists the sources and the tag each would
|
|
22
|
+
* get; without it they are saved. Either way the answer is one row per source
|
|
23
|
+
* without a tag, so the admin view shows the same table before and after.
|
|
20
24
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
25
|
+
* Gated on `opendash:can-admin-tenants` (`Permissions.CORE.tenant_admin`): it
|
|
26
|
+
* reaches into every tenant's sources. That permission is registered on
|
|
27
|
+
* startup and held by od-admin only. The source permission
|
|
28
|
+
* `opendash:source:write-tag-ignore-tenant-prefix` would describe the tag
|
|
29
|
+
* better, but it is never registered — on most instances nobody holds it.
|
|
24
30
|
*
|
|
25
|
-
*
|
|
31
|
+
* The sources are read with the caller's session, so a source whose ACL hides
|
|
32
|
+
* it from the caller is not touched. They are saved with the master key: the
|
|
33
|
+
* generated tag ignores the tenant's tag prefix, and with a session the Source
|
|
34
|
+
* beforeSave would demand exactly that unregistered permission. The afterSave
|
|
35
|
+
* creates the `AccessPermissions` row a tagged source gets, as for a tag
|
|
36
|
+
* entered in the form.
|
|
26
37
|
*
|
|
27
|
-
* @param name The
|
|
38
|
+
* @param name The function name, derived from the file name.
|
|
28
39
|
*/
|
|
29
40
|
async function init(name) {
|
|
30
|
-
node_1.default.Cloud.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
await new node_1.default.Query(index_js_1.Source).each(async (source) => {
|
|
42
|
-
checked++;
|
|
43
|
-
// An empty string counts as missing too — the Source hooks treat it
|
|
44
|
-
// the same way.
|
|
41
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
42
|
+
const sessionToken = request.user?.getSessionToken() ?? undefined;
|
|
43
|
+
await (0, index_js_1.requirePermission)({ sessionToken, master: request.master }, Permissions_js_1.Permissions.CORE.tenant_admin, "You are not allowed to tag sources");
|
|
44
|
+
const dryRun = request.params.dryRun === true;
|
|
45
|
+
const readOptions = request.master
|
|
46
|
+
? { useMasterKey: true }
|
|
47
|
+
: { sessionToken };
|
|
48
|
+
const rows = [];
|
|
49
|
+
await new node_1.default.Query(index_js_2.Source).include("tenant").each(async (source) => {
|
|
50
|
+
// An empty string counts as missing too — the Source hooks treat it the
|
|
51
|
+
// same way.
|
|
45
52
|
if (source.get("tag"))
|
|
46
53
|
return;
|
|
47
54
|
const tenant = source.get("tenant");
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
const row = {
|
|
56
|
+
objectId: source.id,
|
|
57
|
+
name: source.get("name") ?? null,
|
|
58
|
+
tenant: tenant ? (tenant.get("label") ?? tenant.id) : null,
|
|
59
|
+
tag: tenant ? `tenant-${tenant.id}-${source.id}` : null,
|
|
60
|
+
status: tenant ? "pending" : "no_tenant",
|
|
61
|
+
};
|
|
62
|
+
rows.push(row);
|
|
63
|
+
if (dryRun || !row.tag)
|
|
50
64
|
return;
|
|
65
|
+
// One bad row must not stop the rest; it is reported in its row.
|
|
66
|
+
try {
|
|
67
|
+
source.set("tag", row.tag);
|
|
68
|
+
await source.save(null, { useMasterKey: true });
|
|
69
|
+
row.status = "tagged";
|
|
51
70
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
// One bad row must not stop the rest; it is reported at the end.
|
|
59
|
-
failed.push(source.id);
|
|
60
|
-
console.error(`[@openinc/parse-server-opendash][${name}] Could not tag source ${source.id}:`, error);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
row.status = "failed";
|
|
73
|
+
row.error = error instanceof Error ? error.message : String(error);
|
|
74
|
+
console.error(`[@openinc/parse-server-opendash][${name}] Could not tag source ${source.id}:`, error);
|
|
63
75
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
request.message(`${tagged} sources ${verb} so far…`);
|
|
67
|
-
}
|
|
68
|
-
}, { useMasterKey: true });
|
|
69
|
-
if (withoutTenant.length > 0) {
|
|
70
|
-
console.warn(`[@openinc/parse-server-opendash][${name}] Sources without tag and tenant, skipped: ${withoutTenant.join(", ")}`);
|
|
71
|
-
}
|
|
72
|
-
const summary = `${dryRun ? "Dry run — nothing saved. " : ""}` +
|
|
73
|
-
`${checked} sources checked, ` +
|
|
74
|
-
`${tagged} ${verb}, ` +
|
|
75
|
-
`${withoutTenant.length} skipped without tenant, ` +
|
|
76
|
-
`${failed.length} failed.`;
|
|
77
|
-
console.log(`[@openinc/parse-server-opendash][${name}] ${summary}`);
|
|
78
|
-
// Thrown so the job status reads "failed" in the dashboard; the message of
|
|
79
|
-
// a native Error ends up in the status row just like a returned string.
|
|
80
|
-
if (failed.length > 0) {
|
|
81
|
-
throw new Error(`${summary} Failed ids: ${failed.join(", ")}`);
|
|
82
|
-
}
|
|
83
|
-
return summary;
|
|
76
|
+
}, readOptions);
|
|
77
|
+
return rows;
|
|
84
78
|
});
|
|
85
79
|
}
|
|
@@ -29,7 +29,21 @@ async function init() {
|
|
|
29
29
|
const email = user?.getEmail();
|
|
30
30
|
console.log("[@openinc/parse-server-opendash][Notification]", `notification="${object.id}"`, `type="email"`, `to="${email}"`);
|
|
31
31
|
if (email) {
|
|
32
|
-
|
|
32
|
+
const link = await buildEmailLink(object.get("data")?.url, user);
|
|
33
|
+
await (0, index_js_3.sendTemplateEmail)({
|
|
34
|
+
template: "openinc-notification",
|
|
35
|
+
to: email,
|
|
36
|
+
subject: title,
|
|
37
|
+
fallback: link
|
|
38
|
+
? `${description || ""}\n\n${link}`
|
|
39
|
+
: description || "",
|
|
40
|
+
data: {
|
|
41
|
+
title,
|
|
42
|
+
description,
|
|
43
|
+
link,
|
|
44
|
+
data: object.get("data"),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
33
47
|
}
|
|
34
48
|
}
|
|
35
49
|
// Handle Push
|
|
@@ -51,24 +65,20 @@ async function init() {
|
|
|
51
65
|
});
|
|
52
66
|
}
|
|
53
67
|
/**
|
|
54
|
-
*
|
|
55
|
-
* description, followed by a link to the thing the notification is about.
|
|
68
|
+
* Link to the thing a notification is about, for the notification email.
|
|
56
69
|
*
|
|
57
70
|
* Producers store that link in `data.url` as an app-relative path (e.g.
|
|
58
71
|
* `/service/tickets/<id>`), because the host depends on the recipient's tenant
|
|
59
72
|
* and is only known here, at delivery time — the frontend renders the same
|
|
60
73
|
* notification by route and never needs it. Absolute URLs are passed through
|
|
61
|
-
* unchanged for producers that resolved a host themselves.
|
|
74
|
+
* unchanged for producers that resolved a host themselves. Returns an empty
|
|
75
|
+
* string when the notification has no link.
|
|
62
76
|
*/
|
|
63
|
-
async function
|
|
64
|
-
const body = description || "";
|
|
77
|
+
async function buildEmailLink(url, user) {
|
|
65
78
|
if (typeof url !== "string" || url === "") {
|
|
66
|
-
return
|
|
79
|
+
return "";
|
|
67
80
|
}
|
|
68
|
-
|
|
69
|
-
? url
|
|
70
|
-
: `${await (0, appLinks_js_1.getAppBaseUrl)(user)}${url}`;
|
|
71
|
-
return `${body}\n\n${link}`;
|
|
81
|
+
return /^https?:\/\//i.test(url) ? url : `${await (0, appLinks_js_1.getAppBaseUrl)(user)}${url}`;
|
|
72
82
|
}
|
|
73
83
|
async function sendWebPush(subscription, id, title, description, icon, data) {
|
|
74
84
|
try {
|