@tiledesk/tiledesk-server 2.19.13 → 2.19.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,432 +1,754 @@
1
1
  const authEvent = require('../../event/authEvent');
2
2
  const requestEvent = require('../../event/requestEvent');
3
- var Activity = require('./models/activity');
4
- var winston = require('../../config/winston');
3
+ const botEvent = require('../../event/botEvent');
4
+ const kbEvent = require('../../event/kbEvent');
5
+ const assignmentContextUtil = require('../../utils/assignmentContextUtil');
6
+ const projectUserUpdateContextUtil = require('../../utils/projectUserUpdateContextUtil');
7
+ const activityActorUtil = require('../../utils/activityActorUtil');
8
+ const Activity = require('./models/activity');
9
+ const winston = require('../../config/winston');
10
+
11
+ function resolveEventKey(baseKey, queueEnabled) {
12
+ return queueEnabled ? `${baseKey}.queue` : baseKey;
13
+ }
14
+
15
+ async function save(activity) {
16
+ try {
17
+ await activity.save();
18
+ winston.debug('Activity saved', activity.toObject());
19
+ } catch (err) {
20
+ winston.error('Error saving activity ', { activity: activity.toObject(), err: err });
21
+ }
22
+ }
23
+
24
+ function toObject(doc) {
25
+ if (!doc) {
26
+ return doc;
27
+ }
28
+ if (doc.toObject) {
29
+ return doc.toObject();
30
+ }
31
+ return doc;
32
+ }
33
+
34
+ function faqKbTarget(chatbot) {
35
+ const object = toObject(chatbot);
36
+ return {
37
+ type: 'faq_kb',
38
+ id: activityActorUtil.resolveId(object && object._id),
39
+ object: object
40
+ };
41
+ }
42
+
43
+ function namespaceTarget(namespaceId, namespaceObject) {
44
+ const object = namespaceObject ? toObject(namespaceObject) : { id: namespaceId };
45
+ return {
46
+ type: 'kb_namespace',
47
+ id: activityActorUtil.resolveId(namespaceId || (object && object.id)),
48
+ object: object
49
+ };
50
+ }
51
+
52
+ function kbContentTarget(kbId, kbObject) {
53
+ const object = kbObject ? toObject(kbObject) : { _id: kbId };
54
+ return {
55
+ type: 'kb_content',
56
+ id: activityActorUtil.resolveId(kbId || (object && object._id)),
57
+ object: object
58
+ };
59
+ }
60
+
61
+ function resolveInvitedProjectUser(event) {
62
+ return event.savedProject_userPopulated ||
63
+ event.updatedProject_userPopulated ||
64
+ event.updatedPuserPopulated;
65
+ }
66
+
67
+ function buildProjectUserInviteActivity(event, pending) {
68
+ if (!event || !event.req) {
69
+ return null;
70
+ }
71
+
72
+ const body = event.req.body || {};
73
+ const actionObj = {
74
+ email: body.email,
75
+ role: body.role,
76
+ user_available: body.user_available,
77
+ inviteType: pending ? 'pending' : 'registered'
78
+ };
79
+ const actor = activityActorUtil.actorFromReq(event.req);
80
+
81
+ if (pending) {
82
+ const pendingInvitation = toObject(event.savedPendingInvitation);
83
+ if (!pendingInvitation) {
84
+ return null;
85
+ }
86
+ return new Activity({
87
+ id_project: event.req.projectid,
88
+ actor: actor,
89
+ verb: 'PROJECT_USER_INVITE',
90
+ actionObj: actionObj,
91
+ target: {
92
+ type: 'pendinginvitation',
93
+ id: activityActorUtil.resolveId(pendingInvitation._id),
94
+ object: pendingInvitation
95
+ }
96
+ });
97
+ }
98
+
99
+ const projectUser = toObject(resolveInvitedProjectUser(event));
100
+ if (!projectUser) {
101
+ return null;
102
+ }
103
+
104
+ return new Activity({
105
+ id_project: projectUser.id_project || event.req.projectid,
106
+ actor: actor,
107
+ verb: 'PROJECT_USER_INVITE',
108
+ actionObj: actionObj,
109
+ target: {
110
+ type: 'project_user',
111
+ id: activityActorUtil.resolveId(projectUser._id),
112
+ object: projectUser
113
+ }
114
+ });
115
+ }
116
+
117
+ function buildProjectUserDeleteActivity(event) {
118
+ if (!event || !event.req) {
119
+ return null;
120
+ }
121
+
122
+ const projectUser = toObject(event.project_userPopulated);
123
+ if (!projectUser) {
124
+ return null;
125
+ }
126
+
127
+ const user = projectUser.id_user;
128
+ const actor = activityActorUtil.actorFromReq(event.req);
129
+
130
+ return new Activity({
131
+ id_project: projectUser.id_project || event.req.projectid,
132
+ actor: actor,
133
+ verb: 'PROJECT_USER_DELETE',
134
+ actionObj: {
135
+ deleteType: event.deleteType || 'soft',
136
+ role: projectUser.role,
137
+ email: user && user.email
138
+ },
139
+ target: {
140
+ type: 'project_user',
141
+ id: activityActorUtil.resolveId(projectUser._id),
142
+ object: projectUser
143
+ }
144
+ });
145
+ }
5
146
 
6
147
  class ActivityArchiver {
7
148
 
8
- listen() {
149
+ listen() {
150
+
151
+ winston.debug('ActivityArchiver listen');
152
+ console.log("\n\nActivityArchiver listen");
9
153
 
10
- winston.debug('ActivityArchiver listen');
154
+ const enabled = process.env.ACTIVITY_HISTORY_ENABLED || "false";
155
+ winston.debug('ActivityArchiver enabled:' + enabled);
156
+ console.log("\n\nActivityArchiver enabled:" + enabled);
157
+ if (enabled === "true") {
158
+ winston.verbose('ActivityArchiver enabled');
159
+ } else {
160
+ winston.info('ActivityArchiver disabled');
161
+ return 0;
162
+ }
163
+
164
+ if (process.env.MONGOOSE_SYNCINDEX) {
165
+ Activity.syncIndexes();
166
+ winston.info("Activity.syncIndexes called");
167
+ }
11
168
 
12
- var enabled = process.env.ACTIVITY_HISTORY_ENABLED || "false";
13
- winston.debug('ActivityArchiver enabled:'+enabled);
169
+
170
+ // ********** AUTH EVENTS **********
14
171
 
15
- if (enabled==="true") {
16
- winston.debug('ActivityArchiver enabled');
17
- }else {
18
- winston.info('ActivityArchiver disabled');
172
+ // Works only if worker is disabled
173
+ // Doesn't work if job_worker enabled because queue.worker is disabled
174
+ const authProjectUserInvitePendingKey = resolveEventKey('project_user.invite.pending', authEvent.queueEnabled);
175
+ winston.debug('ActivityArchiver authProjectUserInvitePendingKey: ' + authProjectUserInvitePendingKey);
176
+
177
+ authEvent.on(authProjectUserInvitePendingKey, function (event) {
178
+ setImmediate(() => {
179
+ try {
180
+ if (event.skipArchive) {
181
+ return 0;
182
+ }
183
+ const activity = buildProjectUserInviteActivity(event, true);
184
+ if (!activity) {
185
+ return winston.debug('ActivityArchiver skipping project_user.invite.pending: missing data');
186
+ }
187
+ save(activity);
188
+ } catch (e) {
189
+ winston.error('ActivityArchiver error saving project_user.invite.pending activity', e);
190
+ }
191
+ });
192
+ });
193
+
194
+
195
+ const authProjectUserInviteKey = resolveEventKey('project_user.invite', authEvent.queueEnabled);
196
+ winston.debug('ActivityArchiver authProjectUserInviteKey: ' + authProjectUserInviteKey);
197
+
198
+ authEvent.on(authProjectUserInviteKey, function (event) {
199
+ setImmediate(() => {
200
+ try {
201
+ if (event.skipArchive) {
202
+ return 0;
203
+ }
204
+ const activity = buildProjectUserInviteActivity(event, false);
205
+ if (!activity) {
206
+ return winston.debug('ActivityArchiver skipping project_user.invite: missing data');
207
+ }
208
+ save(activity);
209
+ } catch (e) {
210
+ winston.error('ActivityArchiver error saving project_user.invite activity', e);
211
+ }
212
+ });
213
+ });
214
+
215
+
216
+ const authProjectUserUpdateKey = resolveEventKey('project_user.update', authEvent.queueEnabled);
217
+ winston.debug('ActivityArchiver authProjectUserUpdateKey: ' + authProjectUserUpdateKey);
218
+
219
+ authEvent.on(authProjectUserUpdateKey, function (event) {
220
+ setImmediate(() => {
221
+ if (event.skipArchive) {
19
222
  return 0;
20
223
  }
21
224
 
22
- if (process.env.MONGOOSE_SYNCINDEX) {
23
- Activity.syncIndexes();
24
- winston.info("Activity.syncIndexes called");
225
+ let project_user = undefined;
226
+ if (event.updatedProject_userPopulated.toObject) {
227
+ project_user = event.updatedProject_userPopulated.toObject()
228
+ } else {
229
+ project_user = event.updatedProject_userPopulated;
25
230
  }
231
+
232
+ winston.debug('ActivityArchiver authProjectUserUpdateKey event: ', event);
233
+
234
+ if (!event.req.user) {
235
+ return winston.debug('ActivityArchiver skipping archive empty user'); //from i think chat21webhook
236
+ }
237
+
238
+ const fallbackTargetUserId = projectUserUpdateContextUtil.resolveUserId(
239
+ project_user.id_user && project_user.id_user._id ? project_user.id_user : project_user.id_user
240
+ );
241
+ let updateContext = event.updateContext || projectUserUpdateContextUtil.buildProjectUserUpdateContext(
242
+ event.req,
243
+ event.previousUserAvailable,
244
+ event.previousProfileStatus,
245
+ fallbackTargetUserId
246
+ );
247
+ if (event.previousUserAvailable !== undefined && updateContext.previousUserAvailable === undefined) {
248
+ updateContext.previousUserAvailable = event.previousUserAvailable;
249
+ }
250
+ if (event.previousProfileStatus !== undefined && updateContext.previousProfileStatus === undefined) {
251
+ updateContext.previousProfileStatus = event.previousProfileStatus;
252
+ }
253
+ let verb = projectUserUpdateContextUtil.verbForProjectUserUpdate(event.req.body, updateContext);
254
+ const reconciled = projectUserUpdateContextUtil.reconcileAvailabilityVerb(
255
+ event,
256
+ project_user,
257
+ verb,
258
+ updateContext
259
+ );
260
+ verb = reconciled.verb;
261
+ updateContext = reconciled.updateContext;
262
+ const actor = reconciled.actor ||
263
+ projectUserUpdateContextUtil.actorFromProjectUserUpdate(event, verb, updateContext);
264
+ const newStatus = projectUserUpdateContextUtil.availabilityStatusLabel({
265
+ user_available: project_user.user_available,
266
+ profileStatus: project_user.profileStatus
267
+ });
268
+
269
+ var activity = new Activity({
270
+ id_project: event.updatedProject_userPopulated.id_project,
271
+ actor: actor,
272
+ verb: verb,
273
+ actionObj: Object.assign({}, event.req.body, {
274
+ newStatus: newStatus,
275
+ updateType: updateContext.updateType,
276
+ source: updateContext.source
277
+ }),
278
+ target: {
279
+ type: "project_user",
280
+ id: event.updatedProject_userPopulated._id.toString(),
281
+ object: project_user
282
+ }
283
+ });
284
+ save(activity);
285
+ });
286
+ });
287
+
288
+
289
+ const authProjectUserDeleteKey = resolveEventKey('project_user.delete', authEvent.queueEnabled);
290
+ winston.debug('ActivityArchiver authProjectUserDeleteKey: ' + authProjectUserDeleteKey);
291
+
292
+ authEvent.on(authProjectUserDeleteKey, function (event) {
293
+ setImmediate(() => {
294
+ try {
295
+ if (event.skipArchive) {
296
+ return 0;
297
+ }
298
+ const activity = buildProjectUserDeleteActivity(event);
299
+ if (!activity) {
300
+ return winston.debug('ActivityArchiver skipping project_user.delete: missing data');
301
+ }
302
+ save(activity);
303
+ } catch (e) {
304
+ winston.error('ActivityArchiver error saving project_user.delete activity', e);
305
+ }
306
+ });
307
+ });
308
+
309
+
310
+ // ********** REQUEST EVENTS **********
311
+
312
+ const requestCreateKey = resolveEventKey('request.create', requestEvent.queueEnabled);
313
+ winston.debug('ActivityArchiver requestCreateKey: ' + requestCreateKey);
314
+
315
+ requestEvent.on(requestCreateKey, function (request) {
316
+ setImmediate(() => {
317
+ winston.debug('ActivityArchiver requestCreate triggered');
26
318
 
27
- var that = this;
28
-
29
- //modify all to async
30
-
31
-
32
- /*
33
- activityEvent.on('user.verify.email', this.save);
34
-
35
- activityEvent.on('group.create', this.save);
36
- activityEvent.on('group.update', this.save);
37
- activityEvent.on('group.delete', this.save);
38
-
39
- // activityEvent.on('lead.create', this.save);
40
- activityEvent.on('lead.update', this.save);
41
- activityEvent.on('lead.delete', this.save);
42
- activityEvent.on('lead.download.csv', this.save);
43
- */
44
-
45
- // works only if worker is disabled
46
- var authProjectUserInvitePendingKey = 'project_user.invite.pending'; //Don't work if job_worker enabled because queue.worker is disabled
47
- // if (authEvent.queueEnabled) { //queue not supported.
48
- // authProjectUserInvitePendingKey = 'project_user.invite.pending.queue';
49
- // }
50
- winston.debug('ActivityArchiver authProjectUserInvitePendingKey: ' + authProjectUserInvitePendingKey);
51
-
52
- authEvent.on(authProjectUserInvitePendingKey, function(event) {
53
- setImmediate(() => {
54
- if (event.skipArchive) {
55
- return 0;
319
+ try {
320
+
321
+ if (request.preflight === true) {
322
+ winston.debug("preflight request disable archiver")
323
+ return 0;
324
+ }
325
+ const actor = activityActorUtil.actorFromRequestCreate(request);
326
+ let activity = new Activity({
327
+ id_project: request.id_project,
328
+ actor: actor,
329
+ verb: "REQUEST_CREATE",
330
+ actionObj: request,
331
+ target: {
332
+ type: "request",
333
+ id: request._id,
334
+ object: request
56
335
  }
57
- var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
58
- verb: "PROJECT_USER_INVITE", actionObj: event.req.body,
59
- target: {type:"pendinginvitation", id:event.savedPendingInvitation._id.toString(), object: event.savedPendingInvitation },
60
- id_project: event.req.projectid });
61
- that.save(activity);
62
-
63
336
  });
64
-
65
- });
66
-
337
+ save(activity);
67
338
 
339
+ } catch (e) {
340
+ winston.error('ActivityArchiver error saving activity', e);
341
+ }
342
+ });
343
+ });
68
344
 
69
345
 
70
- // works only if worker is disabled
71
- var authProjectUserInviteKey = 'project_user.invite'; //Don't work if job_worker enabled because queue.worker is disabled
72
- // if (authEvent.queueEnabled) { //queue not supported
73
- // authProjectUserInviteKey = 'project_user.invite.queue';
74
- // }
75
- winston.debug('ActivityArchiver authProjectUserInviteKey: ' + authProjectUserInviteKey);
76
-
77
- authEvent.on(authProjectUserInviteKey, function(event) {
78
- setImmediate(() => {
79
- if (event.skipArchive) {
80
- return 0;
81
- }
346
+ const requestUpdatePreflightKey = resolveEventKey('request.update.preflight', requestEvent.queueEnabled);
347
+ winston.debug('ActivityArchiver requestUpdatePreflightKey: ' + requestUpdatePreflightKey);
348
+
349
+ requestEvent.on(requestUpdatePreflightKey, function (request) {
350
+ winston.debug('ActivityArchiver request.update.preflight: ');
351
+
352
+ setImmediate(() => {
82
353
 
354
+ try {
83
355
 
84
- var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
85
- verb: "PROJECT_USER_INVITE", actionObj: event.req.body,
86
- target: {type:"project_user", id: event.savedProject_userPopulated._id.toString(), object: event.savedProject_userPopulated },
87
- id_project: event.req.projectid });
88
- that.save(activity);
89
-
356
+ if (request.preflight === true) {
357
+ winston.debug("preflight request disable archiver")
358
+ return 0;
359
+ }
360
+ const actor = activityActorUtil.actorFromRequestCreate(request);
361
+ let activity = new Activity({
362
+ id_project: request.id_project,
363
+ actor: actor,
364
+ verb: "REQUEST_CREATE",
365
+ actionObj: request,
366
+ target: {
367
+ type: "request",
368
+ id: request._id,
369
+ object: request
370
+ }
90
371
  });
91
- });
372
+ save(activity);
373
+ } catch (e) {
374
+ winston.error('ActivityArchiver error saving activity', e);
375
+ }
376
+ });
377
+ });
378
+
92
379
 
380
+ const requestCloseKey = resolveEventKey('request.close', requestEvent.queueEnabled);
381
+ winston.debug('ActivityArchiver requestCloseKey: ' + requestCloseKey);
93
382
 
383
+ requestEvent.on(requestCloseKey, function (request) {
384
+ setImmediate(async () => {
385
+ try {
386
+ winston.debug('ActivityArchiver close');
94
387
 
95
-
96
- // verified with queue
97
- var authProjectUserUpdateKey = 'project_user.update';
98
- if (authEvent.queueEnabled) {
99
- authProjectUserUpdateKey = 'project_user.update.queue';
388
+ const actor = await activityActorUtil.resolveActorFromClosedBy(request);
389
+
390
+ let activity = new Activity({
391
+ id_project: request.id_project,
392
+ actor: actor,
393
+ verb: "REQUEST_CLOSE",
394
+ actionObj: request,
395
+ target: {
396
+ type: "request",
397
+ id: request._id,
398
+ object: request
399
+ }
400
+ });
401
+ save(activity);
402
+ } catch (e) {
403
+ winston.error('ActivityArchiver error saving activity', e);
100
404
  }
101
- winston.debug('ActivityArchiver authProjectUserUpdateKey: ' + authProjectUserUpdateKey);
102
-
103
- authEvent.on(authProjectUserUpdateKey, function(event) {
104
- setImmediate(() => {
105
- // winston.info('ActivityArchiver authProjectUserUpdateKey: ', event);
106
-
107
- /*
108
- 2019-11-20T10:40:52.686991+00:00 app[web.1]: TypeError: Cannot read property '_id' of undefined
109
- */
110
- if (event.skipArchive) {
111
- return 0;
405
+ });
406
+ });
407
+
408
+
409
+ const requestAssignedKey = resolveEventKey('request.assigned', requestEvent.queueEnabled);
410
+ winston.debug('ActivityArchiver requestAssignedKey: ' + requestAssignedKey);
411
+
412
+ requestEvent.on(requestAssignedKey, function (data) {
413
+ setImmediate(() => {
414
+ try {
415
+ if (!data || !data.request) {
416
+ return winston.debug('ActivityArchiver skipping request.assigned: missing request');
112
417
  }
113
418
 
114
- var project_user = undefined;
115
- if (event.updatedProject_userPopulated.toObject) {
116
- project_user = event.updatedProject_userPopulated.toObject()
117
- } else {
118
- project_user = event.updatedProject_userPopulated;
419
+ const verb = assignmentContextUtil.verbFromAssignmentType(data.assignmentType);
420
+ if (!verb) {
421
+ return winston.debug('ActivityArchiver skipping request.assigned: unknown assignmentType', data.assignmentType);
119
422
  }
120
423
 
121
- winston.debug('ActivityArchiver authProjectUserUpdateKey event: ', event);
424
+ const reconciled = assignmentContextUtil.reconcileAssignmentPayload(data);
425
+
426
+ winston.info('ActivityArchiver request.assigned actor', {
427
+ verb: verb,
428
+ assignmentType: data.assignmentType,
429
+ source: reconciled.source,
430
+ actor: reconciled.actor,
431
+ assigneeId: data.assigneeId,
432
+ assigneeType: data.assigneeType,
433
+ request_id: data.request && data.request.request_id
434
+ });
122
435
 
123
- if (!event.req.user) {
124
- return winston.debug('ActivityArchiver skipping archive empty user'); //from i think chat21webhook
436
+ const activityFields = {
437
+ id_project: data.request.id_project,
438
+ actor: reconciled.actor,
439
+ verb: verb,
440
+ actionObj: {
441
+ assigneeId: data.assigneeId,
442
+ assigneeName: data.assigneeName,
443
+ assigneeType: data.assigneeType || 'user',
444
+ assignmentType: data.assignmentType,
445
+ source: reconciled.source,
446
+ previousAssigneeId: data.previousAssigneeId,
447
+ removedParticipants: data.removedParticipants
448
+ },
449
+ target: {
450
+ type: 'request',
451
+ id: data.request._id,
452
+ object: data.request
453
+ }
454
+ };
455
+
456
+ if (data.assigneeId) {
457
+ activityFields.related = {
458
+ role: verb === 'REQUEST_UNASSIGNED' ? 'unassigned_user' : 'assignee',
459
+ type: data.assigneeType || 'user',
460
+ id: String(data.assigneeId),
461
+ name: data.assigneeName
462
+ };
125
463
  }
126
- var activity = new Activity({actor: {type:"user", id: event.req.user._id, name: event.req.user.fullName },
127
- verb: "PROJECT_USER_UPDATE", actionObj: event.req.body,
128
- target: {type:"project_user", id: event.updatedProject_userPopulated._id.toString(), object: project_user},
129
- id_project: event.updatedProject_userPopulated.id_project });
130
- that.save(activity);
131
-
464
+
465
+ const activity = new Activity(activityFields);
466
+ save(activity);
467
+ } catch (e) {
468
+ winston.error('ActivityArchiver error saving request.assigned activity', e);
469
+ }
132
470
  });
133
-
134
- });
135
-
136
- // works only if worker is disabled
137
- var authProjectUserDeleteKey = 'project_user.delete'; //Don't work if job_worker enabled because queue.worker is disabled
138
- // if (authEvent.queueEnabled) { //queue not supported
139
- // authProjectUserDeleteKey = 'project_user.delete.queue';
140
- // }
141
- winston.debug('ActivityArchiver authProjectUserDeleteKey: ' + authProjectUserDeleteKey);
142
-
143
-
144
- authEvent.on(authProjectUserDeleteKey, function(event) {
145
- setImmediate(() => {
146
- if (event.skipArchive) {
147
- return 0;
471
+ });
472
+
473
+
474
+ const requestParticipantsLeaveKey = resolveEventKey('request.participants.leave', requestEvent.queueEnabled);
475
+ winston.debug('ActivityArchiver requestParticipantsLeaveKey: ' + requestParticipantsLeaveKey);
476
+
477
+ requestEvent.on(requestParticipantsLeaveKey, function (data) {
478
+ setImmediate(() => {
479
+ try {
480
+ if (!data || !data.request) {
481
+ return winston.debug('ActivityArchiver skipping request.participants.leave: missing request');
482
+ }
483
+ if (!data.trackLeave) {
484
+ return winston.debug('ActivityArchiver skipping request.participants.leave: trackLeave false');
485
+ }
486
+ if (!assignmentContextUtil.isHumanParticipant(data.member)) {
487
+ return winston.debug('ActivityArchiver skipping request.participants.leave: bot participant');
148
488
  }
149
489
 
150
- var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
151
- verb: "PROJECT_USER_DELETE", actionObj: event.req.body,
152
- target: {type:"project_user", id:event.req.params.project_userid, object: event.project_userPopulated.toObject() }, //Error saving activity Maximum call stack size exceeded
153
- id_project: event.req.projectid });
154
- that.save(activity);
155
-
156
- });
490
+ const activity = new Activity({
491
+ id_project: data.request.id_project,
492
+ actor: data.actor || activityActorUtil.actorFromUserId(data.member),
493
+ verb: 'LEAVE_CONVERSATION',
494
+ actionObj: {
495
+ member: data.member,
496
+ source: data.source || 'api'
497
+ },
498
+ target: {
499
+ type: 'request',
500
+ id: data.request._id,
501
+ object: data.request
502
+ }
503
+ });
504
+ save(activity);
505
+ } catch (e) {
506
+ winston.error('ActivityArchiver error saving request.participants.leave activity', e);
507
+ }
157
508
  });
509
+ });
158
510
 
159
511
 
160
-
161
- // disabled why? performance?
162
- // var authUserSignineKey = 'user.signin';
163
- // // if (authEvent.queueEnabled) { //queue not supported
164
- // // authUserSignineKey = 'user.signin.queue';
165
- // // }
166
- // winston.info('ActivityArchiver authUserSignineKey: ' + authUserSignineKey);
167
-
168
-
169
- // authEvent.on(authUserSignineKey, function(event) {
170
- // winston.info('ActivityArchiver user.login');
171
- // setImmediate(() => {
172
-
173
-
174
- // if (event.skipArchive) {
175
- // return 0;
176
- // }
177
-
178
- // var activity = new Activity({actor: {type:"user", id: event.user._id, name: event.user.fullName },
179
- // verb: "USER_SIGNIN", actionObj: event.req.body, //insecure it store password
180
- // target: {type:"user", id:event.user._id.toString(), object: null },
181
- // id_project: '*' }); /// * project
182
- // that.save(activity);
183
-
184
- // });
185
- // });
186
-
187
-
188
- // var authUserSigninErrorKey = 'user.login.error';
189
- // // if (authEvent.queueEnabled) { //queue not supported
190
- // // authUserSigninErrorKey = 'user.login.error.queue';
191
- // // }
192
- // winston.info('ActivityArchiver authUserSigninErrorKey: ' + authUserSigninErrorKey);
512
+ // ********** CHATBOT / FAQ_KB EVENTS **********
193
513
 
194
-
195
- // authEvent.on(authUserSigninErrorKey, function(event) {
196
- // setImmediate(() => {
197
-
198
- // if (event.skipArchive) {
199
- // return 0;
200
- // }
201
-
202
- // var activity = new Activity({actor: {type:"user"},
203
- // verb: "USER_SIGNIN_ERROR", actionObj: event.req.body, //insecure it store password
204
- // target: {type:"user", id:null, object: null },
205
- // id_project: '*' }); /// * project
206
- // that.save(activity);
207
-
208
- // });
209
- // });
210
-
211
-
212
- // var authUserResetPasswordKey = 'user.requestresetpassword';
213
- // // if (authEvent.queueEnabled) { //queue not supported
214
- // // authUserResetPasswordKey = 'user.requestresetpassword.queue';
215
- // // }
216
- // winston.info('ActivityArchiver authUserResetPasswordKey: ' + authUserResetPasswordKey);
217
-
218
- // authEvent.on(authUserResetPasswordKey, function(event) {
219
- // setImmediate(() => {
220
-
221
- // if (event.skipArchive) {
222
- // return 0;
223
- // }
224
-
225
- // var activity = new Activity({actor: {type:"user", id: event.updatedUser._id, name: event.updatedUser.fullName },
226
- // verb: "USER_REQUEST_RESETPASSWORD", actionObj: event.req.body,
227
- // target: {type:"user", id:event.updatedUser._id.toString(), object: null },
228
- // id_project: '*' }); /// * project
229
- // that.save(activity);
230
-
231
- // });
232
- // });
233
-
234
-
235
- // var authUserResetPassword2Key = 'user.resetpassword';
236
- // // if (authEvent.queueEnabled) { //queue not supported
237
- // // authUserResetPassword2Key = 'user.resetpassword.queue';
238
- // // }
239
- // winston.info('ActivityArchiver authUserResetPassword2Key: ' + authUserResetPassword2Key);
240
-
241
-
242
- // authEvent.on(authUserResetPassword2Key, function(event) {
243
- // setImmediate(() => {
244
-
245
- // if (event.skipArchive) {
246
- // return 0;
247
- // }
248
-
249
- // var activity = new Activity({actor: {type:"user", id: event.saveUser._id, name: event.saveUser.fullName },
250
- // verb: "USER_RESETPASSWORD", actionObj: null, //req.body otherwise print password
251
- // target: {type:"user", id:event.saveUser._id.toString(), object: null },
252
- // id_project: '*' }); /// * project
253
- // that.save(activity);
254
-
255
- // });
256
- // });
257
-
258
-
259
- // var authUserSignupKey = 'user.signup';
260
- // // if (authEvent.queueEnabled) { //queue not supported
261
- // // authUserSignupKey = 'user.signup.queue';
262
- // // }
263
- // winston.info('ActivityArchiver authUserSignupKey: ' + authUserSignupKey);
264
-
265
-
266
- // authEvent.on(authUserSignupKey, function(event) {
267
- // setImmediate(() => {
268
- // if (event.skipArchive) {
269
- // return 0;
270
- // }
271
-
272
- // var activity = new Activity({actor: {type:"user", id: event.savedUser._id, name: event.savedUser.fullName },
273
- // verb: "USER_SIGNUP", actionObj: event.req.body,
274
- // target: {type:"user", id: event.savedUser._id.toString(), object: null },
275
- // id_project: '*' }); /// * project
276
- // that.save(activity);
277
-
278
- // });
279
- // });
280
-
281
-
282
- // var authUserSignupErrorKey = 'user.signup.error';
283
- // // if (authEvent.queueEnabled) { //queue not supported
284
- // // authUserSignupErrorKey = 'user.signup.error.queue';
285
- // // }
286
- // winston.info('ActivityArchiver authUserSignupErrorKey: ' + authUserSignupErrorKey);
287
-
288
-
289
- // authEvent.on(authUserSignupErrorKey, function(event) {
290
- // setImmediate(() => {
291
- // if (event.skipArchive) {
292
- // return 0;
293
- // }
294
-
295
-
296
- // var activity = new Activity({actor: {type:"user"},
297
- // verb: "USER_SIGNUP_ERROR", actionObj: event.req.body,
298
- // target: {type:"user", id:null, object: null },
299
- // id_project: '*' }); /// * project
300
- // that.save(activity);
301
-
302
- // });
303
- // });
304
-
305
-
306
- var requestCreateKey = 'request.create';
307
- if (requestEvent.queueEnabled) {
308
- requestCreateKey = 'request.create.queue';
309
- }
310
- winston.debug('ActivityArchiver requestCreateKey: ' + requestCreateKey);
311
-
312
- requestEvent.on(requestCreateKey, function(request) {
313
- setImmediate(() => {
314
- winston.debug('ActivityArchiver requestCreate triggered');
315
- // problema requester_id
316
-
317
- // Error saving activity {"_id":"5e06189c6e226d358896d733","actor":{"_id":"5e06189c6e226d358896d734","type":"user","id":null},"verb":"REQUEST_CREATE","actionObj":{"status":200,"participants":["5e06189c6e226d358896d728"],"messages_count":0,"tags":[],"_id":"5e06189c6e226d358896d72e","request_id":"request_id-closeRequest","first_text":"first_text","department":{"routing":"assigned","default":true,"status":1,"_id":"5e06189c6e226d358896d72b","name":"Default Department","id_project":"5e06189c6e226d358896d729","createdBy":"5e06189c6e226d358896d728","createdAt":"2019-12-27T14:43:40.327Z","updatedAt":"2019-12-27T14:43:40.327Z","__v":0},"agents":[{"_id":"5e06189c6e226d358896d72a","id_project":"5e06189c6e226d358896d729","id_user":"5e06189c6e226d358896d728","role":"owner","user_available":true,"createdBy":"5e06189c6e226d358896d728","createdAt":"2019-12-27T14:43:40.324Z","updatedAt":"2019-12-27T14:43:40.324Z","__v":0}],"id_project":"5e06189c6e226d358896d729","createdBy":"requester_id1","channel":{"name":"chat21"},"createdAt":"2019-12-27T14:43:40.586Z","updatedAt":"2019-12-27T14:43:40.586Z","__v":0},"target":{"type":"request","id":"5e06189c6e226d358896d72e","object":{"status":200,"participants":["5e06189c6e226d358896d728"],"messages_count":0,"tags":[],"_id":"5e06189c6e226d358896d72e","request_id":"request_id-closeRequest","first_text":"first_text","department":{"routing":"assigned","default":true,"status":1,"_id":"5e06189c6e226d358896d72b","name":"Default Department","id_project":"5e06189c6e226d358896d729","createdBy":"5e06189c6e226d358896d728","createdAt":"2019-12-27T14:43:40.327Z","updatedAt":"2019-12-27T14:43:40.327Z","__v":0},"agents":[{"_id":"5e06189c6e226d358896d72a","id_project":"5e06189c6e226d358896d729","id_user":"5e06189c6e226d358896d728","role":"owner","user_available":true,"createdBy":"5e06189c6e226d358896d728","createdAt":"2019-12-27T14:43:40.324Z","updatedAt":"2019-12-27T14:43:40.324Z","__v":0}],"id_project":"5e06189c6e226d358896d729","createdBy":"requester_id1","channel":{"name":"chat21"},"createdAt":"2019-12-27T14:43:40.586Z","updatedAt":"2019-12-27T14:43:40.586Z","__v":0}},"id_project":"5e06189c6e226d358896d729"}
318
-
319
- // TODO error: Error saving activity {"activity":{"_id":"5e273b31f13e801703d52515","actor":{"_id":"5e273b31f13e801703d52516","type":"user","id":null},"verb":"REQUEST_CREATE","actionObj":{"status":200,"participants":["5e273b30f13e801703d52508"],"messages_count":0,"tags":[],"_id":"5e273b31f13e801703d52511","request_id":"request_id1","first_text":"first_text","department":{"routing":"assigned","default":false,"status":1,"_id":"5e273b31f13e801703d5250f","name":"PooledDepartment-for-createWithIdWith","id_project":"5e273b31f13e801703d5250a","createdBy":"5e273b30f13e801703d52507","createdAt":"2020-01-21T17:56:01.471Z","updatedAt":"2020-01-21T17:56:01.471Z","__v":0},"agents":[{"_id":"5e273b31f13e801703d5250b","id_project":"5e273b31f13e801703d5250a","id_user":"5e273b30f13e801703d52507","role":"owner","user_available":true,"createdBy":"5e273b30f13e801703d52507","createdAt":"2020-01-21T17:56:01.465Z","updatedAt":"2020-01-21T17:56:01.465Z","__v":0},{"_id":"5e273b31f13e801703d5250e","id_project":"5e273b31f13e801703d5250a","id_user":"5e273b30f13e801703d52508","role":"agent","user_available":true,"createdBy":"5e273b30f13e801703d52508","createdAt":"2020-01-21T17:56:01.469Z","updatedAt":"2020-01-21T17:56:01.469Z","__v":0}],"id_project":"5e273b31f13e801703d5250a","createdBy":"requester_id1","channel":{"name":"chat21"},"createdAt":"2020-01-21T17:56:01.480Z","updatedAt":"2020-01-21T17:56:01.480Z","__v":0},"target":{"type":"request","id":"5e273b31f13e801703d52511","object":{"status":200,"participants":["5e273b30f13e801703d52508"],"messages_count":0,"tags":[],"_id":"5e273b31f13e801703d52511","request_id":"request_id1","first_text":"first_text","department":{"routing":"assigned","default":false,"status":1,"_id":"5e273b31f13e801703d5250f","name":"PooledDepartment-for-createWithIdWith","id_project":"5e273b31f13e801703d5250a","createdBy":"5e273b30f13e801703d52507","createdAt":"2020-01-21T17:56:01.471Z","updatedAt":"2020-01-21T17:56:01.471Z","__v":0},"agents":[{"_id":"5e273b31f13e801703d5250b","id_project":"5e273b31f13e801703d5250a","id_user":"5e273b30f13e801703d52507","role":"owner","user_available":true,"createdBy":"5e273b30f13e801703d52507","createdAt":"2020-01-21T17:56:01.465Z","updatedAt":"2020-01-21T17:56:01.465Z","__v":0},{"_id":"5e273b31f13e801703d5250e","id_project":"5e273b31f13e801703d5250a","id_user":"5e273b30f13e801703d52508","role":"agent","user_available":true,"createdBy":"5e273b30f13e801703d52508","createdAt":"2020-01-21T17:56:01.469Z","updatedAt":"2020-01-21T17:56:01.469Z","__v":0}],"id_project":"5e273b31f13e801703d5250a","createdBy":"requester_id1","channel":{"name":"chat21"},"createdAt":"2020-01-21T17:56:01.480Z","updatedAt":"2020-01-21T17:56:01.480Z","__v":0}},"id_project":"5e273b31f13e801703d5250a"},"err":{"errors":{"actor.id":{"message":"Path `id` is required.","name":"ValidatorError","properties":{"message":"Path `id` is required.","type":"required","path":"id","value":null},"kind":"required","path":"id","value":null},"actor":{"errors":{"id":{"message":"Path `id` is required.","name":"ValidatorError","properties":{"message":"Path `id` is required.","type":"required","path":"id","value":null},"kind":"required","path":"id","value":null}},"_message":"Validation failed","message":"Validation failed: id: Path `id` is required.","name":"ValidationError"}},"_message":"activity validation failed","message":"activity validation failed: actor.id: Path `id` is required., actor: Validation failed: id: Path `id` is required.","name":"ValidationError"}}
320
-
321
- // request is plain object must be mongoose object oto populate
322
-
323
- // if (event.skipArchive) {
324
- // return 0;
325
- // }
326
-
327
- //TODO remove preflight
328
-
329
- try {
330
-
331
- if (request.preflight === true) {
332
- winston.debug("preflight request disable archiver")
333
- return 0;
334
- }
335
- var activity = new Activity({actor: {type:"user", id: request.requester_id},
336
- verb: "REQUEST_CREATE", actionObj: request,
337
- target: {type:"request", id:request._id, object: request },
338
- id_project: request.id_project });
339
- that.save(activity);
340
- } catch(e) {
341
- winston.error('ActivityArchiver error saving activity',e);
342
- }
343
-
344
-
345
- });
346
- });
514
+ const faqbotCreatedKey = resolveEventKey('faqbot.created', botEvent.queueEnabled);
515
+ winston.debug('ActivityArchiver faqbotCreatedKey: ' + faqbotCreatedKey);
347
516
 
517
+ botEvent.on(faqbotCreatedKey, function (data) {
518
+ setImmediate(() => {
519
+ try {
520
+ const chatbot = data && (data.chatbot || data);
521
+ if (!chatbot || !(data.id_project || chatbot.id_project)) {
522
+ return winston.debug('ActivityArchiver skipping faqbot.created: missing chatbot');
523
+ }
348
524
 
349
- // verified with queue
350
- var requestUpdatePreflightKey = 'request.update.preflight';
351
- if (requestEvent.queueEnabled) {
352
- requestUpdatePreflightKey = 'request.update.preflight.queue';
525
+ const activity = new Activity({
526
+ id_project: data.id_project || chatbot.id_project,
527
+ actor: activityActorUtil.actorFromReq(data.req),
528
+ verb: 'FAQ_KB_CREATE',
529
+ actionObj: {
530
+ name: chatbot.name,
531
+ type: chatbot.type,
532
+ subtype: chatbot.subtype
533
+ },
534
+ target: faqKbTarget(chatbot)
535
+ });
536
+ save(activity);
537
+ } catch (e) {
538
+ winston.error('ActivityArchiver error saving faqbot.created activity', e);
353
539
  }
354
- winston.debug('ActivityArchiver requestUpdatePreflightKey: ' + requestUpdatePreflightKey);
540
+ });
541
+ });
542
+
543
+ const faqbotDeletedKey = resolveEventKey('faqbot.deleted', botEvent.queueEnabled);
544
+ winston.debug('ActivityArchiver faqbotDeletedKey: ' + faqbotDeletedKey);
545
+ botEvent.on(faqbotDeletedKey, function (data) {
546
+ setImmediate(() => {
547
+ console.log("\n\nfaqbot.deleted");
548
+ try {
549
+ const chatbot = data && data.chatbot;
550
+ if (!chatbot || !chatbot.id_project) {
551
+ return winston.debug('ActivityArchiver skipping faqbot.deleted: missing chatbot');
552
+ }
355
553
 
356
-
357
- requestEvent.on(requestUpdatePreflightKey, function(request) {
358
- winston.debug('ActivityArchiver request.update.preflight: ');
359
-
360
- setImmediate(() => {
361
-
362
- try {
363
-
364
- if (request.preflight === true) {
365
- winston.debug("preflight request disable archiver")
366
- return 0;
367
- }
368
- var activity = new Activity({actor: {type:"user", id: request.requester_id},
369
- verb: "REQUEST_CREATE", actionObj: request,
370
- target: {type:"request", id:request._id, object: request },
371
- id_project: request.id_project });
372
- that.save(activity);
373
- } catch(e) {
374
- winston.error('ActivityArchiver error saving activity',e);
375
- }
376
-
377
-
378
- });
379
- });
554
+ const activity = new Activity({
555
+ id_project: chatbot.id_project,
556
+ actor: activityActorUtil.actorFromReq(data.req),
557
+ verb: 'FAQ_KB_DELETE',
558
+ actionObj: {
559
+ name: chatbot.name,
560
+ type: chatbot.type
561
+ },
562
+ target: faqKbTarget(chatbot)
563
+ });
564
+ save(activity);
565
+ } catch (e) {
566
+ winston.error('ActivityArchiver error saving faqbot.deleted activity', e);
567
+ }
568
+ });
569
+ });
380
570
 
571
+ const faqbotPublishKey = resolveEventKey('faqbot.publish', botEvent.queueEnabled);
572
+ winston.debug('ActivityArchiver faqbotPublishKey: ' + faqbotPublishKey);
381
573
 
574
+ botEvent.on(faqbotPublishKey, function (data) {
575
+ setImmediate(() => {
576
+ try {
577
+ if (!data || !data.chatbot || !data.chatbot.id_project) {
578
+ return winston.debug('ActivityArchiver skipping faqbot.publish: missing chatbot');
579
+ }
382
580
 
383
- // verified with queue
384
- var requestCloseKey = 'request.close'; //request.close event here queued under job
385
- if (requestEvent.queueEnabled) {
386
- requestCloseKey = 'request.close.queue';
581
+ const activity = new Activity({
582
+ id_project: data.chatbot.id_project,
583
+ actor: activityActorUtil.actorFromReq(data.req),
584
+ verb: 'FAQ_KB_PUBLISH',
585
+ actionObj: {
586
+ name: data.chatbot.name,
587
+ publishedBotId: data.publishedBotId,
588
+ release_note: data.release_note
589
+ },
590
+ target: faqKbTarget(data.chatbot)
591
+ });
592
+ save(activity);
593
+ } catch (e) {
594
+ winston.error('ActivityArchiver error saving faqbot.publish activity', e);
387
595
  }
388
- winston.debug('ActivityArchiver requestCloseKey: ' + requestCloseKey);
389
-
390
-
391
- requestEvent.on(requestCloseKey, function(request) {
392
- winston.debug("request.close event here 7")
393
- setImmediate(() => {
394
-
395
- try {
396
- winston.debug('ActivityArchiver close');
397
-
398
- var activity = new Activity({actor: {type:"user", id: request.closed_by},
399
- verb: "REQUEST_CLOSE", actionObj: request,
400
- target: {type:"request", id:request._id, object: request },
401
- id_project: request.id_project });
402
- that.save(activity);
403
- } catch(e) {
404
- winston.error('ActivityArchiver error saving activity',e);
405
- }
406
-
407
-
408
- });
409
- });
596
+ });
597
+ });
410
598
 
411
599
 
412
-
600
+ // ********** KB / NAMESPACE EVENTS **********
413
601
 
414
- winston.info('ActivityArchiver listening');
602
+ const kbNamespaceCreateKey = resolveEventKey('kb.namespace.create', kbEvent.queueEnabled);
603
+ winston.debug('ActivityArchiver kbNamespaceCreateKey: ' + kbNamespaceCreateKey);
415
604
 
416
- }
605
+ kbEvent.on(kbNamespaceCreateKey, function (data) {
606
+ setImmediate(() => {
607
+ try {
608
+ if (!data || !data.project_id || !data.savedNamespace) {
609
+ return winston.debug('ActivityArchiver skipping kb.namespace.create: missing data');
610
+ }
417
611
 
418
- save(activity) {
419
- activity.save(function(err, savedActivity) {
420
- if (err) {
421
- winston.error('Error saving activity ', {activity: activity.toObject(), err:err});
422
- }else {
423
- winston.debug('Activity saved', savedActivity.toObject());
424
- }
425
- });
426
- }
427
- }
612
+ const activity = new Activity({
613
+ id_project: data.project_id,
614
+ actor: activityActorUtil.actorFromReq(data.req),
615
+ verb: 'KB_NAMESPACE_CREATE',
616
+ actionObj: {
617
+ namespaceName: data.savedNamespace.name,
618
+ hybrid: data.savedNamespace.hybrid,
619
+ default: data.savedNamespace.default === true
620
+ },
621
+ target: namespaceTarget(data.namespace_id || data.savedNamespace.id, data.savedNamespace)
622
+ });
623
+ save(activity);
624
+ } catch (e) {
625
+ winston.error('ActivityArchiver error saving kb.namespace.create activity', e);
626
+ }
627
+ });
628
+ });
428
629
 
429
- var activityArchiver = new ActivityArchiver();
630
+ const kbNamespaceDeleteKey = resolveEventKey('kb.namespace.delete', kbEvent.queueEnabled);
631
+ winston.debug('ActivityArchiver kbNamespaceDeleteKey: ' + kbNamespaceDeleteKey);
632
+
633
+ kbEvent.on(kbNamespaceDeleteKey, function (data) {
634
+ setImmediate(() => {
635
+ try {
636
+ if (!data || !data.project_id || !data.namespace_id) {
637
+ return winston.debug('ActivityArchiver skipping kb.namespace.delete: missing data');
638
+ }
639
+
640
+ const activity = new Activity({
641
+ id_project: data.project_id,
642
+ actor: activityActorUtil.actorFromReq(data.req),
643
+ verb: 'KB_NAMESPACE_DELETE',
644
+ actionObj: {
645
+ namespaceName: data.namespace_name,
646
+ deletedCount: data.deletedCount
647
+ },
648
+ target: namespaceTarget(data.namespace_id, { id: data.namespace_id, name: data.namespace_name })
649
+ });
650
+ save(activity);
651
+ } catch (e) {
652
+ winston.error('ActivityArchiver error saving kb.namespace.delete activity', e);
653
+ }
654
+ });
655
+ });
430
656
 
657
+ const kbContentsAddKey = resolveEventKey('kb.contents.add', kbEvent.queueEnabled);
658
+ winston.debug('ActivityArchiver kbContentsAddKey: ' + kbContentsAddKey);
431
659
 
660
+ kbEvent.on(kbContentsAddKey, function (data) {
661
+ setImmediate(() => {
662
+ try {
663
+ if (!data || !data.project_id || !data.namespace_id) {
664
+ return winston.debug('ActivityArchiver skipping kb.contents.add: missing data');
665
+ }
666
+
667
+ const activity = new Activity({
668
+ id_project: data.project_id,
669
+ actor: activityActorUtil.actorFromReq(data.req),
670
+ verb: 'KB_CONTENTS_ADD',
671
+ actionObj: {
672
+ contentAddType: data.contentAddType,
673
+ namespaceName: data.namespace_name,
674
+ count: data.count,
675
+ type: data.type,
676
+ source: data.source
677
+ },
678
+ target: namespaceTarget(data.namespace_id, { id: data.namespace_id, name: data.namespace_name })
679
+ });
680
+ save(activity);
681
+ } catch (e) {
682
+ winston.error('ActivityArchiver error saving kb.contents.add activity', e);
683
+ }
684
+ });
685
+ });
686
+
687
+ const kbContentsDeleteKey = resolveEventKey('kb.contents.delete', kbEvent.queueEnabled);
688
+ winston.debug('ActivityArchiver kbContentsDeleteKey: ' + kbContentsDeleteKey);
689
+ kbEvent.on(kbContentsDeleteKey, function (data) {
690
+ setImmediate(() => {
691
+ console.log("\n\nkb.contents.delete");
692
+ try {
693
+ if (!data || !data.project_id || !data.namespace_id) {
694
+ return winston.debug('ActivityArchiver skipping kb.contents.delete: missing data');
695
+ }
696
+
697
+ const activity = new Activity({
698
+ id_project: data.project_id,
699
+ actor: activityActorUtil.actorFromReq(data.req),
700
+ verb: 'KB_CONTENTS_DELETE',
701
+ actionObj: {
702
+ namespaceName: data.namespace_name,
703
+ deletedCount: data.deletedCount,
704
+ deleteMode: data.deleteMode || 'contents_only'
705
+ },
706
+ target: namespaceTarget(data.namespace_id, { id: data.namespace_id, name: data.namespace_name })
707
+ });
708
+ save(activity);
709
+ } catch (e) {
710
+ winston.error('ActivityArchiver error saving kb.contents.delete activity', e);
711
+ }
712
+ });
713
+ });
714
+
715
+
716
+ const kbContentDeleteKey = resolveEventKey('kb.content.delete', kbEvent.queueEnabled);
717
+ winston.debug('ActivityArchiver kbContentDeleteKey: ' + kbContentDeleteKey);
718
+ kbEvent.on(kbContentDeleteKey, function (data) {
719
+ setImmediate(() => {
720
+ console.log("\n\nkb.content.delete")
721
+ try {
722
+ if (!data || !data.project_id || !data.kb_id) {
723
+ return winston.debug('ActivityArchiver skipping kb.content.delete: missing data');
724
+ }
725
+
726
+ const kb = data.kb || {};
727
+ const activity = new Activity({
728
+ id_project: data.project_id,
729
+ actor: activityActorUtil.actorFromReq(data.req),
730
+ verb: 'KB_CONTENT_DELETE',
731
+ actionObj: {
732
+ name: kb.name,
733
+ source: kb.source,
734
+ type: kb.type,
735
+ namespaceId: data.namespace_id,
736
+ namespaceName: data.namespace_name
737
+ },
738
+ target: kbContentTarget(data.kb_id, kb)
739
+ });
740
+ save(activity);
741
+ } catch (e) {
742
+ winston.error('ActivityArchiver error saving kb.content.delete activity', e);
743
+ }
744
+ });
745
+ });
746
+
747
+
748
+ winston.info('ActivityArchiver listening');
749
+
750
+ }
751
+ }
752
+
753
+ var activityArchiver = new ActivityArchiver();
432
754
  module.exports = activityArchiver;