@tiledesk/tiledesk-server 2.17.3 → 2.18.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/CHANGELOG.md +7 -0
- package/app.js +2 -0
- package/archive.sh +92 -0
- package/channels/chat21/chat21WebHook.js +6 -1
- package/event/authEvent.js +16 -0
- package/event/projectUserEvent.js +39 -0
- package/event/roleEvent.js +9 -0
- package/middleware/has-role.js +160 -121
- package/middleware/passport.js +180 -179
- package/migrations/1757601159298-project_user_role_type.js +45 -0
- package/models/department.js +3 -0
- package/models/groupMemberSchama.js +19 -0
- package/models/kb_setting.js +6 -2
- package/models/permissionConstants.js +19 -0
- package/models/project_user.js +86 -8
- package/models/request.js +1 -0
- package/models/role.js +31 -0
- package/models/roleConstants.js +2 -0
- package/package.json +1 -1
- package/pubmodules/analytics/analytics.js +2 -2
- package/pubmodules/cache/mongoose-cachegoose-fn.js +37 -0
- package/pubmodules/canned/cannedResponseRoute.js +34 -6
- package/pubmodules/routing-queue/listener.js +7 -1
- package/pubmodules/trigger/rulesTrigger.js +1 -6
- package/routes/auth.js +3 -1
- package/routes/department.js +7 -1
- package/routes/kb.js +25 -1
- package/routes/message.js +4 -1
- package/routes/project.js +41 -3
- package/routes/project_user.js +62 -11
- package/routes/request.js +32 -30
- package/routes/roles.js +151 -0
- package/routes/unanswered.js +1 -1
- package/routes/webhook.js +18 -13
- package/routes/widget.js +3 -1
- package/services/cacheEnabler.js +5 -8
- package/services/departmentService.js +39 -11
- package/services/emailService.js +2 -2
- package/services/pendingInvitationService.js +2 -0
- package/services/projectService.js +3 -1
- package/services/projectUserService.js +67 -4
- package/services/subscriptionNotifierQueued.js +8 -0
- package/services/updateRequestSnapshotQueued.js +0 -3
- package/test/departmentService.js +5 -0
- package/test/messageRoute.js +7 -4
- package/test/projectUserRoute.js +116 -0
- package/test/requestService.js +7 -3
- package/test-int/bot.js +3 -2
- package/websocket/webSocketServer.js +273 -225
- package/routes/auth_newjwt.js +0 -648
package/routes/request.js
CHANGED
|
@@ -33,6 +33,7 @@ const RoleConstants = require('../models/roleConstants');
|
|
|
33
33
|
const eventService = require('../pubmodules/events/eventService');
|
|
34
34
|
const { Scheduler } = require('../services/Scheduler');
|
|
35
35
|
const faq_kb = require('../models/faq_kb');
|
|
36
|
+
|
|
36
37
|
const datesUtil = require('../utils/datesUtil');
|
|
37
38
|
//const JobManager = require('../utils/jobs-worker-queue-manager-v2/JobManagerV2');
|
|
38
39
|
|
|
@@ -188,19 +189,7 @@ router.post('/',
|
|
|
188
189
|
};
|
|
189
190
|
|
|
190
191
|
return requestService.create(new_request).then(function (savedRequest) {
|
|
191
|
-
|
|
192
|
-
// return requestService.createWithIdAndRequester(request_id, req.projectuser._id, createdLead._id, req.projectid,
|
|
193
|
-
// req.body.text, req.body.departmentid, req.body.sourcePage,
|
|
194
|
-
// req.body.language, req.body.userAgent, null, req.user._id, req.body.attributes, req.body.subject).then(function (savedRequest) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// return messageService.create(sender || req.user._id, fullname, request_id, req.body.text,
|
|
198
|
-
// req.projectid, req.user._id, messageStatus, req.body.attributes, req.body.type, req.body.metadata, req.body.language, undefined, req.body.channel).then(function(savedMessage){
|
|
199
|
-
|
|
200
|
-
// create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata) {
|
|
201
|
-
// return messageService.create(req.body.sender || req.user._id, req.body.senderFullname || req.user.fullName, request_id, req.body.text,
|
|
202
|
-
// req.projectid, req.user._id, messageStatus, req.body.attributes, req.body.type, req.body.metadata).then(function(savedMessage){
|
|
203
|
-
|
|
192
|
+
|
|
204
193
|
|
|
205
194
|
winston.debug('res.json(savedRequest)');
|
|
206
195
|
var endTimestamp = new Date();
|
|
@@ -377,7 +366,7 @@ router.put('/:requestid/close', async function (req, res) {
|
|
|
377
366
|
|
|
378
367
|
// TODO make a synchronous chat21 version (with query parameter?) with request.support_group.created
|
|
379
368
|
router.put('/:requestid/reopen', function (req, res) {
|
|
380
|
-
winston.debug(req.body);
|
|
369
|
+
winston.debug(req.body);
|
|
381
370
|
// reopenRequestByRequestId(request_id, id_project) {
|
|
382
371
|
return requestService.reopenRequestByRequestId(req.params.requestid, req.projectid).then(function (reopenRequest) {
|
|
383
372
|
|
|
@@ -399,12 +388,13 @@ router.put('/:requestid/assignee', function (req, res) {
|
|
|
399
388
|
//TODO change assignee
|
|
400
389
|
});
|
|
401
390
|
|
|
391
|
+
// curl -v -X POST -H 'Content-Type:application/json' -u andrea.leo@f21.it:123456 -d '{"member":"ciao"}' http://localhost:3000/68d4135a10e71f7bfa4dcf2f/requests/req123456/participants
|
|
402
392
|
// TODO make a synchronous chat21 version (with query parameter?) with request.support_group.created
|
|
403
393
|
router.post('/:requestid/participants',
|
|
404
394
|
[
|
|
405
395
|
check('member').notEmpty(),
|
|
406
396
|
],
|
|
407
|
-
|
|
397
|
+
async (req, res) => {
|
|
408
398
|
winston.debug(req.body);
|
|
409
399
|
|
|
410
400
|
const errors = validationResult(req);
|
|
@@ -432,7 +422,9 @@ error: uncaughtException: Cannot set property 'participants' of null
|
|
|
432
422
|
2020-03-08T12:53:35.793660+00:00 app[web.1]: at /app/services/requestService.js:672:30
|
|
433
423
|
2020-03-08T12:53:35.793661+00:00 app[web.1]: at /app/node_modules/mongoose/lib/model.js:4779:16
|
|
434
424
|
*/
|
|
435
|
-
|
|
425
|
+
|
|
426
|
+
// curl -v -X PUT -H 'Content-Type:application/json' -u andrea.leo@f21.it:123456 -d '{"member":"ciao"}' http://localhost:3000/68d4135a10e71f7bfa4dcf2f/requests/req123456/participants
|
|
427
|
+
router.put('/:requestid/participants', async (req, res) => {
|
|
436
428
|
winston.debug("req.body", req.body);
|
|
437
429
|
|
|
438
430
|
var participants = [];
|
|
@@ -512,7 +504,7 @@ router.put('/:requestid/replace', async (req, res) => {
|
|
|
512
504
|
})
|
|
513
505
|
|
|
514
506
|
// TODO make a synchronous chat21 version (with query parameter?) with request.support_group.created
|
|
515
|
-
router.delete('/:requestid/participants/:participantid',
|
|
507
|
+
router.delete('/:requestid/participants/:participantid', async (req, res) => {
|
|
516
508
|
winston.debug(req.body);
|
|
517
509
|
//removeParticipantByRequestId(request_id, id_project, member)
|
|
518
510
|
return requestService.removeParticipantByRequestId(req.params.requestid, req.projectid, req.params.participantid).then(function (updatedRequest) {
|
|
@@ -775,6 +767,7 @@ router.post('/:requestid/notes', async function (req, res) {
|
|
|
775
767
|
}
|
|
776
768
|
|
|
777
769
|
// Check if the user is a participant
|
|
770
|
+
// disable this check?
|
|
778
771
|
if (!request.participantsAgents.includes(req.user.id)) {
|
|
779
772
|
winston.verbose("Trying to add a note from a non participating agent");
|
|
780
773
|
return res.status(403).send({ success: false, error: "You are not participating in the conversation"})
|
|
@@ -821,6 +814,7 @@ router.delete('/:requestid/notes/:noteid', async function (req, res) {
|
|
|
821
814
|
}
|
|
822
815
|
|
|
823
816
|
// Check if the user is a participant
|
|
817
|
+
// disable this check?
|
|
824
818
|
if (!request.participantsAgents.includes(req.user.id)) {
|
|
825
819
|
winston.verbose("Trying to delete a note from a non participating agent");
|
|
826
820
|
return res.status(403).send({ success: false, error: "You are not participating in the conversation"})
|
|
@@ -1052,8 +1046,8 @@ router.delete('/:requestid/tag/:tag_id', async (req, res) => {
|
|
|
1052
1046
|
let id_project = req.projectid;
|
|
1053
1047
|
let request_id = req.params.requestid;
|
|
1054
1048
|
let tag_id = req.params.tag_id;
|
|
1055
|
-
|
|
1056
|
-
|
|
1049
|
+
|
|
1050
|
+
|
|
1057
1051
|
|
|
1058
1052
|
Request.findOneAndUpdate({ id_project: id_project, request_id: request_id }, { $pull: { tags: { _id: tag_id } } }, { new: true }).then( async (updatedRequest) => {
|
|
1059
1053
|
|
|
@@ -1088,8 +1082,8 @@ router.delete('/:requestid', function (req, res) {
|
|
|
1088
1082
|
|
|
1089
1083
|
var projectuser = req.projectuser;
|
|
1090
1084
|
|
|
1091
|
-
|
|
1092
|
-
if (projectuser.
|
|
1085
|
+
// request_role_check
|
|
1086
|
+
if (!projectuser.hasPermissionOrRole('request_delete', 'owner')){
|
|
1093
1087
|
return res.status(403).send({ success: false, msg: 'Unauthorized.' });
|
|
1094
1088
|
}
|
|
1095
1089
|
|
|
@@ -1144,8 +1138,8 @@ router.delete('/id/:id', function (req, res) {
|
|
|
1144
1138
|
|
|
1145
1139
|
var projectuser = req.projectuser;
|
|
1146
1140
|
|
|
1147
|
-
|
|
1148
|
-
if (projectuser.
|
|
1141
|
+
// request_role_check
|
|
1142
|
+
if (!projectuser.hasPermissionOrRole('request_delete', 'owner')){
|
|
1149
1143
|
return res.status(403).send({ success: false, msg: 'Unauthorized.' });
|
|
1150
1144
|
}
|
|
1151
1145
|
|
|
@@ -1169,7 +1163,7 @@ router.delete('/id/:id', function (req, res) {
|
|
|
1169
1163
|
});
|
|
1170
1164
|
|
|
1171
1165
|
|
|
1172
|
-
|
|
1166
|
+
// curl -v -X GET -H 'Content-Type:application/json' -u andrea.leo@f21.it:123456 http://localhost:3000/68d4135a10e71f7bfa4dcf2f/requests
|
|
1173
1167
|
|
|
1174
1168
|
router.get('/', function (req, res, next) {
|
|
1175
1169
|
|
|
@@ -1207,16 +1201,24 @@ router.get('/', function (req, res, next) {
|
|
|
1207
1201
|
|
|
1208
1202
|
if (req.user instanceof Subscription) {
|
|
1209
1203
|
// All request
|
|
1210
|
-
|
|
1204
|
+
winston.debug("Subscription All request ");
|
|
1205
|
+
} else if (projectuser.hasPermissionOrRole('request_read_all', ["owner", "admin"])) {
|
|
1211
1206
|
// All request
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
} else {
|
|
1207
|
+
winston.debug("hasPermissionOrRole All request ");
|
|
1208
|
+
} else if (projectuser.hasPermissionOrRole('request_read_group', ["agent"])) {
|
|
1209
|
+
|
|
1217
1210
|
query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
|
|
1211
|
+
|
|
1212
|
+
}
|
|
1213
|
+
// else if (projectuser.hasPermissionOrRole('request_read_mine', ["????"])) {
|
|
1214
|
+
// query["participants"] = req.user.id;
|
|
1215
|
+
// }
|
|
1216
|
+
else {
|
|
1217
|
+
query["participants"] = req.user.id;
|
|
1218
|
+
// generate empty requests response
|
|
1218
1219
|
}
|
|
1219
1220
|
|
|
1221
|
+
|
|
1220
1222
|
if (req.query.dept_id) {
|
|
1221
1223
|
query.department = req.query.dept_id;
|
|
1222
1224
|
}
|
package/routes/roles.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
var express = require('express');
|
|
2
|
+
var router = express.Router();
|
|
3
|
+
var Role = require("../models/role");
|
|
4
|
+
var winston = require('../config/winston');
|
|
5
|
+
const roleEvent = require('../event/roleEvent');
|
|
6
|
+
|
|
7
|
+
router.post('/', function (req, res) {
|
|
8
|
+
|
|
9
|
+
winston.debug(req.body);
|
|
10
|
+
winston.debug("req.user", req.user);
|
|
11
|
+
|
|
12
|
+
var newRole = new Role({
|
|
13
|
+
name: req.body.name,
|
|
14
|
+
permissions: req.body.permissions,
|
|
15
|
+
id_project: req.projectid,
|
|
16
|
+
createdBy: req.user.id,
|
|
17
|
+
updatedBy: req.user.id
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
newRole.save(function(err, savedRole) {
|
|
21
|
+
if (err) {
|
|
22
|
+
winston.error('Error saving the role '+ JSON.stringify(newRole), err)
|
|
23
|
+
return res.status(500).send({ success: false, msg: 'Error inserting object.' });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
roleEvent.emit('role.create', savedRole);
|
|
27
|
+
|
|
28
|
+
return res.json(savedRole);
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
router.put('/:roleid', function (req, res) {
|
|
35
|
+
winston.debug(req.body);
|
|
36
|
+
var update = {};
|
|
37
|
+
|
|
38
|
+
if (req.body.name!=undefined) {
|
|
39
|
+
update.name = req.body.name;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (req.body.permissions!=undefined) {
|
|
43
|
+
update.permissions = req.body.permissions;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Role.findByIdAndUpdate(req.params.roleid, update, { new: true, upsert: true }, function (err, updatedRole) {
|
|
48
|
+
if (err) {
|
|
49
|
+
winston.error('--- > ERROR ', err);
|
|
50
|
+
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
roleEvent.emit('role.update', updatedRole);
|
|
54
|
+
|
|
55
|
+
res.json(updatedRole);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
router.delete('/:roleid', function (req, res) {
|
|
62
|
+
winston.debug(req.body);
|
|
63
|
+
|
|
64
|
+
// Role.remove({ _id: req.params.roleid }, function (err, role) {
|
|
65
|
+
Role.findOneAndDelete({ _id: req.params.roleid }, (err, role) => {
|
|
66
|
+
if (err) {
|
|
67
|
+
winston.error('--- > ERROR ', err);
|
|
68
|
+
return res.status(500).send({ success: false, msg: 'Error deleting object.' });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
roleEvent.emit('role.delete', role);
|
|
72
|
+
|
|
73
|
+
res.json(role);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
router.get('/:roleid', function (req, res) {
|
|
79
|
+
winston.debug(req.body);
|
|
80
|
+
|
|
81
|
+
Role.findById(req.params.roleid, function (err, role) {
|
|
82
|
+
if (err) {
|
|
83
|
+
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
|
84
|
+
}
|
|
85
|
+
if (!role) {
|
|
86
|
+
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
|
87
|
+
}
|
|
88
|
+
res.json(role);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
router.get('/', async(req, res) => {
|
|
94
|
+
|
|
95
|
+
var limit = 40; // Number of request per page
|
|
96
|
+
|
|
97
|
+
if (req.query.limit) {
|
|
98
|
+
limit = parseInt(req.query.limit);
|
|
99
|
+
winston.debug('LEAD ROUTE - limit: '+limit);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var page = 0;
|
|
103
|
+
|
|
104
|
+
if (req.query.page) {
|
|
105
|
+
page = req.query.page;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var skip = page * limit;
|
|
109
|
+
winston.debug('ROLE ROUTE - SKIP PAGE ', skip);
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
var query = {"id_project": req.projectid};
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
var direction = -1; //-1 descending , 1 ascending
|
|
117
|
+
if (req.query.direction) {
|
|
118
|
+
direction = req.query.direction;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
var sortField = "createdAt";
|
|
122
|
+
if (req.query.sort) {
|
|
123
|
+
sortField = req.query.sort;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
var sortQuery = {};
|
|
127
|
+
sortQuery[sortField] = direction;
|
|
128
|
+
|
|
129
|
+
winston.debug("sort query", sortQuery);
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
return Role.find(query).
|
|
134
|
+
skip(skip).limit(limit).
|
|
135
|
+
sort(sortQuery).
|
|
136
|
+
exec(function (err, roles) {
|
|
137
|
+
if (err) {
|
|
138
|
+
winston.error('ROLE ROUTE - REQUEST FIND ERR ', err)
|
|
139
|
+
return (err);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
return res.json(roles);
|
|
144
|
+
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
module.exports = router;
|
package/routes/unanswered.js
CHANGED
|
@@ -67,7 +67,7 @@ router.get('/:namespace', async (req, res) => {
|
|
|
67
67
|
|
|
68
68
|
const page = parseInt(req.query.page) || 0;
|
|
69
69
|
const limit = parseInt(req.query.limit) || 20;
|
|
70
|
-
const sortField = req.query.sortField || '
|
|
70
|
+
const sortField = req.query.sortField || 'createdAt';
|
|
71
71
|
const direction = parseInt(req.query.direction) || -1;
|
|
72
72
|
|
|
73
73
|
const questions = await UnansweredQuestion.find({
|
package/routes/webhook.js
CHANGED
|
@@ -12,7 +12,7 @@ var ObjectId = require('mongoose').Types.ObjectId;
|
|
|
12
12
|
const default_embedding = require('../config/kb/embedding');
|
|
13
13
|
|
|
14
14
|
const port = process.env.PORT || '3000';
|
|
15
|
-
let TILEBOT_ENDPOINT = "http://localhost:" + port + "/modules/tilebot/"
|
|
15
|
+
let TILEBOT_ENDPOINT = "http://localhost:" + port + "/modules/tilebot/";
|
|
16
16
|
if (process.env.TILEBOT_ENDPOINT) {
|
|
17
17
|
TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT + "/"
|
|
18
18
|
}
|
|
@@ -69,18 +69,12 @@ router.post('/kb/reindex', async (req, res) => {
|
|
|
69
69
|
|
|
70
70
|
let content_id = req.body.content_id;
|
|
71
71
|
|
|
72
|
-
let kb
|
|
73
|
-
winston.error("(webhook) Error getting kb content: ", err);
|
|
74
|
-
return res.status(500).send({ success: false, error: "Error getting content with id " + content_id });
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
const namespace_id = kb.namespace;
|
|
78
|
-
let namespace;
|
|
72
|
+
let kb;
|
|
79
73
|
try {
|
|
80
|
-
|
|
74
|
+
kb = await KB.findById(content_id);
|
|
81
75
|
} catch (err) {
|
|
82
|
-
|
|
83
|
-
return res.status(
|
|
76
|
+
winston.error("(webhook) Error getting kb content: ", err);
|
|
77
|
+
return res.status(500).send({ success: false, error: "Error getting content with id " + content_id });
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
if (!kb) {
|
|
@@ -99,8 +93,19 @@ router.post('/kb/reindex', async (req, res) => {
|
|
|
99
93
|
winston.verbose("(webhook) delete response: ", deleteResponse);
|
|
100
94
|
return;
|
|
101
95
|
}, 10000);
|
|
102
|
-
|
|
103
|
-
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const namespace_id = kb.namespace;
|
|
100
|
+
let namespace;
|
|
101
|
+
try {
|
|
102
|
+
namespace = await aiManager.checkNamespace(kb.id_project, namespace_id);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
let errorCode = err?.errorCode ?? 500;
|
|
105
|
+
return res.status(errorCode).send({ success: false, error: err.error });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (kb.type === 'sitemap') {
|
|
104
109
|
|
|
105
110
|
const urls = await aiManager.fetchSitemap(kb.source).catch((err) => {
|
|
106
111
|
winston.error("(webhook) Error fetching sitemap: ", err);
|
package/routes/widget.js
CHANGED
|
@@ -82,7 +82,9 @@ router.get('/', async (req, res, next) => {
|
|
|
82
82
|
operatingHoursService.projectIsOpenNow(req.projectid, function (isOpen, err) {
|
|
83
83
|
winston.debug('isOpen:'+ isOpen);
|
|
84
84
|
if (isOpen) {
|
|
85
|
-
|
|
85
|
+
// rolequery
|
|
86
|
+
Project_user.find({ id_project: req.projectid, user_available: true, roleType: RoleConstants.TYPE_AGENTS, status: "active" }).
|
|
87
|
+
// Project_user.find({ id_project: req.projectid, user_available: true, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}, status: "active" }).
|
|
86
88
|
populate('id_user').
|
|
87
89
|
exec(function (err, project_users) {
|
|
88
90
|
winston.debug('project_users:'+ project_users);
|
package/services/cacheEnabler.js
CHANGED
|
@@ -47,15 +47,12 @@ class CacheEnabler {
|
|
|
47
47
|
this.integrations = false;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
this.role = true;
|
|
51
|
+
if (process.env.CACHE_ROLE_ENABLED=="false" || process.env.CACHE_ROLE_ENABLED==false) {
|
|
52
|
+
this.role = false;
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
// if (process.env.CACHE_MESSAGE_ENABLED=="false" || process.env.CACHE_MESSAGE_ENABLED==false) {
|
|
57
|
-
// this.message = false;
|
|
58
|
-
// }
|
|
55
|
+
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
|
|
@@ -272,9 +272,25 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
|
272
272
|
// console.log('OPERATORS - »»»» BOT IS DEFINED - !!! DEPT HAS NOT GROUP ID')
|
|
273
273
|
// console.log('OPERATORS - »»»» BOT IS DEFINED -> ID BOT', department.id_bot);
|
|
274
274
|
// console.log('OPERATORS - »»»» nobot ', nobot)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
275
|
+
winston.debug("main_flow_cache_2 departmentService project users");
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
// rolequery
|
|
279
|
+
// var role = [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT];
|
|
280
|
+
// var qpu = Project_user.find({ id_project: projectid, role: { $in : role }, status: "active" });
|
|
281
|
+
var qpu = Project_user.find({ id_project: projectid, roleType: RoleConstants.TYPE_AGENTS, status: "active" });
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
// use this. $in doesn't use index very well
|
|
285
|
+
// var qpu = Project_user.findOne({ id_project: projectid, $or: [{ "role": RoleConstants.AGENT }, { "role": RoleConstants.SUPERVISOR }, { "role": RoleConstants.ADMIN }, { "role": RoleConstants.OWNER }], status: "active" })
|
|
286
|
+
|
|
287
|
+
if (cacheEnabler.project_user) {
|
|
288
|
+
qpu.cache(cacheUtil.queryTTL, projectid+":project_users:query:teammates:available") //request_cache
|
|
289
|
+
winston.debug('project_user cache enabled');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
return qpu.exec(function (err, project_users) {
|
|
278
294
|
if (err) {
|
|
279
295
|
winston.error('-- > 2 DEPT FIND BY ID ERR ', err)
|
|
280
296
|
return reject(err);
|
|
@@ -369,12 +385,12 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
|
369
385
|
// console.log('D-2 GROUP -> [ FIND PROJECT USERS: ALL and AVAILABLE (with OH) ] -> MEMBERS LENGHT: ', group[0].members.length);
|
|
370
386
|
// console.log('D-2 GROUP -> [ FIND PROJECT USERS: ALL and AVAILABLE (with OH) ] -> MEMBERS ID: ', group[0].members);
|
|
371
387
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
//
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
//return Project_user.find({ id_project: projectid, id_user: group[0].members, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.AGENT]} }).exec(function (err, project_users) {
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
// rolequery
|
|
391
|
+
|
|
392
|
+
return Project_user.find({ id_project: projectid, id_user: { $in : group[0].members}, roleType: RoleConstants.TYPE_AGENTS, status: "active" }).exec(function (err, project_users) {
|
|
393
|
+
// return Project_user.find({ id_project: projectid, id_user: { $in : group[0].members}, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}, status: "active" }).exec(function (err, project_users) {
|
|
378
394
|
|
|
379
395
|
// console.log('D-2 GROUP -> [ FIND PROJECT USERS: ALL and AVAILABLE (with OH) ] -> PROJECT ID ', projectid);
|
|
380
396
|
if (err) {
|
|
@@ -436,8 +452,20 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
|
436
452
|
|
|
437
453
|
return new Promise(function (resolve, reject) {
|
|
438
454
|
|
|
439
|
-
var role = [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT];
|
|
440
|
-
|
|
455
|
+
// var role = [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT];
|
|
456
|
+
// rolequery
|
|
457
|
+
var qpu = Project_user.find({ id_project: projectid, roleType: RoleConstants.TYPE_AGENTS, status: "active" });
|
|
458
|
+
// var qpu = Project_user.find({ id_project: projectid, role: { $in : role }, status: "active" });
|
|
459
|
+
|
|
460
|
+
// use this. $in doesn't use index very well
|
|
461
|
+
if (cacheEnabler.project_user) {
|
|
462
|
+
qpu.cache(cacheUtil.queryTTL, projectid+":project_users:query:teammates:available") //request_cache
|
|
463
|
+
winston.debug('project_user cache enabled');
|
|
464
|
+
}
|
|
465
|
+
// return Project_user.find({ id_project: projectid , role: { $in : role }, status: "active" }).exec(function (err, project_users) {
|
|
466
|
+
return qpu.exec(function (err, project_users) {
|
|
467
|
+
|
|
468
|
+
|
|
441
469
|
if (err) {
|
|
442
470
|
winston.error('D-3 NO GROUP -> [ FIND PROJECT USERS: ALL and AVAILABLE (with OH) ] -> ERR ', err)
|
|
443
471
|
return reject(err);
|
package/services/emailService.js
CHANGED
|
@@ -282,7 +282,6 @@ class EmailService {
|
|
|
282
282
|
// }
|
|
283
283
|
|
|
284
284
|
async send(mail, quoteEnabled, project, quoteManager) {
|
|
285
|
-
|
|
286
285
|
if (!this.enabled) {
|
|
287
286
|
winston.info('EmailService is disabled. Not sending email');
|
|
288
287
|
return 0;
|
|
@@ -339,7 +338,8 @@ class EmailService {
|
|
|
339
338
|
if (mail.callback) {
|
|
340
339
|
mail.callback(error, { info: info });
|
|
341
340
|
}
|
|
342
|
-
return winston.error("Error sending email ", { error: error, mailConfig: mail.config, mailOptions: mailOptions });
|
|
341
|
+
//return winston.error("Error sending email ", { error: error, mailConfig: mail.config, mailOptions: mailOptions });
|
|
342
|
+
return winston.error("Error sending email ", { error: error, mailConfig: mail.config });
|
|
343
343
|
}
|
|
344
344
|
winston.verbose('Email sent:', { info: info });
|
|
345
345
|
winston.debug('Email sent:', { info: info, mailOptions: mailOptions });
|
|
@@ -4,6 +4,7 @@ var emailService = require("../services/emailService");
|
|
|
4
4
|
var Project_user = require("../models/project_user");
|
|
5
5
|
var mongoose = require('mongoose');
|
|
6
6
|
var winston = require('../config/winston');
|
|
7
|
+
var RoleConstants = require("../models/roleConstants");
|
|
7
8
|
|
|
8
9
|
class Pending_Invitation {
|
|
9
10
|
|
|
@@ -91,6 +92,7 @@ class Pending_Invitation {
|
|
|
91
92
|
id_project: invite.id_project,
|
|
92
93
|
id_user: newUserId,
|
|
93
94
|
role: invite.role,
|
|
95
|
+
roleType : RoleConstants.TYPE_AGENTS,
|
|
94
96
|
user_available: true,
|
|
95
97
|
createdBy: invite.createdBy,
|
|
96
98
|
updatedBy: invite.createdBy
|
|
@@ -8,6 +8,7 @@ var projectEvent = require("../event/projectEvent");
|
|
|
8
8
|
var winston = require('../config/winston');
|
|
9
9
|
const cacheEnabler = require("./cacheEnabler");
|
|
10
10
|
const cacheUtil = require("../utils/cacheUtil");
|
|
11
|
+
var RoleConstants = require("../models/roleConstants");
|
|
11
12
|
|
|
12
13
|
class ProjectService {
|
|
13
14
|
|
|
@@ -33,7 +34,8 @@ class ProjectService {
|
|
|
33
34
|
var newProject_user = new Project_user({
|
|
34
35
|
id_project: savedProject._id,
|
|
35
36
|
id_user: createdBy,
|
|
36
|
-
role:
|
|
37
|
+
role: RoleConstants.OWNER,
|
|
38
|
+
roleType : RoleConstants.TYPE_AGENTS,
|
|
37
39
|
user_available: true,
|
|
38
40
|
createdBy: createdBy,
|
|
39
41
|
updatedBy: createdBy
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var Project = require("../models/project");
|
|
4
3
|
var Project_user = require("../models/project_user");
|
|
5
|
-
var mongoose = require('mongoose');
|
|
6
|
-
var User = require('../models/user');
|
|
7
4
|
var winston = require('../config/winston');
|
|
8
|
-
|
|
5
|
+
|
|
6
|
+
var Role = require('../models/role');
|
|
7
|
+
var cacheUtil = require('../utils/cacheUtil');
|
|
8
|
+
var cacheEnabler = require("../services/cacheEnabler");
|
|
9
9
|
|
|
10
10
|
class ProjectUserService {
|
|
11
11
|
|
|
@@ -42,6 +42,69 @@ class ProjectUserService {
|
|
|
42
42
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
async getWithPermissions(id_user, id_project, user_sub) {
|
|
46
|
+
var project_user = await this.get(id_user, id_project, user_sub);
|
|
47
|
+
winston.debug("getWithPermissions for id_user " + id_user + " project_user ", project_user);
|
|
48
|
+
|
|
49
|
+
if (project_user) {
|
|
50
|
+
winston.debug("getWithPermissions project_user role: " + project_user.role);
|
|
51
|
+
|
|
52
|
+
var role = await this.getPermissions(project_user.role, id_project);
|
|
53
|
+
|
|
54
|
+
if (role) {
|
|
55
|
+
project_user._doc.rolePermissions = role.permissions; //https://github.com/Automattic/mongoose/issues/4614
|
|
56
|
+
// project_user.set("rolePermissions", role);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return project_user;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getPermissions(role, id_project) {
|
|
66
|
+
// var cacheManager = require('../utils/cacheManager');
|
|
67
|
+
// cacheManager.getClient().get("find in cache")
|
|
68
|
+
let q = Role.findOne({"name":role, "id_project": id_project});
|
|
69
|
+
|
|
70
|
+
let cache_key = id_project+":roles:"+role;
|
|
71
|
+
|
|
72
|
+
if (cacheEnabler.role) {
|
|
73
|
+
q.cache(cacheUtil.defaultTTL, cache_key);
|
|
74
|
+
winston.debug("cacheEnabler.role enabled");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var role = await q.exec();
|
|
78
|
+
|
|
79
|
+
if (role)
|
|
80
|
+
winston.debug("getWithPermissions role ", role.toJSON());
|
|
81
|
+
|
|
82
|
+
return role;
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async get(id_user, id_project, user_sub) {
|
|
87
|
+
// JWT_HERE
|
|
88
|
+
var query = { id_project: id_project, id_user: id_user, status: "active"};
|
|
89
|
+
let cache_key = id_project+":project_users:iduser:"+id_user;
|
|
90
|
+
|
|
91
|
+
if (user_sub && (user_sub=="userexternal" || user_sub=="guest")) {
|
|
92
|
+
query = { id_project: id_project, uuid_user: id_user, status: "active"};
|
|
93
|
+
cache_key = id_project+":project_users:uuid_user:"+id_user;
|
|
94
|
+
}
|
|
95
|
+
winston.debug("hasRoleOrType query " + JSON.stringify(query));
|
|
96
|
+
|
|
97
|
+
let q = Project_user.findOne(query);
|
|
98
|
+
if (cacheEnabler.project_user) {
|
|
99
|
+
q.cache(cacheUtil.defaultTTL, cache_key);
|
|
100
|
+
winston.debug("cacheEnabler.project_user enabled");
|
|
101
|
+
}
|
|
102
|
+
var project_user = await q.exec();
|
|
103
|
+
winston.debug("ProjectUserUtil project_user", project_user);
|
|
104
|
+
|
|
105
|
+
return project_user;
|
|
106
|
+
}
|
|
107
|
+
|
|
45
108
|
}
|
|
46
109
|
var projectUserService = new ProjectUserService();
|
|
47
110
|
|
|
@@ -111,6 +111,14 @@ class SubscriptionNotifierQueued {
|
|
|
111
111
|
winston.debug('SubscriptionNotifier project_user.update sent');
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
authEvent.on("project_user.update.agent", function(event) {
|
|
117
|
+
setImmediate(() => {
|
|
118
|
+
subscriptionNotifier.subscribe('project_user.update.agent', event.updatedProject_userPopulated);
|
|
119
|
+
winston.debug('SubscriptionNotifier project_user.update.agent sent');
|
|
120
|
+
});
|
|
121
|
+
});
|
|
114
122
|
|
|
115
123
|
winston.info('SubscriptionNotifierQueued started');
|
|
116
124
|
}
|
|
@@ -25,12 +25,10 @@ class UpdateRequestSnapshotQueued {
|
|
|
25
25
|
requestEvent.on(snapshotUpdateKey, function (data) {
|
|
26
26
|
setImmediate(() => {
|
|
27
27
|
winston.debug("updateRequestSnapshot on request.snapshot.update ", data);
|
|
28
|
-
console.log("updateRequestSnapshot on request.snapshot.update ", data);
|
|
29
28
|
|
|
30
29
|
const request = data.request;
|
|
31
30
|
const snapshot = data.snapshot;
|
|
32
31
|
const agentsArray = snapshot?.agents || [];
|
|
33
|
-
console.log("(queue) updateRequestSnapshot snapshot agents length: ", agentsArray.length);
|
|
34
32
|
|
|
35
33
|
if (!request || !request.request_id || !request.id_project) {
|
|
36
34
|
winston.error("updateRequestSnapshot: Invalid request data", data);
|
|
@@ -57,7 +55,6 @@ class UpdateRequestSnapshotQueued {
|
|
|
57
55
|
return;
|
|
58
56
|
}
|
|
59
57
|
if (updatedRequest) {
|
|
60
|
-
console.log("updateRequestSnapshot updated snapshot.agents for request " + updatedRequest.request_id, new Date());
|
|
61
58
|
winston.debug("updateRequestSnapshot updated snapshot.agents for request " + updatedRequest.request_id);
|
|
62
59
|
} else {
|
|
63
60
|
winston.warn("updateRequestSnapshot: Request not found for " + request.request_id);
|