@openinc/parse-server-opendash 4.15.1 → 4.17.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/permissions/types/Permissions.d.ts +3 -1
- package/dist/features/permissions/types/Permissions.js +13 -0
- 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 +43 -1
- package/package.json +1 -1
|
@@ -38,7 +38,9 @@ export declare namespace Permissions {
|
|
|
38
38
|
metaadmin = "meta:can-see-admin",
|
|
39
39
|
chatadmin = "chat:can-see-admin",
|
|
40
40
|
changelog = "changelog:can-see-app",
|
|
41
|
-
changelog_restore = "changelog:can-restore-deleted"
|
|
41
|
+
changelog_restore = "changelog:can-restore-deleted",
|
|
42
|
+
tenant_admin = "opendash:can-admin-tenants",
|
|
43
|
+
multi_tenant = "opendash:can-work-multitenant"
|
|
42
44
|
}
|
|
43
45
|
enum GTFS {
|
|
44
46
|
global = "gtfs:can-access-global"
|
|
@@ -84,6 +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: 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
|
+
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";
|
|
87
100
|
})(CORE = Permissions.CORE || (Permissions.CORE = {}));
|
|
88
101
|
let GTFS;
|
|
89
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,14 +9,53 @@ 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",
|
|
15
16
|
];
|
|
17
|
+
/**
|
|
18
|
+
* Permissions no tenant role may hold, whichever tenant the object is filed
|
|
19
|
+
* under.
|
|
20
|
+
*
|
|
21
|
+
* A permission is held by whoever can *read* its object (`hasPermission`), and
|
|
22
|
+
* `defaultAclHandler` grants `od-tenant-admin-<tenant>` read and write on every
|
|
23
|
+
* object with a tenant — on purpose for ordinary permissions, which a tenant
|
|
24
|
+
* admin holds and hands on within their tenant. For a cross-tenant permission
|
|
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.
|
|
29
|
+
*/
|
|
30
|
+
const crossTenantPermission = [
|
|
31
|
+
"opendash:can-admin-tenants",
|
|
32
|
+
"opendash:can-work-multitenant",
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* Take back the read/write `defaultAclHandler` gave the object's tenant roles.
|
|
36
|
+
* Runs on every save, master key included, so re-saving an object written
|
|
37
|
+
* before this existed is enough to repair it.
|
|
38
|
+
*/
|
|
39
|
+
function revokeTenantRoles(object) {
|
|
40
|
+
const tenantId = object.get("tenant")?.id;
|
|
41
|
+
const acl = object.getACL();
|
|
42
|
+
if (!tenantId || !acl)
|
|
43
|
+
return;
|
|
44
|
+
for (const role of [
|
|
45
|
+
`od-tenant-admin-${tenantId}`,
|
|
46
|
+
`od-tenant-user-${tenantId}`,
|
|
47
|
+
]) {
|
|
48
|
+
acl.setRoleReadAccess(role, false);
|
|
49
|
+
acl.setRoleWriteAccess(role, false);
|
|
50
|
+
}
|
|
51
|
+
object.setACL(acl);
|
|
52
|
+
}
|
|
16
53
|
async function init() {
|
|
17
54
|
(0, index_js_1.beforeSaveHook)(index_js_2.Permission, async (request) => {
|
|
18
55
|
const { object, original, user } = request;
|
|
19
|
-
if ((masterKeyPermission.includes(object.get("key")) ||
|
|
56
|
+
if ((masterKeyPermission.includes(object.get("key")) ||
|
|
57
|
+
(object.get("key") && object.get("key").startsWith("master:"))) &&
|
|
58
|
+
!request.master) {
|
|
20
59
|
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, `User is not allowed to create or update permission with key '${object.get("key")}' without master key`);
|
|
21
60
|
}
|
|
22
61
|
await (0, index_js_1.defaultHandler)(request);
|
|
@@ -24,6 +63,9 @@ async function init() {
|
|
|
24
63
|
allowCustomACL: true,
|
|
25
64
|
denyTenantUserRead: true,
|
|
26
65
|
});
|
|
66
|
+
if (crossTenantPermission.includes(object.get("key"))) {
|
|
67
|
+
revokeTenantRoles(object);
|
|
68
|
+
}
|
|
27
69
|
});
|
|
28
70
|
(0, index_js_1.afterSaveHook)(index_js_2.Permission, async ({ object, original, user }) => {
|
|
29
71
|
// TODO
|