@openinc/parse-server-opendash 3.20.0 → 3.20.2
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/hooks/Tenant.js +3 -0
- package/dist/hooks/_Role.js +3 -3
- package/dist/index.js +20 -3
- package/package.json +1 -1
package/dist/hooks/Tenant.js
CHANGED
|
@@ -54,6 +54,7 @@ async function init() {
|
|
|
54
54
|
await (0, __1.ensureRole)(`od-tenant-admin-${object.id}`, {
|
|
55
55
|
label: `${object.get("label")} (Admin)`,
|
|
56
56
|
});
|
|
57
|
+
console.log("--------> Ensured tenant admin role");
|
|
57
58
|
await (0, __1.ensureRole)(`od-tenant-user-${object.id}`, {
|
|
58
59
|
label: object.get("label"),
|
|
59
60
|
acl: new Parse.ACL({
|
|
@@ -62,7 +63,9 @@ async function init() {
|
|
|
62
63
|
},
|
|
63
64
|
}),
|
|
64
65
|
});
|
|
66
|
+
console.log("--------> Ensured tenant user role");
|
|
65
67
|
if (!original) {
|
|
68
|
+
console.log("--------> Trigger beforeSave after creation");
|
|
66
69
|
// trigger beforeSave after creation
|
|
67
70
|
await object.save(null, {
|
|
68
71
|
useMasterKey: true,
|
package/dist/hooks/_Role.js
CHANGED
|
@@ -9,9 +9,9 @@ async function init() {
|
|
|
9
9
|
if (request.user && request.user.get("tenant")) {
|
|
10
10
|
tenantId = request.user.get("tenant").id;
|
|
11
11
|
}
|
|
12
|
-
if (!role.get("name") && role.isNew()) {
|
|
13
|
-
|
|
14
|
-
}
|
|
12
|
+
//if (!role.get("name") && role.isNew()) {
|
|
13
|
+
// role.set("name", crypto.randomUUID());
|
|
14
|
+
//}
|
|
15
15
|
//Set ACL to od-tenant-admin-{id_of_tenant}
|
|
16
16
|
if (role.isNew()) {
|
|
17
17
|
role.setACL(new Parse.ACL({
|
package/dist/index.js
CHANGED
|
@@ -275,6 +275,7 @@ async function getConfigBoolean(key) {
|
|
|
275
275
|
* @returns A Promise that resolves when the role is successfully created or updated.
|
|
276
276
|
*/
|
|
277
277
|
async function ensureRole(name, options) {
|
|
278
|
+
console.log("--------> Inside ensureRole");
|
|
278
279
|
const label = options?.label || undefined;
|
|
279
280
|
const acl = options?.acl || new Parse.ACL();
|
|
280
281
|
const childRoles = options?.childRoles || undefined;
|
|
@@ -285,19 +286,32 @@ async function ensureRole(name, options) {
|
|
|
285
286
|
.equalTo("name", name)
|
|
286
287
|
.first({ useMasterKey: true });
|
|
287
288
|
if (!role) {
|
|
289
|
+
console.log("--------> Creating role");
|
|
288
290
|
role = new Parse.Role(name, acl);
|
|
289
291
|
role.set("label", label);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
292
|
+
console.log("--------> CREATING role ", name);
|
|
293
|
+
try {
|
|
294
|
+
await role.save(null, {
|
|
295
|
+
useMasterKey: true,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
console.error("--------> Error creating role", error);
|
|
300
|
+
}
|
|
301
|
+
console.log("--------> NEW Role created");
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
console.log("--------> Role already exists");
|
|
293
305
|
}
|
|
294
306
|
let changed = false;
|
|
295
307
|
if (role.get("label") !== label) {
|
|
296
308
|
role.set("label", label);
|
|
309
|
+
console.log("--------> Updated role label");
|
|
297
310
|
changed = true;
|
|
298
311
|
}
|
|
299
312
|
if (!(0, fast_equals_1.deepEqual)(acl.toJSON(), role.getACL()?.toJSON())) {
|
|
300
313
|
role.setACL(acl);
|
|
314
|
+
console.log("--------> Updated role ACL");
|
|
301
315
|
changed = true;
|
|
302
316
|
}
|
|
303
317
|
if (Array.isArray(childRoles) && childRoles.length > 0) {
|
|
@@ -314,12 +328,15 @@ async function ensureRole(name, options) {
|
|
|
314
328
|
.equalTo("name", childRoleName)
|
|
315
329
|
.find({ useMasterKey: true });
|
|
316
330
|
relation.add(childRole);
|
|
331
|
+
console.log("--------> Added child role", childRoleName);
|
|
317
332
|
changed = true;
|
|
318
333
|
}
|
|
319
334
|
}
|
|
320
335
|
if (changed) {
|
|
336
|
+
console.log("--------> Saving changed role");
|
|
321
337
|
await role.save(null, { useMasterKey: true });
|
|
322
338
|
}
|
|
339
|
+
console.log("--------> Exiting ensureRole");
|
|
323
340
|
}
|
|
324
341
|
/**
|
|
325
342
|
* Ensures that a user has a specific role.
|