@tiledesk/tiledesk-server 2.3.6 → 2.3.7-1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. package/.github/workflows/docker-community-worker-push-latest.yml +23 -0
  2. package/.github/workflows/docker-image-tag-worker-community-tag-push.yml +22 -0
  3. package/CHANGELOG.md +361 -3
  4. package/Dockerfile-jobs +31 -0
  5. package/app.js +62 -69
  6. package/channels/chat21/chat21Handler.js +37 -6
  7. package/channels/chat21/chat21WebHook.js +62 -34
  8. package/channels/chat21/package-lock.json +663 -706
  9. package/channels/chat21/package.json +2 -2
  10. package/config/labels/widget.json +337 -136
  11. package/deploy.sh +2 -0
  12. package/event/messageEvent.js +110 -9
  13. package/jobs.js +80 -0
  14. package/jobsManager.js +47 -0
  15. package/middleware/has-role.js +10 -3
  16. package/middleware/ipFilter.js +220 -0
  17. package/middleware/passport.js +8 -2
  18. package/models/department.js +1 -1
  19. package/models/faq.js +77 -25
  20. package/models/faq_kb.js +19 -0
  21. package/models/message.js +10 -8
  22. package/models/project.js +10 -0
  23. package/models/project_user.js +10 -0
  24. package/models/request.js +12 -1
  25. package/package.json +12 -11
  26. package/pubmodules/activities/activityArchiver.js +216 -90
  27. package/pubmodules/activities/routes/activity.js +1 -1
  28. package/pubmodules/apps/index.js +8 -0
  29. package/pubmodules/apps/listener.js +27 -0
  30. package/pubmodules/cache/index.js +2 -0
  31. package/pubmodules/cache/mongoose-cachegoose-fn.js +630 -0
  32. package/pubmodules/canned/cannedResponse.js +4 -0
  33. package/pubmodules/canned/cannedResponseRoute.js +10 -5
  34. package/pubmodules/dialogflow/index.js +10 -0
  35. package/pubmodules/dialogflow/listener.js +66 -0
  36. package/pubmodules/emailNotification/requestNotification.js +58 -28
  37. package/pubmodules/events/eventRoute.js +49 -24
  38. package/pubmodules/messageTransformer/messageHandlebarsTransformerInterceptor.js +6 -1
  39. package/pubmodules/messageTransformer/messageTransformerInterceptor.js +10 -4
  40. package/pubmodules/pubModulesManager.js +173 -7
  41. package/pubmodules/queue/index.js +4 -0
  42. package/pubmodules/queue/reconnect.js +331 -0
  43. package/pubmodules/queue/reconnectFanout.js +256 -0
  44. package/pubmodules/rasa/listener.js +5 -5
  45. package/pubmodules/routing-queue/index.js +3 -0
  46. package/pubmodules/routing-queue/listener.js +328 -0
  47. package/pubmodules/rules/conciergeBot.js +2 -2
  48. package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +6 -1
  49. package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +7 -1
  50. package/pubmodules/tilebot/index.js +11 -0
  51. package/pubmodules/tilebot/listener.js +85 -0
  52. package/pubmodules/trigger/rulesTrigger.js +137 -14
  53. package/pubmodules/trigger/start.js +5 -1
  54. package/pubmodules/whatsapp/index.js +7 -0
  55. package/pubmodules/whatsapp/listener.js +32 -0
  56. package/routes/auth.js +7 -2
  57. package/routes/campaigns.js +3 -3
  58. package/routes/department.js +3 -2
  59. package/routes/email.js +32 -2
  60. package/routes/faq.js +37 -2
  61. package/routes/faq_kb.js +496 -133
  62. package/routes/faqpub.js +5 -0
  63. package/routes/lead.js +56 -0
  64. package/routes/message.js +196 -14
  65. package/routes/messagesRoot.js +39 -0
  66. package/routes/project.js +76 -4
  67. package/routes/project_user.js +11 -1
  68. package/routes/project_user_test.js +19 -0
  69. package/routes/request.js +134 -30
  70. package/routes/troubleshooting.js +12 -0
  71. package/routes/users-util.js +39 -0
  72. package/routes/users.js +1 -1
  73. package/routes/widget.js +64 -2
  74. package/services/BotSubscriptionNotifier.js +5 -0
  75. package/services/banUserNotifier.js +86 -0
  76. package/services/cacheEnabler.js +56 -0
  77. package/services/chatbotService.js +101 -0
  78. package/services/departmentService.js +25 -3
  79. package/services/emailService.js +170 -28
  80. package/services/faqBotHandler.js +2 -3
  81. package/services/faqService.js +28 -3
  82. package/services/geoService.js +36 -6
  83. package/services/labelService.js +1 -1
  84. package/services/leadService.js +3 -2
  85. package/services/messageService.js +4 -2
  86. package/services/modulesManager.js +23 -76
  87. package/services/operatingHoursService.js +9 -4
  88. package/services/requestService.js +75 -39
  89. package/services/subscriptionNotifier.js +9 -4
  90. package/services/trainingService.js +106 -0
  91. package/template/email/assignedEmailMessage.html +21 -11
  92. package/template/email/assignedRequest.html +21 -11
  93. package/template/email/beenInvitedExistingUser.html +16 -6
  94. package/template/email/beenInvitedNewUser.html +16 -6
  95. package/template/email/emailDirect.html +130 -0
  96. package/template/email/newMessage.html +18 -8
  97. package/template/email/newMessageFollower.html +22 -12
  98. package/template/email/passwordChanged.html +15 -5
  99. package/template/email/pooledEmailMessage.html +21 -11
  100. package/template/email/pooledRequest.html +20 -10
  101. package/template/email/resetPassword.html +15 -5
  102. package/template/email/sendTranscript.html +7 -4
  103. package/template/email/ticket.html +17 -7
  104. package/template/email/verify.html +15 -5
  105. package/test/cannedRoute.js +157 -0
  106. package/test/chatbot-mock.js +127 -0
  107. package/test/example-json-intents.txt +1 -0
  108. package/test/example-json.txt +1 -0
  109. package/test/example.json +1 -0
  110. package/test/faqRoute.js +353 -208
  111. package/test/faqkbRoute.js +669 -64
  112. package/test/imageRoute.js +1 -1
  113. package/test/messageRoute.js +387 -5
  114. package/test/requestRoute.js +6 -6
  115. package/test/requestService.js +55 -4
  116. package/test-int/cache-project.js +90 -0
  117. package/test-int/cache-project_user.js +88 -0
  118. package/utils/UIDGenerator.js +20 -0
  119. package/utils/cacheUtil.js +2 -2
  120. package/utils/orgUtil.js +3 -3
  121. package/utils/promiseUtil.js +31 -0
  122. package/utils/recipientEmailUtil.js +66 -0
  123. package/utils/sendEmailUtil.js +34 -0
  124. package/utils/sendMessageUtil.js +1 -1
  125. package/utils/stringUtil.js +12 -0
  126. package/websocket/webSocketServer.js +33 -10
@@ -0,0 +1,630 @@
1
+ var requestEvent = require("../../event/requestEvent");
2
+ var messageEvent = require("../../event/messageEvent");
3
+ var projectEvent = require("../../event/projectEvent");
4
+ var botEvent = require("../../event/botEvent");
5
+ var departmentEvent = require("../../event/departmentEvent");
6
+ var authEvent = require("../../event/authEvent");
7
+ var labelEvent = require("../../event/labelEvent");
8
+
9
+ var triggerEventEmitter = require("../trigger/event/triggerEventEmitter");
10
+ var subscriptionEvent = require("../../event/subscriptionEvent");
11
+
12
+ var winston = require('../../config/winston');
13
+
14
+ var cachegoose = require('cachegoose');
15
+
16
+ var cacheUtil = require('../../utils/cacheUtil');
17
+
18
+
19
+
20
+ function listen(client) {
21
+
22
+ projectEvent.on("project.create", function(project) {
23
+ setImmediate(() => {
24
+ var key = "projects:id:"+project.id;
25
+ winston.verbose("Creating cache for project.create with key: " + key);
26
+ client.set(key, project, cacheUtil.longTTL, (err, reply) => {
27
+ winston.verbose("Created cache for project.create",{err:err});
28
+ winston.debug("Created cache for project.create reply",reply);
29
+ });
30
+
31
+ key = "projects:query:*";
32
+ winston.verbose("Deleting cache for project.create with key: " + key);
33
+ client.del(key, function (err, reply) {
34
+ winston.verbose("Deleted cache for project.create",{err:err});
35
+ winston.debug("Deleted cache for project.create",reply);
36
+
37
+ });
38
+ });
39
+ });
40
+
41
+ projectEvent.on("project.update", function(project) {
42
+ setImmediate(() => {
43
+ var key = "projects:id:"+project.id;
44
+ winston.verbose("Updating cache for project.update with key: " + key);
45
+ client.set(key, project, cacheUtil.longTTL, (err, reply) => {
46
+ winston.verbose("Updated cache for project.update",{err:err});
47
+ winston.debug("Updated cache for project.update",reply);
48
+
49
+ });
50
+
51
+ key = "projects:query:*";
52
+ winston.verbose("Deleting cache for project.create with key: " + key);
53
+ client.del(key, function (err, reply) {
54
+ winston.debug("Deleted cache for project.create",reply);
55
+ winston.verbose("Deleted cache for project.create",{err:err});
56
+ });
57
+ });
58
+
59
+ });
60
+
61
+ projectEvent.on("project.delete", function(project) {
62
+ setImmediate(() => {
63
+ var key = "projects:id:"+project.id;
64
+ winston.verbose("Deleting cache for project.delete with key: " + key);
65
+ client.del(key, (err, reply) => {
66
+ winston.debug("Deleted cache for project.delete",reply);
67
+ winston.verbose("Deleted cache for project.delete",{err:err});
68
+ });
69
+
70
+ key = "projects:query:*";
71
+ winston.verbose("Deleting cache for project.create with key: " + key);
72
+ client.del(key, function (err, reply) {
73
+ winston.debug("Deleted cache for project.create",reply);
74
+ winston.verbose("Deleted cache for project.create",{err:err});
75
+ });
76
+ });
77
+ });
78
+
79
+ projectEvent.on("project.downgrade", function(project) {
80
+ setImmediate(() => {
81
+ var key = "projects:id:"+project.id;
82
+ winston.verbose("Updating cache for project.downgrade with key: " + key);
83
+
84
+ client.set(key, project, cacheUtil.longTTL, (err, reply) => {
85
+ winston.debug("Updated cache for project.downgrade",reply);
86
+ winston.verbose("Updated cache for project.downgrade",{err:err});
87
+ });
88
+
89
+ key = "projects:query:*";
90
+ winston.verbose("Deleting cache for project.create with key: " + key);
91
+ client.del(key, function (err, reply) {
92
+ winston.debug("Deleted cache for project.create",reply);
93
+ winston.verbose("Deleted cache for project.create",{err:err});
94
+ });
95
+ });
96
+ });
97
+
98
+
99
+
100
+
101
+
102
+
103
+ authEvent.on('project_user.update', function(data) {
104
+ setImmediate(() => {
105
+
106
+ var project_user = data.updatedProject_userPopulated;
107
+
108
+ var key = project_user.id_project+":project_users:id:"+project_user.id;
109
+ winston.verbose("Updating cache for project_user.update with key: " + key);
110
+ client.set(key, project_user, cacheUtil.defaultTTL, (err, reply) => {
111
+ winston.debug("Updated cache for project_user.update",reply);
112
+ winston.verbose("Updated cache for project_user.update",{err:err});
113
+ });
114
+
115
+ if (project_user.id_user) {
116
+ var key = project_user.id_project+":project_users:iduser:"+project_user.id_user;
117
+ winston.verbose("Updating cache for project_user.update with key: " + key);
118
+ client.set(key, project_user, cacheUtil.defaultTTL, (err, reply) => {
119
+ winston.debug("Updated cache for project_user.update",reply);
120
+ winston.verbose("Updated cache for project_user.update",{err:err});
121
+ });
122
+ }
123
+
124
+ if (project_user.uuid_user) {
125
+ var key = project_user.id_project+":project_users:uuid_user:"+project_user.uuid_user;
126
+ winston.verbose("Updating cache for project_user.update with key: " + key);
127
+ client.set(key, project_user, cacheUtil.defaultTTL, (err, reply) => {
128
+ winston.debug("Updated cache for project_user.update",reply);
129
+ winston.verbose("Updated cache for project_user.update",{err:err});
130
+ });
131
+ }
132
+
133
+
134
+
135
+ var role = project_user.role;
136
+
137
+ var TEAMMATE_ROLES = {
138
+ "agent": ["guest","user","agent"],
139
+ "admin": ["guest","user","agent", "admin",],
140
+ "owner": ["guest","user","agent", "admin", "owner"],
141
+ }
142
+ // controllare bene
143
+
144
+ var hierarchicalRoles = TEAMMATE_ROLES[role];
145
+ winston.debug("hierarchicalRoles", hierarchicalRoles);
146
+
147
+ if ( hierarchicalRoles && hierarchicalRoles.includes(role)) {
148
+
149
+ var key = project_user.id_project+":project_users:role:teammate:"+project_user.id;
150
+ winston.verbose("Updating cache for project_user.update with key: " + key);
151
+ client.set(key, project_user, cacheUtil.defaultTTL, (err, reply) => {
152
+ winston.debug("Updated cache for project_user.update",reply);
153
+ winston.verbose("Updated cache for project_user.update",{err:err});
154
+ });
155
+ }
156
+ });
157
+ });
158
+
159
+
160
+
161
+
162
+
163
+ authEvent.on('user.signup', function(data) {
164
+ setImmediate(() => {
165
+ var user = data.savedUser;
166
+
167
+ var key = "users:id:"+user.id;
168
+ winston.verbose("Creating cache for user.signup with key: " + key);
169
+ client.set(key, user, cacheUtil.defaultTTL, (err, reply) => {
170
+ winston.debug("Created cache for user.signup",reply);
171
+ winston.verbose("Created cache for user.signup",{err:err});
172
+ });
173
+
174
+ var key = "users:email:"+user.email;
175
+ winston.verbose("Creating cache for user.signup with key: " + key);
176
+ client.set(key, user, cacheUtil.defaultTTL, (err, reply) => {
177
+ winston.debug("Created cache for user.signup",reply);
178
+ winston.verbose("Created cache for user.signup",{err:err});
179
+ });
180
+ });
181
+ });
182
+
183
+
184
+ authEvent.on('user.update', function(data) {
185
+ setImmediate(() => {
186
+ var user = data.updatedUser;
187
+
188
+ var key = "users:id:"+user.id;
189
+ winston.verbose("Updating cache for user.update with key: " + key);
190
+ client.set(key, user, cacheUtil.defaultTTL, (err, reply) => {
191
+ winston.debug("Updated cache for user.update",reply);
192
+ winston.verbose("Updated cache for user.update",{err:err});
193
+ });
194
+
195
+ var key = "users:email:"+user.email;
196
+ winston.verbose("Updating cache for user.update with key: " + key);
197
+ client.set(key, user, cacheUtil.defaultTTL, (err, reply) => {
198
+ winston.debug("Updated cache for user.update",reply);
199
+ winston.verbose("Updated cache for user.update",{err:err});
200
+ });
201
+ });
202
+ });
203
+
204
+ authEvent.on('user.delete', function(data) {
205
+ setImmediate(() => {
206
+ var user = data.user;
207
+
208
+ var key = "users:id:"+user.id;
209
+ winston.verbose("Deleting cache for user.delete with key: " + key);
210
+ client.del(key, (err, reply) => {
211
+ winston.debug("Deleted cache for user.delete",reply);
212
+ winston.verbose("Deleted cache for user.delete",{err:err});
213
+ });
214
+
215
+ var key = "users:email:"+user.email;
216
+ winston.verbose("Deleting cache for user.delete with key: " + key);
217
+ client.del(key, (err, reply) => {
218
+ winston.debug("Deleted cache for user.delete",reply);
219
+ winston.verbose("Deleted cache for user.delete",{err:err});
220
+ });
221
+ });
222
+ });
223
+
224
+
225
+
226
+
227
+ requestEvent.on("request.create.simple", function(request) {
228
+ setImmediate(() => {
229
+ var key = request.id_project+":requests:id:"+request.id+":simple";
230
+ winston.verbose("Creating cache for request.create.simple with key: " + key);
231
+
232
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
233
+ winston.debug("Created cache for request.create.simple",reply);
234
+ winston.verbose("Created cache for request.create.simple",{err:err});
235
+ });
236
+
237
+
238
+ var key = "requests:id:"+request.request_id+":simple"; //without project for chat21 webhook
239
+ winston.verbose("Creating cache for request.create.simple with key: " + key);
240
+
241
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
242
+ winston.debug("Created cache for request.create.simple",reply);
243
+ winston.verbose("Created cache for request.create.simple",{err:err});
244
+ });
245
+
246
+ var key = request.id_project+":requests:request_id:"+request.request_id+":simple";
247
+ winston.verbose("Creating cache for request.create.simple with key: " + key);
248
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
249
+ winston.debug("Created cache for request.create.simple",reply);
250
+ winston.verbose("Created cache for request.create.simple",{err:err});
251
+ });
252
+
253
+ })
254
+ });
255
+
256
+ requestEvent.on("request.create", function(request) {
257
+ setImmediate(() => {
258
+ var key = request.id_project+":requests:id:"+request.id;
259
+ winston.verbose("Creating cache for request.create with key: " + key);
260
+
261
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
262
+ winston.debug("Created cache for request.create",reply);
263
+ winston.verbose("Created cache for request.create",{err:err});
264
+ });
265
+
266
+ var key = request.id_project+":requests:request_id:"+request.request_id;
267
+ winston.verbose("Creating cache for request.create with key: " + key);
268
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
269
+ winston.debug("Created cache for request.create",reply);
270
+ winston.verbose("Created cache for request.create",{err:err});
271
+ });
272
+
273
+ key = request.id_project+":requests:query:*";
274
+ winston.verbose("Deleting cache for request.create with key: " + key);
275
+ client.del(key, function (err, reply) {
276
+ winston.debug("Deleted cache for request.create",reply);
277
+ winston.verbose("Deleted cache for request.create",{err:err});
278
+ });
279
+ });
280
+ });
281
+
282
+
283
+
284
+ requestEvent.on("request.update", function(request) {
285
+ setImmediate(() => {
286
+ var key = request.id_project+":requests:id:"+request.id;
287
+ winston.verbose("Creating cache for request.update with key: " + key);
288
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
289
+ winston.debug("Created cache for request.update",reply);
290
+ winston.verbose("Created cache for request.update",{err:err});
291
+ });
292
+
293
+ var key = request.id_project+":requests:request_id:"+request.request_id;
294
+ winston.verbose("Creating cache for request.update with key: " + key);
295
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
296
+ winston.debug("Created cache for request.update",reply);
297
+ winston.verbose("Created cache for request.update",{err:err});
298
+ });
299
+
300
+ key = request.id_project+":requests:query:*";
301
+ winston.verbose("Deleting cache for request.create with key: " + key);
302
+ client.del(key, function (err, reply) {
303
+ winston.debug("Deleted cache for request.create",reply);
304
+ winston.verbose("Deleted cache for request.create",{err:err});
305
+ });
306
+ });
307
+ });
308
+
309
+
310
+ requestEvent.on("request.close", function(request) {
311
+ setImmediate(() => {
312
+ var key = request.id_project+":requests:id:"+request.id;
313
+ winston.verbose("Creating cache for request.close with key: " + key);
314
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
315
+ winston.debug("Created cache for request.close",reply);
316
+ winston.verbose("Created cache for request.close",{err:err});
317
+ });
318
+
319
+ var key = request.id_project+":requests:request_id:"+request.request_id;
320
+ winston.verbose("Creating cache for request.close with key: " + key);
321
+ client.set(key, request, cacheUtil.defaultTTL, (err, reply) => {
322
+ winston.debug("Created cache for request.close",reply);
323
+ winston.verbose("Created cache for request.close",{err:err});
324
+ });
325
+
326
+ key = request.id_project+":requests:query:*";
327
+ winston.verbose("Deleting cache for request.create with key: " + key);
328
+ client.del(key, function (err, reply) {
329
+ winston.debug("Deleted cache for request.create",reply);
330
+ winston.verbose("Deleted cache for request.create",{err:err});
331
+ });
332
+ });
333
+ });
334
+
335
+
336
+
337
+
338
+ // non serve tanto
339
+ // messageEvent.on("message.create", function(message) {
340
+ // setImmediate(() => {
341
+ // var key = message.id_project+":requests:id:"+message.request._id + ":messages:id:" + message._id;
342
+ // winston.verbose("Creating cache for message.create with key: " + key);
343
+ // client.set(key, message, cacheUtil.defaultTTL, (err, reply) => {
344
+ // winston.verbose("Created cache for message.create",{err:err, reply:reply});
345
+ // });
346
+
347
+ // var key = message.id_project+":requests:request_id:"+message.request.request_id + ":messages:id:" + message._id;
348
+ // winston.verbose("Creating cache for message.create with key: " + key);
349
+ // client.set(key, message, cacheUtil.defaultTTL, (err, reply) => {
350
+ // winston.verbose("Created cache for message.create",{err:err, reply:reply});
351
+ // });
352
+ // });
353
+ // });
354
+
355
+
356
+
357
+ botEvent.on("faqbot.create", function(faq_kb) {
358
+ setImmediate(() => {
359
+ var key = faq_kb.id_project+":faq_kbs:id:"+faq_kb._id;
360
+ winston.verbose("Creating cache for faq_kb.create with key: " + key);
361
+ client.set(key, faq_kb, cacheUtil.defaultTTL, (err, reply) => {
362
+ winston.debug("Created cache for faq_kb.create",reply);
363
+ winston.verbose("Created cache for faq_kb.create",{err:err});
364
+ });
365
+ });
366
+ });
367
+
368
+
369
+
370
+ botEvent.on("faqbot.update", function(faq_kb) {
371
+ setImmediate(() => {
372
+ var key = faq_kb.id_project+":faq_kbs:id:"+faq_kb._id;
373
+ winston.verbose("Creating cache for faq_kb.update with key: " + key);
374
+ client.set(key, faq_kb, cacheUtil.defaultTTL, (err, reply) => {
375
+ winston.debug("Created cache for faq_kb.create",reply);
376
+ winston.verbose("Created cache for faq_kb.update",{err:err});
377
+ });
378
+ });
379
+ });
380
+
381
+
382
+ botEvent.on("faqbot.delete", function(faq_kb) {
383
+ setImmediate(() => {
384
+ var key = faq_kb.id_project+":faq_kbs:id:"+faq_kb._id;
385
+ winston.verbose("Creating cache for faqbot.delete with key: " + key);
386
+ client.set(key, faq_kb, cacheUtil.defaultTTL, (err, reply) => {
387
+ winston.debug("Created cache for faqbot.delete",reply);
388
+ winston.verbose("Created cache for faqbot.delete",{err:err});
389
+ });
390
+ });
391
+ });
392
+
393
+
394
+ departmentEvent.on("department.create", function(department) {
395
+ setImmediate(() => {
396
+ var key = department.id_project+":departments:id:"+department._id;
397
+ winston.verbose("Creating cache for department.create with key: " + key);
398
+ client.set(key, department, cacheUtil.defaultTTL, (err, reply) => {
399
+ winston.debug("Created cache for department.create",reply);
400
+ winston.verbose("Created cache for department.create",{err:err});
401
+ });
402
+
403
+ key = department.id_project+":departments:query:*";
404
+ winston.verbose("Deleting cache for department.create with key: " + key);
405
+ client.del(key, function (err, reply) {
406
+ winston.debug("Deleted cache for department.create",reply);
407
+ winston.verbose("Deleted cache for department.create",{err:err});
408
+ });
409
+ });
410
+ });
411
+
412
+
413
+
414
+ departmentEvent.on("department.update", function(department) {
415
+ setImmediate(() => {
416
+ var key = department.id_project+":departments:id:"+department._id;
417
+ winston.verbose("Creating cache for department.update with key: " + key);
418
+ client.set(key, department, cacheUtil.defaultTTL, (err, reply) => {
419
+ winston.debug("Created cache for department.update",reply);
420
+ winston.verbose("Created cache for department.update",{err:err});
421
+ });
422
+
423
+ key = department.id_project+":departments:query:*";
424
+ winston.verbose("Deleting cache for department.update with key: " + key);
425
+ client.del(key, function (err, reply) {
426
+ winston.debug("Deleted cache for department.update",reply);
427
+ winston.verbose("Deleted cache for department.update",{err:err});
428
+ });
429
+ });
430
+ });
431
+
432
+
433
+ departmentEvent.on("department.delete", function(department) {
434
+ setImmediate(() => {
435
+ var key = department.id_project+":departments:id:"+department._id;
436
+ winston.verbose("Creating cache for department.delete with key: " + key);
437
+ client.set(key, department, cacheUtil.defaultTTL, (err, reply) => {
438
+ winston.debug("Created cache for department.delete",reply);
439
+ winston.verbose("Created cache for department.delete",{err:err});
440
+ });
441
+
442
+ key = department.id_project+":departments:query:*";
443
+ winston.verbose("Deleting cache for department.delete with key: " + key);
444
+ client.del(key, function (err, reply) {
445
+ winston.debug("Deleted cache for department.delete",reply);
446
+ winston.verbose("Deleted cache for department.delete",{err:err});
447
+ });
448
+ });
449
+ });
450
+
451
+
452
+ labelEvent.on("label.create", function(label) {
453
+ setImmediate(() => {
454
+ var key = label.id_project+":labels:query:*";
455
+ winston.verbose("Deleting cache for label.create with key: " + key);
456
+ client.del(key, function (err, reply) {
457
+ winston.debug("Deleted cache for label.create",reply);
458
+ winston.verbose("Deleted cache for label.create",{err:err});
459
+ });
460
+ });
461
+ });
462
+
463
+
464
+
465
+ labelEvent.on("label.update", function(label) {
466
+ setImmediate(() => {
467
+ var key = label.id_project+":labels:query:*";
468
+ winston.verbose("Deleting cache for label.update with key: " + key);
469
+ client.del(key, function (err, reply) {
470
+ winston.debug("Deleted cache for label.update",reply);
471
+ winston.verbose("Deleted cache for label.update",{err:err});
472
+ });
473
+ });
474
+ });
475
+
476
+
477
+ labelEvent.on("label.clone", function(label) {
478
+ setImmediate(() => {
479
+ var key = label.id_project+":labels:query:*";
480
+ winston.verbose("Deleting cache for label.clone with key: " + key);
481
+ client.del(key, function (err, reply) {
482
+ winston.debug("Deleted cache for label.clone",reply);
483
+ winston.verbose("Deleted cache for label.clone",{err:err});
484
+ });
485
+ });
486
+ });
487
+
488
+
489
+ labelEvent.on("label.delete", function(label) {
490
+ setImmediate(() => {
491
+ var key = label.id_project+":labels:query:*";
492
+ winston.verbose("Deleting cache for label.delete with key: " + key);
493
+ client.del(key, function (err, reply) {
494
+ winston.debug("Deleted cache for label.delete",reply);
495
+ winston.verbose("Deleted cache for label.delete",{err:err});
496
+ });
497
+ });
498
+ });
499
+
500
+ // fai cache per subscription.create, .update .delete
501
+
502
+
503
+ if (subscriptionEvent) {
504
+ subscriptionEvent.on('subscription.create', function(trigger) {
505
+ setImmediate(() => {
506
+
507
+ var key =trigger.id_project+":subscriptions:*";
508
+ winston.verbose("Deleting cache for subscription.create with key: " + key);
509
+ client.del(key, function (err, reply) {
510
+ winston.debug("Deleted cache for subscription.create",reply);
511
+ winston.verbose("Deleted cache for subscription.create",{err:err});
512
+ });
513
+ });
514
+ });
515
+
516
+ subscriptionEvent.on('subscription.update', function(trigger) {
517
+ setImmediate(() => {
518
+ var key =trigger.id_project+":subscriptions:*";
519
+ winston.verbose("Deleting cache for subscription.update with key: " + key);
520
+ client.del(key, function (err, reply) {
521
+ winston.debug("Deleted cache for subscription.update",reply);
522
+ winston.verbose("Deleted cache for subscription.update",{err:err});
523
+ });
524
+ });
525
+ });
526
+
527
+ subscriptionEvent.on("subscription.delete", function(trigger) {
528
+ setImmediate(() => {
529
+ var key =trigger.id_project+":subscriptions:*";
530
+ winston.verbose("Deleting cache for subscription.delete with key: " + key);
531
+ client.del(key, function (err, reply) {
532
+ winston.debug("Deleted cache for subscription.delete",reply);
533
+ winston.verbose("Deleted cache for subscription.delete",{err:err});
534
+ });
535
+ });
536
+ });
537
+
538
+ }
539
+
540
+
541
+ if (triggerEventEmitter) {
542
+ triggerEventEmitter.on('trigger.create', function(trigger) {
543
+ setImmediate(() => {
544
+
545
+ var key =trigger.id_project+":triggers:*";
546
+ winston.verbose("Deleting cache for trigger.create with key: " + key);
547
+ client.del(key, function (err, reply) {
548
+ winston.debug("Deleted cache for trigger.create",reply);
549
+ winston.verbose("Deleted cache for trigger.create",{err:err});
550
+ });
551
+ });
552
+ });
553
+
554
+ triggerEventEmitter.on('trigger.update', function(trigger) {
555
+ setImmediate(() => {
556
+ var key =trigger.id_project+":triggers:*";
557
+ winston.verbose("Deleting cache for trigger.update with key: " + key);
558
+ client.del(key, function (err, reply) {
559
+ winston.debug("Deleted cache for trigger.update",reply);
560
+ winston.verbose("Deleted cache for trigger.update",{err:err});
561
+ });
562
+ });
563
+ });
564
+
565
+ triggerEventEmitter.on("trigger.delete", function(trigger) {
566
+ setImmediate(() => {
567
+ var key =trigger.id_project+":triggers:*";
568
+ winston.verbose("Deleting cache for trigger.delete with key: " + key);
569
+ client.del(key, function (err, reply) {
570
+ winston.debug("Deleted cache for trigger.delete",reply);
571
+ winston.verbose("Deleted cache for trigger.delete",{err:err});
572
+ });
573
+ });
574
+ });
575
+
576
+ }
577
+
578
+ //jwt
579
+
580
+ // fai cache faq
581
+
582
+ }
583
+
584
+ module.exports = function (mongoose, option) {
585
+
586
+ if (process.env.CACHE_ENABLED == true || process.env.CACHE_ENABLED == "true") {
587
+ var engine = process.env.CACHE_ENGINE;
588
+ winston.debug("Redis engine: "+ engine);
589
+
590
+ // var endPoint = process.env.CACHE_REDIS_ENDPOINT || "redis://127.0.0.1:6379";
591
+ // winston.debug("Redis endpoint: "+ endPoint);
592
+
593
+ var port = process.env.CACHE_REDIS_PORT || 6379;
594
+ winston.debug("Redis port: "+ port);
595
+
596
+ var host = process.env.CACHE_REDIS_HOST || "127.0.0.1"
597
+ winston.debug("Redis host: "+ host);
598
+
599
+ var password = process.env.CACHE_REDIS_PASSWORD;
600
+ winston.debug("Redis password: "+ password);
601
+
602
+ winston.info("Mongoose Cachegoose fn initialized, engine: " + engine + ", port: "+ port + ", host: "+ host + " defaultTTL: " +cacheUtil.defaultTTL + ", password: "+ password);
603
+ // winston.info("Mongoose Cachegoose fn initialized, engine: " + engine + ", endpoint: "+endPoint +", port: "+ port + ", host: "+ host + ", password: "+ password);
604
+
605
+
606
+
607
+
608
+ // cachegoose(mongoose, endPoint);
609
+
610
+ cachegoose(mongoose, {
611
+ engine: engine, /* If you don't specify the redis engine, */
612
+ port: port, /* the query results will be cached in memory. */
613
+ host: host,
614
+ password: password
615
+ });
616
+
617
+ var client = cachegoose._cache;
618
+ listen(client);
619
+ }else {
620
+ winston.info("Mongoose Cachegoose disabled");
621
+ }
622
+
623
+ // console.log("init",init);
624
+ // console.log("cachegoose._cache",cachegoose._cache);
625
+ // cachegoose._cache.get("/projects/5ea800091147f28c72b90c5e", (err, cachedResults) => { //
626
+ // console.log("cachedResults",cachedResults);
627
+ // });
628
+
629
+
630
+ }
@@ -14,6 +14,10 @@ var CannedResponseSchema = new Schema({
14
14
  type: String,
15
15
  required: true,
16
16
  },
17
+ shared: {
18
+ type: Boolean,
19
+ required: true
20
+ },
17
21
  attributes: {
18
22
  type: Object,
19
23
  },
@@ -12,12 +12,18 @@ router.post('/', function (req, res) {
12
12
 
13
13
  var newCannedResponse = new CannedResponse({
14
14
  title: req.body.title,
15
- text: req.body.text,
15
+ text: req.body.text,
16
16
  id_project: req.projectid,
17
17
  createdBy: req.user.id,
18
18
  updatedBy: req.user.id
19
19
  });
20
20
 
21
+ if (req.projectuser.role == 'owner' || req.projectuser.role == 'admin') {
22
+ newCannedResponse.shared = true;
23
+ } else {
24
+ newCannedResponse.shared = false;
25
+ }
26
+
21
27
  newCannedResponse.save(function (err, savedCannedResponse) {
22
28
  if (err) {
23
29
  winston.error('--- > ERROR ', err)
@@ -104,7 +110,7 @@ router.get('/:cannedResponseid', function (req, res) {
104
110
  });
105
111
 
106
112
  router.get('/', function (req, res) {
107
- var limit = 40; // Number of CannedResponses per page
113
+ var limit = 1000; // Number of CannedResponses per page
108
114
  var page = 0;
109
115
 
110
116
  if (req.query.page) {
@@ -114,15 +120,14 @@ router.get('/', function (req, res) {
114
120
  var skip = page * limit;
115
121
  winston.debug('CannedResponse ROUTE - SKIP PAGE ', skip);
116
122
 
117
-
118
- var query = { "id_project": req.projectid, "status": {$lt:1000}};
123
+ // var query = { "id_project": req.projectid, "status": {$lt:1000}};
124
+ var query = {"id_project": req.projectid, "status": { $lt:1000 }, $or:[ { shared: true }, { shared : { $exists: false }}, { createdBy: req.user._id } ] }
119
125
 
120
126
  if (req.query.full_text) {
121
127
  winston.debug('CannedResponse ROUTE req.query.fulltext', req.query.full_text);
122
128
  query.$text = { "$search": req.query.full_text };
123
129
  }
124
130
 
125
-
126
131
  var direction = -1; //-1 descending , 1 ascending
127
132
  if (req.query.direction) {
128
133
  direction = req.query.direction;