@openinc/parse-server-opendash 3.32.5 → 3.32.6
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.
|
@@ -1,19 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
|
-
const schema_1 = require("../features/schema");
|
|
5
4
|
const scheduleToEvent_1 = require("../features/openservice/schedules/calendarSync/functions/scheduleToEvent");
|
|
6
5
|
const CalendarManager_1 = require("../features/openservice/schedules/calendarSync/service/CalendarManager");
|
|
6
|
+
const schema_1 = require("../features/schema");
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
async function init() {
|
|
9
9
|
(0, schema_1.beforeSaveHook)(types_1.Maintenance_Schedule, async (request) => {
|
|
10
10
|
const { object, original, user } = request;
|
|
11
11
|
await (0, schema_1.defaultHandler)(request);
|
|
12
|
-
await (
|
|
12
|
+
// await defaultAclHandler(request, { allowCustomACL: true });
|
|
13
13
|
});
|
|
14
14
|
(0, schema_1.afterSaveHook)(types_1.Maintenance_Schedule, async (request) => {
|
|
15
15
|
const { object, original, user, master } = request;
|
|
16
16
|
if (!original) {
|
|
17
|
+
// Set ACL for new Maintenance_Schedule
|
|
18
|
+
// If is new: User should see but not tenant users
|
|
19
|
+
let acl = object.getACL();
|
|
20
|
+
if (!acl) {
|
|
21
|
+
acl = new Parse.ACL();
|
|
22
|
+
}
|
|
23
|
+
// If this is a new object, the acl will be set to the user who saved it only.
|
|
24
|
+
if (user) {
|
|
25
|
+
const tenant = object.get("tenant") || user.get("tenant");
|
|
26
|
+
if (tenant) {
|
|
27
|
+
acl.setRoleReadAccess("od-tenant-user-" + tenant.id, false);
|
|
28
|
+
}
|
|
29
|
+
acl.setReadAccess(user.id, true);
|
|
30
|
+
acl.setWriteAccess(user.id, true);
|
|
31
|
+
}
|
|
32
|
+
acl.setRoleReadAccess("od-admin", true);
|
|
33
|
+
acl.setRoleWriteAccess("od-admin", true);
|
|
34
|
+
acl.setPublicReadAccess(false);
|
|
35
|
+
acl.setPublicWriteAccess(false);
|
|
36
|
+
object.setACL(acl);
|
|
37
|
+
if (!master) {
|
|
38
|
+
await object.save(null, { useMasterKey: true });
|
|
39
|
+
}
|
|
17
40
|
await addToTemplateSources(object);
|
|
18
41
|
if (!master) {
|
|
19
42
|
await addToCalendar(object);
|
|
@@ -39,6 +62,11 @@ async function init() {
|
|
|
39
62
|
}
|
|
40
63
|
});
|
|
41
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Add schedule's source to its template's sources relation
|
|
67
|
+
* @param schedule Maintenance_Schedule
|
|
68
|
+
* @returns Promise<void>
|
|
69
|
+
*/
|
|
42
70
|
async function addToTemplateSources(schedule) {
|
|
43
71
|
const template = schedule.get("template");
|
|
44
72
|
if (!template)
|
|
@@ -6,13 +6,33 @@ const types_1 = require("../types");
|
|
|
6
6
|
async function init() {
|
|
7
7
|
(0, schema_1.beforeSaveHook)(types_1.Maintenance_Schedule_Template, async (request) => {
|
|
8
8
|
const { object, original, user } = request;
|
|
9
|
+
// If this is a new object, the acl will be set to the user who saved it only.
|
|
10
|
+
if (object.isNew()) {
|
|
11
|
+
let acl = object.getACL();
|
|
12
|
+
if (!acl) {
|
|
13
|
+
acl = new Parse.ACL();
|
|
14
|
+
}
|
|
15
|
+
if (user) {
|
|
16
|
+
const tenant = object.get("tenant") || user.get("tenant");
|
|
17
|
+
if (tenant) {
|
|
18
|
+
acl.setRoleReadAccess("od-tenant-user-" + tenant.id, false);
|
|
19
|
+
}
|
|
20
|
+
acl.setReadAccess(user.id, true);
|
|
21
|
+
acl.setWriteAccess(user.id, true);
|
|
22
|
+
}
|
|
23
|
+
acl.setRoleReadAccess("od-admin", true);
|
|
24
|
+
acl.setRoleWriteAccess("od-admin", true);
|
|
25
|
+
acl.setPublicReadAccess(false);
|
|
26
|
+
acl.setPublicWriteAccess(false);
|
|
27
|
+
object.setACL(acl);
|
|
28
|
+
}
|
|
9
29
|
await (0, schema_1.defaultHandler)(request);
|
|
10
|
-
await (
|
|
30
|
+
// await defaultAclHandler(request, { allowCustomACL: true });
|
|
11
31
|
});
|
|
12
32
|
(0, schema_1.afterSaveHook)(types_1.Maintenance_Schedule_Template, async (request) => {
|
|
13
33
|
const { object, original, user } = request;
|
|
14
|
-
if (object)
|
|
15
|
-
await createSchedulesWithTemplate(object);
|
|
34
|
+
if (object && user)
|
|
35
|
+
await createSchedulesWithTemplate(object, user);
|
|
16
36
|
});
|
|
17
37
|
(0, schema_1.beforeDeleteHook)(types_1.Maintenance_Schedule_Template, async (request) => {
|
|
18
38
|
const { object, original, user } = request;
|
|
@@ -25,7 +45,7 @@ async function init() {
|
|
|
25
45
|
* Creates schedules based on the provided template.
|
|
26
46
|
* @param template the maintenance schedule template
|
|
27
47
|
*/
|
|
28
|
-
async function createSchedulesWithTemplate(template) {
|
|
48
|
+
async function createSchedulesWithTemplate(template, user) {
|
|
29
49
|
// find existing schedules based on the template
|
|
30
50
|
const matchingSchedules = await new Parse.Query(types_1.Maintenance_Schedule)
|
|
31
51
|
.equalTo("template", template)
|
|
@@ -49,7 +69,9 @@ async function createSchedulesWithTemplate(template) {
|
|
|
49
69
|
enabled: true,
|
|
50
70
|
tenant: template.get("tenant"),
|
|
51
71
|
});
|
|
52
|
-
const savedSchedule = await newSchedule.save(null, {
|
|
72
|
+
const savedSchedule = await newSchedule.save(null, {
|
|
73
|
+
sessionToken: user.getSessionToken(),
|
|
74
|
+
});
|
|
53
75
|
// Add steps to the schedule steps relation
|
|
54
76
|
const templateStepsRelation = template.relation("steps");
|
|
55
77
|
const scheduleStepsRelation = savedSchedule.relation("steps");
|
|
@@ -59,6 +81,8 @@ async function createSchedulesWithTemplate(template) {
|
|
|
59
81
|
for (const step of templateSteps) {
|
|
60
82
|
scheduleStepsRelation.add(step);
|
|
61
83
|
}
|
|
62
|
-
await savedSchedule.save(null, {
|
|
84
|
+
await savedSchedule.save(null, {
|
|
85
|
+
sessionToken: user.getSessionToken(),
|
|
86
|
+
});
|
|
63
87
|
}
|
|
64
88
|
}
|