@openinc/parse-server-opendash 4.16.0 → 4.17.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.
- package/dist/features/permissions/types/Permissions.d.ts +2 -1
- package/dist/features/permissions/types/Permissions.js +12 -5
- package/dist/features/schema/helper/defaultHandler.d.ts +1 -1
- package/dist/features/schema/helper/defaultHandler.js +25 -8
- package/dist/hooks/Meta_Entry.js +2 -2
- package/dist/hooks/Permission.js +9 -5
- package/dist/hooks/Service_Ticket.js +11 -2
- package/package.json +1 -1
|
@@ -39,7 +39,8 @@ export declare namespace Permissions {
|
|
|
39
39
|
chatadmin = "chat:can-see-admin",
|
|
40
40
|
changelog = "changelog:can-see-app",
|
|
41
41
|
changelog_restore = "changelog:can-restore-deleted",
|
|
42
|
-
tenant_admin = "opendash:can-admin-tenants"
|
|
42
|
+
tenant_admin = "opendash:can-admin-tenants",
|
|
43
|
+
multi_tenant = "opendash:can-work-multitenant"
|
|
43
44
|
}
|
|
44
45
|
enum GTFS {
|
|
45
46
|
global = "gtfs:can-access-global"
|
|
@@ -84,12 +84,19 @@ var Permissions;
|
|
|
84
84
|
// Restoring a deleted object writes with the master key, so it is kept
|
|
85
85
|
// separate from merely reading the changelog.
|
|
86
86
|
CORE["changelog_restore"] = "changelog:can-restore-deleted";
|
|
87
|
-
// Cross-tenant administration: `defaultHandler`
|
|
88
|
-
// `tenant`
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
87
|
+
// Cross-tenant administration: the tenant admin pages, and `defaultHandler`
|
|
88
|
+
// honours a submitted `tenant` for a holder. Registered so od-admin holds
|
|
89
|
+
// it without manual setup — and *only* od-admin: the `Permission`
|
|
90
|
+
// beforeSave hook keeps the tenant roles off it, which every other
|
|
91
|
+
// registered permission is granted to.
|
|
92
92
|
CORE["tenant_admin"] = "opendash:can-admin-tenants";
|
|
93
|
+
// Working across tenants without administering them — someone who handles
|
|
94
|
+
// tickets for several tenants. `defaultHandler` honours a submitted
|
|
95
|
+
// `tenant` for a holder, and the plugins offer the tenant field, the active
|
|
96
|
+
// tenant notices and tenant-aware views to them. Kept apart from
|
|
97
|
+
// `tenant_admin` so it does not come with the tenant administration.
|
|
98
|
+
// Same handling: od-admin only by default, granted with the master key.
|
|
99
|
+
CORE["multi_tenant"] = "opendash:can-work-multitenant";
|
|
93
100
|
})(CORE = Permissions.CORE || (Permissions.CORE = {}));
|
|
94
101
|
let GTFS;
|
|
95
102
|
(function (GTFS) {
|
|
@@ -2,7 +2,7 @@ import { SessionTokenType } from "../index.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Handles the default beforeSave() logic for a Parse.Object.
|
|
4
4
|
*
|
|
5
|
-
* This function will check if a user or tenant field is present in the schema and set the value to the current user and/or the tenant of the current user
|
|
5
|
+
* This function will check if a user or tenant field is present in the schema and set the value to the current user and/or the tenant of the current user. A tenant submitted on create is kept for a holder of `opendash:can-work-multitenant` or `opendash:can-admin-tenants`.
|
|
6
6
|
* This will also mark the user and tenant fields as immutable, preventing them from being edited in the future.
|
|
7
7
|
*
|
|
8
8
|
* @param request - The Parse.Cloud.BeforeSaveRequest object.
|
|
@@ -13,7 +13,7 @@ const migrationMode_js_1 = require("./migrationMode.js");
|
|
|
13
13
|
/**
|
|
14
14
|
* Handles the default beforeSave() logic for a Parse.Object.
|
|
15
15
|
*
|
|
16
|
-
* This function will check if a user or tenant field is present in the schema and set the value to the current user and/or the tenant of the current user
|
|
16
|
+
* This function will check if a user or tenant field is present in the schema and set the value to the current user and/or the tenant of the current user. A tenant submitted on create is kept for a holder of `opendash:can-work-multitenant` or `opendash:can-admin-tenants`.
|
|
17
17
|
* This will also mark the user and tenant fields as immutable, preventing them from being edited in the future.
|
|
18
18
|
*
|
|
19
19
|
* @param request - The Parse.Cloud.BeforeSaveRequest object.
|
|
@@ -57,18 +57,35 @@ async function defaultHandler(request) {
|
|
|
57
57
|
const user = (await request.user?.fetch({
|
|
58
58
|
useMasterKey: true,
|
|
59
59
|
}));
|
|
60
|
-
|
|
61
|
-
await (
|
|
62
|
-
if (!request.object.get("tenant")) {
|
|
63
|
-
request.object.set("tenant", user.get("tenant"));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
60
|
+
if (!request.object.get("tenant") ||
|
|
61
|
+
!(await mayChooseTenant(request.sessionToken))) {
|
|
67
62
|
request.object.set("tenant", user.get("tenant"));
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* The keys that let a writer choose the tenant of a new object instead of
|
|
69
|
+
* getting their own: `opendash:can-work-multitenant` for someone who works in
|
|
70
|
+
* several tenants (the frontend submits the *active* one — the tenant of the
|
|
71
|
+
* selected header source, whose statuses, projects and equipment its pickers
|
|
72
|
+
* offered), and `opendash:can-admin-tenants` for the platform administration.
|
|
73
|
+
* Separate keys, so working across tenants does not come with administering
|
|
74
|
+
* them.
|
|
75
|
+
*/
|
|
76
|
+
const TENANT_CHOICE_PERMISSIONS = [
|
|
77
|
+
"opendash:can-work-multitenant",
|
|
78
|
+
"opendash:can-admin-tenants",
|
|
79
|
+
];
|
|
80
|
+
async function mayChooseTenant(sessionToken) {
|
|
81
|
+
if (!sessionToken)
|
|
82
|
+
return false;
|
|
83
|
+
for (const key of TENANT_CHOICE_PERMISSIONS) {
|
|
84
|
+
if (await (0, index_js_1.hasPermission)(sessionToken, key))
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
72
89
|
/**
|
|
73
90
|
* Handles the default Parse.ACL beforeSave() logic for a Parse.Object.
|
|
74
91
|
*
|
package/dist/hooks/Meta_Entry.js
CHANGED
|
@@ -50,8 +50,8 @@ function allowSubjectUserWrite(object) {
|
|
|
50
50
|
* `afterSave` below then registered the context under A as well.
|
|
51
51
|
*
|
|
52
52
|
* Runs after `defaultHandler` on purpose: that function overwrites `tenant`
|
|
53
|
-
* with the writer's own for any caller without `opendash:can-
|
|
54
|
-
* so correcting it beforehand would be undone.
|
|
53
|
+
* with the writer's own for any caller without `opendash:can-work-multitenant`
|
|
54
|
+
* or `opendash:can-admin-tenants`, so correcting it beforehand would be undone.
|
|
55
55
|
*
|
|
56
56
|
* Only on create, or on a master-key write — `immutableField` refuses a tenant
|
|
57
57
|
* change for everyone else, and a master-key re-save is therefore also the
|
package/dist/hooks/Permission.js
CHANGED
|
@@ -9,6 +9,7 @@ const index_js_1 = require("../features/schema/index.js");
|
|
|
9
9
|
const index_js_2 = require("../types/index.js");
|
|
10
10
|
const masterKeyPermission = [
|
|
11
11
|
"opendash:can-admin-tenants",
|
|
12
|
+
"opendash:can-work-multitenant",
|
|
12
13
|
"opendash:tenant:change-tag-prefix",
|
|
13
14
|
"opendash:source:write-tag-ignore-tenant-prefix",
|
|
14
15
|
"opendash:source:write-tag-group",
|
|
@@ -21,12 +22,15 @@ const masterKeyPermission = [
|
|
|
21
22
|
* `defaultAclHandler` grants `od-tenant-admin-<tenant>` read and write on every
|
|
22
23
|
* object with a tenant — on purpose for ordinary permissions, which a tenant
|
|
23
24
|
* admin holds and hands on within their tenant. For a cross-tenant permission
|
|
24
|
-
* that default is an escalation:
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* that default is an escalation: these are registered for every tenant on
|
|
26
|
+
* startup, so they would make every tenant's admin a cross-tenant one.
|
|
27
|
+
* Granting them to anyone beyond od-admin stays possible, with the master key,
|
|
28
|
+
* through a user or a role of its own in the ACL.
|
|
28
29
|
*/
|
|
29
|
-
const crossTenantPermission = [
|
|
30
|
+
const crossTenantPermission = [
|
|
31
|
+
"opendash:can-admin-tenants",
|
|
32
|
+
"opendash:can-work-multitenant",
|
|
33
|
+
];
|
|
30
34
|
/**
|
|
31
35
|
* Take back the read/write `defaultAclHandler` gave the object's tenant roles.
|
|
32
36
|
* Runs on every save, master key included, so re-saving an object written
|
|
@@ -237,8 +237,15 @@ async function nextTenantTicketNumber(tenant) {
|
|
|
237
237
|
}
|
|
238
238
|
/** Pointer fields on a ticket that must belong to the ticket's own tenant. */
|
|
239
239
|
const TENANT_SCOPED_POINTERS = ["status", "project", "equipment"];
|
|
240
|
-
/**
|
|
241
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Pointer-array fields whose entries must belong to the ticket's own tenant.
|
|
242
|
+
*
|
|
243
|
+
* Not `assignedUsers`: people work across tenants — a customer assigns the
|
|
244
|
+
* service provider's staff to its tickets — so an assignee of another tenant
|
|
245
|
+
* is legitimate. Who can be picked is what the assigner may read; the ticket
|
|
246
|
+
* ACL then grants the assignee access.
|
|
247
|
+
*/
|
|
248
|
+
const TENANT_SCOPED_POINTER_ARRAYS = ["tags"];
|
|
242
249
|
/**
|
|
243
250
|
* Shadow columns the ticket carries so the table can sort by a pointer.
|
|
244
251
|
*
|
|
@@ -335,6 +342,8 @@ async function loadReferencedRows(object) {
|
|
|
335
342
|
*
|
|
336
343
|
* `assignedRoles` is deliberately not checked: `_Role` has no tenant column at
|
|
337
344
|
* all — a role's tenant lives in its name — so there is nothing to compare.
|
|
345
|
+
* Nor is `assignedUsers` (see {@link TENANT_SCOPED_POINTER_ARRAYS}): people are
|
|
346
|
+
* not master data of one tenant.
|
|
338
347
|
*/
|
|
339
348
|
function assertSameTenantReferences(object, rows) {
|
|
340
349
|
const tenantId = object.get("tenant")?.id;
|