@openinc/parse-server-opendash 4.15.0 → 4.15.1

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.
@@ -37,9 +37,57 @@ function allowSubjectUserWrite(object) {
37
37
  acl.setWriteAccess(subjectId, true);
38
38
  object.setACL(acl);
39
39
  }
40
+ /**
41
+ * File an entry under the tenant of the object it is *about*, not under the
42
+ * tenant of whoever wrote it.
43
+ *
44
+ * `defaultHandler` can only answer "whose is this?" with the writer's own
45
+ * tenant — it knows nothing about `entryClassName` / `entryObjectId`. That was
46
+ * wrong for anyone who edits across tenants: an `od-admin` of tenant A adding
47
+ * meta to tenant B's equipment produced an entry owned by A, and since
48
+ * `defaultAclHandler` keys its grants on the entry's tenant, **B could not read
49
+ * the meta data on its own record** — only od-admin and tenant A could. The
50
+ * `afterSave` below then registered the context under A as well.
51
+ *
52
+ * Runs after `defaultHandler` on purpose: that function overwrites `tenant`
53
+ * with the writer's own for any caller without `opendash:can-admin-tenants`,
54
+ * so correcting it beforehand would be undone.
55
+ *
56
+ * Only on create, or on a master-key write — `immutableField` refuses a tenant
57
+ * change for everyone else, and a master-key re-save is therefore also the
58
+ * repair path for entries written before this existed.
59
+ *
60
+ * Every failure leaves `defaultHandler`'s answer in place: a linked object that
61
+ * does not exist, a class without a tenant column, an entry that names no
62
+ * object at all. The tenant is never cleared, only corrected.
63
+ */
64
+ async function applyLinkedObjectTenant(request) {
65
+ if (request.original && !request.master)
66
+ return;
67
+ const className = request.object.entryClassName;
68
+ const objectId = request.object.entryObjectId;
69
+ if (!className || !objectId)
70
+ return;
71
+ try {
72
+ const linked = await new node_1.default.Query(className)
73
+ .equalTo("objectId", objectId)
74
+ .first({ useMasterKey: true });
75
+ const tenant = linked?.get("tenant");
76
+ if (!tenant)
77
+ return;
78
+ if (request.object.tenant?.id === tenant.id)
79
+ return;
80
+ request.object.tenant = tenant;
81
+ }
82
+ catch (error) {
83
+ console.error("[@openinc/parse-server-opendash][Meta_Entry] Failed to resolve the linked object's tenant", className, objectId, error);
84
+ }
85
+ }
40
86
  async function init() {
41
87
  (0, index_js_2.beforeSaveHook)(index_js_3.Meta_Entry, async (request) => {
42
88
  await (0, index_js_2.defaultHandler)(request);
89
+ // Before the ACL handler: it derives every grant from `tenant`.
90
+ await applyLinkedObjectTenant(request);
43
91
  await (0, index_js_2.defaultAclHandler)(request, {
44
92
  // Meta entries are collaborative header data: the tenant's users are the
45
93
  // ones filling them in from the ticket/equipment UI, so they need write
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.15.0",
3
+ "version": "4.15.1",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.8.1",
6
6
  "keywords": [