@tiledesk/tiledesk-server 2.2.39 → 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 +17 -3
- package/app.js +21 -60
- 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/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 -12
- 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 +129 -5
- package/pubmodules/rasa/listener.js +5 -5
- package/pubmodules/rules/conciergeBot.js +4 -4
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +3 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +3 -1
- 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 +122 -16
- 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/faqService.js +2 -2
- package/services/geoService.js +30 -4
- package/services/leadService.js +2 -0
- package/services/modulesManager.js +7 -188
- 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/routes/request.js
CHANGED
|
@@ -162,6 +162,20 @@ router.patch('/:requestid', function (req, res) {
|
|
|
162
162
|
update.priority = req.body.priority;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
if (req.body.smartAssignment!=undefined) {
|
|
166
|
+
update.smartAssignment = req.body.smartAssignment;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (req.body.workingStatus!=undefined) {
|
|
170
|
+
update.workingStatus = req.body.workingStatus;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
if (req.body.channelName) {
|
|
175
|
+
update["channel.name"] = req.body.channelName;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
165
179
|
|
|
166
180
|
winston.verbose("Request patch update",update);
|
|
167
181
|
|
|
@@ -196,8 +210,9 @@ router.patch('/:requestid', function (req, res) {
|
|
|
196
210
|
router.put('/:requestid/close', function (req, res) {
|
|
197
211
|
winston.debug(req.body);
|
|
198
212
|
|
|
199
|
-
// closeRequestByRequestId(request_id, id_project)
|
|
200
|
-
|
|
213
|
+
// closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
|
|
214
|
+
const closed_by = req.user.id;
|
|
215
|
+
return requestService.closeRequestByRequestId(req.params.requestid, req.projectid, false, true, closed_by).then(function(closedRequest) {
|
|
201
216
|
|
|
202
217
|
winston.verbose("request closed", closedRequest);
|
|
203
218
|
|
|
@@ -518,6 +533,72 @@ router.delete('/:requestid/notes/:noteid', function (req, res) {
|
|
|
518
533
|
|
|
519
534
|
});
|
|
520
535
|
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
router.post('/:requestid/followers',
|
|
542
|
+
[
|
|
543
|
+
check('member').notEmpty(),
|
|
544
|
+
],
|
|
545
|
+
function (req, res) {
|
|
546
|
+
winston.info("followers add", req.body);
|
|
547
|
+
|
|
548
|
+
const errors = validationResult(req);
|
|
549
|
+
if (!errors.isEmpty()) {
|
|
550
|
+
return res.status(422).json({ errors: errors.array() });
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
//addParticipantByRequestId(request_id, id_project, member)
|
|
554
|
+
return requestService.addFollowerByRequestId(req.params.requestid, req.projectid, req.body.member ).then(function(updatedRequest) {
|
|
555
|
+
|
|
556
|
+
winston.verbose("participant added", updatedRequest);
|
|
557
|
+
|
|
558
|
+
return res.json(updatedRequest);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
router.put('/:requestid/followers', function (req, res) {
|
|
565
|
+
winston.debug("req.body", req.body);
|
|
566
|
+
|
|
567
|
+
var followers = [];
|
|
568
|
+
req.body.forEach(function(follower,index) {
|
|
569
|
+
followers.push(follower);
|
|
570
|
+
});
|
|
571
|
+
winston.debug("var followers", followers);
|
|
572
|
+
|
|
573
|
+
// setFollowersByRequestId(request_id, id_project, newfollowers)
|
|
574
|
+
return requestService.setFollowersByRequestId(req.params.requestid, req.projectid, followers ).then(function(updatedRequest) {
|
|
575
|
+
|
|
576
|
+
winston.debug("followers set", updatedRequest);
|
|
577
|
+
|
|
578
|
+
return res.json(updatedRequest);
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
router.delete('/:requestid/followers/:followerid', function (req, res) {
|
|
584
|
+
winston.debug(req.body);
|
|
585
|
+
|
|
586
|
+
//removeFollowerByRequestId(request_id, id_project, member)
|
|
587
|
+
return requestService.removeFollowerByRequestId(req.params.requestid, req.projectid, req.params.followerid ).then(function(updatedRequest) {
|
|
588
|
+
|
|
589
|
+
winston.verbose("follower removed", updatedRequest);
|
|
590
|
+
|
|
591
|
+
return res.json(updatedRequest);
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
521
602
|
// TODO make a synchronous chat21 version (with query parameter?) with request.support_group.created
|
|
522
603
|
router.delete('/:requestid', function (req, res) {
|
|
523
604
|
|
|
@@ -589,6 +670,8 @@ router.delete('/id/:id', function (req, res) {
|
|
|
589
670
|
|
|
590
671
|
router.get('/', function (req, res, next) {
|
|
591
672
|
|
|
673
|
+
const startExecTime = new Date();
|
|
674
|
+
|
|
592
675
|
winston.debug("req projectid", req.projectid);
|
|
593
676
|
winston.debug("req.query.sort", req.query.sort);
|
|
594
677
|
winston.debug('REQUEST ROUTE - QUERY ', req.query)
|
|
@@ -641,6 +724,10 @@ router.get('/', function (req, res, next) {
|
|
|
641
724
|
winston.debug('REQUEST ROUTE - QUERY DEPT ID', query.department);
|
|
642
725
|
}
|
|
643
726
|
|
|
727
|
+
if (req.query.requester_email) {
|
|
728
|
+
query["snapshot.lead.email"] = req.query.requester_email;
|
|
729
|
+
}
|
|
730
|
+
|
|
644
731
|
if (req.query.full_text) {
|
|
645
732
|
winston.debug('req.query.fulltext', req.query.full_text);
|
|
646
733
|
query.$text = { "$search": req.query.full_text };
|
|
@@ -709,7 +796,8 @@ router.get('/', function (req, res, next) {
|
|
|
709
796
|
* THE SEARCH FOR DATE INTERVAL OF THE HISTORY OF REQUESTS ARE DISABLED AND
|
|
710
797
|
* ARE DISPLAYED ONLY THE REQUESTS OF THE LAST 14 DAYS
|
|
711
798
|
*/
|
|
712
|
-
|
|
799
|
+
//fixato. secondo me qui manca un parentesi tonda per gli or
|
|
800
|
+
if ( history_search === true && req.project && req.project.profile && ((req.project.profile.type === 'free' && req.project.trialExpired === true) || (req.project.profile.type === 'payment' && req.project.isActiveSubscription === false))) {
|
|
713
801
|
|
|
714
802
|
|
|
715
803
|
var startdate = moment().subtract(14, "days").format("YYYY-MM-DD");
|
|
@@ -813,7 +901,14 @@ router.get('/', function (req, res, next) {
|
|
|
813
901
|
}
|
|
814
902
|
|
|
815
903
|
if (req.query.channel) {
|
|
816
|
-
|
|
904
|
+
if (req.query.channel === "offline") {
|
|
905
|
+
query["channel.name"] = {"$in" : ["email", "form"]}
|
|
906
|
+
} else if (req.query.channel === "online") {
|
|
907
|
+
query["channel.name"] = {"$nin" : ["email", "form"]}
|
|
908
|
+
} else {
|
|
909
|
+
query["channel.name"] = req.query.channel
|
|
910
|
+
}
|
|
911
|
+
|
|
817
912
|
winston.debug('REQUEST ROUTE - QUERY channel', query.channel);
|
|
818
913
|
}
|
|
819
914
|
|
|
@@ -835,14 +930,17 @@ router.get('/', function (req, res, next) {
|
|
|
835
930
|
|
|
836
931
|
winston.debug("sort query", sortQuery);
|
|
837
932
|
|
|
838
|
-
winston.
|
|
933
|
+
winston.debug('REQUEST ROUTE - REQUEST FIND ', query);
|
|
839
934
|
|
|
840
935
|
var projection = undefined;
|
|
841
936
|
|
|
842
937
|
if (req.query.full_text) {
|
|
843
|
-
winston.debug('fulltext projection');
|
|
844
938
|
|
|
845
|
-
|
|
939
|
+
if (req.query.no_textscore!= "true" && req.query.no_textscore!= true) {
|
|
940
|
+
winston.info('fulltext projection on');
|
|
941
|
+
projection = {score: { $meta: "textScore" } };
|
|
942
|
+
}
|
|
943
|
+
|
|
846
944
|
}
|
|
847
945
|
// requestcachefarequi populaterequired
|
|
848
946
|
var q1 = Request.find(query, projection).
|
|
@@ -874,7 +972,9 @@ router.get('/', function (req, res, next) {
|
|
|
874
972
|
|
|
875
973
|
if (req.query.full_text) {
|
|
876
974
|
winston.debug('fulltext sort');
|
|
877
|
-
|
|
975
|
+
if (req.query.no_textscore!= "true" && req.query.no_textscore!= true) {
|
|
976
|
+
q1.sort( { score: { $meta: "textScore" } } ) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
|
|
977
|
+
}
|
|
878
978
|
} else {
|
|
879
979
|
q1.sort(sortQuery);
|
|
880
980
|
}
|
|
@@ -890,6 +990,11 @@ router.get('/', function (req, res, next) {
|
|
|
890
990
|
|
|
891
991
|
var q2 = Request.countDocuments(query).exec();
|
|
892
992
|
|
|
993
|
+
if (req.query.no_count && req.query.no_count =="true") {
|
|
994
|
+
winston.info('REQUEST ROUTE - no_count ');
|
|
995
|
+
q2 = 0;
|
|
996
|
+
}
|
|
997
|
+
|
|
893
998
|
var promises = [
|
|
894
999
|
q1,
|
|
895
1000
|
q2
|
|
@@ -901,7 +1006,12 @@ router.get('/', function (req, res, next) {
|
|
|
901
1006
|
count: results[1],
|
|
902
1007
|
requests: results[0]
|
|
903
1008
|
};
|
|
1009
|
+
winston.debug('REQUEST ROUTE - objectToReturn ');
|
|
904
1010
|
winston.debug('REQUEST ROUTE - objectToReturn ', objectToReturn);
|
|
1011
|
+
|
|
1012
|
+
const endExecTime = new Date();
|
|
1013
|
+
winston.verbose('REQUEST ROUTE - exec time: ' + (endExecTime-startExecTime));
|
|
1014
|
+
|
|
905
1015
|
return res.json(objectToReturn);
|
|
906
1016
|
|
|
907
1017
|
}).catch(function(err){
|
|
@@ -1025,7 +1135,11 @@ router.get('/csv', function (req, res, next) {
|
|
|
1025
1135
|
winston.debug("sort query", sortQuery);
|
|
1026
1136
|
|
|
1027
1137
|
|
|
1138
|
+
// TODO ORDER BY SCORE
|
|
1139
|
+
// return Faq.find(query, {score: { $meta: "textScore" } })
|
|
1140
|
+
// .sort( { score: { $meta: "textScore" } } ) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
|
|
1028
1141
|
|
|
1142
|
+
// aggiungi filtro per data marco
|
|
1029
1143
|
|
|
1030
1144
|
winston.debug('REQUEST ROUTE - REQUEST FIND ', query)
|
|
1031
1145
|
return Request.find(query, '-transcript -status -__v').
|
|
@@ -1126,14 +1240,6 @@ router.get('/csv', function (req, res, next) {
|
|
|
1126
1240
|
|
|
1127
1241
|
winston.debug('REQUEST ROUTE - REQUEST AS CSV', requests);
|
|
1128
1242
|
|
|
1129
|
-
// return Request.count(query, function(err, totalRowCount) {
|
|
1130
|
-
|
|
1131
|
-
// var objectToReturn = {
|
|
1132
|
-
// perPage: limit,
|
|
1133
|
-
// count: totalRowCount,
|
|
1134
|
-
// requests : requests
|
|
1135
|
-
// };
|
|
1136
|
-
// console.log('REQUEST ROUTE - objectToReturn ', objectToReturn);
|
|
1137
1243
|
return res.csv(requests, true);
|
|
1138
1244
|
});
|
|
1139
1245
|
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var express = require('express');
|
|
2
|
+
var router = express.Router();
|
|
3
|
+
var Subscription = require("../models/subscription");
|
|
4
|
+
var SubscriptionLog = require("../models/subscriptionLog");
|
|
5
|
+
var subscriptionEvent = require("../event/subscriptionEvent");
|
|
6
|
+
var winston = require('../config/winston');
|
|
7
|
+
|
|
8
|
+
//space
|
|
9
|
+
|
|
10
|
+
router.post('/', function (req, res) {
|
|
11
|
+
|
|
12
|
+
winston.debug(req.body);
|
|
13
|
+
winston.debug("req.user", req.user);
|
|
14
|
+
|
|
15
|
+
var subscription = new Subscription({
|
|
16
|
+
target: req.body.target,
|
|
17
|
+
event: req.body.event,
|
|
18
|
+
id_project: req.projectid,
|
|
19
|
+
createdBy: req.user.id
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
subscription.save(function (err, subscriptionSaved) {
|
|
23
|
+
if (err) {
|
|
24
|
+
if (err.code === 11000) { //error for dupes
|
|
25
|
+
return Subscription.findOne({id_project:req.projectid, event: req.body.event}).select("+secret")
|
|
26
|
+
.exec(function (err, subscriptionSaved) {
|
|
27
|
+
res.setHeader('x-hook-secret', subscriptionSaved.secret);
|
|
28
|
+
res.json(subscriptionSaved);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
winston.error('--- > ERROR ', err)
|
|
32
|
+
return res.status(500).send({ success: false, msg: 'Error saving object.' });
|
|
33
|
+
}
|
|
34
|
+
// http://resthooks.org/docs/security/
|
|
35
|
+
|
|
36
|
+
res.setHeader('x-hook-secret', subscriptionSaved.secret);
|
|
37
|
+
|
|
38
|
+
subscriptionEvent.emit('subscription.create', subscriptionSaved );
|
|
39
|
+
res.json(subscriptionSaved);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
router.post('/test', function (req, res) {
|
|
45
|
+
|
|
46
|
+
winston.debug("test subscription body", req.body);
|
|
47
|
+
|
|
48
|
+
res.json(req);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
router.put('/:subscriptionid', function (req, res) {
|
|
52
|
+
|
|
53
|
+
winston.debug(req.body);
|
|
54
|
+
|
|
55
|
+
Subscription.findByIdAndUpdate(req.params.subscriptionid, req.body, { new: true, upsert: true }, function (err, subscriptionUpd) {
|
|
56
|
+
if (err) {
|
|
57
|
+
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
|
58
|
+
}
|
|
59
|
+
subscriptionEvent.emit('subscription.update', subscriptionUpd );
|
|
60
|
+
res.json(subscriptionUpd);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
router.delete('/:subscriptionid', function (req, res) {
|
|
66
|
+
|
|
67
|
+
winston.debug(req.body);
|
|
68
|
+
|
|
69
|
+
Subscription.remove({ _id: req.params.subscriptionid }, function (err, subscriptionUpd) {
|
|
70
|
+
if (err) {
|
|
71
|
+
return res.status(500).send({ success: false, msg: 'Error deleting object.' });
|
|
72
|
+
}
|
|
73
|
+
subscriptionEvent.emit('subscription.delete', subscriptionUpd );
|
|
74
|
+
res.json(subscriptionUpd);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
router.get('/', function (req, res) {
|
|
82
|
+
|
|
83
|
+
return Subscription.find({ "id_project": req.projectid }).
|
|
84
|
+
exec(function (err, subscriptions, next) {
|
|
85
|
+
if (err) {
|
|
86
|
+
winston.error('Subscription ROUTE - REQUEST FIND ERR ', err)
|
|
87
|
+
return next(err);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return res.json(subscriptions);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
router.get('/history', function (req, res) {
|
|
96
|
+
|
|
97
|
+
var limit = 40; // Number of leads per page
|
|
98
|
+
var page = 0;
|
|
99
|
+
|
|
100
|
+
if (req.query.page) {
|
|
101
|
+
page = req.query.page;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var skip = page * limit;
|
|
105
|
+
winston.debug('Subscription ROUTE - SKIP PAGE ', skip);
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
return SubscriptionLog.find({ "id_project": req.projectid }).
|
|
109
|
+
skip(skip).limit(limit)
|
|
110
|
+
.sort({createdAt: 'desc'}).
|
|
111
|
+
exec(function (err, subscriptions, next) {
|
|
112
|
+
if (err) {
|
|
113
|
+
winston.error('Subscription ROUTE - REQUEST FIND ERR ', err)
|
|
114
|
+
return next(err);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return res.json(subscriptions);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
router.get('/:subscriptionid', function (req, res) {
|
|
124
|
+
|
|
125
|
+
winston.debug(req.body);
|
|
126
|
+
|
|
127
|
+
Subscription.findById(req.params.subscriptionid, function (err, subscriptionUpd) {
|
|
128
|
+
if (err) {
|
|
129
|
+
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
|
130
|
+
}
|
|
131
|
+
if (!subscriptionUpd) {
|
|
132
|
+
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
|
133
|
+
}
|
|
134
|
+
res.json(subscriptionUpd);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
module.exports = router;
|
package/routes/tag.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
var express = require('express');
|
|
2
|
+
var router = express.Router();
|
|
3
|
+
var TagLibrary = require("../models/tagLibrary");
|
|
4
|
+
var winston = require('../config/winston');
|
|
5
|
+
|
|
6
|
+
router.post('/', function (req, res) {
|
|
7
|
+
|
|
8
|
+
winston.debug(req.body);
|
|
9
|
+
winston.debug("req.user", req.user);
|
|
10
|
+
|
|
11
|
+
var newTag = new TagLibrary({
|
|
12
|
+
tag: req.body.tag,
|
|
13
|
+
color: req.body.color,
|
|
14
|
+
id_project: req.projectid,
|
|
15
|
+
createdBy: req.user.id,
|
|
16
|
+
updatedBy: req.user.id
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
newTag.save(function (err, savedTag) {
|
|
20
|
+
if (err) {
|
|
21
|
+
// winston.error('--- > ERROR ', err)
|
|
22
|
+
if (err.code === 11000) { //error for dupes
|
|
23
|
+
return TagLibrary.findOne({id_project:req.projectid, tag: req.body.tag },function (err, savedTag) {
|
|
24
|
+
res.json(savedTag);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
winston.error('--- > ERROR ', err)
|
|
28
|
+
return res.status(500).send({ success: false, msg: 'Error saving object.' });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
res.json(savedTag);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
router.put('/:tagid', function (req, res) {
|
|
36
|
+
winston.debug(req.body);
|
|
37
|
+
var update = {};
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
update.tag = req.body.tag;
|
|
41
|
+
update.color = req.body.color;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
TagLibrary.findByIdAndUpdate(req.params.tagid, update, { new: true, upsert: true }, function (err, updatedTag) {
|
|
45
|
+
if (err) {
|
|
46
|
+
winston.error('--- > ERROR ', err);
|
|
47
|
+
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// TagEvent.emit('Tag.update', updatedTag);
|
|
53
|
+
res.json(updatedTag);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
router.delete('/:tagid', function (req, res) {
|
|
58
|
+
winston.debug(req.body);
|
|
59
|
+
|
|
60
|
+
TagLibrary.remove({ _id: req.params.tagid }, function (err, tag) {
|
|
61
|
+
if (err) {
|
|
62
|
+
winston.error('--- > ERROR ', err);
|
|
63
|
+
return res.status(500).send({ success: false, msg: 'Error deleting object.' });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// TagEvent.emit('Tag.delete', Tag);
|
|
68
|
+
|
|
69
|
+
res.json(tag);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
router.get('/:tagid', function (req, res) {
|
|
74
|
+
winston.debug(req.body);
|
|
75
|
+
|
|
76
|
+
TagLibrary.findById(req.params.tagid, function (err, tag) {
|
|
77
|
+
if (err) {
|
|
78
|
+
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
|
79
|
+
}
|
|
80
|
+
if (!tag) {
|
|
81
|
+
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
|
82
|
+
}
|
|
83
|
+
res.json(tag);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
router.get('/', function (req, res) {
|
|
88
|
+
var limit = 40; // Number of Tags per page
|
|
89
|
+
var page = 0;
|
|
90
|
+
|
|
91
|
+
if (req.query.page) {
|
|
92
|
+
page = req.query.page;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var skip = page * limit;
|
|
96
|
+
winston.debug('Tag ROUTE - SKIP PAGE ', skip);
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
var query = { "id_project": req.projectid};
|
|
100
|
+
|
|
101
|
+
// if (req.query.full_text) {
|
|
102
|
+
// winston.debug('Tag ROUTE req.query.fulltext', req.query.full_text);
|
|
103
|
+
// query.$text = { "$search": req.query.full_text };
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
var direction = -1; //-1 descending , 1 ascending
|
|
108
|
+
if (req.query.direction) {
|
|
109
|
+
direction = req.query.direction;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var sortField = "createdAt";
|
|
113
|
+
if (req.query.sort) {
|
|
114
|
+
sortField = req.query.sort;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var sortQuery = {};
|
|
118
|
+
sortQuery[sortField] = direction;
|
|
119
|
+
|
|
120
|
+
winston.debug("sort query", sortQuery);
|
|
121
|
+
|
|
122
|
+
return TagLibrary.find(query).
|
|
123
|
+
skip(skip).limit(limit).
|
|
124
|
+
sort(sortQuery).
|
|
125
|
+
exec(function (err, tags) {
|
|
126
|
+
if (err) {
|
|
127
|
+
winston.error('Tag ROUTE - REQUEST FIND ERR ', err)
|
|
128
|
+
return (err);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return res.json(tags);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
module.exports = router;
|
package/routes/user-request.js
CHANGED
|
@@ -59,8 +59,9 @@ router.patch('/:requestid/rating', function (req, res) {
|
|
|
59
59
|
router.put('/:requestid/closeg', function (req, res) {
|
|
60
60
|
winston.debug(req.body);
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
// closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
|
|
63
|
+
const closed_by = req.user.id;
|
|
64
|
+
return requestService.closeRequestByRequestId(req.params.requestid, req.projectid, false, true, closed_by).then(function(closedRequest) {
|
|
64
65
|
|
|
65
66
|
winston.verbose("request closed", closedRequest);
|
|
66
67
|
|
package/routes/users.js
CHANGED
|
@@ -25,7 +25,7 @@ router.put('/', function (req, res) {
|
|
|
25
25
|
|
|
26
26
|
User.findByIdAndUpdate(req.user.id, update, { new: true, upsert: true }, function (err, updatedUser) {
|
|
27
27
|
if (err) {
|
|
28
|
-
winston.error(err);
|
|
28
|
+
winston.error("Error putting user",err);
|
|
29
29
|
return res.status(500).send({ success: false, msg: err });
|
|
30
30
|
}
|
|
31
31
|
|
package/routes/widget.js
CHANGED
|
@@ -96,6 +96,7 @@ router.get('/', function(req, res, next) {
|
|
|
96
96
|
winston.debug("req.project:" + JSON.stringify(req.project));
|
|
97
97
|
|
|
98
98
|
if (req.project) {
|
|
99
|
+
//secondo me qui manca un parentesi tonda per gli or
|
|
99
100
|
if (req.project.profile && (req.project.profile.type === 'free' && req.project.trialExpired === true) || (req.project.profile.type === 'payment' && req.project.isActiveSubscription === false)) {
|
|
100
101
|
query.default = true;
|
|
101
102
|
}
|
|
@@ -129,10 +130,28 @@ router.get('/', function(req, res, next) {
|
|
|
129
130
|
return reject({err: "Project Not Found"});
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
|
|
133
|
+
|
|
134
|
+
winston.debug("project", project);
|
|
135
|
+
|
|
136
|
+
// ProjectSetter project not found with id: 62d8cf8b2b10b30013bb9b99
|
|
137
|
+
// Informazioni
|
|
138
|
+
// 2022-07-27 14:32:14.772 CESTerror: Error getting widget. {"err":"Project Not Found"}
|
|
139
|
+
// Informazioni
|
|
140
|
+
// 2022-07-27 14:32:14.778 CESTerror: uncaughtException: Cannot read property 'profile' of null
|
|
141
|
+
// Informazioni
|
|
142
|
+
// 2022-07-27 14:32:14.778 CESTTypeError: Cannot read property 'profile' of null at /usr/src/app/routes/widget.js:132:124 at /usr/src/app/node_modules/mongoose/lib/model.js:5074:18 at processTicksAndRejections (internal/process/task_queues.js:79:11) {"date":"Wed Jul 27 2022 12:32:14 GMT+0000 (Coordinated Universal Time)","error":{},"exception":true,"os":{"loadavg":[0.26,0.51,0.58],"uptime":1028128},"process":{"argv":["/usr/local/bin/node","/usr/src/app/bin/www"],"cwd":"/usr/src/app","execPath":"/usr/local/bin/node","gid":0,"memoryUsage":{"arrayBuffers":128833077,"external":130521753,"heapTotal":110641152,"heapUsed":85605912,"rss":310054912},"pid":26,"uid":0,"version":"v12.22.12"},"stack":"TypeError: Cannot read property 'profile' of null\n at /usr/src/app/routes/widget.js:132:124\n at /usr/src/app/node_modules/mongoose/lib/model.js:5074:18\n at processTicksAndRejections (internal/process/task_queues.js:79:11)","trace":[{"column":124,"file":"/usr/src/app/routes/widget.js","function":null,"line":132,"method":null,"native":false},{"column":18,"file":"/usr/src/app/node_modules/mongoose/lib/model.js","function":null,"line":5074,"method":null,"native":false},{"column":11,"file":"internal/process/task_queues.js","function":"processTicksAndRejections","line":79,"method":null,"native":false}]}
|
|
143
|
+
|
|
144
|
+
// console.log("project!=null",project!=null);
|
|
145
|
+
// console.log("project.profile",project.profile);
|
|
146
|
+
//secondo me qui manca un parentesi tonda per gli or
|
|
147
|
+
if (project && project.profile && ((project.profile.type === 'free' && project.trialExpired === true) || (project.profile.type === 'payment' && project.isActiveSubscription === false))) {
|
|
133
148
|
winston.debug('getProject remove poweredBy tag', project);
|
|
134
|
-
|
|
135
|
-
project.widget
|
|
149
|
+
|
|
150
|
+
if (project.widget) {
|
|
151
|
+
project.widget.poweredBy = undefined;
|
|
152
|
+
project.widget.baloonImage = undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
136
155
|
}
|
|
137
156
|
|
|
138
157
|
return resolve(project);
|
|
@@ -175,7 +194,65 @@ router.get('/', function(req, res, next) {
|
|
|
175
194
|
|
|
176
195
|
|
|
177
196
|
|
|
197
|
+
router.get('/ip', function(req, res, next) {
|
|
178
198
|
|
|
199
|
+
var xforwarded = req.headers['x-forwarded-for'];
|
|
200
|
+
winston.info('xforwarded'+ xforwarded);
|
|
201
|
+
|
|
202
|
+
var connectionRemoteAddress = req.connection.remoteAddress;
|
|
203
|
+
winston.info('connectionRemoteAddress'+ connectionRemoteAddress);
|
|
204
|
+
|
|
205
|
+
var socketRemoteAddress = req.socket.remoteAddress;
|
|
206
|
+
winston.info('socketRemoteAddress'+ socketRemoteAddress);
|
|
207
|
+
|
|
208
|
+
if (req.connection.socket ) {
|
|
209
|
+
var connectionSocketRemoteAddress = req.connection.socket.remoteAddress;
|
|
210
|
+
winston.info('connectionSocketRemoteAddress'+ connectionSocketRemoteAddress);
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
var ip = req.headers['x-forwarded-for'] ||
|
|
216
|
+
req.connection.remoteAddress ||
|
|
217
|
+
req.socket.remoteAddress ||
|
|
218
|
+
(req.connection.socket ? req.connection.socket.remoteAddress : null);
|
|
219
|
+
winston.info("ip:"+ ip);
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
const ipStandard = (req.headers['x-forwarded-for'] || '').split(',').shift().trim() || //https://stackoverflow.com/questions/8107856/how-to-determine-a-users-ip-address-in-node
|
|
225
|
+
req.socket.remoteAddress
|
|
226
|
+
|
|
227
|
+
winston.info("standard ip: "+ipStandard); // ip address of the user
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
// const parseIp = (req) =>
|
|
232
|
+
// req.headers['x-forwarded-for']?.split(',').shift()
|
|
233
|
+
// || req.socket?.remoteAddress
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
let parseIp = req.socket.remoteAddress;
|
|
238
|
+
|
|
239
|
+
const xFor = req.headers['x-forwarded-for'];
|
|
240
|
+
winston.info("parseIp xFor: "+xFor);
|
|
241
|
+
|
|
242
|
+
if (xFor ) {
|
|
243
|
+
const xForArr = xFor.split(',');
|
|
244
|
+
if (xForArr && xForArr.length>0) {
|
|
245
|
+
parseIp = xForArr.shift();
|
|
246
|
+
winston.info("parseIp xFor parseIp: "+parseIp);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
winston.info("parseIp: "+parseIp); // ip address of the user
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
res.json( {ip:ip, ipStandard:ipStandard, parseIp: parseIp} );
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
});
|
|
179
256
|
|
|
180
257
|
|
|
181
258
|
|
package/routes/widgetLoader.js
CHANGED
|
@@ -12,9 +12,40 @@ router.get('/load', function(req, res) {
|
|
|
12
12
|
winston.debug(query);
|
|
13
13
|
// TODO chech if query is null
|
|
14
14
|
res.redirect(widgetLocation+'?'+query);
|
|
15
|
+
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
|
|
19
|
+
router.get('/v5/:project_id', function(req, res) {
|
|
20
|
+
|
|
21
|
+
var project_id = req.params.project_id;
|
|
22
|
+
winston.debug("project_id: " + project_id);
|
|
23
|
+
|
|
24
|
+
res.type('.js');
|
|
25
|
+
|
|
26
|
+
var js = `
|
|
27
|
+
window.tiledeskSettings=
|
|
28
|
+
{
|
|
29
|
+
projectid: "${project_id}"
|
|
30
|
+
};
|
|
31
|
+
(function(d, s, id) {
|
|
32
|
+
var w=window; var d=document; var i=function(){i.c(arguments);};
|
|
33
|
+
i.q=[]; i.c=function(args){i.q.push(args);}; w.Tiledesk=i;
|
|
34
|
+
var js, fjs=d.getElementsByTagName(s)[0];
|
|
35
|
+
if (d.getElementById(id)) return;
|
|
36
|
+
js=d.createElement(s);
|
|
37
|
+
js.id=id; js.async=true; js.src="${widgetLocation}/launch.js";
|
|
38
|
+
fjs.parentNode.insertBefore(js, fjs);
|
|
39
|
+
}(document,'script','tiledesk-jssdk'));
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
winston.debug("js: " + js);
|
|
43
|
+
|
|
44
|
+
res.send(js);
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
|
|
18
49
|
var widgetTestLocation = process.env.WIDGET_TEST_LOCATION || widgetConfig.testLocation;
|
|
19
50
|
|
|
20
51
|
router.get('/test/load', function(req, res) {
|