@openinc/parse-server-opendash 2.4.90 → 2.4.91
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/app_types/ConfigKeys.d.ts +9 -0
- package/dist/app_types/ConfigKeys.js +14 -0
- package/dist/app_types/Notifications.d.ts +10 -0
- package/dist/app_types/Notifications.js +16 -0
- package/dist/app_types/Permissions.d.ts +42 -0
- package/dist/app_types/Permissions.js +61 -0
- package/dist/app_types/index.d.ts +3 -0
- package/dist/app_types/index.js +9 -0
- package/dist/featuremap.json +7 -5
- package/dist/functions/openinc-deregister-permission.js +2 -2
- package/dist/functions/openinc-openservice-save-ticket-data.d.ts +40 -0
- package/dist/functions/openinc-openservice-save-ticket-data.js +328 -0
- package/dist/functions/openinc-openservice-ticket-data.js +16 -32
- package/dist/functions/openinc-register-permission.js +1 -1
- package/dist/functions/openinc-user-roles.js +1 -1
- package/dist/helper/TicketData.d.ts +15 -0
- package/dist/helper/TicketData.js +2 -0
- package/dist/helper/pdf2img.d.ts +4 -1
- package/dist/helper/pdf2img.js +151 -104
- package/dist/helper/registerNotification.d.ts +25 -0
- package/dist/helper/registerNotification.js +61 -0
- package/dist/helper/registerPermissions.d.ts +0 -42
- package/dist/helper/registerPermissions.js +5 -62
- package/dist/hooks/Assets.js +17 -0
- package/dist/hooks/Documentation_Category.d.ts +1 -0
- package/dist/hooks/Documentation_Category.js +17 -0
- package/dist/hooks/Documentation_Document.d.ts +1 -0
- package/dist/hooks/Documentation_Document.js +17 -0
- package/dist/hooks/Knowledge_Document.js +35 -2
- package/dist/hooks/Maintenance_Schedule_Execution.js +4 -4
- package/dist/hooks/Maintenance_Schedule_Template.js +19 -8
- package/dist/hooks/Maintenance_Ticket.js +1 -4
- package/dist/hooks/Maintenance_Ticket_Kanban_State_Current.js +1 -1
- package/dist/hooks/Notification_Setting.d.ts +1 -0
- package/dist/hooks/Notification_Setting.js +55 -0
- package/dist/hooks/User_Setting.d.ts +1 -0
- package/dist/hooks/User_Setting.js +17 -0
- package/dist/hooks/_User.js +0 -12
- package/dist/index.js +12 -0
- package/dist/jobs/open_service_notifyOnSchedule.js +125 -20
- package/dist/types/Assets.d.ts +27 -0
- package/dist/types/Assets.js +41 -0
- package/dist/types/Documentation_Document.d.ts +0 -6
- package/dist/types/Documentation_Document.js +0 -12
- package/dist/types/Knowledge_Document.d.ts +3 -0
- package/dist/types/Knowledge_Document.js +6 -0
- package/dist/types/Maintenance_Message.d.ts +6 -0
- package/dist/types/Maintenance_Message.js +9 -0
- package/dist/types/Notification_Setting.d.ts +29 -0
- package/dist/types/Notification_Setting.js +41 -0
- package/dist/types/User_Setting.d.ts +13 -0
- package/dist/types/User_Setting.js +17 -0
- package/dist/types/_User.d.ts +2 -0
- package/dist/types/index.d.ts +6 -2
- package/dist/types/index.js +8 -4
- package/package.json +4 -4
- package/schema/Assets.json +52 -0
- package/schema/Documentation_Document.json +0 -10
- package/schema/Knowledge_Document.json +5 -0
- package/schema/Maintenance_Message.json +9 -0
- package/schema/Notification_Setting.json +57 -0
- package/schema/User_Setting.json +35 -0
- package/dist/hooks/Group.js +0 -55
- package/dist/types/Group.d.ts +0 -31
- package/dist/types/Group.js +0 -47
- package/schema/Group.json +0 -62
- /package/dist/hooks/{Group.d.ts → Assets.d.ts} +0 -0
|
@@ -1,75 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegisteredPermission =
|
|
3
|
+
exports.RegisteredPermission = void 0;
|
|
4
4
|
exports.getAllPermissions = getAllPermissions;
|
|
5
|
-
|
|
6
|
-
* Permissions that should be registered in the database by default when the server starts.
|
|
7
|
-
* The ACLs are set to od-admin only.
|
|
8
|
-
* Adding new Permissions here requires the server to restart for registering those.
|
|
9
|
-
*/
|
|
10
|
-
var Permissions;
|
|
11
|
-
(function (Permissions) {
|
|
12
|
-
// needs to be exported for getAllPermissions() to work
|
|
13
|
-
let OpenService;
|
|
14
|
-
(function (OpenService) {
|
|
15
|
-
// Create
|
|
16
|
-
OpenService["ticket"] = "maintenance:can-create-ticket";
|
|
17
|
-
OpenService["schedule"] = "maintenance:can-create-schedule";
|
|
18
|
-
OpenService["message"] = "maintenance:can-create-message";
|
|
19
|
-
OpenService["machinelog_ticket"] = "maintenance:can-create-machinelog-ticket";
|
|
20
|
-
OpenService["machinelog_schedule"] = "maintenance:can-create-machinelog-schedule";
|
|
21
|
-
OpenService["machinelog_message"] = "maintenance:can-create-machinelog-message";
|
|
22
|
-
// Access
|
|
23
|
-
OpenService["global"] = "maintenance:can-access-global";
|
|
24
|
-
OpenService["monitor"] = "maintenance:can-access-monitor";
|
|
25
|
-
OpenService["material"] = "maintenance:can-access-material";
|
|
26
|
-
OpenService["scheduletemplate"] = "maintenance:can-access-scheduletemplate";
|
|
27
|
-
OpenService["dailySchedule"] = "maintenance:can-access-dailySchedule";
|
|
28
|
-
OpenService["downtime"] = "maintenance:can-access-downtime";
|
|
29
|
-
OpenService["restriction"] = "maintenance:can-access-restriction";
|
|
30
|
-
OpenService["frequency"] = "maintenance:can-access-frequency";
|
|
31
|
-
OpenService["downtimeField0"] = "maintenance:can-access-downtime-field-0";
|
|
32
|
-
OpenService["downtimeField1"] = "maintenance:can-access-downtime-field-1";
|
|
33
|
-
OpenService["downtimeField2"] = "maintenance:can-access-downtime-field-2";
|
|
34
|
-
OpenService["downtimeField3"] = "maintenance:can-access-downtime-field-3";
|
|
35
|
-
OpenService["downtimeField4"] = "maintenance:can-access-downtime-field-4";
|
|
36
|
-
OpenService["restrictionField0"] = "maintenance:can-access-restriction-field-0";
|
|
37
|
-
OpenService["restrictionField1"] = "maintenance:can-access-restriction-field-1";
|
|
38
|
-
OpenService["restrictionField2"] = "maintenance:can-access-restriction-field-2";
|
|
39
|
-
OpenService["frequencyField0"] = "maintenance:can-access-frequency-field-0";
|
|
40
|
-
OpenService["frequencyField1"] = "maintenance:can-access-frequency-field-1";
|
|
41
|
-
OpenService["frequencyField2"] = "maintenance:can-access-frequency-field-2";
|
|
42
|
-
OpenService["frequencyField3"] = "maintenance:can-access-frequency-field-3";
|
|
43
|
-
OpenService["frequencyField4"] = "maintenance:can-access-frequency-field-4";
|
|
44
|
-
OpenService["priority"] = "maintenance:can-access-priority";
|
|
45
|
-
OpenService["priorityNumber"] = "maintenance:can-access-priority-number";
|
|
46
|
-
OpenService["priorityLabel"] = "maintenance:can-access-priority-label";
|
|
47
|
-
// Update
|
|
48
|
-
OpenService["issuecategory"] = "maintenance:can-update-issuecategory";
|
|
49
|
-
OpenService["monitorstate"] = "maintenance:can-update-monitorstate";
|
|
50
|
-
OpenService["kanban_view"] = "maintenance:can-update-kanban-view";
|
|
51
|
-
})(OpenService = Permissions.OpenService || (Permissions.OpenService = {}));
|
|
52
|
-
// can also be used for nested permissions
|
|
53
|
-
// Example:
|
|
54
|
-
// export namespace TestPlugin {
|
|
55
|
-
// export enum TestPermission {
|
|
56
|
-
// test = "test:can-test",
|
|
57
|
-
// }
|
|
58
|
-
// export enum TestPermission2 {
|
|
59
|
-
// test2 = "test:can-test2",
|
|
60
|
-
// }
|
|
61
|
-
// }
|
|
62
|
-
})(Permissions || (exports.Permissions = Permissions = {}));
|
|
5
|
+
const app_types_1 = require("../app_types");
|
|
63
6
|
/**
|
|
64
7
|
* Returns all permissions from the OpenService plugin defined in types/config.ts as an array of Permission objects.
|
|
65
8
|
* @returns all permissions from the OpenService plugin
|
|
66
9
|
*/
|
|
67
10
|
function getAllPermissions() {
|
|
68
11
|
const permissions = []; // stores all permissions
|
|
69
|
-
for (const key in Permissions) {
|
|
12
|
+
for (const key in app_types_1.Permissions) {
|
|
70
13
|
// iterate over the objects / enums of the Permissions namespace
|
|
71
|
-
if (Object.prototype.hasOwnProperty.call(Permissions, key)) {
|
|
72
|
-
const element = Permissions[key]; // get the object / enum
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(app_types_1.Permissions, key)) {
|
|
15
|
+
const element = app_types_1.Permissions[key]; // get the object / enum
|
|
73
16
|
const createdPermissions = createPermission(element); // create Permission objects recursively
|
|
74
17
|
permissions.push(...createdPermissions);
|
|
75
18
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
async function init() {
|
|
7
|
+
(0, __1.beforeSaveHook)(types_1.Assets, async (request) => {
|
|
8
|
+
const { object, original, user } = request;
|
|
9
|
+
await (0, __1.defaultHandler)(request);
|
|
10
|
+
await (0, __1.defaultAclHandler)(request);
|
|
11
|
+
// TODO
|
|
12
|
+
});
|
|
13
|
+
(0, __1.afterSaveHook)(types_1.Assets, async (request) => {
|
|
14
|
+
const { object, original, user } = request;
|
|
15
|
+
// TODO
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
async function init() {
|
|
7
|
+
(0, __1.beforeSaveHook)(types_1.Documentation_Category, async (request) => {
|
|
8
|
+
const { object, original, user } = request;
|
|
9
|
+
await (0, __1.defaultHandler)(request);
|
|
10
|
+
await (0, __1.defaultAclHandler)(request);
|
|
11
|
+
// TODO
|
|
12
|
+
});
|
|
13
|
+
(0, __1.afterSaveHook)(types_1.Documentation_Category, async (request) => {
|
|
14
|
+
const { object, original, user } = request;
|
|
15
|
+
// TODO
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
async function init() {
|
|
7
|
+
(0, __1.beforeSaveHook)(types_1.Documentation_Document, async (request) => {
|
|
8
|
+
const { object, original, user } = request;
|
|
9
|
+
await (0, __1.defaultHandler)(request);
|
|
10
|
+
await (0, __1.defaultAclHandler)(request);
|
|
11
|
+
// TODO
|
|
12
|
+
});
|
|
13
|
+
(0, __1.afterSaveHook)(types_1.Documentation_Document, async (request) => {
|
|
14
|
+
const { object, original, user } = request;
|
|
15
|
+
// TODO
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.init = init;
|
|
4
|
-
const pdf2img_1 = require("../helper/pdf2img");
|
|
5
37
|
const __1 = require("..");
|
|
6
38
|
const types_1 = require("../types");
|
|
7
39
|
async function init() {
|
|
@@ -25,7 +57,8 @@ async function init() {
|
|
|
25
57
|
await page.image.destroy();
|
|
26
58
|
await page.destroy({ useMasterKey: true });
|
|
27
59
|
}
|
|
28
|
-
const
|
|
60
|
+
const pdf2img = await Promise.resolve().then(() => __importStar(require("pdf-img-convert")));
|
|
61
|
+
const images = await pdf2img.convert(pdfUrl, {
|
|
29
62
|
base64: true,
|
|
30
63
|
width: 2000,
|
|
31
64
|
});
|
|
@@ -17,7 +17,7 @@ async function init() {
|
|
|
17
17
|
: Parse.User.current()
|
|
18
18
|
? Parse.User.current().get("tenant")
|
|
19
19
|
: undefined;
|
|
20
|
-
if (
|
|
20
|
+
if (object.origin === undefined || tenant === undefined) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const [fetchedOriginError, fetchedOrigin] = await (0, catchError_1.catchError)(new Parse.Query(types_1.Maintenance_Schedule_Template)
|
|
@@ -25,7 +25,7 @@ async function init() {
|
|
|
25
25
|
.get(object.origin.id, {
|
|
26
26
|
useMasterKey: true,
|
|
27
27
|
}));
|
|
28
|
-
if (
|
|
28
|
+
if (fetchedOrigin === undefined) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
const [stepserror, steps] = await (0, catchError_1.catchError)(fetchedOrigin
|
|
@@ -50,11 +50,11 @@ async function init() {
|
|
|
50
50
|
fields: step.get("fields"),
|
|
51
51
|
});
|
|
52
52
|
const mediarelation = executionstep.relation("media");
|
|
53
|
-
if (
|
|
53
|
+
if (media !== undefined) {
|
|
54
54
|
mediarelation.add(media);
|
|
55
55
|
}
|
|
56
56
|
const rolesrelation = executionstep.relation("roles");
|
|
57
|
-
if (
|
|
57
|
+
if (roles !== undefined) {
|
|
58
58
|
rolesrelation.add(roles);
|
|
59
59
|
}
|
|
60
60
|
const [stepsaveerror, stepsaveobject] = await (0, catchError_1.catchError)(executionstep.save(null, { useMasterKey: true }));
|
|
@@ -21,6 +21,7 @@ async function init() {
|
|
|
21
21
|
const { object, original, user } = request;
|
|
22
22
|
//TODO: Create notification object
|
|
23
23
|
//TODO: Send mail or anything that is enabled
|
|
24
|
+
//TODO: Move bree to a separate file and use as singleton
|
|
24
25
|
startBree([object]);
|
|
25
26
|
});
|
|
26
27
|
/**
|
|
@@ -35,7 +36,7 @@ async function init() {
|
|
|
35
36
|
console.error("Error while querying Maintenance_Schedule_Template objects", queryError);
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
|
-
//TODO
|
|
39
|
+
//TODO: Do I need to reschedule all jobs when server restarts?
|
|
39
40
|
}
|
|
40
41
|
async function startBree(query) {
|
|
41
42
|
console.log("Starting Bree");
|
|
@@ -46,15 +47,17 @@ async function init() {
|
|
|
46
47
|
if (cron["scheduletype"] === "human") {
|
|
47
48
|
jobs.push({
|
|
48
49
|
name: `Schedule ${schedule.id}`,
|
|
49
|
-
path: "open_service_notifyOnSchedule",
|
|
50
|
+
path: node_path_1.default.join(__dirname, "..", "jobs", "open_service_notifyOnSchedule.js"),
|
|
50
51
|
timeout: 0,
|
|
51
52
|
interval: createHumanReadableFormat(cron["run_cron"]),
|
|
52
53
|
hasSeconds: true,
|
|
53
54
|
worker: {
|
|
54
55
|
workerData: {
|
|
55
56
|
scheduleId: schedule.id,
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
ParseAppId: Parse.applicationId,
|
|
58
|
+
ParseJSKey: Parse.javaScriptKey,
|
|
59
|
+
ParseMasterKey: Parse.masterKey,
|
|
60
|
+
ParseServerURL: Parse.serverURL,
|
|
58
61
|
},
|
|
59
62
|
},
|
|
60
63
|
});
|
|
@@ -63,15 +66,17 @@ async function init() {
|
|
|
63
66
|
jobs.push({
|
|
64
67
|
name: `Schedule ${schedule.id}`,
|
|
65
68
|
cron: cron["run_cron"],
|
|
66
|
-
path: "open_service_notifyOnSchedule",
|
|
69
|
+
path: node_path_1.default.join(__dirname, "..", "jobs", "open_service_notifyOnSchedule.js"),
|
|
67
70
|
timeout: 0,
|
|
68
71
|
interval: 0,
|
|
69
72
|
hasSeconds: true,
|
|
70
73
|
worker: {
|
|
71
74
|
workerData: {
|
|
72
75
|
scheduleId: schedule.id,
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
ParseAppId: Parse.applicationId,
|
|
77
|
+
ParseJSKey: Parse.javaScriptKey,
|
|
78
|
+
ParseMasterKey: Parse.masterKey,
|
|
79
|
+
ParseServerURL: Parse.serverURL,
|
|
75
80
|
},
|
|
76
81
|
},
|
|
77
82
|
});
|
|
@@ -84,8 +89,14 @@ async function init() {
|
|
|
84
89
|
errorHandler: (error, workerMetadata) => {
|
|
85
90
|
console.error(`An error occurred in worker ${workerMetadata.name} with the following error: ${error}`);
|
|
86
91
|
},
|
|
92
|
+
workerMessageHandler: (message) => {
|
|
93
|
+
console.log(`Worker ${message.name} sent the following message: ${message.message}`);
|
|
94
|
+
},
|
|
87
95
|
root: node_path_1.default.join(__dirname, "..", "jobs"),
|
|
88
|
-
jobs: [
|
|
96
|
+
jobs: [...jobs],
|
|
97
|
+
acceptedExtensions: ["js"],
|
|
98
|
+
defaultExtension: "js",
|
|
99
|
+
outputWorkerMetadata: false,
|
|
89
100
|
});
|
|
90
101
|
//Start bree object
|
|
91
102
|
// const graceful = new Graceful({ brees: [bree] });
|
|
@@ -13,9 +13,6 @@ async function init() {
|
|
|
13
13
|
});
|
|
14
14
|
(0, __1.afterSaveHook)(types_1.Maintenance_Ticket, async (request) => {
|
|
15
15
|
const { object, original, user, master } = request;
|
|
16
|
-
if (!master && original && original.get("createdAt")) {
|
|
17
|
-
object.save({ createdAt: original.get("createdAt") }, { useMasterKey: true });
|
|
18
|
-
}
|
|
19
16
|
});
|
|
20
17
|
async function initClass() {
|
|
21
18
|
// Query all of Maintenance_Ticket and find all of Maintenance_Priority sort by createdAt in descending order
|
|
@@ -31,7 +28,7 @@ async function init() {
|
|
|
31
28
|
console.error("Maintenance_Priority error", priorityError);
|
|
32
29
|
return;
|
|
33
30
|
}
|
|
34
|
-
if (
|
|
31
|
+
if (priorityResult === undefined) {
|
|
35
32
|
console.log("Maintenance_Ticket init: Check and save latestPriority: No priority found for ticket", ticket.id);
|
|
36
33
|
return;
|
|
37
34
|
}
|
|
@@ -35,7 +35,7 @@ async function initCurrentTicketStates() {
|
|
|
35
35
|
.first({ useMasterKey: true });
|
|
36
36
|
const tenant = ticket.get("tenant");
|
|
37
37
|
const user = ticket.get("user");
|
|
38
|
-
if (
|
|
38
|
+
if (tenant === undefined || user === undefined) {
|
|
39
39
|
console.error("Tenant or user is undefined for ticket", ticket.id);
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const catchError_1 = require("../helper/catchError");
|
|
6
|
+
const registerNotification_1 = require("../helper/registerNotification");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
async function init() {
|
|
9
|
+
registerNotifications();
|
|
10
|
+
(0, __1.beforeSaveHook)(types_1.Notification_Setting, async (request) => {
|
|
11
|
+
const { object, original, user } = request;
|
|
12
|
+
await (0, __1.defaultHandler)(request);
|
|
13
|
+
await (0, __1.defaultAclHandler)(request);
|
|
14
|
+
// TODO
|
|
15
|
+
});
|
|
16
|
+
(0, __1.afterSaveHook)(types_1.Notification_Setting, async (request) => {
|
|
17
|
+
const { object, original, user } = request;
|
|
18
|
+
// TODO
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Register all notification settings in the database, if not already registered.
|
|
23
|
+
*/
|
|
24
|
+
async function registerNotifications() {
|
|
25
|
+
//Check if only one tenant is present in the database
|
|
26
|
+
const [tenantCountError, tenantCount] = await (0, catchError_1.catchError)(new Parse.Query(types_1.Tenant).count({ useMasterKey: true }));
|
|
27
|
+
if (tenantCountError) {
|
|
28
|
+
console.error("Error while counting Tenant object", tenantCountError);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
//If only one tenant is present, register all notifications for this tenant
|
|
32
|
+
const tenant = tenantCount === 1
|
|
33
|
+
? await new Parse.Query(types_1.Tenant).first({ useMasterKey: true })
|
|
34
|
+
: undefined;
|
|
35
|
+
console.log("Register all notification settings");
|
|
36
|
+
(0, registerNotification_1.getAllNotifications)().forEach((notification) => {
|
|
37
|
+
new Parse.Query(types_1.Notification_Setting)
|
|
38
|
+
.equalTo("key", notification.key)
|
|
39
|
+
.first({ useMasterKey: true })
|
|
40
|
+
.then((result) => {
|
|
41
|
+
if (!result) {
|
|
42
|
+
console.log("Create notification", notification.key);
|
|
43
|
+
const newNotification = new types_1.Notification_Setting();
|
|
44
|
+
newNotification.set("key", notification.key);
|
|
45
|
+
newNotification.set("description", notification.description);
|
|
46
|
+
newNotification.set("label", notification.label);
|
|
47
|
+
newNotification.set("tenant", tenant);
|
|
48
|
+
newNotification.save({}, { useMasterKey: true });
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.log("Notification already exists", notification.key);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
async function init() {
|
|
7
|
+
(0, __1.beforeSaveHook)(types_1.User_Setting, async (request) => {
|
|
8
|
+
const { object, original, user } = request;
|
|
9
|
+
await (0, __1.defaultHandler)(request);
|
|
10
|
+
await (0, __1.defaultAclHandler)(request);
|
|
11
|
+
// TODO
|
|
12
|
+
});
|
|
13
|
+
(0, __1.afterSaveHook)(types_1.User_Setting, async (request) => {
|
|
14
|
+
const { object, original, user } = request;
|
|
15
|
+
// TODO
|
|
16
|
+
});
|
|
17
|
+
}
|
package/dist/hooks/_User.js
CHANGED
|
@@ -44,14 +44,6 @@ async function init() {
|
|
|
44
44
|
// @ts-ignore
|
|
45
45
|
request.context.tenantChanged = true;
|
|
46
46
|
}
|
|
47
|
-
// fetch user groups
|
|
48
|
-
const groups = user.id
|
|
49
|
-
? await new Parse.Query(types_1.Group)
|
|
50
|
-
.equalTo("users", user)
|
|
51
|
-
.equalTo("usersSeeEachOther", true)
|
|
52
|
-
.limit(1000000)
|
|
53
|
-
.find({ useMasterKey: true })
|
|
54
|
-
: [];
|
|
55
47
|
user.setACL(new Parse.ACL({
|
|
56
48
|
...(tenantId && {
|
|
57
49
|
[`role:od-tenant-user-${tenantId}`]: { read: true },
|
|
@@ -63,10 +55,6 @@ async function init() {
|
|
|
63
55
|
...(user.id && {
|
|
64
56
|
[user.id]: { read: true },
|
|
65
57
|
}),
|
|
66
|
-
...Object.fromEntries(groups.map((group) => [
|
|
67
|
-
"role:od-group-user-" + group.id,
|
|
68
|
-
{ read: true },
|
|
69
|
-
])),
|
|
70
58
|
"role:od-admin": { read: true, write: true },
|
|
71
59
|
}));
|
|
72
60
|
});
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ var Core_Email_2 = require("./hooks/Core_Email");
|
|
|
36
36
|
Object.defineProperty(exports, "sendSimpleEmail", { enumerable: true, get: function () { return Core_Email_2.sendSimpleEmail; } });
|
|
37
37
|
Object.defineProperty(exports, "sendTemplateEmail", { enumerable: true, get: function () { return Core_Email_2.sendTemplateEmail; } });
|
|
38
38
|
const PREFIX = "OD3_";
|
|
39
|
+
// const lang_deu = require("../i18n/deu.json");
|
|
39
40
|
let schema = {};
|
|
40
41
|
/**
|
|
41
42
|
* Initializes the Cloud Code for open.DASH.
|
|
@@ -53,6 +54,7 @@ async function init() {
|
|
|
53
54
|
}
|
|
54
55
|
catch (error) { }
|
|
55
56
|
await config_1.config.init(true);
|
|
57
|
+
await initTranslations();
|
|
56
58
|
await (0, Core_Email_1.initEmailTransport)();
|
|
57
59
|
await initWebPush();
|
|
58
60
|
await initSchema();
|
|
@@ -62,6 +64,16 @@ async function init() {
|
|
|
62
64
|
await (0, _init_1.init)();
|
|
63
65
|
await initAutoload();
|
|
64
66
|
}
|
|
67
|
+
async function initTranslations() {
|
|
68
|
+
// try {
|
|
69
|
+
// registerLanguage("deu", "Deutsch", "eng", true);
|
|
70
|
+
// registerTranslationResolver("deu", "server", async () => lang_deu);
|
|
71
|
+
// } catch (error) {
|
|
72
|
+
// console.error("Error while initializing translations");
|
|
73
|
+
// console.error(error);
|
|
74
|
+
// process.exit(1);
|
|
75
|
+
// }
|
|
76
|
+
}
|
|
65
77
|
async function initWebPush() {
|
|
66
78
|
try {
|
|
67
79
|
if (config_1.config.getBoolean("WEB_PUSH_ENABLED")) {
|
|
@@ -3,31 +3,136 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// import {
|
|
7
|
+
// changeLanguage,
|
|
8
|
+
// getCurrentLanguageSync,
|
|
9
|
+
// useTranslation,
|
|
10
|
+
// } from "@opendash/i18n";
|
|
6
11
|
const node_process_1 = __importDefault(require("node:process"));
|
|
7
12
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const node_js_1 = __importDefault(require("parse/node.js"));
|
|
14
|
+
const ConfigKeys_js_1 = require("../app_types/ConfigKeys.js");
|
|
15
|
+
const Notifications_js_1 = require("../app_types/Notifications.js");
|
|
16
|
+
const openinc_openservice_save_ticket_data_js_1 = require("../functions/openinc-openservice-save-ticket-data.js");
|
|
17
|
+
const catchError_js_1 = require("../helper/catchError.js");
|
|
18
|
+
const Config_js_1 = require("../types/Config.js");
|
|
19
|
+
const Maintenance_Schedule_Template_js_1 = require("../types/Maintenance_Schedule_Template.js");
|
|
20
|
+
const Notification_js_1 = require("../types/Notification.js");
|
|
21
|
+
const Notification_Setting_js_1 = require("../types/Notification_Setting.js");
|
|
22
|
+
function l(message) {
|
|
23
|
+
if (node_worker_threads_1.parentPort) {
|
|
24
|
+
node_worker_threads_1.parentPort.postMessage(message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
(async () => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
l("Initializing Parse with worker data: " + JSON.stringify(node_worker_threads_1.workerData));
|
|
29
|
+
node_js_1.default.initialize(node_worker_threads_1.workerData.ParseAppId, node_worker_threads_1.workerData.ParseJSKey !== "unused" ? node_worker_threads_1.workerData.ParseJSKey : undefined, node_worker_threads_1.workerData.ParseMasterKey);
|
|
30
|
+
node_js_1.default.serverURL = node_worker_threads_1.workerData.ParseServerURL;
|
|
31
|
+
l("Schedule is due.");
|
|
32
|
+
// Check OD3_Config class for key ConfigKeys.OpenService.createTicketOnSchedule. If value is true, proceed with ticket creation
|
|
33
|
+
const [configError, config] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Config_js_1.Config.className)
|
|
34
|
+
.equalTo("key", ConfigKeys_js_1.ConfigKeys.OpenService.createTicketOnSchedule)
|
|
35
|
+
.first({ useMasterKey: true }));
|
|
36
|
+
//Get schedule object from worker data
|
|
37
|
+
const [scheduleError, schedule] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Maintenance_Schedule_Template_js_1.Maintenance_Schedule_Template.className).get(node_worker_threads_1.workerData.scheduleId, { useMasterKey: true }));
|
|
38
|
+
if (configError) {
|
|
39
|
+
l("Error while querying OD3_Config for 'createTicketOnSchedule' key: " +
|
|
40
|
+
configError);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (scheduleError || schedule === undefined) {
|
|
44
|
+
l("Error while querying Maintenance_Schedule_Template object: " +
|
|
45
|
+
scheduleError);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (config === undefined || !/true/.test(config.get("value"))) {
|
|
49
|
+
l("Config 'createTicketOnSchedule' not set or false, skipping ticket creation for schedule.");
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
//Get all sources from schedule object
|
|
53
|
+
const [sourcesError, sources] = await (0, catchError_js_1.catchError)(schedule
|
|
54
|
+
.relation("sources")
|
|
55
|
+
.query()
|
|
56
|
+
.find({ useMasterKey: true }));
|
|
57
|
+
if (sourcesError) {
|
|
58
|
+
l("Error while querying sources from Maintenance_Schedule_Template object: " +
|
|
59
|
+
sourcesError);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
for await (const source of sources) {
|
|
63
|
+
//Create a new ticket
|
|
64
|
+
await (0, openinc_openservice_save_ticket_data_js_1.saveTicketData)({
|
|
65
|
+
title: "",
|
|
66
|
+
source: source.id,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
l("Config 'createTicketOnSchedule' is true, creating new ticket object");
|
|
71
|
+
const [notificationSettingsError, notificationSettings] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Notification_Setting_js_1.Notification_Setting)
|
|
72
|
+
.equalTo("key", Notifications_js_1.Notifications.OpenService.schedule_due)
|
|
73
|
+
.find({ useMasterKey: true }));
|
|
74
|
+
if (notificationSettingsError) {
|
|
75
|
+
l("Error while querying Notification_Setting for 'Notifications.OpenService.schedule_due' key: " +
|
|
76
|
+
notificationSettingsError);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const recipients = [];
|
|
80
|
+
const users = notificationSettings.map((setting) => setting
|
|
81
|
+
.relation("users")
|
|
82
|
+
.query()
|
|
83
|
+
.include("settings")
|
|
84
|
+
.find({ useMasterKey: true }));
|
|
85
|
+
for await (const user of users) {
|
|
86
|
+
recipients.push(...user);
|
|
87
|
+
}
|
|
88
|
+
const rolesPromises = notificationSettings.map((setting) => setting.relation("roles").query().find({ useMasterKey: true }));
|
|
89
|
+
for await (const roles of rolesPromises) {
|
|
90
|
+
const usersFromRoles = roles.map((role) => role
|
|
91
|
+
.relation("users")
|
|
92
|
+
.query()
|
|
93
|
+
.include("settings")
|
|
94
|
+
.find({ useMasterKey: true }));
|
|
95
|
+
for await (const usersFromRole of usersFromRoles) {
|
|
96
|
+
recipients.push(...usersFromRole);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//Filter out duplicates
|
|
100
|
+
recipients.filter((user, index, self) => {
|
|
101
|
+
return (index ===
|
|
102
|
+
self.findIndex((t) => t.id === user.id && t.className === user.className));
|
|
103
|
+
});
|
|
104
|
+
l("Recipients for notification: " + JSON.stringify(recipients));
|
|
105
|
+
//TODO: When available as ESM, use i18n module to get the correct language for the user
|
|
106
|
+
for await (const recipient of recipients) {
|
|
107
|
+
l("Creating new notification object for user: " + recipient.id);
|
|
108
|
+
//Get preferred_language from user object
|
|
109
|
+
const language = recipient.get("settings")
|
|
110
|
+
? recipient.get("settings").get("preferred_language")
|
|
111
|
+
: "deu";
|
|
112
|
+
// if (getCurrentLanguageSync() !== language) {
|
|
113
|
+
// changeLanguage(language);
|
|
114
|
+
// }
|
|
115
|
+
//Get the correct notification title and description based on the user's preferred language
|
|
116
|
+
// const t = useTranslation();
|
|
117
|
+
const findtitle = require(`../i18n/${language}.json`)["maintenance.schedule.notification.title"];
|
|
118
|
+
const finddescription = require(`../i18n/${language}.json`)["maintenance.schedule.notification.description"];
|
|
119
|
+
//Create a new notification object in the database, class name: OD3_Notification
|
|
120
|
+
const notificationObject = new node_js_1.default.Object(Notification_js_1.Notification.className);
|
|
121
|
+
notificationObject.set("title",
|
|
122
|
+
// t("server:maintenance.schedule.notification.title")
|
|
123
|
+
findtitle);
|
|
124
|
+
notificationObject.set("description",
|
|
125
|
+
// t("server:maintenance.schedule.notification.description", {
|
|
126
|
+
// schedule:
|
|
127
|
+
// schedule.get("title") !== undefined ? schedule.get("title")! : "",
|
|
128
|
+
// })
|
|
129
|
+
finddescription);
|
|
130
|
+
notificationObject.set("user", recipient);
|
|
131
|
+
await notificationObject.save(null, { useMasterKey: true });
|
|
132
|
+
}
|
|
28
133
|
// signal to parent that the job is done
|
|
29
134
|
if (node_worker_threads_1.parentPort) {
|
|
30
|
-
|
|
135
|
+
l("done");
|
|
31
136
|
}
|
|
32
137
|
else {
|
|
33
138
|
node_process_1.default.exit(0);
|