@tiledesk/tiledesk-server 2.7.2 → 2.7.3

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 CHANGED
@@ -5,6 +5,10 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.7.3
9
+ - Updated project profile call
10
+ - Updated tybot-connector to 0.2.59
11
+
8
12
  # 2.7.2
9
13
  - Improved QuoteManager with kbs and chatbots (disabled)
10
14
  - Improved QuoteManager with AI multipliers
@@ -184,8 +184,22 @@ class RoleChecker {
184
184
  }
185
185
  } else {
186
186
 
187
+ /**
188
+ * Updated by Johnny - 29mar2024 - START
189
+ */
190
+ // console.log("req.user: ", req.user);
191
+ if (req.user.email === process.env.ADMIN_EMAIL) {
192
+ req.user.attributes = { isSuperadmin: true };
193
+ next();
194
+ } else {
195
+ res.status(403).send({success: false, msg: 'you dont belong to the project.'});
196
+ }
197
+ /**
198
+ * Updated by Johnny - 29mar2024 - END
199
+ */
200
+
187
201
  // if (req.user) equals super admin next()
188
- res.status(403).send({success: false, msg: 'you dont belong to the project.'});
202
+ //res.status(403).send({success: false, msg: 'you dont belong to the project.'});
189
203
  }
190
204
 
191
205
  });
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.7.2",
4
+ "version": "2.7.3",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -48,7 +48,7 @@
48
48
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
49
49
  "@tiledesk/tiledesk-telegram-connector": "^0.1.10",
50
50
  "@tiledesk/tiledesk-train-jobworker": "^0.0.7",
51
- "@tiledesk/tiledesk-tybot-connector": "^0.2.57",
51
+ "@tiledesk/tiledesk-tybot-connector": "^0.2.59",
52
52
  "@tiledesk/tiledesk-whatsapp-connector": "^0.1.64",
53
53
  "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.7",
54
54
  "amqplib": "^0.5.5",
@@ -711,7 +711,8 @@ class RulesTrigger {
711
711
 
712
712
 
713
713
 
714
- var startText = "\\start";
714
+ var startText = "\start";
715
+ // var startText = "\\start";
715
716
  if (action.parameters && action.parameters.text) {
716
717
  startText = action.parameters.text;
717
718
  }
@@ -787,7 +788,7 @@ class RulesTrigger {
787
788
  'system',
788
789
  'Bot',
789
790
  request_id,
790
- '\\start', // / start
791
+ '\\start', // TODO CHANGE TO / start
791
792
  id_project,
792
793
  null,
793
794
  {subtype:'info', updateconversation : false}
@@ -1037,6 +1038,7 @@ class RulesTrigger {
1037
1038
  if (eventAttributes.participants && eventAttributes.participants.length>0) {
1038
1039
  participants = eventAttributes.participants;
1039
1040
  if (participants[0].indexOf("bot_")>-1) {
1041
+ // TODO CHANGE TO /start
1040
1042
  text = "\\start"; //if participants is passed than the bot reply to the first message "welcome" so I changed "welcome" with "\start"
1041
1043
  }
1042
1044
  // status = RequestConstants.ASSIGNED;
package/routes/auth.js CHANGED
@@ -72,14 +72,29 @@ router.post('/signup',
72
72
  } else {
73
73
  return userService.signup(req.body.email, req.body.password, req.body.firstname, req.body.lastname, false)
74
74
  .then(function (savedUser) {
75
-
76
-
75
+
77
76
  winston.debug('-- >> -- >> savedUser ', savedUser.toObject());
78
77
 
78
+ // let skipVerificationEmail = false;
79
+ // if (req.headers.authorization) {
80
+
81
+ // let token = req.headers.authorization.split(" ")[1];
82
+ // let decode = jwt.verify(token, configSecret)
83
+ // if (decode && (decode.email === process.env.ADMIN_EMAIL)) {
84
+ // skipVerificationEmail = true;
85
+ // winston.verbose("skip sending verification email")
86
+ // }
87
+ // }
88
+
89
+ // if (!req.body.disableEmail){
90
+ // if (!skipVerificationEmail) {
91
+ // emailService.sendVerifyEmailAddress(savedUser.email, savedUser);
92
+ // }
93
+ // }
94
+
79
95
  if (!req.body.disableEmail){
80
- emailService.sendVerifyEmailAddress(savedUser.email, savedUser);
96
+ emailService.sendVerifyEmailAddress(savedUser.email, savedUser);
81
97
  }
82
-
83
98
 
84
99
 
85
100
  /*
package/routes/project.js CHANGED
@@ -11,6 +11,7 @@ var operatingHoursService = require("../services/operatingHoursService");
11
11
  var winston = require('../config/winston');
12
12
  var roleChecker = require('../middleware/has-role');
13
13
 
14
+
14
15
  // THE THREE FOLLOWS IMPORTS ARE USED FOR AUTHENTICATION IN THE ROUTE
15
16
  var passport = require('passport');
16
17
  require('../middleware/passport')(passport);
@@ -20,6 +21,21 @@ var cacheUtil = require('../utils/cacheUtil');
20
21
  var orgUtil = require("../utils/orgUtil");
21
22
  var cacheEnabler = require("../services/cacheEnabler");
22
23
 
24
+ /**
25
+ * NEW
26
+ */
27
+ var jwt = require('jsonwebtoken');
28
+ var config = require('../config/database');
29
+
30
+ let configSecret = process.env.GLOBAL_SECRET || config.secret;
31
+ var pKey = process.env.GLOBAL_SECRET_OR_PUB_KEY;
32
+ if (pKey) {
33
+ configSecret = pKey.replace(/\\n/g, '\n');
34
+ }
35
+ /**
36
+ * End NEW
37
+ */
38
+
23
39
  router.post('/', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], async (req, res) => {
24
40
 
25
41
  // create(name, createdBy, settings)
@@ -71,10 +87,219 @@ router.delete('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
71
87
  });
72
88
  });
73
89
 
90
+ // router.put('/:projectid/update', function (req, res) {
91
+ // // router.put('/:projectid/profile', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], function (req, res) {
92
+
93
+ // // Get token from header authorization
94
+ // let token = req.headers.authorization;
95
+ // token = token.split(" ")[1];
96
+
97
+ // try {
98
+ // let decoded = jwt.verify(token, configSecret)
99
+ // winston.debug("user decode: ", decoded);
100
+
101
+ // if (!process.env.ADMIN_EMAIL) {
102
+ // winston.warn("Missing admin email parameter in environment");
103
+ // return res.status(401).send({ success: false, error: "Missing admin email parameter"});
104
+ // }
105
+
106
+ // if (decoded.email !== process.env.ADMIN_EMAIL) {
107
+ // winston.warn("Profile modification: permission denied.");
108
+ // return res.status(403).send({ success: false, error: "You don't have the permission required to modify the project profile"});
109
+ // }
110
+
111
+ // /**
112
+ // * modify the project profile here
113
+ // */
114
+ // var update = {};
115
+
116
+ // if (req.body.name!=undefined) {
117
+ // update.name = req.body.name;
118
+ // }
119
+
120
+ // if (req.body.activeOperatingHours!=undefined) {
121
+ // update.activeOperatingHours = req.body.activeOperatingHours;
122
+ // }
123
+
124
+ // if (req.body.operatingHours!=undefined) {
125
+ // update.operatingHours = req.body.operatingHours;
126
+ // }
127
+
128
+ // if (req.body.settings!=undefined) {
129
+ // update.settings = req.body.settings;
130
+ // }
131
+
132
+ // if (req.body["settings.email.autoSendTranscriptToRequester"]!=undefined) {
133
+ // update["settings.email.autoSendTranscriptToRequester"] = req.body["settings.email.autoSendTranscriptToRequester"];
134
+ // }
135
+ // if (req.body["settings.email.notification.conversation.assigned"]!=undefined) {
136
+ // update["settings.email.notification.conversation.assigned"] = req.body["settings.email.notification.conversation.assigned"];
137
+ // }
138
+ // if (req.body["settings.email.notification.conversation.pooled"]!=undefined) {
139
+ // update["settings.email.notification.conversation.pooled"] = req.body["settings.email.notification.conversation.pooled"];
140
+ // }
141
+ // if (req.body["settings.email.templates.assignedRequest"]!=undefined) {
142
+ // update["settings.email.templates.assignedRequest"] = req.body["settings.email.templates.assignedRequest"];
143
+ // }
144
+ // if (req.body["settings.email.templates.assignedEmailMessage"]!=undefined) {
145
+ // update["settings.email.templates.assignedEmailMessage"] = req.body["settings.email.templates.assignedEmailMessage"];
146
+ // }
147
+ // if (req.body["settings.email.templates.pooledRequest"]!=undefined) {
148
+ // update["settings.email.templates.pooledRequest"] = req.body["settings.email.templates.pooledRequest"];
149
+ // }
150
+ // if (req.body["settings.email.templates.pooledEmailMessage"]!=undefined) {
151
+ // update["settings.email.templates.pooledEmailMessage"] = req.body["settings.email.templates.pooledEmailMessage"];
152
+ // }
153
+ // if (req.body["settings.email.templates.newMessage"]!=undefined) {
154
+ // update["settings.email.templates.newMessage"] = req.body["settings.email.templates.newMessage"];
155
+ // }
156
+ // if (req.body["settings.email.templates.newMessageFollower"]!=undefined) {
157
+ // update["settings.email.templates.newMessageFollower"] = req.body["settings.email.templates.newMessageFollower"];
158
+ // }
159
+ // if (req.body["settings.email.templates.ticket"]!=undefined) {
160
+ // update["settings.email.templates.ticket"] = req.body["settings.email.templates.ticket"];
161
+ // }
162
+ // if (req.body["settings.email.templates.sendTranscript"]!=undefined) {
163
+ // update["settings.email.templates.sendTranscript"] = req.body["settings.email.templates.sendTranscript"];
164
+ // }
165
+ // if (req.body["settings.email.templates.emailDirect"]!=undefined) {
166
+ // update["settings.email.templates.emailDirect"] = req.body["settings.email.templates.emailDirect"];
167
+ // }
168
+ // if (req.body["settings.email.from"]!=undefined) {
169
+ // update["settings.email.from"] = req.body["settings.email.from"];
170
+ // }
171
+ // if (req.body["settings.email.config.host"]!=undefined) {
172
+ // update["settings.email.config.host"] = req.body["settings.email.config.host"];
173
+ // }
174
+ // if (req.body["settings.email.config.port"]!=undefined) {
175
+ // update["settings.email.config.port"] = req.body["settings.email.config.port"];
176
+ // }
177
+ // if (req.body["settings.email.config.secure"]!=undefined) {
178
+ // update["settings.email.config.secure"] = req.body["settings.email.config.secure"];
179
+ // }
180
+ // if (req.body["settings.email.config.user"]!=undefined) {
181
+ // update["settings.email.config.user"] = req.body["settings.email.config.user"];
182
+ // }
183
+ // if (req.body["settings.email.config.pass"]!=undefined) {
184
+ // update["settings.email.config.pass"] = req.body["settings.email.config.pass"];
185
+ // }
186
+ // if (req.body["settings.chat_limit_on"]!=undefined) {
187
+ // update["settings.chat_limit_on"] = req.body["settings.chat_limit_on"];
188
+ // }
189
+ // if (req.body["settings.max_agent_assigned_chat"]!=undefined) {
190
+ // update["settings.max_agent_assigned_chat"] = req.body["settings.max_agent_assigned_chat"];
191
+ // }
192
+ // if (req.body["settings.reassignment_on"]!=undefined) {
193
+ // update["settings.reassignment_on"] = req.body["settings.reassignment_on"];
194
+ // }
195
+ // if (req.body["settings.reassignment_delay"]!=undefined) {
196
+ // update["settings.reassignment_delay"] = req.body["settings.reassignment_delay"];
197
+ // }
198
+ // if (req.body["settings.automatic_unavailable_status_on"]!=undefined) {
199
+ // update["settings.automatic_unavailable_status_on"] = req.body["settings.automatic_unavailable_status_on"];
200
+ // }
201
+ // if (req.body["settings.automatic_idle_chats"]!=undefined) {
202
+ // update["settings.automatic_idle_chats"] = req.body["settings.automatic_idle_chats"];
203
+ // }
204
+
205
+ // if (req.body.widget!=undefined) {
206
+ // update.widget = req.body.widget;
207
+ // }
208
+ // if (req.body.versions!=undefined) {
209
+ // update.versions = req.body.versions;
210
+ // }
211
+ // if (req.body.channels!=undefined) {
212
+ // update.channels = req.body.channels;
213
+ // }
214
+ // if (req.body.ipFilterEnabled!=undefined) {
215
+ // update.ipFilterEnabled = req.body.ipFilterEnabled;
216
+ // }
217
+ // if (req.body.ipFilter!=undefined) {
218
+ // update.ipFilter = req.body.ipFilter;
219
+ // }
220
+ // if (req.body.ipFilterDenyEnabled!=undefined) {
221
+ // update.ipFilterDenyEnabled = req.body.ipFilterDenyEnabled;
222
+ // }
223
+ // if (req.body.ipFilterDeny!=undefined) {
224
+ // update.ipFilterDeny = req.body.ipFilterDeny;
225
+ // }
226
+ // if (req.body.bannedUsers!=undefined) {
227
+ // update.bannedUsers = req.body.bannedUsers;
228
+ // }
229
+ // if (req.body.profile!=undefined) {
230
+ // update.profile = req.body.profile;
231
+ // }
232
+
233
+ // winston.debug('UPDATE PROJECT REQ BODY ', update);
234
+
235
+ // Project.findByIdAndUpdate(req.params.projectid, update, { new: true, upsert: true }, function (err, updatedProject) {
236
+ // if (err) {
237
+ // winston.error('Error putting project ', err);
238
+ // return res.status(500).send({ success: false, msg: 'Error updating object.' });
239
+ // }
240
+ // projectEvent.emit('project.update', updatedProject );
241
+ // res.json(updatedProject);
242
+ // });
243
+
244
+ // } catch (err) {
245
+ // winston.warn("Profile modification: permission denied.");
246
+ // res.status(403).send({ success: false, error: "You don't have the permission required to modify the project profile"});
247
+ // }
248
+
249
+ // })
250
+
74
251
  router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('admin')], function (req, res) {
252
+
75
253
  winston.debug('UPDATE PROJECT REQ BODY ', req.body);
76
254
 
77
255
  var update = {};
256
+
257
+ console.log("ADMIN EMAIL: ", process.env.ADMIN_EMAIL)
258
+ if (req.body.profile) {
259
+
260
+ if (req.user &&
261
+ req.user.attributes &&
262
+ req.user.attributes.isSuperadmin === true) {
263
+
264
+ winston.debug("Superadmin can modify the project profile")
265
+ update.profile = req.body.profile;
266
+
267
+ delete req.user.attributes.isSuperadmin;
268
+ }
269
+
270
+ else {
271
+ winston.verbose("Project profile can't be modified by the current user " + req.user._id);
272
+ return res.status(403).send({ success: false, error: "You don't have the permission required to modify the project profile"});
273
+ }
274
+
275
+ // check if super admin
276
+ // let token = req.headers.authorization
277
+ // token = token.split(" ")[1];
278
+
279
+ // let decoded = jwt.verify(token, configSecret);
280
+ // winston.debug("user decoded: ", decoded);
281
+ // console.log("user decoded: ", decoded);
282
+
283
+ // if (!process.env.ADMIN_EMAIL) {
284
+ // winston.warn("Missing admin email parameter in environment");
285
+ // return res.status(401).send({ success: false, error: "Missing admin email parameter"});
286
+ // }
287
+
288
+ // if (!decoded) {
289
+ // winston.warn("Profile modification: permission denied.");
290
+ // return res.status(403).send({ success: false, error: "You don't have the permission required to modify the project profile. Can't decode user."});
291
+ // }
292
+
293
+ // if (decoded.email !== process.env.ADMIN_EMAIL) {
294
+ // winston.warn("Profile modification: permission denied.");
295
+ // return res.status(403).send({ success: false, error: "You don't have the permission required to modify the project profile"});
296
+ // }
297
+
298
+ // console.log("You can modify the project profile");
299
+
300
+ // winston.info("Illegal field profile detected. Deny project profile update.");
301
+ // return res.status(403).send({ success: false, error: "You cannot edit the project profile."});
302
+ }
78
303
 
79
304
  //like patch
80
305
  if (req.body.name!=undefined) {
@@ -232,10 +457,6 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
232
457
  if (req.body.bannedUsers!=undefined) {
233
458
  update.bannedUsers = req.body.bannedUsers;
234
459
  }
235
-
236
- if (req.body.profile != undefined) {
237
- update.profile = req.body.profile;
238
- }
239
460
 
240
461
  // if (req.body.defaultLanguage!=undefined) {
241
462
  // update.defaultLanguage = req.body.defaultLanguage;
@@ -243,7 +464,6 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
243
464
 
244
465
 
245
466
  winston.debug('UPDATE PROJECT REQ BODY ', update);
246
-
247
467
  // console.log("update",JSON.stringify(update));
248
468
 
249
469
  Project.findByIdAndUpdate(req.params.projectid, update, { new: true, upsert: true }, function (err, updatedProject) {
@@ -1,6 +1,6 @@
1
1
  //During the test the env variable is set to test
2
2
  process.env.NODE_ENV = 'test';
3
-
3
+ process.env.ADMIN_EMAIL = "admin@tiledesk.com";
4
4
  //var User = require('../models/user');
5
5
  var projectService = require('../services/projectService');
6
6
  var requestService = require('../services/requestService');
@@ -201,6 +201,33 @@ describe('/signup', () => {
201
201
 
202
202
  });
203
203
 
204
+ // it('signUpAdminNoVerificationEmail', (done) => {
205
+
206
+ // var email = "test-signup-" + Date.now() + "@email.com";
207
+ // var pwd = "pwd";
208
+
209
+ // chai.request(server)
210
+ // .post("/auth/signin")
211
+ // .send({ email: "admin@tiledesk.com", password: "adminadmin" })
212
+ // .end((err, res) => {
213
+
214
+ // // console.log("login with superadmin res.body: ", res.body)
215
+ // let superadmin_token = res.body.token;
216
+
217
+ // chai.request(server)
218
+ // .post("/auth/signup")
219
+ // .set('Authorization', superadmin_token)
220
+ // .send({ email: email, password: pwd, lastname: "lastname", firstname: "firstname", disableEmail: true })
221
+ // .end((err, res) => {
222
+
223
+ // // console.log("res.body: ", res.body);
224
+ // done();
225
+ // })
226
+ // })
227
+
228
+
229
+ // })
230
+
204
231
  // mocha test/authentication.js --grep 'signupUpperCaseEmail'
205
232
 
206
233
 
@@ -0,0 +1,97 @@
1
+ //During the test the env variable is set to test
2
+ process.env.NODE_ENV = 'test';
3
+ process.env.ADMIN_EMAIL = "admin@tiledesk.com";
4
+
5
+ let log = false;
6
+ var projectService = require('../services/projectService');
7
+ var userService = require('../services/userService');
8
+
9
+ //Require the dev-dependencies
10
+ let chai = require('chai');
11
+ let chaiHttp = require('chai-http');
12
+ let server = require('../app');
13
+ let should = chai.should();
14
+ var fs = require('fs');
15
+ const path = require('path');
16
+
17
+ // chai.config.includeStack = true;
18
+
19
+ var expect = chai.expect;
20
+ var assert = chai.assert;
21
+
22
+ chai.use(chaiHttp);
23
+
24
+ describe('ProjectRoute', () => {
25
+
26
+ describe('/create', () => {
27
+
28
+ it('updateProjectProfileWithSuperAdminCredential', (done) => {
29
+
30
+ var email = "test-signup-" + Date.now() + "@email.com";
31
+ var pwd = "pwd";
32
+
33
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
34
+ projectService.create("test-project-create", savedUser._id).then((savedProject) => {
35
+
36
+ chai.request(server)
37
+ .post('/auth/signin')
38
+ .send({ email: "admin@tiledesk.com", password: "adminadmin" })
39
+ .end((err, res) => {
40
+
41
+ if (log) { console.log("login with superadmin res.body: ", res.body) };
42
+ res.should.have.status(200);
43
+ res.body.should.be.a('object');
44
+ expect(res.body.success).to.equal(true);
45
+ expect(res.body.token).not.equal(null);
46
+
47
+ let superadmin_token = res.body.token;
48
+
49
+ chai.request(server)
50
+ // .put('/projects/' + savedProject._id + "/update")
51
+ .put('/projects/' + savedProject._id)
52
+ .set('Authorization', superadmin_token)
53
+ .send({ profile: { name: "Custom", quotes: { kbs: 1000} } })
54
+ .end((err, res) => {
55
+
56
+ if (log) { console.log("update project profile res.body: ", res.body) };
57
+ res.should.have.status(200);
58
+ res.body.should.be.a('object');
59
+ expect(res.body.profile.name).to.equal("Custom");
60
+ // expect(res.body.profile.quotes.kbs).to.equal(1000);
61
+
62
+ done();
63
+ })
64
+ })
65
+ })
66
+ })
67
+ }).timeout(10000)
68
+
69
+ it('denyUpdateProjectProfile', (done) => {
70
+
71
+ var email = "test-signup-" + Date.now() + "@email.com";
72
+ var pwd = "pwd";
73
+
74
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
75
+ projectService.create("test-project-create", savedUser._id).then((savedProject) => {
76
+
77
+ chai.request(server)
78
+ .put('/projects/' + savedProject._id)
79
+ // .put('/projects/' + savedProject._id + "/update")
80
+ .auth(email, pwd)
81
+ .send({ profile: { name: "Custom", quotes: { kbs: 1000} } })
82
+ .end((err, res) => {
83
+
84
+ if (log) { console.log("update project profile res.body: ", res.body) };
85
+ res.should.have.status(403);
86
+ expect(res.body.success).to.equal(false);
87
+ expect(res.body.error).to.equal("You don't have the permission required to modify the project profile");
88
+ done();
89
+ })
90
+ })
91
+ })
92
+ }).timeout(10000)
93
+ });
94
+
95
+ });
96
+
97
+