@tiledesk/tiledesk-server 2.2.37 → 2.3.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 +8 -1
- package/LICENSE +14 -657
- package/README.md +21 -18
- package/app.js +27 -3
- package/config/labels/widget.json +320 -0
- package/event/subscriptionEvent.js +11 -0
- package/models/subscriptionEvent.js +11 -0
- package/models/subscriptionLog.js +34 -0
- package/models/tagLibrary.js +42 -0
- package/package.json +5 -11
- package/pubmodules/activities/activityArchiver.js +295 -0
- package/pubmodules/activities/index.js +3 -0
- package/pubmodules/activities/models/activity.js +88 -0
- package/pubmodules/activities/routes/activity.js +710 -0
- package/pubmodules/activities/test/activityRoute.js +85 -0
- package/pubmodules/analytics/analytics.js +1719 -0
- package/pubmodules/analytics/index.js +3 -0
- package/pubmodules/canned/cannedResponse.js +51 -0
- package/pubmodules/canned/cannedResponseRoute.js +157 -0
- package/pubmodules/canned/index.js +3 -0
- package/pubmodules/pubModulesManager.js +115 -7
- package/pubmodules/rasa/index.js +8 -1
- package/pubmodules/rasa/listener.js +28 -7
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +2 -2
- package/pubmodules/trigger/default.js +271 -0
- package/pubmodules/trigger/event/actionEventEmitter.js +10 -0
- package/pubmodules/trigger/event/flowEventEmitter.js +10 -0
- package/pubmodules/trigger/event/triggerEventEmitter.js +10 -0
- package/pubmodules/trigger/index.js +3 -0
- package/pubmodules/trigger/models/trigger.js +149 -0
- package/pubmodules/trigger/rulesTrigger.js +1180 -0
- package/pubmodules/trigger/start.js +114 -0
- package/pubmodules/trigger/triggerRoute.js +150 -0
- package/routes/department.js +51 -0
- package/routes/group.js +140 -0
- package/routes/project.js +52 -0
- package/routes/request.js +3 -2
- package/routes/subscription.js +140 -0
- package/routes/tag.js +138 -0
- package/services/faqBotHandler.js +2 -2
- package/services/faqBotSupport.js +0 -1
- package/services/faqService.js +1 -1
- package/services/modulesManager.js +16 -182
- package/services/subscriptionNotifier.js +485 -0
- package/template/email/assignedEmailMessage.html +1 -1
- package/template/email/assignedRequest.html +1 -1
- package/template/email/newMessage.html +1 -1
- package/template/email/passwordChanged.html +1 -1
- package/template/email/pooledEmailMessage.html +1 -1
- package/template/email/pooledRequest.html +1 -1
- package/template/email/resetPassword.html +2 -2
- package/template/email/ticket.html +1 -1
- package/views/messages.jade +1 -1
@@ -0,0 +1,710 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var router = express.Router();
|
3
|
+
var Activity = require("../models/activity");
|
4
|
+
var winston = require('../../../config/winston');
|
5
|
+
var moment = require('moment');
|
6
|
+
var ObjectId = require('mongoose').Types.ObjectId;
|
7
|
+
|
8
|
+
csv = require('csv-express');
|
9
|
+
csv.separator = ';';
|
10
|
+
// csv = require('csv-express');
|
11
|
+
// csv.separator = ';';
|
12
|
+
|
13
|
+
|
14
|
+
// router.post('/', function (req, res) {
|
15
|
+
|
16
|
+
// winston.debug(req.body);
|
17
|
+
// winston.debug("req.user", req.user);
|
18
|
+
|
19
|
+
// var newLead = new Lead({
|
20
|
+
// fullname: req.body.fullname,
|
21
|
+
// lead_id: req.body.lead_id,
|
22
|
+
// email: req.body.email,
|
23
|
+
// id_project: req.projectid,
|
24
|
+
// createdBy: req.user.id,
|
25
|
+
// updatedBy: req.user.id
|
26
|
+
// });
|
27
|
+
|
28
|
+
// newLead.save(function (err, savedLead) {
|
29
|
+
// if (err) {
|
30
|
+
// winston.debug('--- > ERROR ', err)
|
31
|
+
// return res.status(500).send({ success: false, msg: 'Error saving object.' });
|
32
|
+
// }
|
33
|
+
// res.json(savedLead);
|
34
|
+
// });
|
35
|
+
// });
|
36
|
+
|
37
|
+
// router.get('/:leadid', function (req, res) {
|
38
|
+
// winston.debug(req.body);
|
39
|
+
|
40
|
+
// Lead.findById(req.params.leadid, function (err, lead) {
|
41
|
+
// if (err) {
|
42
|
+
// return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
43
|
+
// }
|
44
|
+
// if (!lead) {
|
45
|
+
// return res.status(404).send({ success: false, msg: 'Object not found.' });
|
46
|
+
// }
|
47
|
+
// res.json(lead);
|
48
|
+
// });
|
49
|
+
// });
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
router.get('/', function (req, res) {
|
54
|
+
var limit = 40; // Number of activities per page
|
55
|
+
var page = 0;
|
56
|
+
|
57
|
+
if (req.query.page) {
|
58
|
+
page = req.query.page;
|
59
|
+
}
|
60
|
+
|
61
|
+
var skip = page * limit;
|
62
|
+
winston.debug('Activity ROUTE - SKIP PAGE ', skip);
|
63
|
+
// winston.debug('Activity ROUTE - SKIP PAGE ', skip);
|
64
|
+
|
65
|
+
winston.debug('Activity ROUTE - QUERY ', req.query)
|
66
|
+
|
67
|
+
|
68
|
+
var query = { "id_project": req.projectid };
|
69
|
+
|
70
|
+
|
71
|
+
/**
|
72
|
+
* DATE RANGE */
|
73
|
+
if (req.query.start_date && req.query.end_date) {
|
74
|
+
winston.debug('Activity ROUTE - REQ QUERY start_date ', req.query.start_date);
|
75
|
+
winston.debug('Activity ROUTE - REQ QUERY end_date ', req.query.end_date);
|
76
|
+
|
77
|
+
/**
|
78
|
+
* USING MOMENT */
|
79
|
+
var startDate = moment(req.query.start_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
|
80
|
+
var endDate = moment(req.query.end_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
|
81
|
+
|
82
|
+
winston.debug('Activity ROUTE - REQ QUERY FORMATTED START DATE ', startDate);
|
83
|
+
winston.debug('Activity ROUTE - REQ QUERY FORMATTED END DATE ', endDate);
|
84
|
+
|
85
|
+
// ADD ONE DAY TO THE END DAY
|
86
|
+
var date = new Date(endDate);
|
87
|
+
var newdate = new Date(date);
|
88
|
+
var endDate_plusOneDay = newdate.setDate(newdate.getDate() + 1);
|
89
|
+
winston.debug('Activity ROUTE - REQ QUERY FORMATTED END DATE + 1 DAY ', endDate_plusOneDay);
|
90
|
+
// var endDate_plusOneDay = moment('2018-09-03').add(1, 'd')
|
91
|
+
// var endDate_plusOneDay = endDate.add(1).day();
|
92
|
+
// var toDate = new Date(Date.parse(endDate_plusOneDay)).toISOString()
|
93
|
+
|
94
|
+
query.createdAt = { $gte: new Date(Date.parse(startDate)).toISOString(), $lte: new Date(endDate_plusOneDay).toISOString() }
|
95
|
+
winston.debug('Activity ROUTE - QUERY CREATED AT ', query.createdAt);
|
96
|
+
|
97
|
+
} else if (req.query.start_date && !req.query.end_date) {
|
98
|
+
winston.debug('Activity ROUTE - REQ QUERY END DATE IS EMPTY (so search only for start date)');
|
99
|
+
var startDate = moment(req.query.start_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
|
100
|
+
|
101
|
+
query.createdAt = { $gte: new Date(Date.parse(startDate)).toISOString() };
|
102
|
+
winston.debug('Activity ROUTE - QUERY CREATED AT (only for start date)', query.createdAt);
|
103
|
+
}
|
104
|
+
|
105
|
+
if (req.query.agent_id) {
|
106
|
+
winston.debug('req.query.agent', req.query.agent_id);
|
107
|
+
query["$or"] = [
|
108
|
+
{ "target.object.id_user._id": new ObjectId(req.query.agent_id) },
|
109
|
+
{ "actor.id": req.query.agent_id }
|
110
|
+
];
|
111
|
+
|
112
|
+
// query["$or"] = [
|
113
|
+
// { $or: [{"target.object.id_user._id": new ObjectId(req.query.agent_id) }, { "actor.id": new ObjectId(req.query.agent_id) }]}
|
114
|
+
// ];
|
115
|
+
}
|
116
|
+
|
117
|
+
if (req.query.activities) {
|
118
|
+
winston.debug('req.query.activities:', req.query.activities);
|
119
|
+
|
120
|
+
let verbs = req.query.activities.split(",")
|
121
|
+
|
122
|
+
winston.debug('verbs: ', verbs);
|
123
|
+
query.verb = verbs;
|
124
|
+
|
125
|
+
// to test
|
126
|
+
// query.verb = ['PROJECT_USER_DELETE','PROJECT_USER_INVITE']
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
var direction = -1; //-1 descending , 1 ascending
|
131
|
+
if (req.query.direction) {
|
132
|
+
direction = req.query.direction;
|
133
|
+
}
|
134
|
+
winston.debug("direction", direction);
|
135
|
+
|
136
|
+
var sortField = "createdAt";
|
137
|
+
if (req.query.sort) {
|
138
|
+
sortField = req.query.sort;
|
139
|
+
}
|
140
|
+
winston.debug("sortField", sortField);
|
141
|
+
|
142
|
+
var sortQuery = {};
|
143
|
+
sortQuery[sortField] = direction;
|
144
|
+
|
145
|
+
winston.debug("sort query", sortQuery);
|
146
|
+
|
147
|
+
winston.debug('Activity ROUTE - Activity.find(query) ', query)
|
148
|
+
return Activity.find(query).
|
149
|
+
skip(skip).limit(limit).
|
150
|
+
sort(sortQuery).
|
151
|
+
exec(function (err, activities) {
|
152
|
+
if (err) {
|
153
|
+
winston.error('Activity ROUTE - REQUEST FIND ERR ', err)
|
154
|
+
return (err);
|
155
|
+
}
|
156
|
+
|
157
|
+
return Activity.count(query, function (err, totalRowCount) {
|
158
|
+
if (err) {
|
159
|
+
winston.error('Activity ROUTE - REQUEST FIND ERR ', err)
|
160
|
+
return (err);
|
161
|
+
}
|
162
|
+
|
163
|
+
var objectToReturn = {
|
164
|
+
perPage: limit,
|
165
|
+
count: totalRowCount,
|
166
|
+
activities: activities
|
167
|
+
};
|
168
|
+
winston.debug('Activity ROUTE - objectToReturn ', objectToReturn);
|
169
|
+
|
170
|
+
objectToReturn.activities.forEach(activity => {
|
171
|
+
winston.debug('Activity ROUTE - activity.target ', activity.target);
|
172
|
+
if (activity.target && activity.target.object && activity.target.object.id_user) {
|
173
|
+
winston.debug('Activity ROUTE - *** 9-+activity.target.id_user ', activity.target.object.id_user._id);
|
174
|
+
}
|
175
|
+
});
|
176
|
+
|
177
|
+
return res.json(objectToReturn);
|
178
|
+
});
|
179
|
+
});
|
180
|
+
});
|
181
|
+
|
182
|
+
// DOWNLOAD ACTIVITIES AS CSV
|
183
|
+
router.get('/csv', function (req, res) {
|
184
|
+
var limit = 100000; // Number of activities per page
|
185
|
+
var page = 0;
|
186
|
+
|
187
|
+
if (req.query.page) {
|
188
|
+
page = req.query.page;
|
189
|
+
}
|
190
|
+
|
191
|
+
var skip = page * limit;
|
192
|
+
winston.debug('Activity ROUTE - SKIP PAGE ', skip);
|
193
|
+
// winston.debug('Activity ROUTE - SKIP PAGE ', skip);
|
194
|
+
|
195
|
+
winston.debug('Activity ROUTE - QUERY ', req.query)
|
196
|
+
|
197
|
+
|
198
|
+
var query = { "id_project": req.projectid };
|
199
|
+
|
200
|
+
/**
|
201
|
+
* DATE RANGE */
|
202
|
+
if (req.query.start_date && req.query.end_date) {
|
203
|
+
winston.debug('Activity ROUTE - REQ QUERY start_date ', req.query.start_date);
|
204
|
+
winston.debug('Activity ROUTE - REQ QUERY end_date ', req.query.end_date);
|
205
|
+
|
206
|
+
/**
|
207
|
+
* USING MOMENT */
|
208
|
+
var startDate = moment(req.query.start_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
|
209
|
+
var endDate = moment(req.query.end_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
|
210
|
+
|
211
|
+
winston.debug('Activity ROUTE - REQ QUERY FORMATTED START DATE ', startDate);
|
212
|
+
winston.debug('Activity ROUTE - REQ QUERY FORMATTED END DATE ', endDate);
|
213
|
+
|
214
|
+
// ADD ONE DAY TO THE END DAY
|
215
|
+
var date = new Date(endDate);
|
216
|
+
var newdate = new Date(date);
|
217
|
+
var endDate_plusOneDay = newdate.setDate(newdate.getDate() + 1);
|
218
|
+
winston.debug('Activity ROUTE - REQ QUERY FORMATTED END DATE + 1 DAY ', endDate_plusOneDay);
|
219
|
+
// var endDate_plusOneDay = moment('2018-09-03').add(1, 'd')
|
220
|
+
// var endDate_plusOneDay = endDate.add(1).day();
|
221
|
+
// var toDate = new Date(Date.parse(endDate_plusOneDay)).toISOString()
|
222
|
+
|
223
|
+
query.createdAt = { $gte: new Date(Date.parse(startDate)).toISOString(), $lte: new Date(endDate_plusOneDay).toISOString() }
|
224
|
+
winston.debug('Activity ROUTE - QUERY CREATED AT ', query.createdAt);
|
225
|
+
|
226
|
+
} else if (req.query.start_date && !req.query.end_date) {
|
227
|
+
winston.debug('Activity ROUTE - REQ QUERY END DATE IS EMPTY (so search only for start date)');
|
228
|
+
var startDate = moment(req.query.start_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
|
229
|
+
|
230
|
+
query.createdAt = { $gte: new Date(Date.parse(startDate)).toISOString() };
|
231
|
+
winston.debug('Activity ROUTE - QUERY CREATED AT (only for start date)', query.createdAt);
|
232
|
+
}
|
233
|
+
|
234
|
+
if (req.query.agent_id) {
|
235
|
+
winston.debug('req.query.agent', req.query.agent_id);
|
236
|
+
query["$or"] = [
|
237
|
+
{ "target.object.id_user._id": new ObjectId(req.query.agent_id) },
|
238
|
+
{ "actor.id": req.query.agent_id }
|
239
|
+
];
|
240
|
+
|
241
|
+
// query["$or"] = [
|
242
|
+
// { $or: [{"target.object.id_user._id": new ObjectId(req.query.agent_id) }, { "actor.id": new ObjectId(req.query.agent_id) }]}
|
243
|
+
// ];
|
244
|
+
}
|
245
|
+
|
246
|
+
if (req.query.activities) {
|
247
|
+
winston.debug('req.query.activities:', req.query.activities);
|
248
|
+
|
249
|
+
let verbs = req.query.activities.split(",")
|
250
|
+
|
251
|
+
winston.debug('verbs: ', verbs);
|
252
|
+
query.verb = verbs;
|
253
|
+
|
254
|
+
// to test
|
255
|
+
// query.verb = ['PROJECT_USER_DELETE','PROJECT_USER_INVITE']
|
256
|
+
}
|
257
|
+
|
258
|
+
if (req.query.lang) {
|
259
|
+
winston.debug('req.query.lang:', req.query.lang);
|
260
|
+
var lang = req.query.lang;
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
var direction = -1; //-1 descending , 1 ascending
|
265
|
+
if (req.query.direction) {
|
266
|
+
direction = req.query.direction;
|
267
|
+
}
|
268
|
+
winston.debug("direction", direction);
|
269
|
+
|
270
|
+
var sortField = "createdAt";
|
271
|
+
if (req.query.sort) {
|
272
|
+
sortField = req.query.sort;
|
273
|
+
}
|
274
|
+
winston.debug("sortField", sortField);
|
275
|
+
|
276
|
+
var sortQuery = {};
|
277
|
+
sortQuery[sortField] = direction;
|
278
|
+
|
279
|
+
winston.debug("sort query", sortQuery);
|
280
|
+
|
281
|
+
winston.debug('Activity ROUTE - Activity.find(query) ', query)
|
282
|
+
return Activity.find(query).
|
283
|
+
skip(skip).limit(limit).
|
284
|
+
lean().
|
285
|
+
sort(sortQuery).
|
286
|
+
exec(function (err, activities) {
|
287
|
+
if (err) {
|
288
|
+
winston.error('Activity ROUTE - REQUEST FIND ERR ', err)
|
289
|
+
return (err);
|
290
|
+
}
|
291
|
+
winston.debug('activities: ', activities);
|
292
|
+
|
293
|
+
|
294
|
+
// csvActivitiesToReturn = [];
|
295
|
+
csvActivitiesToReturn = buildCsv(activities, lang);
|
296
|
+
|
297
|
+
|
298
|
+
winston.debug('csvActivitiesToReturn: ', csvActivitiesToReturn);
|
299
|
+
|
300
|
+
return res.csv(csvActivitiesToReturn, true);
|
301
|
+
|
302
|
+
|
303
|
+
});
|
304
|
+
|
305
|
+
|
306
|
+
function translateString(string, lang) {
|
307
|
+
var translatedString = ''
|
308
|
+
|
309
|
+
if (string === 'hasChanged') {
|
310
|
+
if (lang === 'it') {
|
311
|
+
translatedString = 'ha cambiato'
|
312
|
+
} else {
|
313
|
+
translatedString = 'has changed'
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
if (string === 'hisStatus') {
|
318
|
+
if (lang === 'it') {
|
319
|
+
translatedString = ' il suo stato'
|
320
|
+
} else {
|
321
|
+
translatedString = ' his status'
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
if (string === 'theAvailabilityStatusOf') {
|
326
|
+
if (lang === 'it') {
|
327
|
+
translatedString = ' lo stato di disponibilità di'
|
328
|
+
} else {
|
329
|
+
translatedString = ' the availability status of'
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
if (string === 'theRoleOf') {
|
335
|
+
if (lang === 'it') {
|
336
|
+
translatedString = ' il ruolo di'
|
337
|
+
} else {
|
338
|
+
translatedString = ' the role of'
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
342
|
+
if (string === 'intoUnavailable') {
|
343
|
+
if (lang === 'it') {
|
344
|
+
translatedString = ' in non disponibile'
|
345
|
+
} else {
|
346
|
+
translatedString = ' into unavailable'
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
350
|
+
if (string === 'intoAvailable') {
|
351
|
+
if (lang === 'it') {
|
352
|
+
translatedString = ' in disponibile'
|
353
|
+
} else {
|
354
|
+
translatedString = ' into available'
|
355
|
+
}
|
356
|
+
}
|
357
|
+
|
358
|
+
if (string === 'intoAdministrator') {
|
359
|
+
if (lang === 'it') {
|
360
|
+
translatedString = ' in Amministratore'
|
361
|
+
} else {
|
362
|
+
translatedString = ' into Administrator'
|
363
|
+
}
|
364
|
+
}
|
365
|
+
|
366
|
+
if (string === 'intoAgent') {
|
367
|
+
if (lang === 'it') {
|
368
|
+
translatedString = ' in Agente'
|
369
|
+
} else {
|
370
|
+
translatedString = ' into Agent'
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
|
375
|
+
if (string === 'HasRemoved') {
|
376
|
+
if (lang === 'it') {
|
377
|
+
translatedString = ' ha rimosso'
|
378
|
+
} else {
|
379
|
+
translatedString = ' has removed'
|
380
|
+
}
|
381
|
+
}
|
382
|
+
|
383
|
+
if (string === 'FromTheProject') {
|
384
|
+
if (lang === 'it') {
|
385
|
+
translatedString = ' dal progetto'
|
386
|
+
} else {
|
387
|
+
translatedString = ' from the project'
|
388
|
+
}
|
389
|
+
}
|
390
|
+
|
391
|
+
if (string === 'HasInvited') {
|
392
|
+
if (lang === 'it') {
|
393
|
+
translatedString = ' ha invitato'
|
394
|
+
} else {
|
395
|
+
translatedString = ' has invited'
|
396
|
+
}
|
397
|
+
}
|
398
|
+
|
399
|
+
if (string === 'ToTakeOnTheRoleOf') {
|
400
|
+
if (lang === 'it') {
|
401
|
+
translatedString = ' ad assumere il ruolo di'
|
402
|
+
} else {
|
403
|
+
translatedString = ' to take on the role of'
|
404
|
+
}
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
return translatedString
|
414
|
+
}
|
415
|
+
|
416
|
+
function buildMsg_REQUEST_CREATE(lang, activity) {
|
417
|
+
winston.debug('buildMsg_REQUEST_CREATE - lang: ', lang, ' activity: ', activity)
|
418
|
+
}
|
419
|
+
|
420
|
+
function buildMsg_PROJECT_USER_INVITE(actor_name, target_fullname, lang, activity) {
|
421
|
+
var action = '';
|
422
|
+
|
423
|
+
|
424
|
+
action = translateString('HasInvited', lang) + ' ' + target_fullname
|
425
|
+
|
426
|
+
|
427
|
+
// email with round brackets if it not is a pendinginvitation
|
428
|
+
if (activity.target && activity.target.type !== 'pendinginvitation') {
|
429
|
+
|
430
|
+
if (activity.actionObj && activity.actionObj.email) {
|
431
|
+
|
432
|
+
action = action + '(' + activity.actionObj.email + ')'
|
433
|
+
|
434
|
+
} else {
|
435
|
+
|
436
|
+
// email without round brackets if it is a pendinginvitation
|
437
|
+
|
438
|
+
action = action + activity.actionObj.email
|
439
|
+
}
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
action = action + translateString('ToTakeOnTheRoleOf', lang)
|
444
|
+
|
445
|
+
|
446
|
+
return message = actor_name + action
|
447
|
+
|
448
|
+
}
|
449
|
+
|
450
|
+
|
451
|
+
function buildMsg_PROJECT_USER_DELETE(actor_name, target_fullname, lang) {
|
452
|
+
var action = '';
|
453
|
+
action = translateString('HasRemoved', lang) + ' ' + target_fullname + translateString('FromTheProject', lang)
|
454
|
+
|
455
|
+
return message = actor_name + action
|
456
|
+
|
457
|
+
}
|
458
|
+
|
459
|
+
function buildMsg_PROJECT_USER_UPDATE(actor_name, target_fullname, lang, activity) {
|
460
|
+
|
461
|
+
var action = '';
|
462
|
+
|
463
|
+
action = translateString('hasChanged', lang)
|
464
|
+
// if (lang === 'it') {
|
465
|
+
// action = 'ha cambiato'
|
466
|
+
// } else {
|
467
|
+
// action = 'has changed'
|
468
|
+
// }
|
469
|
+
|
470
|
+
if (activity.actor && activity.actor.id) {
|
471
|
+
if (activity.target &&
|
472
|
+
activity.target.object &&
|
473
|
+
activity.target.object.id_user &&
|
474
|
+
activity.target.object.id_user._id) {
|
475
|
+
|
476
|
+
var target_user_id = JSON.stringify(activity.target.object.id_user._id).replace(/['"]+/g, '')
|
477
|
+
|
478
|
+
if (activity.actor.id === target_user_id) {
|
479
|
+
// USE CASE 1: THE TARGET OF THE ACTION IS THE CURRENT USER (YOURSELF)
|
480
|
+
|
481
|
+
action = action + translateString('hisStatus', lang)
|
482
|
+
|
483
|
+
} else {
|
484
|
+
|
485
|
+
// USE CASE 2: THE TARGET OF THE ACTION IS ANOTHER USER (NOT THE LOGGED USER)
|
486
|
+
winston.debug('here + activity.actionObj.user_available ', activity.actionObj.user_available)
|
487
|
+
if (activity.actionObj && activity.actionObj.user_available === false || activity.actionObj.user_available === true) {
|
488
|
+
|
489
|
+
winston.debug('here ++')
|
490
|
+
|
491
|
+
action = action + translateString('theAvailabilityStatusOf', lang)
|
492
|
+
|
493
|
+
// if (lang === 'it') {
|
494
|
+
// action = action + ' lo stato di disponibilità di'
|
495
|
+
// } else {
|
496
|
+
// action = action + ' the availability status of'
|
497
|
+
// }
|
498
|
+
|
499
|
+
}
|
500
|
+
else if (activity.actionObj && activity.actionObj.role) {
|
501
|
+
|
502
|
+
action = action + translateString('theRoleOf', lang)
|
503
|
+
|
504
|
+
// if (lang === 'it') {
|
505
|
+
// action = action + ' il ruolo di'
|
506
|
+
// } else {
|
507
|
+
// action = action + ' the role of'
|
508
|
+
// }
|
509
|
+
}
|
510
|
+
|
511
|
+
action = action + ' ' + target_fullname
|
512
|
+
|
513
|
+
}
|
514
|
+
|
515
|
+
if (activity.actionObj && activity.actionObj.user_available === false) {
|
516
|
+
|
517
|
+
action = action + translateString('intoUnavailable', lang);
|
518
|
+
|
519
|
+
// if (lang === 'it') {
|
520
|
+
// action = action + ' in non disponibile'
|
521
|
+
// } else {
|
522
|
+
// action = action + ' into unavailable'
|
523
|
+
// }
|
524
|
+
|
525
|
+
} else if (activity.actionObj && activity.actionObj.user_available === true) {
|
526
|
+
|
527
|
+
action = action + translateString('intoAvailable', lang);
|
528
|
+
|
529
|
+
// if (lang === 'it') {
|
530
|
+
// action = action + ' in disponibile'
|
531
|
+
// } else {
|
532
|
+
// action = action + ' into available'
|
533
|
+
// }
|
534
|
+
}
|
535
|
+
|
536
|
+
if (activity.actionObj && activity.actionObj.role === 'admin') {
|
537
|
+
|
538
|
+
action = action + translateString('intoAdministrator', lang);
|
539
|
+
|
540
|
+
// if (lang === 'it') {
|
541
|
+
// action = action + ' in Amministratore'
|
542
|
+
// } else {
|
543
|
+
// action = action + ' into Administrator'
|
544
|
+
// }
|
545
|
+
|
546
|
+
} else if (activity.actionObj && activity.actionObj.role === 'agent') {
|
547
|
+
|
548
|
+
action = action + translateString('intoAgent', lang);
|
549
|
+
|
550
|
+
// if (lang === 'it') {
|
551
|
+
// action = action + ' in Agente'
|
552
|
+
// } else {
|
553
|
+
// action = action + ' into Agent'
|
554
|
+
// }
|
555
|
+
|
556
|
+
}
|
557
|
+
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
|
567
|
+
return message = actor_name + ' ' + action
|
568
|
+
}
|
569
|
+
|
570
|
+
|
571
|
+
function buildCsv(activities, lang) {
|
572
|
+
csvActivitiesToReturn = []
|
573
|
+
activities.forEach(activity => {
|
574
|
+
|
575
|
+
// if (lang) {
|
576
|
+
winston.debug('buildCsv lang: ', lang);
|
577
|
+
|
578
|
+
var actor_name = '';
|
579
|
+
var target_fullname = '';
|
580
|
+
if (activity.actor) {
|
581
|
+
actor_name = activity.actor.name;
|
582
|
+
|
583
|
+
}
|
584
|
+
|
585
|
+
if (activity.target &&
|
586
|
+
activity.target.object &&
|
587
|
+
activity.target.object.id_user &&
|
588
|
+
activity.target.object.id_user.firstname) {
|
589
|
+
|
590
|
+
target_fullname = activity.target.object.id_user.firstname
|
591
|
+
|
592
|
+
if (activity.target.object.id_user.lastname) {
|
593
|
+
|
594
|
+
target_fullname = target_fullname + ' ' + activity.target.object.id_user.lastname
|
595
|
+
}
|
596
|
+
|
597
|
+
}
|
598
|
+
|
599
|
+
if (activity.verb === "PROJECT_USER_UPDATE") {
|
600
|
+
var message = buildMsg_PROJECT_USER_UPDATE(actor_name, target_fullname, lang, activity)
|
601
|
+
}
|
602
|
+
|
603
|
+
if (activity.verb === "PROJECT_USER_DELETE") {
|
604
|
+
var message = buildMsg_PROJECT_USER_DELETE(actor_name, target_fullname, lang)
|
605
|
+
}
|
606
|
+
|
607
|
+
if (activity.verb === "PROJECT_USER_INVITE") {
|
608
|
+
var message = buildMsg_PROJECT_USER_INVITE(actor_name, target_fullname, lang, activity)
|
609
|
+
}
|
610
|
+
|
611
|
+
if (activity.verb === "REQUEST_CREATE") {
|
612
|
+
var message = buildMsg_REQUEST_CREATE(lang, activity)
|
613
|
+
}
|
614
|
+
|
615
|
+
|
616
|
+
if (activity.actionObj && activity.actionObj.email) {
|
617
|
+
var actionObj_email = activity.actionObj.email;
|
618
|
+
} else {
|
619
|
+
var actionObj_email = ""
|
620
|
+
}
|
621
|
+
|
622
|
+
if (activity.actionObj && activity.actionObj.id_project) {
|
623
|
+
var actionObj_id_project = activity.actionObj.id_project;
|
624
|
+
} else {
|
625
|
+
var actionObj_id_project = ""
|
626
|
+
}
|
627
|
+
|
628
|
+
if (activity.actionObj && activity.actionObj.project_name) {
|
629
|
+
var actionObj_project_name = activity.actionObj.project_name;
|
630
|
+
} else {
|
631
|
+
var actionObj_project_name = ""
|
632
|
+
}
|
633
|
+
|
634
|
+
if (activity.actionObj && activity.actionObj.role) {
|
635
|
+
var actionObj_role = activity.actionObj.role;
|
636
|
+
} else {
|
637
|
+
var actionObj_role = ""
|
638
|
+
}
|
639
|
+
|
640
|
+
if (activity.actionObj && activity.actionObj.user_available) {
|
641
|
+
var actionObj_user_available = activity.actionObj.user_available;
|
642
|
+
} else {
|
643
|
+
var actionObj_user_available = ""
|
644
|
+
}
|
645
|
+
|
646
|
+
if (activity.target) {
|
647
|
+
var target_id = activity.target.id
|
648
|
+
var target_type = activity.target.type
|
649
|
+
}
|
650
|
+
|
651
|
+
if (activity.target && activity.target.object) {
|
652
|
+
var target_createdAt = activity.target.object.createdAt;
|
653
|
+
var target_createdBy = activity.target.object.createdBy;
|
654
|
+
var target_role = activity.target.object.role;
|
655
|
+
var target_user_available = activity.target.object.user_available;
|
656
|
+
// var target_id = activity.target.object._id;
|
657
|
+
}
|
658
|
+
|
659
|
+
if (activity.target && activity.target.object && activity.target.object.id_user) {
|
660
|
+
var target_user_fullname = activity.target.object.id_user.firstname + " " + activity.target.object.id_user.lastname;
|
661
|
+
var target_user_id = activity.target.object.id_user._id
|
662
|
+
} else {
|
663
|
+
var target_user_fullname = "";
|
664
|
+
var target_user_id = "";
|
665
|
+
}
|
666
|
+
|
667
|
+
if (activity.target && activity.target.object && activity.target.object.email) {
|
668
|
+
var target_email = activity.target.object.email;
|
669
|
+
} else {
|
670
|
+
var target_email = "";
|
671
|
+
}
|
672
|
+
|
673
|
+
|
674
|
+
csvActivitiesToReturn.push({
|
675
|
+
'message': message,
|
676
|
+
"activity_id": activity._id,
|
677
|
+
"createdAt": activity.createdAt,
|
678
|
+
"updatedAt": activity.updatedAt,
|
679
|
+
"project_id": activity.id_project,
|
680
|
+
"actor_name": activity.actor.name,
|
681
|
+
"actor_id": activity.actor.id,
|
682
|
+
"actor_type": activity.actor.type,
|
683
|
+
"verb": activity.verb,
|
684
|
+
"target_user_fullname": target_user_fullname,
|
685
|
+
"target_email": target_email,
|
686
|
+
"target_type": target_type,
|
687
|
+
"target_user_id": target_user_id,
|
688
|
+
"actionObj_email": actionObj_email,
|
689
|
+
"actionObj_id_project": actionObj_id_project,
|
690
|
+
"actionObj_project_name": actionObj_project_name,
|
691
|
+
"actionObj_role": actionObj_role,
|
692
|
+
"actionObj_user_available": actionObj_user_available,
|
693
|
+
"target_id": target_id,
|
694
|
+
"target_createdAt": target_createdAt,
|
695
|
+
"target_createdBy": target_createdBy,
|
696
|
+
"target_role": target_role,
|
697
|
+
"target_user_available": target_user_available,
|
698
|
+
})
|
699
|
+
|
700
|
+
});
|
701
|
+
|
702
|
+
return csvActivitiesToReturn
|
703
|
+
}
|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
});
|
708
|
+
|
709
|
+
|
710
|
+
module.exports = router;
|