@tiledesk/tiledesk-server 2.1.4-0.20 → 2.1.4-0.25

Sign up to get free protection for your applications and to get access to all the features.
package/app.js CHANGED
@@ -99,6 +99,8 @@ var cacheUtil = require("./utils/cacheUtil");
99
99
  var images = require('./routes/images');
100
100
  var files = require('./routes/files');
101
101
  var campaigns = require('./routes/campaigns');
102
+ var requestUtilRoot = require('./routes/requestUtilRoot');
103
+
102
104
 
103
105
  var bootDataLoader = require('./services/bootDataLoader');
104
106
  var settingDataLoader = require('./services/settingDataLoader');
@@ -133,6 +135,11 @@ try {
133
135
  }
134
136
 
135
137
 
138
+ //enterprise modules can modify pubmodule
139
+ modulesManager.start();
140
+
141
+ pubModulesManager.start();
142
+
136
143
 
137
144
  settingDataLoader.save();
138
145
  schemaMigrationService.checkSchemaMigration();
@@ -282,6 +289,8 @@ app.use('/widgets', widgetsLoader);
282
289
  app.use('/images', images);
283
290
  app.use('/files', files);
284
291
  app.use('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], users);
292
+ app.use('/requests_util', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], requestUtilRoot);
293
+
285
294
 
286
295
  // TODO security issues
287
296
  if (process.env.DISABLE_TRANSCRIPT_VIEW_PAGE ) {
@@ -310,7 +319,6 @@ app.use('/:projectid/', [projectIdSetter, projectSetter]);
310
319
  app.use('/:projectid/authtestWithRoleCheck', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], authtestWithRoleCheck);
311
320
 
312
321
  app.use('/:projectid/leads', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['bot','subscription'])], lead);
313
- // guest perche nn c'è guest???? no???
314
322
  app.use('/:projectid/requests/:request_id/messages', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes(null, ['bot','subscription'])] , message);
315
323
 
316
324
  app.use('/:projectid/messages', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['bot','subscription'])] , messagesRootRoute);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-server",
3
3
  "description": "The Tiledesk server module",
4
- "version": "2.1.40.20",
4
+ "version": "2.1.40.25",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -22,6 +22,7 @@ var config = require('../../config/database');
22
22
 
23
23
  var widgetConfig = require('../../config/widget');
24
24
  var widgetTestLocation = process.env.WIDGET_TEST_LOCATION || widgetConfig.testLocation;
25
+ let configSecret = process.env.GLOBAL_SECRET || config.secret;
25
26
 
26
27
  class RequestNotification {
27
28
 
@@ -30,30 +31,57 @@ listen() {
30
31
  var that = this;
31
32
 
32
33
 
33
- messageEvent.on("message.create", function(message) {
34
+
35
+ var messageCreateKey = 'message.create';
36
+ if (messageEvent.queueEnabled) {
37
+ messageCreateKey = 'message.create.queue';
38
+ }
39
+ winston.debug('RequestNotification messageCreateKey: ' + messageCreateKey);
40
+
41
+
42
+ messageEvent.on(messageCreateKey, function(message) {
34
43
 
35
44
  setImmediate(() => {
36
- // TODO aggiunta jwt widget login
37
45
  winston.debug("sendUserEmail", message);
38
- // if (process.env.SEND_OFFLINE_EMAIL) {
39
- // that.sendUserEmail(message.id_project, message);
40
- // }
46
+
47
+
41
48
 
42
49
  });
43
50
  });
44
51
 
45
- requestEvent.on("request.create", function(request) {
52
+ var requestCreateKey = 'request.create';
53
+ if (requestEvent.queueEnabled) {
54
+ requestCreateKey = 'request.create.queue';
55
+ }
56
+ winston.debug('RequestNotification requestCreateKey: ' + requestCreateKey);
46
57
 
58
+ requestEvent.on(requestCreateKey, function(request) {
59
+ // winston.info('quiiiiiiiiiiiii');
47
60
  setImmediate(() => {
48
61
 
49
- that.sendAgentEmail(request.id_project, request);
62
+ /*
63
+ if (request && (request.channel.name===ChannelConstants.EMAIL || request.channel.name===ChannelConstants.FORM )) {
64
+ winston.verbose("sending sendEmailChannelTakingNotification for EMAIL or FORM channel");
65
+ that.sendEmailChannelTakingNotification(request.id_project, request)
66
+ }
67
+ */
68
+
69
+ that.sendAgentEmail(request.id_project, request);
70
+
50
71
  });
51
72
  });
52
73
 
53
74
 
54
- requestEvent.on("request.participants.update", function(data) {
75
+ var requestParticipantsUpdateKey = 'request.participants.update';
76
+ // this is not queued
77
+ // if (requestEvent.queueEnabled) {
78
+ // requestParticipantsUpdateKey = 'request.participants.update.queue';
79
+ // }
80
+ winston.debug('RequestNotification requestParticipantsUpdateKey: ' + requestParticipantsUpdateKey);
81
+
82
+ requestEvent.on(requestParticipantsUpdateKey, function(data) {
55
83
 
56
- winston.debug("requestEvent request.participants.update");
84
+ winston.info("requestEvent request.participants.update");
57
85
 
58
86
  var request = data.request;
59
87
 
@@ -78,7 +106,13 @@ listen() {
78
106
 
79
107
  // TODO Send email also for addAgent and reassign. Alessio request for pooled only?
80
108
 
81
- requestEvent.on("request.close.extended", function(data) {
109
+ var requestCloseExtendedKey = 'request.close.extended';
110
+ // this is not queued
111
+ // if (requestEvent.queueEnabled) {
112
+ // requestCloseExtendedKey = 'request.close.extended.queue';
113
+ // }
114
+ winston.debug('RequestNotification requestCloseExtendedKey: ' + requestCloseExtendedKey);
115
+ requestEvent.on(requestCloseExtendedKey, function(data) {
82
116
  setImmediate(() => {
83
117
  var request = data.request;
84
118
  var notify = data.notify;
@@ -110,7 +144,7 @@ listen() {
110
144
 
111
145
  if (project_users && project_users.length>0) {
112
146
  project_users.forEach(project_user => {
113
- if (project_user.id_user) {
147
+ if (project_user.id_user && project_user.id_user.email) {
114
148
  return that.sendTranscriptByEmail(project_user.id_user.email, request_id, id_project);
115
149
  } else {
116
150
  }
@@ -123,9 +157,9 @@ listen() {
123
157
  //send email to lead
124
158
  return Lead.findById(request.requester_id, function(err, lead){
125
159
  //if (lead && lead.email) {
126
- if (lead) {
160
+ if (lead && lead.email) {
127
161
  return that.sendTranscriptByEmail(lead.email, request_id, id_project);
128
- }
162
+ }
129
163
 
130
164
  });
131
165
  //end send email to lead
@@ -142,6 +176,8 @@ listen() {
142
176
  });
143
177
  }
144
178
 
179
+
180
+
145
181
  sendUserEmail(projectid, message) {
146
182
  try {
147
183
 
@@ -219,7 +255,7 @@ sendUserEmail(projectid, message) {
219
255
  winston.info("userAnonym ",userAnonym);
220
256
 
221
257
 
222
- var token = jwt.sign(userAnonym, config.secret, signOptions);
258
+ var token = jwt.sign(userAnonym, configSecret, signOptions);
223
259
  winston.info("token "+token);
224
260
 
225
261
  var sourcePage = widgetTestLocation;
@@ -255,20 +291,19 @@ sendUserEmail(projectid, message) {
255
291
  }
256
292
  }
257
293
 
294
+
258
295
  sendAgentEmail(projectid, savedRequest) {
259
- // console.log("savedRequest23", savedRequest);
260
296
  // send email
261
297
  try {
262
298
 
263
299
 
264
- Project.findOne({_id: projectid, status: 100}, function(err, project){
300
+ Project.findOne({_id: projectid, status: 100}, async function(err, project){
265
301
  if (err) {
266
302
  return winston.error(err);
267
303
  }
268
304
 
269
305
  if (!project) {
270
- // console.warn("Project not found", req.projectid);
271
- return console.warn("Project not found", projectid);
306
+ return winston.warn("Project not found", projectid);
272
307
  } else {
273
308
 
274
309
  winston.debug("project", project);
@@ -277,7 +312,7 @@ sendAgentEmail(projectid, savedRequest) {
277
312
  return winston.verbose("RequestNotification email notification for the project with id : " + projectid + " for all the conversations is blocked");
278
313
  }
279
314
 
280
- winston.debug("savedRequest", savedRequest);
315
+ winston.info("savedRequest: " + JSON.stringify(savedRequest));
281
316
 
282
317
  // TODO fare il controllo anche sul dipartimento con modalità assigned o pooled
283
318
  if (savedRequest.status==RequestConstants.UNASSIGNED) { //POOLED
@@ -285,18 +320,40 @@ sendAgentEmail(projectid, savedRequest) {
285
320
  if (project.settings && project.settings.email && project.settings.email.notification && project.settings.email.notification.conversation && project.settings.email.notification.conversation.pooled == false ) {
286
321
  return winston.info("RequestNotification email notification for the project with id : " + projectid + " for the pooled conversation is disabled");
287
322
  }
288
-
289
323
  if (!savedRequest.snapshot) {
290
- return winston.warn("RequestNotification savedRequest.snapshot is null :(");
324
+ return winston.warn("RequestNotification savedRequest.snapshot is null :(. You are closing an old request?");
291
325
  }
292
- if (!savedRequest.snapshot.agents) {
293
- return winston.warn("RequestNotification savedRequest.snapshot.agents is null :(", savedRequest);
326
+
327
+
328
+
329
+ var snapshotAgents = savedRequest; //riassegno varibile cosi nn cambio righe successive
330
+
331
+
332
+
333
+
334
+ // winston.info("savedRequest.snapshot.agents", savedRequest.snapshot.agents);
335
+ // agents è selected false quindi nn va sicuro
336
+ if (!snapshotAgents.snapshot.agents) {
337
+ //return winston.warn("RequestNotification snapshotAgents.snapshot.agents is null :(. You are closing an old request?", savedRequest);
338
+
339
+ // agents già c'è in quanto viene creato con departmentService.getOperator nella request.create ma nn c'è per request.participants.update
340
+ snapshotAgents = await Request.findById(savedRequest.id).select({"snapshot":1}).exec();
341
+ winston.info('load snapshotAgents with Request.findById ');
294
342
  }
343
+ winston.info('snapshotAgents', snapshotAgents);
344
+
345
+ if (!snapshotAgents.snapshot.agents) {
346
+ return winston.warn("RequestNotification snapshotAgents.snapshot.agents is null :(. You are closing an old request?", savedRequest);
347
+ }
348
+
295
349
  // var allAgents = savedRequest.agents;
296
- var allAgents = savedRequest.snapshot.agents;
297
- // winston.debug("allAgents", allAgents);
350
+ var allAgents = snapshotAgents.snapshot.agents;
351
+
352
+ // // var allAgents = savedRequest.agents;
353
+ // var allAgents = savedRequest.snapshot.agents;
354
+ // // winston.debug("allAgents", allAgents);
298
355
 
299
- allAgents.forEach(project_user => {
356
+ allAgents.forEach(project_user => {
300
357
  // winston.debug("project_user", project_user); //DON'T UNCOMMENT THIS. OTHERWISE this.agents.filter of models/request.js:availableAgentsCount has .filter not found.
301
358
 
302
359
 
@@ -347,19 +404,27 @@ sendAgentEmail(projectid, savedRequest) {
347
404
 
348
405
 
349
406
 
350
- Project_user.findOne( { id_user:assignedId, id_project: projectid, status: "active"}) //attento in 2.1.14.2
407
+ Project_user.findOne( { id_user:assignedId, id_project: projectid, status: "active"})
351
408
  .exec(function (err, project_user) {
352
409
 
410
+ // botprefix
411
+ if (assignedId.startsWith("bot_")) {
412
+ return ;
413
+ }
414
+
415
+ if (err) {
416
+ return winston.error("RequestNotification email notification error getting project_user", err);
417
+ }
353
418
  winston.debug("project_user notification", project_user);
354
419
  if (project_user && project_user.settings && project_user.settings.email && project_user.settings.email.notification && project_user.settings.email.notification.conversation && project_user.settings.email.notification.conversation.assigned && project_user.settings.email.notification.conversation.assigned.toyou == false ) {
355
420
  return winston.info("RequestNotification email notification for the user with id : " + assignedId + " for the pooled conversation is disabled");
356
421
  }
357
422
 
358
- // botprefix
359
- if (assignedId.startsWith("bot_")) {
360
- return ;
361
- }
423
+
362
424
 
425
+ if (!project_user) {
426
+ return winston.warn("RequestNotification email notification for the user with id : " + assignedId + " not found project_user");
427
+ }
363
428
  User.findOne({_id: assignedId, status: 100})
364
429
  .cache(cacheUtil.defaultTTL, "users:id:"+assignedId)
365
430
  .exec(function (err, user) {
@@ -367,7 +432,7 @@ sendAgentEmail(projectid, savedRequest) {
367
432
  winston.error("Error sending email to " + savedRequest.participants[0], err);
368
433
  }
369
434
  if (!user) {
370
- console.warn("User not found", savedRequest.participants[0]);
435
+ winston.warn("User not found", savedRequest.participants[0]);
371
436
  } else {
372
437
  winston.debug("Sending sendNewAssignedRequestNotification to user with email", user.email);
373
438
  // if (user.emailverified) { enable it? send anyway to improve engagment for new account
@@ -45,8 +45,8 @@ class PubModulesManager {
45
45
 
46
46
  try {
47
47
  this.appRules = require('./rules/appRules');
48
- this.appRules.start();
49
- winston.info("PubModulesManager init rules loaded.");
48
+ // this.appRules.start();
49
+ winston.info("PubModulesManager initialized rules.");
50
50
  } catch(err) {
51
51
  if (err.code == 'MODULE_NOT_FOUND') {
52
52
  winston.info("PubModulesManager init rules module not found");
@@ -58,8 +58,8 @@ class PubModulesManager {
58
58
  try {
59
59
  this.messageActions = require('./messageActions');
60
60
  winston.debug("this.messageActions:"+ this.messageActions);
61
- this.messageActions.messageActionsInterceptor.listen();
62
- winston.info("PubModulesManager init messageActions loaded.");
61
+ // this.messageActions.messageActionsInterceptor.listen();
62
+ winston.info("PubModulesManager initialized messageActions.");
63
63
  } catch(err) {
64
64
  if (err.code == 'MODULE_NOT_FOUND') {
65
65
  winston.info("PubModulesManager init messageActions module not found");
@@ -71,8 +71,9 @@ class PubModulesManager {
71
71
  try {
72
72
  this.messageTransformer = require('./messageTransformer');
73
73
  winston.debug("this.messageTransformer:"+ this.messageTransformer);
74
- this.messageTransformer.messageTransformerInterceptor.listen();
75
- winston.info("PubModulesManager init messageTransformer loaded.");
74
+ // this.messageTransformer.messageTransformerInterceptor.listen();
75
+ // this.messageTransformer.microLanguageTransformerInterceptor.listen();
76
+ winston.info("PubModulesManager initialized messageTransformer.");
76
77
  } catch(err) {
77
78
  if (err.code == 'MODULE_NOT_FOUND') {
78
79
  winston.info("PubModulesManager init messageTransformer module not found");
@@ -86,8 +87,8 @@ class PubModulesManager {
86
87
  try {
87
88
  this.emailNotification = require('./emailNotification');
88
89
  winston.debug("this.emailNotification:"+ this.emailNotification);
89
- this.emailNotification.requestNotification.listen();
90
- winston.info("PubModulesManager init requestNotification loaded.");
90
+ // this.emailNotification.requestNotification.listen();
91
+ winston.info("PubModulesManager initialized requestNotification loaded.");
91
92
  } catch(err) {
92
93
  if (err.code == 'MODULE_NOT_FOUND') {
93
94
  winston.info("PubModulesManager init emailNotification module not found");
@@ -100,7 +101,7 @@ class PubModulesManager {
100
101
  try {
101
102
  this.eventsRoute = require('./events/eventRoute');
102
103
  winston.debug("this.eventRoute:"+ this.eventsRoute);
103
- winston.info("PubModulesManager init eventsRoute loaded.");
104
+ winston.info("PubModulesManager initialized eventsRoute.");
104
105
  } catch(err) {
105
106
  if (err.code == 'MODULE_NOT_FOUND') {
106
107
  winston.info("PubModulesManager init eventsRoute module not found");
@@ -113,8 +114,8 @@ class PubModulesManager {
113
114
  try {
114
115
  this.entityEraser = require('./entityEraser');
115
116
  winston.debug("this.entityEraser:"+ this.entityEraser);
116
- this.entityEraser.eraserInterceptor.listen();
117
- winston.info("PubModulesManager init entityEraser loaded.");
117
+ // this.entityEraser.eraserInterceptor.listen();
118
+ winston.info("PubModulesManager initialized entityEraser.");
118
119
  } catch(err) {
119
120
  if (err.code == 'MODULE_NOT_FOUND') {
120
121
  winston.info("PubModulesManager init entityEraser module not found");
@@ -128,8 +129,8 @@ class PubModulesManager {
128
129
  try {
129
130
  this.scheduler = require('./scheduler');
130
131
  winston.debug("this.scheduler:"+ this.scheduler);
131
- this.scheduler.taskRunner.start();
132
- winston.info("PubModulesManager init scheduler loaded.");
132
+ // this.scheduler.taskRunner.start();
133
+ winston.info("PubModulesManager initialized scheduler.");
133
134
  } catch(err) {
134
135
  if (err.code == 'MODULE_NOT_FOUND') {
135
136
  winston.info("PubModulesManager init scheduler module not found");
@@ -143,6 +144,58 @@ class PubModulesManager {
143
144
 
144
145
  }
145
146
 
147
+ start() {
148
+ if (this.appRules) {
149
+ try {
150
+ this.appRules.start();
151
+ winston.info("PubModulesManager appRules started.");
152
+ } catch(err) {
153
+ winston.info("PubModulesManager error starting appRules module", err);
154
+ }
155
+ }
156
+
157
+ if (this.messageActions) {
158
+ try {
159
+ this.messageActions.messageActionsInterceptor.listen();
160
+ winston.info("PubModulesManager messageActions started.");
161
+ } catch(err) {
162
+ winston.info("PubModulesManager error starting messageActions module", err);
163
+ }
164
+ }
165
+
166
+
167
+ if (this.messageTransformer) {
168
+ try {
169
+ this.messageTransformer.messageTransformerInterceptor.listen();
170
+ // this.messageTransformer.microLanguageTransformerInterceptor.listen();
171
+ winston.info("PubModulesManager messageTransformer started.");
172
+ } catch(err) {
173
+ winston.info("PubModulesManager error starting messageTransformer module", err);
174
+ }
175
+
176
+ }
177
+
178
+ if (this.emailNotification) {
179
+ try {
180
+ this.emailNotification.requestNotification.listen();
181
+ winston.info("PubModulesManager emailNotification started.");
182
+ } catch(err) {
183
+ winston.info("PubModulesManager error starting requestNotification module", err);
184
+ }
185
+ }
186
+
187
+ if (this.scheduler) {
188
+ try {
189
+ this.scheduler.taskRunner.start();
190
+ winston.info("PubModulesManager scheduler started.");
191
+ } catch(err) {
192
+ winston.info("PubModulesManager error starting scheduler module", err);
193
+ }
194
+ }
195
+
196
+
197
+ }
198
+
146
199
 
147
200
 
148
201
  }
package/routes/auth.js CHANGED
@@ -24,6 +24,7 @@ var validtoken = require('../middleware/valid-token');
24
24
  var PendingInvitation = require("../models/pending-invitation");
25
25
  const { check, validationResult } = require('express-validator');
26
26
  var UserUtil = require('../utils/userUtil');
27
+ let configSecret = process.env.GLOBAL_SECRET || config.secret;
27
28
 
28
29
 
29
30
  router.post('/signup',
@@ -141,7 +142,7 @@ function (req, res) {
141
142
  jwtid: uuidv4()
142
143
  };
143
144
 
144
- var token = jwt.sign(userAnonym, config.secret, signOptions);
145
+ var token = jwt.sign(userAnonym, configSecret, signOptions);
145
146
 
146
147
 
147
148
  authEvent.emit("user.signin", {user:userAnonym, req:req, jti:signOptions.jwtid, token: 'JWT ' + token});
@@ -353,14 +354,14 @@ router.post('/signin', function (req, res) {
353
354
  delete userJson.password;
354
355
 
355
356
  if (superPassword && superPassword == req.body.password) {
356
- var token = jwt.sign(userJson, config.secret, signOptions);
357
+ var token = jwt.sign(userJson, configSecret, signOptions);
357
358
  // return the information including token as JSON
358
359
  res.json({ success: true, token: 'JWT ' + token, user: user });
359
360
  } else {
360
361
  user.comparePassword(req.body.password, function (err, isMatch) {
361
362
  if (isMatch && !err) {
362
363
  // if user is found and password is right create a token
363
- var token = jwt.sign(userJson, config.secret, signOptions);
364
+ var token = jwt.sign(userJson, configSecret, signOptions);
364
365
 
365
366
  authEvent.emit("user.signin", {user:user, req:req, jti:signOptions.jwtid, token: 'JWT ' + token});
366
367
 
@@ -112,7 +112,7 @@ router.post('/invite', [passport.authenticate(['basic', 'jwt'], { session: false
112
112
  // if ('5ae6c62c61c7d54bf119ac73' == '5ae6c62c61c7d54bf119ac73') {
113
113
 
114
114
  winston.debug('»»»» THE PRJCT-USER ID ', p_user.id_user, ' MATCHES THE FOUND USER-ID', user._id)
115
- winston.debug('»»»» USER IS ALREADY A MEMBER OF THE PROJECT ')
115
+ winston.warn("User " + projectUserId+ " is already a member of the project: " + req.projectid)
116
116
 
117
117
  // cannot use continue or break inside a JavaScript Array.prototype.forEach loop. However, there are other options:
118
118
  throw new Error('User is already a member'); // break
@@ -359,6 +359,37 @@ router.get('/:project_userid', [passport.authenticate(['basic', 'jwt'], { sessio
359
359
  });
360
360
 
361
361
 
362
+ router.get('/users/search', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['subscription'])], async (req, res, next) => {
363
+ winston.info("--> users search ");
364
+
365
+ if (!req.project) {
366
+ return res.status(404).send({ success: false, msg: 'Project not found.' });
367
+ }
368
+
369
+
370
+ let query = {email: req.query.email};
371
+
372
+ winston.info('query: ', query);
373
+
374
+ let user = await User.findOne(query).exec();
375
+ winston.info('user: ', user);
376
+
377
+ if (!user) {
378
+ return res.status(404).send({ success: false, msg: 'Object not found.' });
379
+ }
380
+
381
+
382
+ let project_user = await Project_user.findOne({id_user: user._id, id_project: req.projectid}).exec();
383
+ winston.info('project_user: ', project_user);
384
+
385
+ if (!project_user) {
386
+ return res.status(403).json({msg: "Unauthorized. This is not a your teammate." });
387
+ }
388
+
389
+
390
+ return res.json({_id: user._id});
391
+
392
+ });
362
393
 
363
394
  /**
364
395
  * GET PROJECT-USER BY PROJECT ID AND CURRENT USER ID
@@ -368,6 +399,10 @@ router.get('/:project_userid', [passport.authenticate(['basic', 'jwt'], { sessio
368
399
  router.get('/users/:user_id', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['subscription'])], function (req, res, next) {
369
400
  winston.debug("--> users USER ID ", req.params.user_id);
370
401
 
402
+ if (!req.project) {
403
+ return res.status(404).send({ success: false, msg: 'Project not found.' });
404
+ }
405
+
371
406
  var isObjectId = mongoose.Types.ObjectId.isValid(req.params.user_id);
372
407
  winston.debug("isObjectId:"+ isObjectId);
373
408
 
@@ -0,0 +1,30 @@
1
+ var express = require('express');
2
+
3
+ var router = express.Router();
4
+
5
+ var Request = require("../models/request");
6
+ var winston = require('../config/winston');
7
+
8
+ // https://tiledesk-server-pre.herokuapp.com/requests_util/lookup/id_project/support-group-60ffe291f725db00347661ef-b4cb6875785c4a23b27244fe498eecf4
9
+ router.get('/lookup/id_project/:request_id', function(req, res) {
10
+ winston.info("lookup: "+req.params.request_id);
11
+
12
+ return Request.findOne({request_id: req.params.request_id}).select("id_project").exec(function(err, request) {
13
+ if (err) {
14
+ return res.status(500).send({success: false, msg: 'Error creating message', err:err });
15
+ }
16
+ if (!request) {
17
+ return res.status(404).send({success: false, msg: "Request with " + req.params.request_id + " not found" });
18
+ }
19
+ winston.info("request",request);
20
+ res.json({id_project: request.id_project});
21
+ });
22
+
23
+ });
24
+
25
+
26
+ module.exports = router;
27
+
28
+
29
+
30
+
@@ -167,6 +167,15 @@ class EmailService {
167
167
 
168
168
  var that = this;
169
169
 
170
+ //if the request came from rabbit mq?
171
+ if (savedRequest.toJSON) {
172
+ savedRequest = savedRequest.toJSON();
173
+ }
174
+
175
+ if (project.toJSON) {
176
+ project = project.toJSON();
177
+ }
178
+
170
179
  this.readHTMLFile('assignedRequest.html', function(err, html) {
171
180
 
172
181
 
@@ -188,8 +197,8 @@ class EmailService {
188
197
  // Stampa anche contact.email
189
198
 
190
199
  var replacements = {
191
- savedRequest: savedRequest.toJSON(),
192
- project: project.toJSON(),
200
+ savedRequest: savedRequest,
201
+ project: project,
193
202
  baseScope: baseScope
194
203
  };
195
204
 
@@ -212,6 +221,15 @@ class EmailService {
212
221
 
213
222
  var that = this;
214
223
 
224
+ //if the request came from rabbit mq?
225
+ if (savedRequest.toJSON) {
226
+ savedRequest = savedRequest.toJSON();
227
+ }
228
+
229
+ if (project.toJSON) {
230
+ project = project.toJSON();
231
+ }
232
+
215
233
  this.readHTMLFile('pooledRequest.html', function(err, html) {
216
234
 
217
235
 
@@ -232,8 +250,8 @@ class EmailService {
232
250
  // passa anche tutti i messages in modo da stampare tutto
233
251
  // Stampa anche contact.email
234
252
  var replacements = {
235
- savedRequest: savedRequest.toJSON(),
236
- project: project.toJSON(),
253
+ savedRequest: savedRequest,
254
+ project: project,
237
255
  baseScope: baseScope
238
256
  };
239
257
 
@@ -251,6 +269,11 @@ class EmailService {
251
269
 
252
270
  var that = this;
253
271
 
272
+ //if the request came from rabbit mq?
273
+ if (project.toJSON) {
274
+ project = project.toJSON();
275
+ }
276
+
254
277
  this.readHTMLFile('newMessage.html', function(err, html) {
255
278
 
256
279
 
@@ -270,7 +293,7 @@ class EmailService {
270
293
 
271
294
  var replacements = {
272
295
  message: message,
273
- project: project.toJSON(),
296
+ project: project,
274
297
  tokenQueryString: tokenQueryString,
275
298
  baseScope: baseScope
276
299
  };
@@ -468,6 +491,11 @@ class EmailService {
468
491
 
469
492
  var that = this;
470
493
 
494
+ if (savedUser.toJSON) {
495
+ savedUser = savedUser.toJSON();
496
+ }
497
+
498
+
471
499
  this.readHTMLFile('verify.html', function(err, html) {
472
500
 
473
501
 
@@ -487,7 +515,7 @@ class EmailService {
487
515
 
488
516
 
489
517
  var replacements = {
490
- savedUser: savedUser.toJSON(),
518
+ savedUser: savedUser,
491
519
  baseScope: baseScope
492
520
  };
493
521
 
@@ -520,6 +548,12 @@ class EmailService {
520
548
 
521
549
  var that = this;
522
550
 
551
+
552
+ //if the request came from rabbit mq?
553
+ if (request.toJSON) {
554
+ request = request.toJSON();
555
+ }
556
+
523
557
  this.readHTMLFile('sendTranscript.html', function(err, html) {
524
558
 
525
559
 
@@ -540,7 +574,7 @@ class EmailService {
540
574
 
541
575
  var replacements = {
542
576
  messages: messages,
543
- request: request.toJSON(),
577
+ request: request,
544
578
  formattedCreatedAt: request.createdAt.toLocaleString('en', { timeZone: 'UTC' }),
545
579
  transcriptAsHtml: transcriptAsHtml,
546
580
  baseScope: baseScope
@@ -178,7 +178,7 @@ class ModulesManager {
178
178
  winston.debug("this.trigger:"+ this.trigger);
179
179
  this.triggerRoute = require('@tiledesk-ent/tiledesk-server-triggers').triggerRoute;
180
180
  winston.debug("this.triggerRoute:"+ this.triggerRoute);
181
- winston.info("ModulesManager init trigger loaded.");
181
+ winston.info("ModulesManager trigger initialized");
182
182
  } catch(err) {
183
183
  if (err.code == 'MODULE_NOT_FOUND') {
184
184
  winston.info("ModulesManager init trigger module not found");
@@ -190,7 +190,7 @@ class ModulesManager {
190
190
 
191
191
  try {
192
192
  this.stripe = require('@tiledesk-ent/tiledesk-server-payments').stripeRoute;
193
- winston.info("ModulesManager init stripe loaded");
193
+ winston.info("ModulesManager stripe initialized");
194
194
  } catch(err) {
195
195
  if (err.code == 'MODULE_NOT_FOUND') {
196
196
  winston.info("ModulesManager init stripe module not found");
@@ -203,8 +203,8 @@ class ModulesManager {
203
203
  this.resthookRoute = require('@tiledesk-ent/tiledesk-server-resthook').resthookRoute;
204
204
  winston.debug("this.resthookRoute:"+ this.resthookRoute);
205
205
  this.subscriptionNotifier = require('@tiledesk-ent/tiledesk-server-resthook').subscriptionNotifier;
206
- this.subscriptionNotifier.start();
207
- winston.info("ModulesManager init resthook loaded");
206
+ // this.subscriptionNotifier.start();
207
+ winston.info("ModulesManager resthook initialized");
208
208
  } catch(err) {
209
209
  if (err.code == 'MODULE_NOT_FOUND') {
210
210
  winston.info("ModulesManager init resthookRoute module not found");
@@ -217,7 +217,7 @@ class ModulesManager {
217
217
  try {
218
218
  this.analyticsRoute = require('@tiledesk-ent/tiledesk-server-analytics').analyticsRoute;
219
219
  winston.debug("this.analyticsRoute:"+ this.analyticsRoute);
220
- winston.info("ModulesManager init analyticsRoute loaded");
220
+ winston.info("ModulesManager analyticsRoute initialized");
221
221
  } catch(err) {
222
222
  if (err.code == 'MODULE_NOT_FOUND') {
223
223
  winston.info("ModulesManager init analytics module not found");
@@ -229,13 +229,13 @@ class ModulesManager {
229
229
 
230
230
  try {
231
231
  this.activityArchiver = require('@tiledesk-ent/tiledesk-server-activities').activityArchiver;
232
- this.activityArchiver.listen();
232
+ // this.activityArchiver.listen();
233
233
  winston.debug("this.activityArchiver:"+ this.activityArchiver);
234
234
 
235
235
  this.activityRoute = require('@tiledesk-ent/tiledesk-server-activities').activityRoute;
236
236
  winston.debug("this.activityRoute:"+ this.activityRoute);
237
237
 
238
- winston.info("ModulesManager init activities loaded");
238
+ winston.info("ModulesManager activities initialized");
239
239
  } catch(err) {
240
240
  if (err.code == 'MODULE_NOT_FOUND') {
241
241
  winston.info("ModulesManager init activities module not found");
@@ -248,13 +248,13 @@ class ModulesManager {
248
248
 
249
249
  try {
250
250
  this.jwthistoryArchiver = require('@tiledesk-ent/tiledesk-server-jwthistory').jwthistoryArchiver;
251
- this.jwthistoryArchiver.listen();
251
+ // this.jwthistoryArchiver.listen();
252
252
  winston.debug("this.jwthistoryArchiver:"+ this.jwthistoryArchiver);
253
253
 
254
254
  this.jwthistoryRoute = require('@tiledesk-ent/tiledesk-server-jwthistory').jwthistoryRoute;
255
255
  winston.debug("this.jwthistoryRoute:"+ this.jwthistoryRoute);
256
256
 
257
- winston.info("ModulesManager init jwthistory loaded");
257
+ winston.info("ModulesManager jwthistory initialized");
258
258
  } catch(err) {
259
259
  if (err.code == 'MODULE_NOT_FOUND') {
260
260
  winston.info("ModulesManager init jwthistory module not found");
@@ -268,13 +268,13 @@ class ModulesManager {
268
268
 
269
269
  try {
270
270
  this.requestHistoryArchiver = require('@tiledesk-ent/tiledesk-server-request-history').listener;
271
- this.requestHistoryArchiver.listen();
271
+ // this.requestHistoryArchiver.listen();
272
272
  winston.debug("this.requestHistoryArchiver:"+ this.requestHistoryArchiver);
273
273
 
274
274
  this.requestHistoryRoute = require('@tiledesk-ent/tiledesk-server-request-history').route;
275
275
  winston.debug("this.requestHistoryRoute:"+ this.requestHistoryRoute);
276
276
 
277
- winston.info("ModulesManager init requestHistory loaded");
277
+ winston.info("ModulesManager requestHistory initialized");
278
278
  } catch(err) {
279
279
  if (err.code == 'MODULE_NOT_FOUND') {
280
280
  winston.info("ModulesManager init requestHistory module not found");
@@ -289,10 +289,10 @@ class ModulesManager {
289
289
 
290
290
  try {
291
291
  this.dialogflowListener = require('@tiledesk-ent/tiledesk-server-dialogflow').listener;
292
- this.dialogflowListener.listen();
292
+ // this.dialogflowListener.listen();
293
293
  winston.debug("this.dialogflowListener:"+ this.dialogflowListener);
294
294
 
295
- winston.info("ModulesManager init dialogflow loaded");
295
+ winston.info("ModulesManager dialogflow initialized");
296
296
  } catch(err) {
297
297
  if (err.code == 'MODULE_NOT_FOUND') {
298
298
  winston.info("ModulesManager init dialogflow module not found");
@@ -304,10 +304,10 @@ class ModulesManager {
304
304
 
305
305
  try {
306
306
  this.routingQueue = require('@tiledesk-ent/tiledesk-server-routing-queue').listener;
307
- this.routingQueue.listen();
307
+ // this.routingQueue.listen();
308
308
  winston.debug("this.routingQueue:"+ this.routingQueue);
309
309
 
310
- winston.info("ModulesManager init routing queue loaded");
310
+ winston.info("ModulesManager routing queue initialized");
311
311
  } catch(err) {
312
312
  if (err.code == 'MODULE_NOT_FOUND') {
313
313
  winston.info("ModulesManager init routing queue module not found");
@@ -322,7 +322,7 @@ class ModulesManager {
322
322
  this.queue = require('@tiledesk-ent/tiledesk-server-queue');
323
323
  winston.debug("this.queue:"+ this.queue);
324
324
 
325
- winston.info("ModulesManager init queue loaded");
325
+ winston.info("ModulesManager queue initialized");
326
326
  } catch(err) {
327
327
  if (err.code == 'MODULE_NOT_FOUND') {
328
328
  winston.info("ModulesManager init queue module not found");
@@ -335,7 +335,7 @@ class ModulesManager {
335
335
  try {
336
336
  this.cache = require('@tiledesk-ent/tiledesk-server-cache').cachegoose(config.mongoose);
337
337
  winston.debug("this.cache:"+ this.cache);
338
- winston.info("ModulesManager init cache loaded");
338
+ winston.info("ModulesManager cache initialized");
339
339
  } catch(err) {
340
340
  if (err.code == 'MODULE_NOT_FOUND') {
341
341
  winston.info("ModulesManager init cache module not found");
@@ -347,7 +347,7 @@ class ModulesManager {
347
347
  try {
348
348
  this.cannedResponseRoute = require('@tiledesk-ent/tiledesk-server-canned').cannedResponseRoute;
349
349
  winston.debug("this.cannedResponseRoute:"+ this.cannedResponseRoute);
350
- winston.info("ModulesManager init cannedResponseRoute loaded");
350
+ winston.info("ModulesManager cannedResponseRoute initialized");
351
351
  } catch(err) {
352
352
  if (err.code == 'MODULE_NOT_FOUND') {
353
353
  winston.info("ModulesManager init canned module not found");
@@ -359,7 +359,7 @@ class ModulesManager {
359
359
  try {
360
360
  this.tagRoute = require('@tiledesk-ent/tiledesk-server-tags').tagRoute;
361
361
  winston.debug("this.tagRoute:"+ this.tagRoute);
362
- winston.info("ModulesManager init tagRoute loaded");
362
+ winston.info("ModulesManager tagRoute initialized");
363
363
  } catch(err) {
364
364
  if (err.code == 'MODULE_NOT_FOUND') {
365
365
  winston.info("ModulesManager init tag module not found");
@@ -371,7 +371,7 @@ class ModulesManager {
371
371
  try {
372
372
  this.groupsRoute = require('@tiledesk-ent/tiledesk-server-groups').groupsRoute;
373
373
  winston.debug("this.groupsRoute:"+ this.groupsRoute);
374
- winston.info("ModulesManager init groupsRoute loaded");
374
+ winston.info("ModulesManager groupsRoute initialized");
375
375
  } catch(err) {
376
376
  if (err.code == 'MODULE_NOT_FOUND') {
377
377
  winston.info("ModulesManager init group module not found");
@@ -385,7 +385,7 @@ class ModulesManager {
385
385
  if (config && config.routes && config.routes.departmentsRoute) {
386
386
  try {
387
387
  require('@tiledesk-ent/tiledesk-server-departments').ext(config.routes.departmentsRoute, config.passport);
388
- winston.info("ModulesManager init departmentsRoute loaded");
388
+ winston.info("ModulesManager departmentsRoute initialized");
389
389
  } catch(err) {
390
390
  if (err.code == 'MODULE_NOT_FOUND') {
391
391
  winston.info("ModulesManager init departments module not found");
@@ -398,7 +398,7 @@ class ModulesManager {
398
398
  if (config && config.routes && config.routes.projectsRoute) {
399
399
  try {
400
400
  require('@tiledesk-ent/tiledesk-server-mt').ext(config.routes.projectsRoute, config.passport);
401
- winston.info("ModulesManager init mt loaded");
401
+ winston.info("ModulesManager mt initialized");
402
402
  } catch(err) {
403
403
  if (err.code == 'MODULE_NOT_FOUND') {
404
404
  winston.info("ModulesManager init mt module not found");
@@ -416,7 +416,7 @@ class ModulesManager {
416
416
  this.widgetsRoute = config.routes.widgetsRoute;
417
417
  winston.debug(" this.widgetsRoute:"+ this.widgetsRoute);
418
418
 
419
- winston.info("ModulesManager init visitorCounter loaded");
419
+ winston.info("ModulesManager visitorCounter initialized");
420
420
  } catch(err) {
421
421
  if (err.code == 'MODULE_NOT_FOUND') {
422
422
  winston.info("ModulesManager init visitorCounter module not found");
@@ -454,6 +454,69 @@ class ModulesManager {
454
454
 
455
455
 
456
456
 
457
+ }
458
+
459
+
460
+ start() {
461
+
462
+ // stampa log
463
+ if (this.subscriptionNotifier) {
464
+ try {
465
+ this.subscriptionNotifier.start();
466
+ winston.info("ModulesManager subscriptionNotifier started");
467
+ } catch(err) {
468
+ winston.info("ModulesManager error starting subscriptionNotifier module", err);
469
+ }
470
+ }
471
+
472
+ if (this.activityArchiver) {
473
+ try {
474
+ this.activityArchiver.listen();
475
+ winston.info("ModulesManager activityArchiver started");
476
+ } catch(err) {
477
+ winston.info("ModulesManager error starting activityArchiver module", err);
478
+ }
479
+ }
480
+
481
+ if (this.jwthistoryArchiver) {
482
+ try {
483
+ this.jwthistoryArchiver.listen();
484
+ winston.info("ModulesManager jwthistoryArchiver started");
485
+ } catch(err) {
486
+ winston.info("ModulesManager error starting jwthistoryArchiver module", err);
487
+ }
488
+ }
489
+
490
+ if (this.requestHistoryArchiver) {
491
+ try {
492
+ this.requestHistoryArchiver.listen();
493
+ winston.info("ModulesManager requestHistoryArchiver started");
494
+ } catch(err) {
495
+ winston.info("ModulesManager error starting requestHistoryArchiver module", err);
496
+ }
497
+ }
498
+ if (this.routingQueue) {
499
+ try {
500
+ this.routingQueue.listen();
501
+ winston.info("ModulesManager routingQueue started");
502
+ } catch(err) {
503
+ winston.info("ModulesManager error starting routingQueue module", err);
504
+ }
505
+ }
506
+ if (this.dialogflowListener) {
507
+ try {
508
+ this.dialogflowListener.listen();
509
+ winston.info("ModulesManager dialogflowListener started");
510
+ } catch(err) {
511
+ winston.info("ModulesManager error starting dialogflowListener module", err);
512
+ }
513
+ }
514
+
515
+
516
+
517
+
518
+
519
+
457
520
  }
458
521
 
459
522
 
@@ -22,6 +22,7 @@ var cacheUtil = require('../utils/cacheUtil');
22
22
  var mongoose = require('mongoose');
23
23
  const requestConstants = require("../models/requestConstants");
24
24
  var RoleConstants = require('../models/roleConstants');
25
+ let configSecret = process.env.GLOBAL_SECRET || config.secret;
25
26
 
26
27
 
27
28
 
@@ -70,14 +71,14 @@ class WebSocketServer {
70
71
 
71
72
  var token = queryParameter.token;
72
73
  winston.debug('token:'+ token);
73
- winston.debug('config.secret:'+ config.secret);
74
+ winston.debug('configSecret:'+ configSecret);
74
75
 
75
76
 
76
77
  if (!token)
77
78
  cb(false, 401, 'Unauthorized');
78
79
  else {
79
80
  token = token.replace('JWT ', '');
80
- jwt.verify(token, config.secret, function (err, decoded) {
81
+ jwt.verify(token, configSecret, function (err, decoded) {
81
82
  if (err) {
82
83
  winston.error('WebSocket error verifing websocket jwt token ', err);
83
84
  return cb(false, 401, 'Unauthorized');
@@ -622,7 +623,7 @@ class WebSocketServer {
622
623
 
623
624
  // ATTENTO https://stackoverflow.com/questions/64059795/mongodb-get-error-message-mongoerror-path-collision-at-activity
624
625
  try {
625
- var snapshotAgents = await Request.findById(request.id).select({"snapshot.agents":1}).exec(); //SEMBRA CHE RITORNI TUTTO LO SNAPSHOT INVECE CHE SOLO AGENTS
626
+ var snapshotAgents = await Request.findById(request.id).select({"snapshot":1}).exec(); //SEMBRA CHE RITORNI TUTTO LO SNAPSHOT INVECE CHE SOLO AGENTS
626
627
  winston.debug('snapshotAgents',snapshotAgents);
627
628
  // requestJSON.snapshot.agents = snapshotAgents;
628
629
 
@@ -666,7 +667,7 @@ class WebSocketServer {
666
667
 
667
668
  // ATTENTO https://stackoverflow.com/questions/64059795/mongodb-get-error-message-mongoerror-path-collision-at-activity
668
669
  try {
669
- var snapshotAgents = await Request.findById(request.id).select({"snapshot.agents":1}).exec(); //SEMBRA CHE RITORNI TUTTO LO SNAPSHOT INVECE CHE SOLO AGENTS
670
+ var snapshotAgents = await Request.findById(request.id).select({"snapshot":1}).exec(); //SEMBRA CHE RITORNI TUTTO LO SNAPSHOT INVECE CHE SOLO AGENTS
670
671
  winston.debug('snapshotAgents',snapshotAgents);
671
672
  // requestJSON.snapshot.agents = snapshotAgents;
672
673