@tiledesk/tiledesk-server 2.2.38 → 2.3.1-8.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 +121 -0
- package/LICENSE +14 -657
- package/README.md +36 -21
- package/app.js +35 -62
- package/channels/chat21/chat21Handler.js +18 -3
- package/channels/chat21/chat21WebHook.js +31 -15
- package/channels/chat21/package-lock.json +663 -706
- package/channels/chat21/package.json +2 -2
- package/config/labels/widget.json +320 -0
- package/deploy.sh +2 -0
- package/event/botEvent.js +1 -1
- package/event/subscriptionEvent.js +11 -0
- package/fonts/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto-Regular.ttf +0 -0
- package/middleware/ipFilter.js +220 -0
- package/middleware/passport.js +11 -2
- package/models/lead.js +2 -0
- package/models/project.js +10 -0
- package/models/project_user.js +4 -0
- package/models/request.js +50 -12
- package/models/subscriptionLog.js +34 -0
- package/models/tagLibrary.js +42 -0
- package/package.json +6 -11
- package/pubmodules/activities/activityArchiver.js +314 -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 +55 -0
- package/pubmodules/canned/cannedResponseRoute.js +163 -0
- package/pubmodules/canned/index.js +3 -0
- package/pubmodules/emailNotification/requestNotification.js +215 -28
- package/pubmodules/events/eventRoute.js +37 -7
- package/pubmodules/messageActions/messageActionsInterceptor.js +4 -2
- package/pubmodules/pubModulesManager.js +140 -7
- package/pubmodules/rasa/index.js +8 -1
- package/pubmodules/rasa/listener.js +30 -9
- package/pubmodules/rules/conciergeBot.js +4 -4
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +3 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +5 -3
- package/pubmodules/tilebot/index.js +11 -0
- package/pubmodules/tilebot/listener.js +69 -0
- 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 +1181 -0
- package/pubmodules/trigger/start.js +118 -0
- package/pubmodules/trigger/triggerRoute.js +150 -0
- package/routes/auth.js +7 -2
- package/routes/department.js +51 -0
- package/routes/faq.js +7 -0
- package/routes/faq_kb.js +1 -1
- package/routes/group.js +140 -0
- package/routes/lead.js +24 -1
- package/routes/message.js +6 -3
- package/routes/project.js +118 -0
- package/routes/project_user.js +9 -0
- package/routes/public-request.js +280 -2
- package/routes/request.js +124 -17
- package/routes/subscription.js +140 -0
- package/routes/tag.js +138 -0
- package/routes/user-request.js +3 -2
- package/routes/users.js +1 -1
- package/routes/widget.js +80 -3
- package/routes/widgetLoader.js +31 -0
- package/services/banUserNotifier.js +86 -0
- package/services/emailService.js +189 -11
- package/services/faqBotHandler.js +2 -2
- package/services/faqBotSupport.js +0 -1
- package/services/faqService.js +2 -2
- package/services/geoService.js +30 -4
- package/services/leadService.js +2 -0
- package/services/modulesManager.js +16 -182
- package/services/requestService.js +364 -6
- 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/newMessageFollower.html +236 -0
- 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/test/cannedRoute.js +166 -0
- package/test/messageRoute.js +69 -0
- package/test/requestService.js +3 -1
- package/utils/orgUtil.js +3 -3
- package/views/messages.jade +2 -2
- package/websocket/webSocketServer.js +23 -5
package/models/project.js
CHANGED
|
@@ -111,6 +111,16 @@ var ProjectSchema = new Schema({
|
|
|
111
111
|
ipFilter: [{
|
|
112
112
|
type: String
|
|
113
113
|
}],
|
|
114
|
+
ipFilterDenyEnabled:{
|
|
115
|
+
type: Boolean,
|
|
116
|
+
default: false
|
|
117
|
+
},
|
|
118
|
+
ipFilterDeny: [{
|
|
119
|
+
type: String
|
|
120
|
+
}],
|
|
121
|
+
bannedUsers: [{
|
|
122
|
+
id: String, ip: String
|
|
123
|
+
}],
|
|
114
124
|
// defaultLanguage: {
|
|
115
125
|
// type: String,
|
|
116
126
|
// required: true,
|
package/models/project_user.js
CHANGED
|
@@ -37,6 +37,9 @@ var TagSchema = require("../models/tag");
|
|
|
37
37
|
index: true
|
|
38
38
|
// required: true
|
|
39
39
|
},
|
|
40
|
+
profileStatus: {
|
|
41
|
+
type: String,
|
|
42
|
+
},
|
|
40
43
|
presence: PresenceSchema,
|
|
41
44
|
attributes: {
|
|
42
45
|
type: Object,
|
|
@@ -108,5 +111,6 @@ Project_userSchema.virtual('isAuthenticated').get(function () {
|
|
|
108
111
|
// Project_user.find({ id_project: projectid, id_user: { $in : group[0].members}, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.AGENT]} })
|
|
109
112
|
Project_userSchema.index({ id_project: 1, id_user:1, role: 1 });
|
|
110
113
|
|
|
114
|
+
|
|
111
115
|
module.exports = mongoose.model('project_user', Project_userSchema);;
|
|
112
116
|
|
package/models/request.js
CHANGED
|
@@ -58,7 +58,7 @@ var RequestSchema = new Schema({
|
|
|
58
58
|
type: Schema.Types.ObjectId,
|
|
59
59
|
ref: 'project_user',
|
|
60
60
|
required: false, //ENABLEIT,
|
|
61
|
-
index: true
|
|
61
|
+
// index: true //unused
|
|
62
62
|
},
|
|
63
63
|
|
|
64
64
|
|
|
@@ -100,7 +100,7 @@ var RequestSchema = new Schema({
|
|
|
100
100
|
type: Number,
|
|
101
101
|
required: false,
|
|
102
102
|
default: RequestConstants.UNASSIGNED,
|
|
103
|
-
index: true
|
|
103
|
+
// index: true //unused
|
|
104
104
|
},
|
|
105
105
|
|
|
106
106
|
|
|
@@ -134,17 +134,20 @@ var RequestSchema = new Schema({
|
|
|
134
134
|
index: true,
|
|
135
135
|
default: "medium" //translate on client side
|
|
136
136
|
},
|
|
137
|
-
|
|
137
|
+
|
|
138
|
+
followers: [{
|
|
139
|
+
type: Schema.Types.ObjectId,
|
|
140
|
+
ref: 'project_user' }],
|
|
138
141
|
|
|
139
142
|
participantsAgents: {
|
|
140
143
|
type: Array,
|
|
141
144
|
required: false,
|
|
142
|
-
index: true,
|
|
145
|
+
// index: true, //i think unused
|
|
143
146
|
},
|
|
144
147
|
participantsBots: {
|
|
145
148
|
type: Array,
|
|
146
149
|
required: false,
|
|
147
|
-
index: true,
|
|
150
|
+
// index: true, //i think unused
|
|
148
151
|
},
|
|
149
152
|
department: {
|
|
150
153
|
type: Schema.Types.ObjectId,
|
|
@@ -161,20 +164,20 @@ var RequestSchema = new Schema({
|
|
|
161
164
|
// First reply time is the time between ticket creation and the first public comment from an agent, displayed in minutes. Some qualifications include:
|
|
162
165
|
first_response_at: {
|
|
163
166
|
type: Date,
|
|
164
|
-
index: true
|
|
167
|
+
// index: true // unused
|
|
165
168
|
},
|
|
166
169
|
|
|
167
170
|
//timestamp when the agent reply the first time to a visitor
|
|
168
171
|
assigned_at: {
|
|
169
172
|
type: Date,
|
|
170
|
-
index: true
|
|
173
|
+
// index: true //unused
|
|
171
174
|
},
|
|
172
175
|
|
|
173
176
|
// Wait Time (Average and Longest): The average and longest times visitors have been waiting for their chats to be served.
|
|
174
177
|
// Wait time is calculated as duration between the first visitor message in the chat and the first agent message. Wait time will be 0 for agent initiated or trigger initiated chats.
|
|
175
178
|
waiting_time: {
|
|
176
179
|
type: Number,
|
|
177
|
-
index: true
|
|
180
|
+
// index: true // why?
|
|
178
181
|
},
|
|
179
182
|
|
|
180
183
|
|
|
@@ -187,9 +190,12 @@ var RequestSchema = new Schema({
|
|
|
187
190
|
// default: 0
|
|
188
191
|
// },
|
|
189
192
|
|
|
190
|
-
closed_at: {
|
|
193
|
+
closed_at: {
|
|
191
194
|
type: Date
|
|
192
195
|
},
|
|
196
|
+
closed_by: {
|
|
197
|
+
type: String
|
|
198
|
+
},
|
|
193
199
|
|
|
194
200
|
tags: [TagSchema],
|
|
195
201
|
|
|
@@ -205,7 +211,11 @@ var RequestSchema = new Schema({
|
|
|
205
211
|
},
|
|
206
212
|
snapshot: {
|
|
207
213
|
type: RequestSnapshotSchema,
|
|
208
|
-
select: true
|
|
214
|
+
select: true,
|
|
215
|
+
//index: false,
|
|
216
|
+
// includeIndices: false,
|
|
217
|
+
excludeIndexes: true //testa bene
|
|
218
|
+
|
|
209
219
|
// select: false
|
|
210
220
|
},
|
|
211
221
|
|
|
@@ -254,13 +264,25 @@ var RequestSchema = new Schema({
|
|
|
254
264
|
required: false
|
|
255
265
|
},
|
|
256
266
|
location: LocationSchema,
|
|
257
|
-
|
|
267
|
+
auto_close: {
|
|
268
|
+
type: Number,
|
|
269
|
+
index: true
|
|
270
|
+
},
|
|
258
271
|
id_project: {
|
|
259
272
|
type: String,
|
|
260
273
|
required: true,
|
|
261
274
|
index: true
|
|
262
275
|
},
|
|
263
|
-
|
|
276
|
+
smartAssignment: {
|
|
277
|
+
type: Boolean,
|
|
278
|
+
default: true,
|
|
279
|
+
index: true
|
|
280
|
+
},
|
|
281
|
+
workingStatus: { //new, pending
|
|
282
|
+
type: String,
|
|
283
|
+
required: false,
|
|
284
|
+
index: true
|
|
285
|
+
},
|
|
264
286
|
createdBy: {
|
|
265
287
|
type: String,
|
|
266
288
|
required: true
|
|
@@ -434,8 +456,24 @@ RequestSchema.index({ id_project: 1, preflight:1, updatedAt: -1 }); // used quer
|
|
|
434
456
|
|
|
435
457
|
RequestSchema.index({ hasBot: 1, createdAt: 1 }); // suggested by atlas
|
|
436
458
|
|
|
459
|
+
// suggested by atlas
|
|
460
|
+
RequestSchema.index({ lead: 1, id_project: 1, participants: 1, preflight: 1, createdAt: -1 });
|
|
461
|
+
// suggested by atlas
|
|
462
|
+
RequestSchema.index({ lead: 1, id_project: 1, preflight: 1, createdAt: -1 });
|
|
463
|
+
|
|
464
|
+
// suggested by atlas
|
|
465
|
+
RequestSchema.index({ lead: 1, "snapshot.agents.id_user": 1, id_project: 1, preflight: 1, createdAt: -1 });
|
|
466
|
+
|
|
467
|
+
// suggested by atlas
|
|
437
468
|
RequestSchema.index({ id_project: 1, ticket_id: 1 });
|
|
438
469
|
|
|
470
|
+
// suggested by atlas
|
|
471
|
+
RequestSchema.index({ id_project: 1, createdAt: 1, preflight: 1});
|
|
472
|
+
|
|
473
|
+
//suggested by atlas profiler. Used by auto closing requests
|
|
474
|
+
RequestSchema.index({ hasBot: 1, status: 1, createdAt: 1});
|
|
475
|
+
|
|
476
|
+
|
|
439
477
|
|
|
440
478
|
|
|
441
479
|
// cannot index parallel arrays [agents] [participants] {"driv
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var mongoose = require('mongoose');
|
|
2
|
+
var Schema = mongoose.Schema;
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var SubscriptionLogSchema = new Schema({
|
|
7
|
+
event: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true
|
|
10
|
+
},
|
|
11
|
+
target: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true
|
|
14
|
+
},
|
|
15
|
+
response: {
|
|
16
|
+
type: String,
|
|
17
|
+
},
|
|
18
|
+
body: {
|
|
19
|
+
type: String,
|
|
20
|
+
},
|
|
21
|
+
err: {
|
|
22
|
+
type: String,
|
|
23
|
+
},
|
|
24
|
+
id_project: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: true,
|
|
27
|
+
index:true
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
timestamps: true
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
module.exports = mongoose.model('subscriptionLog', SubscriptionLogSchema);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var mongoose = require('mongoose');
|
|
2
|
+
var Schema = mongoose.Schema;
|
|
3
|
+
var TagSchema = require('./tag');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var TagLibrarySchema = new Schema({
|
|
8
|
+
...TagSchema.obj,
|
|
9
|
+
// tag: {
|
|
10
|
+
// type: String,
|
|
11
|
+
// required: true,
|
|
12
|
+
// index: true
|
|
13
|
+
// },
|
|
14
|
+
// color: {
|
|
15
|
+
// type: String,
|
|
16
|
+
// required: false,
|
|
17
|
+
// index: false
|
|
18
|
+
// },
|
|
19
|
+
// attributes: {
|
|
20
|
+
// type: Object,
|
|
21
|
+
// },
|
|
22
|
+
id_project: {
|
|
23
|
+
type: String,
|
|
24
|
+
required: true,
|
|
25
|
+
index: true
|
|
26
|
+
},
|
|
27
|
+
createdBy: {
|
|
28
|
+
type: String,
|
|
29
|
+
required: true
|
|
30
|
+
}
|
|
31
|
+
},{
|
|
32
|
+
timestamps: true
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
TagLibrarySchema.index({ id_project: 1, tag: 1 }, { unique: true });
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
var Tag = mongoose.model('tag', TagLibrarySchema);
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
module.exports = Tag;
|
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.
|
|
4
|
+
"version": "2.3.18.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "node ./bin/www",
|
|
7
7
|
"pretest": "mongodb-runner start",
|
|
@@ -29,28 +29,22 @@
|
|
|
29
29
|
"tiledesk-server": "./bin/www"
|
|
30
30
|
},
|
|
31
31
|
"optionalDependencies": {
|
|
32
|
-
"@tiledesk-ent/tiledesk-server-activities": "^1.1.18",
|
|
33
|
-
"@tiledesk-ent/tiledesk-server-analytics": "^1.1.12",
|
|
34
32
|
"@tiledesk-ent/tiledesk-server-cache": "^1.1.10",
|
|
35
|
-
"@tiledesk-ent/tiledesk-server-canned": "^1.1.2",
|
|
36
|
-
"@tiledesk-ent/tiledesk-server-departments": "^1.1.3",
|
|
37
33
|
"@tiledesk-ent/tiledesk-server-dialogflow": "^1.1.6",
|
|
38
|
-
"@tiledesk-ent/tiledesk-server-groups": "^1.1.3",
|
|
39
34
|
"@tiledesk-ent/tiledesk-server-jwthistory": "^1.1.9",
|
|
40
|
-
"@tiledesk-ent/tiledesk-server-mt": "^1.1.8",
|
|
41
35
|
"@tiledesk-ent/tiledesk-server-payments": "^1.1.6",
|
|
42
36
|
"@tiledesk-ent/tiledesk-server-queue": "^1.1.11",
|
|
43
37
|
"@tiledesk-ent/tiledesk-server-request-history": "^1.1.5",
|
|
44
|
-
"@tiledesk-ent/tiledesk-server-resthook": "^1.1.53",
|
|
45
38
|
"@tiledesk-ent/tiledesk-server-routing-queue": "^1.1.11",
|
|
46
|
-
"@tiledesk-ent/tiledesk-server-tags": "^1.1.2",
|
|
47
|
-
"@tiledesk-ent/tiledesk-server-triggers": "^1.1.82",
|
|
48
39
|
"@tiledesk-ent/tiledesk-server-visitorcounter": "^1.1.1",
|
|
49
40
|
"@tiledesk-ent/tiledesk-server-enterprise": "^1.0.0"
|
|
50
41
|
},
|
|
51
42
|
"dependencies": {
|
|
52
|
-
"@tiledesk/tiledesk-chat21-app": "^1.1.
|
|
43
|
+
"@tiledesk/tiledesk-chat21-app": "^1.1.7",
|
|
53
44
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.33",
|
|
45
|
+
"@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
|
|
46
|
+
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
|
47
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.1.10",
|
|
54
48
|
"app-root-path": "^3.0.0",
|
|
55
49
|
"bcrypt-nodejs": "0.0.3",
|
|
56
50
|
"body-parser": "^1.20.0",
|
|
@@ -93,6 +87,7 @@
|
|
|
93
87
|
"passport": "^0.4.1",
|
|
94
88
|
"passport-http": "^0.3.0",
|
|
95
89
|
"passport-jwt": "^4.0.0",
|
|
90
|
+
"pdfmake": "^0.2.5",
|
|
96
91
|
"promise-events": "^0.2.4",
|
|
97
92
|
"request": "^2.88.2",
|
|
98
93
|
"request-promise": "^4.2.6",
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
const authEvent = require('../../event/authEvent');
|
|
2
|
+
const requestEvent = require('../../event/requestEvent');
|
|
3
|
+
var Activity = require('./models/activity');
|
|
4
|
+
var winston = require('../../config/winston');
|
|
5
|
+
|
|
6
|
+
class ActivityArchiver {
|
|
7
|
+
|
|
8
|
+
listen() {
|
|
9
|
+
|
|
10
|
+
winston.debug('ActivityArchiver listen');
|
|
11
|
+
|
|
12
|
+
var enabled = process.env.ACTIVITY_HISTORY_ENABLED || "false";
|
|
13
|
+
winston.debug('ActivityArchiver enabled:'+enabled);
|
|
14
|
+
|
|
15
|
+
if (enabled==="true") {
|
|
16
|
+
winston.debug('ActivityArchiver enabled');
|
|
17
|
+
}else {
|
|
18
|
+
winston.info('ActivityArchiver disabled');
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (process.env.MONGOOSE_SYNCINDEX) {
|
|
23
|
+
Activity.syncIndexes();
|
|
24
|
+
winston.info("Activity.syncIndexes called");
|
|
25
|
+
}
|
|
26
|
+
|
|
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
|
+
authEvent.on('project_user.invite.pending', function(event) {
|
|
46
|
+
setImmediate(() => {
|
|
47
|
+
if (event.skipArchive) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
51
|
+
verb: "PROJECT_USER_INVITE", actionObj: event.req.body,
|
|
52
|
+
target: {type:"pendinginvitation", id:event.savedPendingInvitation._id.toString(), object: event.savedPendingInvitation },
|
|
53
|
+
id_project: event.req.projectid });
|
|
54
|
+
that.save(activity);
|
|
55
|
+
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
authEvent.on('project_user.invite', function(event) {
|
|
61
|
+
setImmediate(() => {
|
|
62
|
+
if (event.skipArchive) {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
68
|
+
verb: "PROJECT_USER_INVITE", actionObj: event.req.body,
|
|
69
|
+
target: {type:"project_user", id: event.savedProject_userPopulated._id.toString(), object: event.savedProject_userPopulated },
|
|
70
|
+
id_project: event.req.projectid });
|
|
71
|
+
that.save(activity);
|
|
72
|
+
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
authEvent.on('project_user.update', function(event) {
|
|
78
|
+
setImmediate(() => {
|
|
79
|
+
/*
|
|
80
|
+
2019-11-20T10:40:52.686991+00:00 app[web.1]: TypeError: Cannot read property '_id' of undefined
|
|
81
|
+
*/
|
|
82
|
+
if (event.skipArchive) {
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var project_user = undefined;
|
|
87
|
+
if (event.updatedProject_userPopulated.toObject) {
|
|
88
|
+
project_user = event.updatedProject_userPopulated.toObject()
|
|
89
|
+
}else {
|
|
90
|
+
project_user = event.updatedProject_userPopulated;
|
|
91
|
+
}
|
|
92
|
+
var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
93
|
+
verb: "PROJECT_USER_UPDATE", actionObj: event.req.body,
|
|
94
|
+
target: {type:"project_user", id: event.updatedProject_userPopulated._id.toString(), object: project_user},
|
|
95
|
+
id_project: event.req.projectid });
|
|
96
|
+
that.save(activity);
|
|
97
|
+
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
authEvent.on('project_user.delete', function(event) {
|
|
103
|
+
setImmediate(() => {
|
|
104
|
+
if (event.skipArchive) {
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
109
|
+
verb: "PROJECT_USER_DELETE", actionObj: event.req.body,
|
|
110
|
+
target: {type:"project_user", id:event.req.params.project_userid, object: event.project_userPopulated.toObject() }, //Error saving activity Maximum call stack size exceeded
|
|
111
|
+
id_project: event.req.projectid });
|
|
112
|
+
that.save(activity);
|
|
113
|
+
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
authEvent.on('user.signin', function(event) {
|
|
119
|
+
winston.debug('ActivityArchiver user.login');
|
|
120
|
+
setImmediate(() => {
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
if (event.skipArchive) {
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
var activity = new Activity({actor: {type:"user", id: event.user._id, name: event.user.fullName },
|
|
128
|
+
verb: "USER_SIGNIN", actionObj: event.req.body,
|
|
129
|
+
target: {type:"user", id:event.user._id.toString(), object: null },
|
|
130
|
+
id_project: '*' });
|
|
131
|
+
that.save(activity);
|
|
132
|
+
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
authEvent.on('user.login.error', function(event) {
|
|
136
|
+
setImmediate(() => {
|
|
137
|
+
|
|
138
|
+
if (event.skipArchive) {
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
var activity = new Activity({actor: {type:"user"},
|
|
143
|
+
verb: "USER_SIGNIN_ERROR", actionObj: event.req.body,
|
|
144
|
+
target: {type:"user", id:null, object: null },
|
|
145
|
+
id_project: '*' });
|
|
146
|
+
that.save(activity);
|
|
147
|
+
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
authEvent.on('user.requestresetpassword', function(event) {
|
|
152
|
+
setImmediate(() => {
|
|
153
|
+
|
|
154
|
+
if (event.skipArchive) {
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var activity = new Activity({actor: {type:"user", id: event.updatedUser._id, name: event.updatedUser.fullName },
|
|
159
|
+
verb: "USER_REQUEST_RESETPASSWORD", actionObj: event.req.body,
|
|
160
|
+
target: {type:"user", id:event.updatedUser._id.toString(), object: null },
|
|
161
|
+
id_project: '*' });
|
|
162
|
+
that.save(activity);
|
|
163
|
+
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
authEvent.on('user.resetpassword', function(event) {
|
|
168
|
+
setImmediate(() => {
|
|
169
|
+
|
|
170
|
+
if (event.skipArchive) {
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var activity = new Activity({actor: {type:"user", id: event.saveUser._id, name: event.saveUser.fullName },
|
|
175
|
+
verb: "USER_RESETPASSWORD", actionObj: null, //req.body otherwise print password
|
|
176
|
+
target: {type:"user", id:event.saveUser._id.toString(), object: null },
|
|
177
|
+
id_project: '*' });
|
|
178
|
+
that.save(activity);
|
|
179
|
+
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
authEvent.on('user.signup', function(event) {
|
|
185
|
+
setImmediate(() => {
|
|
186
|
+
if (event.skipArchive) {
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var activity = new Activity({actor: {type:"user", id: event.savedUser._id, name: event.savedUser.fullName },
|
|
191
|
+
verb: "USER_SIGNUP", actionObj: event.req.body,
|
|
192
|
+
target: {type:"user", id: event.savedUser._id.toString(), object: null },
|
|
193
|
+
id_project: '*' });
|
|
194
|
+
that.save(activity);
|
|
195
|
+
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
authEvent.on('user.signup.error', function(event) {
|
|
200
|
+
setImmediate(() => {
|
|
201
|
+
if (event.skipArchive) {
|
|
202
|
+
return 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
var activity = new Activity({actor: {type:"user"},
|
|
207
|
+
verb: "USER_SIGNUP_ERROR", actionObj: event.req.body,
|
|
208
|
+
target: {type:"user", id:null, object: null },
|
|
209
|
+
id_project: '*' });
|
|
210
|
+
that.save(activity);
|
|
211
|
+
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
requestEvent.on('request.create', function(request) {
|
|
216
|
+
setImmediate(() => {
|
|
217
|
+
// problema requester_id
|
|
218
|
+
|
|
219
|
+
// 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"}
|
|
220
|
+
|
|
221
|
+
// 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"}}
|
|
222
|
+
|
|
223
|
+
// request is plain object must be mongoose object oto populate
|
|
224
|
+
|
|
225
|
+
// if (event.skipArchive) {
|
|
226
|
+
// return 0;
|
|
227
|
+
// }
|
|
228
|
+
|
|
229
|
+
//TODO remove preflight
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
|
|
233
|
+
if (request.preflight === true) {
|
|
234
|
+
winston.debug("preflight request disable archiver")
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
var activity = new Activity({actor: {type:"user", id: request.requester_id},
|
|
238
|
+
verb: "REQUEST_CREATE", actionObj: request,
|
|
239
|
+
target: {type:"request", id:request._id, object: request },
|
|
240
|
+
id_project: request.id_project });
|
|
241
|
+
that.save(activity);
|
|
242
|
+
} catch(e) {
|
|
243
|
+
winston.error('ActivityArchiver error saving activity',e);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
requestEvent.on('request.update.preflight', function(request) {
|
|
252
|
+
setImmediate(() => {
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
|
|
256
|
+
if (request.preflight === true) {
|
|
257
|
+
winston.debug("preflight request disable archiver")
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
var activity = new Activity({actor: {type:"user", id: request.requester_id},
|
|
261
|
+
verb: "REQUEST_CREATE", actionObj: request,
|
|
262
|
+
target: {type:"request", id:request._id, object: request },
|
|
263
|
+
id_project: request.id_project });
|
|
264
|
+
that.save(activity);
|
|
265
|
+
} catch(e) {
|
|
266
|
+
winston.error('ActivityArchiver error saving activity',e);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
requestEvent.on('request.close', function(request) {
|
|
275
|
+
setImmediate(() => {
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
winston.debug('ActivityArchiver close');
|
|
279
|
+
|
|
280
|
+
var activity = new Activity({actor: {type:"user", id: request.closed_by},
|
|
281
|
+
verb: "REQUEST_CLOSE", actionObj: request,
|
|
282
|
+
target: {type:"request", id:request._id, object: request },
|
|
283
|
+
id_project: request.id_project });
|
|
284
|
+
that.save(activity);
|
|
285
|
+
} catch(e) {
|
|
286
|
+
winston.error('ActivityArchiver error saving activity',e);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
winston.info('ActivityArchiver listening');
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
save(activity) {
|
|
301
|
+
activity.save(function(err, savedActivity) {
|
|
302
|
+
if (err) {
|
|
303
|
+
winston.error('Error saving activity ', {activity: activity.toObject(), err:err});
|
|
304
|
+
}else {
|
|
305
|
+
winston.debug('Activity saved', savedActivity.toObject());
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
var activityArchiver = new ActivityArchiver();
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
module.exports = activityArchiver;
|