Skip to content

Commit baa5edb

Browse files
committed
Merge branch 'AR/main' into AR/sync/20260520
# Conflicts: # middleware/has-role.js # middleware/passport.js # models/kb_setting.js # pubmodules/analytics/analytics.js # pubmodules/trigger/rulesTrigger.js # routes/auth.js # routes/project_user.js
2 parents 2ec83bf + 109e3a3 commit baa5edb

17 files changed

Lines changed: 632 additions & 439 deletions

File tree

middleware/has-role.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ class RoleChecker {
222222
winston.debug("project_user: ", JSON.stringify(project_user));
223223

224224
}
225-
226225
if (project_user) {
227226

228227
req.projectuser = project_user;

middleware/passport.js

Lines changed: 493 additions & 369 deletions
Large diffs are not rendered by default.

models/kb_setting.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ let expireAnsweredAfterSeconds = ttlSecondsFromEnv(
2020
DEFAULT_ANSWERED_TTL_SEC
2121
);
2222

23-
2423
const EngineSchema = new Schema({
2524
name: {
2625
type: String,

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubmodules/trigger/rulesTrigger.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,6 @@ class RulesTrigger {
11641164
lead: createdLead, requester: puser
11651165
};
11661166

1167-
11681167
return requestService.create(new_request).then(function (savedRequest) {
11691168

11701169
if (attributes) {

routes/auth.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -784,27 +784,36 @@ router.get("/google/callback", passport.authenticate("google", { session: false
784784

785785
router.get("/oauth2", function (req, res, next) {
786786
winston.debug("(oauth2) redirect_url: " + req.query.redirect_url);
787-
req.session.redirect_url = req.query.redirect_url;
787+
// req.session.redirect_url = req.query.redirect_url;
788788

789789
winston.debug("(oauth2) forced_redirect_url: " + req.query.forced_redirect_url);
790-
req.session.forced_redirect_url = req.query.forced_redirect_url;
790+
// req.session.forced_redirect_url = req.query.forced_redirect_url;
791+
792+
req.session.save(() => {
793+
passport.authenticate('oauth2',{
794+
state: JSON.stringify({
795+
redirect_url: req.query.redirect_url,
796+
forced_redirect_url: req.query.forced_redirect_url
797+
})
798+
})(req, res, next);
799+
});
791800

792-
passport.authenticate(
793-
'oauth2', { prompt: 'select_account' }
794-
)(req, res, next);
801+
// passport.authenticate(
802+
// 'oauth2'
803+
// )(req, res, next);
795804
});
796805

797806
// router.get('/oauth2',
798807
// passport.authenticate('oauth2'));
799808

800809
router.get('/oauth2/callback', passport.authenticate('oauth2', { session: false }), function (req, res) {
801-
winston.debug("'/oauth2/callback: ", req.query);
802-
winston.debug("/oauth2/callback --> req.session.redirect_url", req.session.redirect_url);
803-
winston.debug("/oauth2/callback --> req.session.forced_redirect_url", req.session.forced_redirect_url);
810+
winston.debug("'(/oauth2/callback): ", req.query);
811+
const state = JSON.parse(req.query.state);
812+
winston.debug("(/oauth2/callback) redirect_url:"+ state.redirect_url);
813+
winston.debug("(/oauth2/callback) forced_redirect_url:"+ state.forced_redirect_url);
804814

805815
var user = req.user;
806816
winston.debug("(/oauth2/callback) user", user);
807-
winston.debug("(/oauth2/callback) req.session.redirect_url: " + req.session.redirect_url);
808817
var userJson = user.toObject();
809818

810819
delete userJson.password;
@@ -828,21 +837,20 @@ router.get('/oauth2/callback', passport.authenticate('oauth2', { session: false
828837
// res.json(returnObject);
829838

830839
let dashboard_base_url = process.env.EMAIL_BASEURL || config.baseUrl;
831-
winston.debug("(/oauth2/callback) Google Redirect dashboard_base_url: ", dashboard_base_url);
840+
winston.debug("(/oauth2/callback) Google Redirect dashboard_base_url: "+ dashboard_base_url);
832841

833842
let homeurl = "/#/";
834-
835843
const separator = homeurl.includes('?') ? '&' : '?';
836844
var url = dashboard_base_url+homeurl+ separator + "token=JWT "+token;
837-
838-
if (req.session.redirect_url) {
839-
const separator = req.session.redirect_url.includes('?') ? '&' : '?';
840-
url = req.session.redirect_url+ separator + "token=JWT "+token;
845+
846+
if (state?.redirect_url) {
847+
const separator = state.redirect_url.includes('?') ? '&' : '?';
848+
url = state.redirect_url+ separator + "token=JWT "+token;
841849
}
842850

843-
if (req.session.forced_redirect_url) {
844-
const separator = req.session.forced_redirect_url.includes('?') ? '&' : '?';
845-
url = req.session.forced_redirect_url+ separator + "jwt=JWT "+token; //attention we use jwt= (ionic) instead token=(dashboard) for ionic
851+
if (state?.forced_redirect_url) {
852+
const separator = state.forced_redirect_url.includes('?') ? '&' : '?';
853+
url = state.forced_redirect_url+ separator + "jwt=JWT "+token; //attention we use jwt= (ionic) instead token=(dashboard) for ionic
846854
}
847855

848856
winston.debug("(/oauth2/callback) Google Redirect: " + url);

routes/files.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,33 @@ if (MAX_UPLOAD_FILE_SIZE) {
2929
} else {
3030
winston.info("Max upload file size is infinity");
3131
}
32-
const upload = multer({ storage: fileService.getStorage("files"),limits: uploadlimits});
32+
33+
let files_allowed = process.env.UPLOAD_FILES_ALLOW_LIST || "text/plain,application/octet-stream,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,image/png,audio/mpeg,application/json,application/pdf";
34+
winston.info("Files upload allowed list " + files_allowed);
35+
36+
const fileFilter = (req, file, cb) => {
37+
winston.debug("fileFilter " + files_allowed);
38+
const ext = file.originalname.toLowerCase().endsWith('.html') || file.originalname.toLowerCase().endsWith('.htm');
39+
40+
if (ext) {
41+
winston.debug("file extension not allowed: " + file.originalname);
42+
cb(new multer.MulterError('fileFilter not allowed'));
43+
return;
44+
}
45+
46+
if (files_allowed === "*" ||
47+
(files_allowed && files_allowed.length > 0 && files_allowed.split(",").indexOf(file.mimetype) > -1)) {
48+
winston.debug("file.mimetype allowed: " + file.mimetype);
49+
cb(null, true);
50+
} else {
51+
winston.debug("file.mimetype not allowed. " + file.mimetype);
52+
cb(new multer.MulterError('fileFilter not allowed'));
53+
}
54+
};
55+
56+
57+
const upload = multer({ storage: fileService.getStorage("files"), fileFilter: fileFilter, limits: uploadlimits}).single('file');
58+
3359

3460
/*
3561
curl -u andrea.leo@f21.it:123456 \
@@ -50,6 +76,8 @@ curl -u andrea.leo@f21.it:123456 \
5076
// });
5177

5278
/*
79+
80+
5381
curl \
5482
-F "file=@/Users/andrealeo/dev/chat21/tiledesk-server-dev-org/README.md" \
5583
http://localhost:3000/files/public/

routes/images.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,28 @@ const fileService = new FileGridFsService("images");
2525

2626

2727

28+
let images_allowed = process.env.UPLOAD_IMAGES_ALLOW_LIST || "image/jpeg,image/png,image/gif,image/vnd.microsoft.icon,image/webp";
29+
winston.info("Images upload allowed list " + images_allowed);
30+
2831
const fileFilter = (req, file, cb) => {
29-
if (file.mimetype == 'image/jpeg' || file.mimetype == 'image/png'
30-
|| file.mimetype == 'image/gif'|| file.mimetype == 'image/vnd.microsoft.icon'
31-
|| file.mimetype == 'image/webp') {
32-
cb(null, true);
33-
} else {
34-
cb(null, false);
35-
}
36-
}
32+
winston.debug("fileFilter " + images_allowed);
33+
const ext = file.originalname.toLowerCase().endsWith('.html') || file.originalname.toLowerCase().endsWith('.htm');
34+
35+
if (ext) {
36+
winston.debug("file extension not allowed: " + file.originalname);
37+
cb(new multer.MulterError('fileFilter not allowed'));
38+
return;
39+
}
40+
41+
if (images_allowed === "*" ||
42+
(images_allowed && images_allowed.length > 0 && images_allowed.split(",").indexOf(file.mimetype) > -1)) {
43+
winston.debug("file.mimetype allowed: " + file.mimetype);
44+
cb(null, true);
45+
} else {
46+
winston.debug("file.mimetype not allowed. " + file.mimetype);
47+
cb(new multer.MulterError('fileFilter not allowed'));
48+
}
49+
};
3750

3851

3952
let MAX_UPLOAD_FILE_SIZE = process.env.MAX_UPLOAD_FILE_SIZE;
@@ -54,7 +67,7 @@ if (MAX_UPLOAD_FILE_SIZE) {
5467
// }
5568

5669

57-
const upload = multer({ storage: fileService.getStorage("images"), fileFilter: fileFilter, limits: uploadlimits });
70+
const upload = multer({ storage: fileService.getStorage("images"), fileFilter: fileFilter, limits: uploadlimits }).single('file');
5871

5972
/*
6073
curl -u andrea.leo@f21.it:123456 \
@@ -392,6 +405,10 @@ the image binary file
392405
393406
Example:
394407
408+
409+
curl -v -X POST -H 'Content-Type: multipart/form-data' -F "file=@/Users/andrealeo/dev/chat21/tiledesk-server-dev-org/test.jpg" http://localhost:3000/images/public/
410+
411+
395412
```text
396413
curl -v -X POST -H 'Content-Type: multipart/form-data' -F "file=@/Users/andrealeo/dev/chat21/tiledesk-server-dev-org/test.jpg" https://api.tiledesk.com/v2/images/public
397414
```

routes/kb.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const KB_WEBHOOK_TOKEN = process.env.KB_WEBHOOK_TOKEN || 'kbcustomtoken';
2929
const PINECONE_RERANKING = process.env.PINECONE_RERANKING === true || process.env.PINECONE_RERANKING === "true";
3030
const apiUrl = process.env.API_URL || configGlobal.apiUrl;
3131

32+
let rerankingOff = false;
33+
if (process.env.RERANKING_OFF && (process.env.RERANKING_OFF === "true" || process.env.RERANKING_OFF === true)) {
34+
rerankingOff = true;
35+
}
36+
3237

3338
let MAX_UPLOAD_FILE_SIZE = process.env.MAX_UPLOAD_FILE_SIZE;
3439
let uploadlimits = undefined;

routes/message.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ async (req, res) => {
183183
proactive: true
184184
};
185185

186+
186187
return requestService.create(new_request).then(function (savedRequest) {
187188

188189

@@ -256,7 +257,8 @@ async (req, res) => {
256257
} else {
257258

258259
winston.debug("request exists", request.toObject());
259-
if (request.channel?.name === 'form') {
260+
261+
if (request.channel?.name === 'form' || request.channel?.name === 'email') {
260262
if (!sender && request.participantsAgents?.[0] !== req.user.id) {
261263
return res.status(403).send({ success: false, message: "Error creating message", err: "You don't belong the conversation" });
262264
}

0 commit comments

Comments
 (0)