@openinc/parse-server-opendash 4.28.0 → 4.30.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.
@@ -0,0 +1,30 @@
1
+ /**
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
+ *
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.
10
+ *
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.
14
+ *
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.
20
+ *
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.
27
+ *
28
+ * @param name The function name, derived from the file name.
29
+ */
30
+ export declare function init(name: string): Promise<void>;
@@ -0,0 +1,79 @@
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 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");
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).
14
+ *
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.
20
+ *
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.
24
+ *
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.
30
+ *
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.
37
+ *
38
+ * @param name The function name, derived from the file name.
39
+ */
40
+ async function init(name) {
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.
52
+ if (source.get("tag"))
53
+ return;
54
+ const tenant = source.get("tenant");
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)
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";
70
+ }
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);
75
+ }
76
+ }, readOptions);
77
+ return rows;
78
+ });
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.28.0",
3
+ "version": "4.30.0",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.8.1",
6
6
  "keywords": [