@tiledesk/tiledesk-server 2.10.51 → 2.10.52
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 +4 -0
- package/app.js +2 -2
- package/package.json +2 -2
- package/routes/faq.js +31 -20
- package/routes/request.js +1 -1
- package/test/faqRoute.js +865 -746
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.10.52
|
9
|
+
- updated tybot-connector to 0.2.148
|
10
|
+
- updated faqRoute /get endpoint with restricted mode
|
11
|
+
|
8
12
|
# 2.10.51
|
9
13
|
- updated /replace endpoint adding trashed: false inside query
|
10
14
|
|
package/app.js
CHANGED
@@ -557,8 +557,8 @@ app.use('/:projectid/tags', [passport.authenticate(['basic', 'jwt'], { session:
|
|
557
557
|
app.use('/:projectid/subscriptions', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('admin')], resthook);
|
558
558
|
|
559
559
|
//deprecated
|
560
|
-
app.use('/:projectid/faq', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken
|
561
|
-
app.use('/:projectid/intents', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken
|
560
|
+
app.use('/:projectid/faq', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], faq);
|
561
|
+
app.use('/:projectid/intents', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], faq);
|
562
562
|
|
563
563
|
//Deprecated??
|
564
564
|
app.use('/:projectid/faqpub', faqpub);
|
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.10.
|
4
|
+
"version": "2.10.52",
|
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.14",
|
50
50
|
"@tiledesk/tiledesk-train-jobworker": "^0.0.11",
|
51
|
-
"@tiledesk/tiledesk-tybot-connector": "^0.2.
|
51
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.2.148",
|
52
52
|
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.76",
|
53
53
|
"@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.11",
|
54
54
|
"@tiledesk/tiledesk-sms-connector": "^0.1.11",
|
package/routes/faq.js
CHANGED
@@ -16,11 +16,12 @@ csv.separator = ';';
|
|
16
16
|
const axios = require("axios").default;
|
17
17
|
var configGlobal = require('../config/global');
|
18
18
|
const roleConstants = require('../models/roleConstants');
|
19
|
+
const roleChecker = require('../middleware/has-role');
|
19
20
|
|
20
21
|
const apiUrl = process.env.API_URL || configGlobal.apiUrl;
|
21
22
|
|
22
23
|
// POST CSV FILE UPLOAD FROM CLIENT
|
23
|
-
router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next) {
|
24
|
+
router.post('/uploadcsv', roleChecker.hasRoleOrTypes('admin', ['bot', 'subscription']), upload.single('uploadFile'), function (req, res, next) {
|
24
25
|
winston.debug(' -> -> REQ BODY ', req.body);
|
25
26
|
winston.debug(' -> ID FAQ-KB ', req.body.id_faq_kb);
|
26
27
|
winston.debug(' -> DELIMITER ', req.body.delimiter);
|
@@ -138,7 +139,7 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
|
|
138
139
|
});
|
139
140
|
|
140
141
|
|
141
|
-
router.post('/', function (req, res) {
|
142
|
+
router.post('/', roleChecker.hasRoleOrTypes('admin', ['bot', 'subscription']), function (req, res) {
|
142
143
|
|
143
144
|
winston.debug(req.body);
|
144
145
|
|
@@ -205,7 +206,7 @@ router.post('/', function (req, res) {
|
|
205
206
|
});
|
206
207
|
});
|
207
208
|
|
208
|
-
router.post('/ops_update', async (req, res) => {
|
209
|
+
router.post('/ops_update', roleChecker.hasRoleOrTypes('admin', ['bot', 'subscription']), async (req, res) => {
|
209
210
|
|
210
211
|
let id_faq_kb = req.body.id_faq_kb;
|
211
212
|
let operations = req.body.operations;
|
@@ -321,7 +322,7 @@ router.post('/ops_update', async (req, res) => {
|
|
321
322
|
|
322
323
|
})
|
323
324
|
|
324
|
-
router.patch('/:faqid/attributes', function (req, res) {
|
325
|
+
router.patch('/:faqid/attributes', roleChecker.hasRoleOrTypes('admin', ['bot', 'subscription']), function (req, res) {
|
325
326
|
let data = req.body;
|
326
327
|
winston.debug("data: ", data);
|
327
328
|
|
@@ -374,7 +375,7 @@ router.patch('/:faqid/attributes', function (req, res) {
|
|
374
375
|
})
|
375
376
|
})
|
376
377
|
|
377
|
-
router.put('/:faqid', function (req, res) {
|
378
|
+
router.put('/:faqid', roleChecker.hasRoleOrTypes('admin', ['bot', 'subscription']), function (req, res) {
|
378
379
|
|
379
380
|
winston.debug('UPDATE FAQ ', req.body);
|
380
381
|
let faqid = req.params.faqid;
|
@@ -470,7 +471,7 @@ router.put('/:faqid', function (req, res) {
|
|
470
471
|
|
471
472
|
|
472
473
|
// DELETE REMOTE AND LOCAL FAQ
|
473
|
-
router.delete('/:faqid', function (req, res) {
|
474
|
+
router.delete('/:faqid', roleChecker.hasRoleOrTypes('admin', ['bot', 'subscription']), function (req, res) {
|
474
475
|
|
475
476
|
winston.debug('DELETE FAQ - FAQ ID ', req.params.faqid);
|
476
477
|
|
@@ -521,7 +522,7 @@ router.delete('/:faqid', function (req, res) {
|
|
521
522
|
});
|
522
523
|
|
523
524
|
// EXPORT FAQ TO CSV
|
524
|
-
router.get('/csv', function (req, res) {
|
525
|
+
router.get('/csv', roleChecker.hasRoleOrTypes('admin', ['bot', 'subscription']), function (req, res) {
|
525
526
|
var query = {};
|
526
527
|
|
527
528
|
winston.debug('req.query', req.query);
|
@@ -554,7 +555,7 @@ router.get('/csv', function (req, res) {
|
|
554
555
|
});
|
555
556
|
|
556
557
|
|
557
|
-
router.get('/:faqid', function (req, res) {
|
558
|
+
router.get('/:faqid', roleChecker.hasRoleOrTypes('admin', ['bot', 'subscription']), function (req, res) {
|
558
559
|
|
559
560
|
winston.debug(req.body);
|
560
561
|
|
@@ -570,12 +571,18 @@ router.get('/:faqid', function (req, res) {
|
|
570
571
|
});
|
571
572
|
|
572
573
|
|
573
|
-
|
574
|
-
router.get('/', function (req, res, next) {
|
574
|
+
router.get('/', roleChecker.hasRoleOrTypes('agent', ['bot', 'subscription']), function (req, res, next) {
|
575
575
|
var query = {};
|
576
576
|
|
577
577
|
winston.debug("GET ALL FAQ OF THE BOT ID (req.query): ", req.query);
|
578
578
|
|
579
|
+
let restricted_mode;
|
580
|
+
|
581
|
+
let project_user = req.projectuser;
|
582
|
+
if (project_user && project_user.role === roleConstants.AGENT) {
|
583
|
+
restricted_mode = true;
|
584
|
+
}
|
585
|
+
|
579
586
|
if (req.query.id_faq_kb) {
|
580
587
|
query.id_faq_kb = req.query.id_faq_kb;
|
581
588
|
}
|
@@ -610,8 +617,7 @@ router.get('/', function (req, res, next) {
|
|
610
617
|
query.intent_display_name = req.query.intent_display_name
|
611
618
|
}
|
612
619
|
|
613
|
-
|
614
|
-
if (project_user && project_user.role === roleConstants.AGENT) {
|
620
|
+
if (restricted_mode) {
|
615
621
|
query.agents_available = {
|
616
622
|
$in: [ null, true ]
|
617
623
|
}
|
@@ -631,21 +637,26 @@ router.get('/', function (req, res, next) {
|
|
631
637
|
// console.log("result: ", result);
|
632
638
|
// })
|
633
639
|
|
634
|
-
return Faq.find(query)
|
635
|
-
skip(skip).limit(limit)
|
636
|
-
populate({ path: 'faq_kb' })
|
637
|
-
.
|
638
|
-
|
640
|
+
return Faq.find(query)
|
641
|
+
.skip(skip).limit(limit)
|
642
|
+
.populate({ path: 'faq_kb' })
|
643
|
+
.lean()
|
644
|
+
.exec(function (err, faqs) {
|
645
|
+
|
646
|
+
winston.debug("GET FAQ ", faqs);
|
639
647
|
|
640
648
|
if (err) {
|
641
649
|
winston.debug('GET FAQ err ', err)
|
642
650
|
return next(err)
|
643
651
|
};
|
644
|
-
winston.debug('GET FAQ ', faq)
|
645
|
-
res.json(faq);
|
646
652
|
|
647
|
-
|
653
|
+
if (restricted_mode === true) {
|
654
|
+
faqs = faqs.map(({ webhook_enabled, faq_kb, actions, attributes, createdBy, createdAt, updatedAt, __v, ...keepAttrs }) => keepAttrs)
|
655
|
+
faqs = faqs.filter(f => (f.intent_display_name !== "start" && f.intent_display_name !== 'defaultFallback'));
|
656
|
+
}
|
648
657
|
|
658
|
+
res.status(200).send(faqs);
|
659
|
+
});
|
649
660
|
|
650
661
|
});
|
651
662
|
|