@tiledesk/tiledesk-server 3.3.5 → 3.5.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 +20 -0
- package/app.js +7 -0
- package/deploynew.sh +7 -1
- package/docs/activities-client.md +27 -0
- package/docs/mcp-oauth2-it.md +279 -0
- package/docs/mcp-oauth2.md +279 -0
- package/docs/numeric-input-validation.md +91 -0
- package/docs/superpowers/plans/2026-11-10-mcp-oauth2-server-it.md +155 -0
- package/docs/superpowers/plans/2026-11-10-mcp-oauth2-server.md +155 -0
- package/docs/superpowers/plans/2026-11-10-mcp-oauth2-tybot-it.md +63 -0
- package/docs/superpowers/plans/2026-11-10-mcp-oauth2-tybot.md +63 -0
- package/docs/superpowers/specs/2026-11-10-mcp-oauth2-design-it.md +207 -0
- package/docs/superpowers/specs/2026-11-10-mcp-oauth2-design.md +207 -0
- package/jobs.js +15 -0
- package/models/mcpOAuthConnection.js +131 -0
- package/models/request.js +8 -0
- package/package.json +1 -1
- package/pubmodules/activities/activityMessageUtil.js +137 -0
- package/pubmodules/activities/models/activity.js +2 -0
- package/pubmodules/activities/routes/activity.js +39 -11
- package/pubmodules/activities/test/execution-filter.test.js +133 -0
- package/pubmodules/activities/test/execution-messages.test.js +158 -0
- package/pubmodules/canned/cannedResponseRoute.js +6 -9
- package/pubmodules/events/eventRoute.js +6 -9
- package/pubmodules/executions-publisher/index.js +457 -0
- package/pubmodules/executions-publisher/test/audit-consumer.test.js +384 -0
- package/pubmodules/executions-publisher/test/executions-publisher.test.js +204 -0
- package/pubmodules/pubModulesManager.js +12 -0
- package/routes/answered.js +7 -3
- package/routes/campaigns.js +7 -3
- package/routes/department.js +14 -3
- package/routes/executions-refire.js +148 -0
- package/routes/faq.js +6 -14
- package/routes/filesp.js +9 -4
- package/routes/kb.js +40 -15
- package/routes/lead.js +23 -28
- package/routes/logs.js +8 -1
- package/routes/mcp.js +11 -8
- package/routes/mcpOAuth.js +133 -0
- package/routes/mcpOAuthCallback.js +75 -0
- package/routes/message.js +3 -1
- package/routes/messagesRoot.js +5 -18
- package/routes/project.js +57 -12
- package/routes/project_user.js +21 -4
- package/routes/property.js +18 -20
- package/routes/request.js +36 -45
- package/routes/roles.js +8 -18
- package/routes/segment.js +8 -18
- package/routes/subscription.js +4 -5
- package/routes/tag.js +6 -9
- package/routes/unanswered.js +7 -3
- package/routes/user-request.js +29 -34
- package/routes/webhook.js +120 -54
- package/services/mcpOAuthDiscovery.js +248 -0
- package/services/mcpOAuthGoogleScopes.js +55 -0
- package/services/mcpOAuthService.js +732 -0
- package/services/mcpService.js +111 -15
- package/services/requestService.js +4 -2
- package/services/webhookService.js +4 -2
- package/test/executions-refire.test.js +362 -0
- package/test/kbRoute.js +4 -7
- package/test/mcpOAuthDiscovery.test.js +331 -0
- package/test/mcpOAuthGoogleScopes.test.js +25 -0
- package/test/mcpOAuthRoute.test.js +455 -0
- package/test/mcpOAuthService.test.js +693 -0
- package/test/mcpOAuthUtils.test.js +348 -0
- package/test/mcpServiceOAuth.test.js +267 -0
- package/test/numericInput.js +137 -0
- package/test/requestRoute.js +57 -0
- package/test/webhookConversationRoute.js +51 -0
- package/utils/logRedactor.js +4 -2
- package/utils/mcpOAuthCrypto.js +69 -0
- package/utils/mcpOAuthPkce.js +20 -0
- package/utils/numericInput.js +200 -0
- package/utils/outboundUrlGuard.js +131 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
let express = require('express');
|
|
2
|
+
let router = express.Router();
|
|
3
|
+
let winston = require('../config/winston');
|
|
4
|
+
const roleChecker = require('../middleware/has-role');
|
|
5
|
+
const Faq_kb = require('../models/faq_kb');
|
|
6
|
+
const Subscription = require('../models/subscription');
|
|
7
|
+
const Integration = require('../models/integrations');
|
|
8
|
+
const McpOAuthConnection = require('../models/mcpOAuthConnection');
|
|
9
|
+
const integrationEvent = require('../event/integrationEvent');
|
|
10
|
+
const mcpOAuthService = require('../services/mcpOAuthService');
|
|
11
|
+
|
|
12
|
+
function sendError(res, error, message) {
|
|
13
|
+
const status = error.status || 500;
|
|
14
|
+
if (status >= 500) {
|
|
15
|
+
winston.error(message + ': ', error);
|
|
16
|
+
} else {
|
|
17
|
+
winston.debug(message + ': ' + error.message);
|
|
18
|
+
}
|
|
19
|
+
res.status(status).send({
|
|
20
|
+
success: false,
|
|
21
|
+
error: status === 500 ? message : error.message,
|
|
22
|
+
code: error.code
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Tokens are served to chatbots and subscriptions of the project only, never to dashboard users.
|
|
27
|
+
function botOrSubscriptionOnly(req, res, next) {
|
|
28
|
+
const user = req.user;
|
|
29
|
+
const isMachine = user instanceof Faq_kb || user instanceof Subscription;
|
|
30
|
+
if (!isMachine || !roleChecker.belongsToProject(user, req.projectid)) {
|
|
31
|
+
return res.status(403).send({ success: false, error: 'Only chatbots of the project can read MCP OAuth tokens' });
|
|
32
|
+
}
|
|
33
|
+
next();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Removes the reference to a deleted connection from the servers of the project mcp integration. */
|
|
37
|
+
async function detachConnection(id_project, connection_id) {
|
|
38
|
+
const integration = await Integration.findOne({ id_project: id_project, name: 'mcp' });
|
|
39
|
+
const servers = integration && Array.isArray(integration.value && integration.value.servers) ? integration.value.servers : [];
|
|
40
|
+
let detached = 0;
|
|
41
|
+
const updatedServers = servers.map((server) => {
|
|
42
|
+
if (server && server.oauth && String(server.oauth.connection_id) === String(connection_id)) {
|
|
43
|
+
detached++;
|
|
44
|
+
const { oauth, ...rest } = server;
|
|
45
|
+
return rest;
|
|
46
|
+
}
|
|
47
|
+
return server;
|
|
48
|
+
});
|
|
49
|
+
if (detached === 0) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
integration.value = { ...integration.value, servers: updatedServers };
|
|
53
|
+
integration.markModified('value');
|
|
54
|
+
await integration.save();
|
|
55
|
+
const integrations = await Integration.find({ id_project: id_project });
|
|
56
|
+
integrationEvent.emit('integration.update', integrations, id_project);
|
|
57
|
+
return detached;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
router.use((req, res, next) => {
|
|
61
|
+
if (!mcpOAuthService.isConfigured()) {
|
|
62
|
+
return res.status(503).send({ success: false, error: 'MCP OAuth is not available on this installation', code: 'not_configured' });
|
|
63
|
+
}
|
|
64
|
+
next();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* POST /mcp/oauth/authorize
|
|
69
|
+
* Body: { server_url, mode: 'mcp'|'google'|'manual', name?, scopes?, return_url?, manual? }
|
|
70
|
+
* Returns the URL to open in the browser to authorize the connection.
|
|
71
|
+
*/
|
|
72
|
+
router.post('/authorize', roleChecker.hasRole('admin'), async (req, res) => {
|
|
73
|
+
try {
|
|
74
|
+
const result = await mcpOAuthService.startAuthorization(req.projectid, req.user._id, req.body);
|
|
75
|
+
res.status(200).send({ success: true, ...result });
|
|
76
|
+
} catch (error) {
|
|
77
|
+
sendError(res, error, 'Error starting MCP OAuth authorization');
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
router.get('/connections', roleChecker.hasRole('admin'), async (req, res) => {
|
|
82
|
+
try {
|
|
83
|
+
const connections = await mcpOAuthService.listConnections(req.projectid);
|
|
84
|
+
res.status(200).send(connections.map((connection) => McpOAuthConnection.toPublic(connection)));
|
|
85
|
+
} catch (error) {
|
|
86
|
+
sendError(res, error, 'Error getting MCP OAuth connections');
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
router.get('/connections/:connection_id', roleChecker.hasRole('admin'), async (req, res) => {
|
|
91
|
+
try {
|
|
92
|
+
const connection = await mcpOAuthService.getConnection(req.projectid, req.params.connection_id);
|
|
93
|
+
res.status(200).send(McpOAuthConnection.toPublic(connection));
|
|
94
|
+
} catch (error) {
|
|
95
|
+
sendError(res, error, 'Error getting MCP OAuth connection');
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
router.post('/connections/:connection_id/refresh', roleChecker.hasRole('admin'), async (req, res) => {
|
|
100
|
+
try {
|
|
101
|
+
await mcpOAuthService.getAccessToken(req.projectid, req.params.connection_id, { force: true });
|
|
102
|
+
const connection = await mcpOAuthService.getConnection(req.projectid, req.params.connection_id);
|
|
103
|
+
res.status(200).send(McpOAuthConnection.toPublic(connection));
|
|
104
|
+
} catch (error) {
|
|
105
|
+
sendError(res, error, 'Error refreshing MCP OAuth connection');
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
router.delete('/connections/:connection_id', roleChecker.hasRole('admin'), async (req, res) => {
|
|
110
|
+
try {
|
|
111
|
+
const result = await mcpOAuthService.revokeAndDelete(req.projectid, req.params.connection_id);
|
|
112
|
+
await detachConnection(req.projectid, req.params.connection_id);
|
|
113
|
+
res.status(200).send({ success: true, revoked: result.revoked });
|
|
114
|
+
} catch (error) {
|
|
115
|
+
sendError(res, error, 'Error deleting MCP OAuth connection');
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* GET /mcp/oauth/connections/:connection_id/token
|
|
121
|
+
* Chatbots only: a valid access token, refreshed when it is about to expire.
|
|
122
|
+
*/
|
|
123
|
+
router.get('/connections/:connection_id/token', botOrSubscriptionOnly, async (req, res) => {
|
|
124
|
+
try {
|
|
125
|
+
const token = await mcpOAuthService.getAccessToken(req.projectid, req.params.connection_id);
|
|
126
|
+
res.set('Cache-Control', 'no-store');
|
|
127
|
+
res.status(200).send(token);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
sendError(res, error, 'Error getting MCP OAuth token');
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
module.exports = router;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
let express = require('express');
|
|
2
|
+
let router = express.Router();
|
|
3
|
+
let winston = require('../config/winston');
|
|
4
|
+
const mcpOAuthService = require('../services/mcpOAuthService');
|
|
5
|
+
|
|
6
|
+
function escapeHtml(value) {
|
|
7
|
+
return String(value).replace(/[&<>"']/g, (char) => ({
|
|
8
|
+
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
|
9
|
+
}[char]));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function sendPage(res, status, title, message) {
|
|
13
|
+
res.status(status)
|
|
14
|
+
.set('Content-Type', 'text/html; charset=utf-8')
|
|
15
|
+
.send('<!DOCTYPE html><html><head><meta charset="utf-8"><title>' + escapeHtml(title) + '</title></head>' +
|
|
16
|
+
'<body style="font-family:sans-serif;text-align:center;padding-top:15vh">' +
|
|
17
|
+
'<h2>' + escapeHtml(title) + '</h2><p>' + escapeHtml(message) + '</p></body></html>');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Hash-routed dashboards read the query inside the fragment: https://panel/#/route?x=1
|
|
21
|
+
function withParams(returnUrl, params) {
|
|
22
|
+
const url = new URL(returnUrl);
|
|
23
|
+
const query = new URLSearchParams(params).toString();
|
|
24
|
+
if (url.hash) {
|
|
25
|
+
url.hash = url.hash + (url.hash.includes('?') ? '&' : '?') + query;
|
|
26
|
+
} else {
|
|
27
|
+
Object.entries(params).forEach(([key, value]) => url.searchParams.set(key, value));
|
|
28
|
+
}
|
|
29
|
+
return url.toString();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* GET /oauth2/mcp/callback?code&state
|
|
34
|
+
* Redirect URI registered at the OAuth providers. Authenticated by the single-use state.
|
|
35
|
+
*/
|
|
36
|
+
router.get('/callback', async (req, res) => {
|
|
37
|
+
// The authorization code is in the URL: never leak it through the Referer header.
|
|
38
|
+
res.set('Referrer-Policy', 'no-referrer');
|
|
39
|
+
res.set('Cache-Control', 'no-store');
|
|
40
|
+
|
|
41
|
+
if (!mcpOAuthService.isConfigured()) {
|
|
42
|
+
return sendPage(res, 503, 'Not available', 'MCP OAuth is not available on this installation.');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let result;
|
|
46
|
+
try {
|
|
47
|
+
result = await mcpOAuthService.completeAuthorization({
|
|
48
|
+
code: req.query.code,
|
|
49
|
+
state: req.query.state,
|
|
50
|
+
error: req.query.error,
|
|
51
|
+
error_description: req.query.error_description
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error.status === 400 || error.status === 404) {
|
|
55
|
+
return sendPage(res, 400, 'Authorization link expired', 'This authorization link is invalid or has expired. Start the connection again.');
|
|
56
|
+
}
|
|
57
|
+
winston.error('MCP OAuth callback error: ', error);
|
|
58
|
+
return sendPage(res, error.status || 500, 'Authorization failed', 'The connection could not be completed. Try again later.');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const connectionId = result.connection._id.toString();
|
|
62
|
+
if (result.return_url) {
|
|
63
|
+
const params = result.error
|
|
64
|
+
? { mcp_oauth: 'error', error: result.error, connection_id: connectionId }
|
|
65
|
+
: { mcp_oauth: 'success', connection_id: connectionId };
|
|
66
|
+
return res.redirect(302, withParams(result.return_url, params));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (result.error) {
|
|
70
|
+
return sendPage(res, 200, 'Authorization failed', 'The provider answered: ' + result.error + '. You can close this window.');
|
|
71
|
+
}
|
|
72
|
+
return sendPage(res, 200, 'Connected', 'The MCP server is connected. You can close this window.');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
module.exports = router;
|
package/routes/message.js
CHANGED
|
@@ -16,6 +16,7 @@ var MessageConstants = require("../models/messageConstants");
|
|
|
16
16
|
|
|
17
17
|
var cacheUtil = require('../utils/cacheUtil');
|
|
18
18
|
var cacheEnabler = require("../services/cacheEnabler");
|
|
19
|
+
var numericInput = require('../utils/numericInput');
|
|
19
20
|
|
|
20
21
|
const { check, validationResult } = require('express-validator');
|
|
21
22
|
|
|
@@ -61,7 +62,8 @@ async (req, res) => {
|
|
|
61
62
|
var fullname = req.body.senderFullname || req.user.fullName;
|
|
62
63
|
var email = req.body.email || req.user.email;
|
|
63
64
|
|
|
64
|
-
let messageStatus = req.body.status
|
|
65
|
+
let messageStatus = numericInput.takeMessageStatus(res, req.body.status);
|
|
66
|
+
if (messageStatus === null) return;
|
|
65
67
|
winston.debug('messageStatus: ' + messageStatus);
|
|
66
68
|
|
|
67
69
|
let q = Request.findOne({request_id: req.params.request_id, id_project: req.projectid});
|
package/routes/messagesRoot.js
CHANGED
|
@@ -11,6 +11,7 @@ var winston = require('../config/winston');
|
|
|
11
11
|
var fastCsv = require("fast-csv");
|
|
12
12
|
var roleChecker = require('../middleware/has-role');
|
|
13
13
|
const { check, validationResult } = require('express-validator');
|
|
14
|
+
var numericInput = require('../utils/numericInput');
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
router.post('/',
|
|
@@ -68,24 +69,10 @@ router.post('/',
|
|
|
68
69
|
|
|
69
70
|
router.get('/',roleChecker.hasRoleOrTypes('owner'), function(req, res) {
|
|
70
71
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
var limit =
|
|
74
|
-
|
|
75
|
-
// console.log("req.query.populate_request",req.query.populate_request);
|
|
76
|
-
if (req.query.limit) {
|
|
77
|
-
limit = parseInt(req.query.limit);
|
|
78
|
-
}
|
|
79
|
-
if (limit > 50) {
|
|
80
|
-
limit = DEFAULT_LIMIT;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var page = 0;
|
|
85
|
-
|
|
86
|
-
if (req.query.page) {
|
|
87
|
-
page = req.query.page;
|
|
88
|
-
}
|
|
72
|
+
const paging = numericInput.takePagination(res, req.query, { defaultLimit: 10, maxLimit: 50, overMax: 'default' });
|
|
73
|
+
if (!paging) return;
|
|
74
|
+
var limit = paging.limit;
|
|
75
|
+
var page = paging.page;
|
|
89
76
|
|
|
90
77
|
var skip = page * limit;
|
|
91
78
|
|
package/routes/project.js
CHANGED
|
@@ -12,6 +12,47 @@ var Department = require('../models/department');
|
|
|
12
12
|
var Group = require('../models/group');
|
|
13
13
|
|
|
14
14
|
var winston = require('../config/winston');
|
|
15
|
+
var numericInput = require('../utils/numericInput');
|
|
16
|
+
|
|
17
|
+
function validateProjectNumbers(res, body) {
|
|
18
|
+
var parsed = {};
|
|
19
|
+
var checks = [
|
|
20
|
+
['versions', body.versions, 0, 99999999, 'versions must be an integer between 0 and 99999999'],
|
|
21
|
+
['settings.max_agent_assigned_chat', body['settings.max_agent_assigned_chat'], -1, 100000, 'settings.max_agent_assigned_chat must be -1 (unlimited) or an integer between 0 and 100000'],
|
|
22
|
+
['settings.reassignment_delay', body['settings.reassignment_delay'], 0, 315360000, 'settings.reassignment_delay must be an integer between 0 and 315360000'],
|
|
23
|
+
['settings.email.config.port', body['settings.email.config.port'], 1, 65535, 'settings.email.config.port must be an integer between 1 and 65535']
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
for (var i = 0; i < checks.length; i++) {
|
|
27
|
+
var key = checks[i][0];
|
|
28
|
+
var value = checks[i][1];
|
|
29
|
+
if (value === undefined) continue;
|
|
30
|
+
var n = numericInput.parseBoundedInteger(value, checks[i][2], checks[i][3]);
|
|
31
|
+
if (n === null) {
|
|
32
|
+
return numericInput.sendInvalidNumber(res, checks[i][4]);
|
|
33
|
+
}
|
|
34
|
+
parsed[key] = n;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (body.settings && typeof body.settings === 'object' && !Array.isArray(body.settings)) {
|
|
38
|
+
if (body.settings.max_agent_assigned_chat !== undefined) {
|
|
39
|
+
var maxAgentAssignedChat = numericInput.parseBoundedInteger(body.settings.max_agent_assigned_chat, -1, 100000);
|
|
40
|
+
if (maxAgentAssignedChat === null) {
|
|
41
|
+
return numericInput.sendInvalidNumber(res, 'settings.max_agent_assigned_chat must be -1 (unlimited) or an integer between 0 and 100000');
|
|
42
|
+
}
|
|
43
|
+
body.settings.max_agent_assigned_chat = maxAgentAssignedChat;
|
|
44
|
+
}
|
|
45
|
+
if (body.settings.reassignment_delay !== undefined) {
|
|
46
|
+
var reassignmentDelay = numericInput.parseBoundedInteger(body.settings.reassignment_delay, 0, 315360000);
|
|
47
|
+
if (reassignmentDelay === null) {
|
|
48
|
+
return numericInput.sendInvalidNumber(res, 'settings.reassignment_delay must be an integer between 0 and 315360000');
|
|
49
|
+
}
|
|
50
|
+
body.settings.reassignment_delay = reassignmentDelay;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
15
56
|
var roleChecker = require('../middleware/has-role');
|
|
16
57
|
var config = require('../config/database');
|
|
17
58
|
|
|
@@ -260,6 +301,8 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
|
260
301
|
winston.debug('UPDATE PROJECT REQ BODY ', req.body);
|
|
261
302
|
|
|
262
303
|
var update = {};
|
|
304
|
+
var projectNumbers = validateProjectNumbers(res, req.body);
|
|
305
|
+
if (projectNumbers === null) return;
|
|
263
306
|
let updating_quotes = false;
|
|
264
307
|
|
|
265
308
|
if (req.body.profile) {
|
|
@@ -418,8 +461,8 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
|
418
461
|
update["settings.chat_limit_on"] = req.body["settings.chat_limit_on"];
|
|
419
462
|
}
|
|
420
463
|
|
|
421
|
-
if (
|
|
422
|
-
update["settings.max_agent_assigned_chat"] =
|
|
464
|
+
if (projectNumbers["settings.max_agent_assigned_chat"] !== undefined) {
|
|
465
|
+
update["settings.max_agent_assigned_chat"] = projectNumbers["settings.max_agent_assigned_chat"];
|
|
423
466
|
}
|
|
424
467
|
|
|
425
468
|
|
|
@@ -428,8 +471,8 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
|
428
471
|
update["settings.reassignment_on"] = req.body["settings.reassignment_on"];
|
|
429
472
|
}
|
|
430
473
|
|
|
431
|
-
if (
|
|
432
|
-
update["settings.reassignment_delay"] =
|
|
474
|
+
if (projectNumbers["settings.reassignment_delay"] !== undefined) {
|
|
475
|
+
update["settings.reassignment_delay"] = projectNumbers["settings.reassignment_delay"];
|
|
433
476
|
}
|
|
434
477
|
|
|
435
478
|
|
|
@@ -469,8 +512,8 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
|
469
512
|
update.widget = req.body.widget;
|
|
470
513
|
}
|
|
471
514
|
|
|
472
|
-
if (
|
|
473
|
-
update.versions =
|
|
515
|
+
if (projectNumbers.versions !== undefined) {
|
|
516
|
+
update.versions = projectNumbers.versions;
|
|
474
517
|
}
|
|
475
518
|
|
|
476
519
|
if (req.body.channels!=undefined) {
|
|
@@ -525,6 +568,8 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
525
568
|
winston.debug('PATCH PROJECT REQ BODY ', req.body);
|
|
526
569
|
|
|
527
570
|
var update = {};
|
|
571
|
+
var projectNumbers = validateProjectNumbers(res, req.body);
|
|
572
|
+
if (projectNumbers === null) return;
|
|
528
573
|
|
|
529
574
|
if (req.body.name!=undefined) {
|
|
530
575
|
update.name = req.body.name;
|
|
@@ -604,8 +649,8 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
604
649
|
update["settings.chat_limit_on"] = req.body["settings.chat_limit_on"];
|
|
605
650
|
}
|
|
606
651
|
|
|
607
|
-
if (
|
|
608
|
-
update["settings.max_agent_assigned_chat"] =
|
|
652
|
+
if (projectNumbers["settings.max_agent_assigned_chat"] !== undefined) {
|
|
653
|
+
update["settings.max_agent_assigned_chat"] = projectNumbers["settings.max_agent_assigned_chat"];
|
|
609
654
|
}
|
|
610
655
|
|
|
611
656
|
|
|
@@ -614,8 +659,8 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
614
659
|
update["settings.reassignment_on"] = req.body["settings.reassignment_on"];
|
|
615
660
|
}
|
|
616
661
|
|
|
617
|
-
if (
|
|
618
|
-
update["settings.reassignment_delay"] =
|
|
662
|
+
if (projectNumbers["settings.reassignment_delay"] !== undefined) {
|
|
663
|
+
update["settings.reassignment_delay"] = projectNumbers["settings.reassignment_delay"];
|
|
619
664
|
}
|
|
620
665
|
|
|
621
666
|
|
|
@@ -633,8 +678,8 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
633
678
|
update.widget = req.body.widget;
|
|
634
679
|
}
|
|
635
680
|
|
|
636
|
-
if (
|
|
637
|
-
update.versions =
|
|
681
|
+
if (projectNumbers.versions !== undefined) {
|
|
682
|
+
update.versions = projectNumbers.versions;
|
|
638
683
|
}
|
|
639
684
|
|
|
640
685
|
if (req.body.channels!=undefined) {
|
package/routes/project_user.js
CHANGED
|
@@ -18,6 +18,7 @@ var validtoken = require('../middleware/valid-token')
|
|
|
18
18
|
var roleChecker = require('../middleware/has-role');
|
|
19
19
|
const puEvent = require('../event/projectUserEvent');
|
|
20
20
|
const { track } = require('../lib/analyticsClient');
|
|
21
|
+
var numericInput = require('../utils/numericInput');
|
|
21
22
|
const projectUserUpdateContextUtil = require('../utils/projectUserUpdateContextUtil');
|
|
22
23
|
|
|
23
24
|
function emitProjectUserDeleteActivity(req, project_user, deleteType) {
|
|
@@ -220,11 +221,19 @@ router.put('/', [passport.authenticate(['basic', 'jwt'], { session: false }), va
|
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
if (req.body.max_assigned_chat!=undefined) {
|
|
223
|
-
|
|
224
|
+
var maxAssignedChat = numericInput.parseBoundedInteger(req.body.max_assigned_chat, -1, 100000);
|
|
225
|
+
if (maxAssignedChat === null) {
|
|
226
|
+
return numericInput.sendInvalidNumber(res, 'max_assigned_chat must be -1 (unlimited) or an integer between 0 and 100000');
|
|
227
|
+
}
|
|
228
|
+
update.max_assigned_chat = maxAssignedChat;
|
|
224
229
|
}
|
|
225
230
|
|
|
226
231
|
if (req.body.number_assigned_requests!=undefined) {
|
|
227
|
-
|
|
232
|
+
var numberAssignedRequests = numericInput.parseBoundedInteger(req.body.number_assigned_requests, 0, 1000000);
|
|
233
|
+
if (numberAssignedRequests === null) {
|
|
234
|
+
return numericInput.sendInvalidNumber(res, 'number_assigned_requests must be an integer between 0 and 1000000');
|
|
235
|
+
}
|
|
236
|
+
update.number_assigned_requests = numberAssignedRequests;
|
|
228
237
|
}
|
|
229
238
|
|
|
230
239
|
if (req.body.attributes!=undefined) {
|
|
@@ -292,11 +301,19 @@ router.put('/:project_userid', [passport.authenticate(['basic', 'jwt'], { sessio
|
|
|
292
301
|
}
|
|
293
302
|
|
|
294
303
|
if (req.body.max_assigned_chat!=undefined) {
|
|
295
|
-
|
|
304
|
+
var maxAssignedChat = numericInput.parseBoundedInteger(req.body.max_assigned_chat, -1, 100000);
|
|
305
|
+
if (maxAssignedChat === null) {
|
|
306
|
+
return numericInput.sendInvalidNumber(res, 'max_assigned_chat must be -1 (unlimited) or an integer between 0 and 100000');
|
|
307
|
+
}
|
|
308
|
+
update.max_assigned_chat = maxAssignedChat;
|
|
296
309
|
}
|
|
297
310
|
|
|
298
311
|
if (req.body.number_assigned_requests!=undefined) {
|
|
299
|
-
|
|
312
|
+
var numberAssignedRequests = numericInput.parseBoundedInteger(req.body.number_assigned_requests, 0, 1000000);
|
|
313
|
+
if (numberAssignedRequests === null) {
|
|
314
|
+
return numericInput.sendInvalidNumber(res, 'number_assigned_requests must be an integer between 0 and 1000000');
|
|
315
|
+
}
|
|
316
|
+
update.number_assigned_requests = numberAssignedRequests;
|
|
300
317
|
}
|
|
301
318
|
|
|
302
319
|
if (req.body.attributes!=undefined) {
|
package/routes/property.js
CHANGED
|
@@ -2,6 +2,7 @@ var express = require('express');
|
|
|
2
2
|
var router = express.Router();
|
|
3
3
|
var Property = require("../models/property");
|
|
4
4
|
var winston = require('../config/winston');
|
|
5
|
+
var numericInput = require('../utils/numericInput');
|
|
5
6
|
|
|
6
7
|
router.post('/', function (req, res) {
|
|
7
8
|
|
|
@@ -43,7 +44,11 @@ router.put('/:propertyid', function (req, res) {
|
|
|
43
44
|
update.type = req.body.type;
|
|
44
45
|
}
|
|
45
46
|
if (req.body.status!=undefined) {
|
|
46
|
-
|
|
47
|
+
var propertyStatus = numericInput.takeOptionalAllowedInteger(res, req.body.status, numericInput.PROPERTY_STATUSES, 'status');
|
|
48
|
+
if (propertyStatus === null) return;
|
|
49
|
+
if (propertyStatus !== undefined) {
|
|
50
|
+
update.status = propertyStatus;
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
|
|
@@ -113,20 +118,11 @@ router.get('/:propertyid', function (req, res) {
|
|
|
113
118
|
|
|
114
119
|
router.get('/', function (req, res) {
|
|
115
120
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
var page = 0;
|
|
124
|
-
|
|
125
|
-
if (req.query.page) {
|
|
126
|
-
page = req.query.page;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
var skip = page * limit;
|
|
121
|
+
const paging = numericInput.takePagination(res, req.query, { defaultLimit: 40, maxLimit: 1000, overMax: 'reject' });
|
|
122
|
+
if (!paging) return;
|
|
123
|
+
var limit = paging.limit;
|
|
124
|
+
var skip = paging.skip;
|
|
125
|
+
winston.debug('property ROUTE - limit: '+limit);
|
|
130
126
|
winston.debug('property ROUTE - SKIP PAGE ', skip);
|
|
131
127
|
|
|
132
128
|
|
|
@@ -138,13 +134,15 @@ router.get('/', function (req, res) {
|
|
|
138
134
|
}
|
|
139
135
|
|
|
140
136
|
if (req.query.status) {
|
|
141
|
-
|
|
137
|
+
var propertyStatus = numericInput.takeOptionalAllowedInteger(res, req.query.status, numericInput.PROPERTY_STATUSES, 'status');
|
|
138
|
+
if (propertyStatus === null) return;
|
|
139
|
+
if (propertyStatus !== undefined) {
|
|
140
|
+
query.status = propertyStatus;
|
|
141
|
+
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
var direction =
|
|
145
|
-
if (
|
|
146
|
-
direction = req.query.direction;
|
|
147
|
-
}
|
|
144
|
+
var direction = numericInput.takeSortDirection(res, req.query.direction);
|
|
145
|
+
if (direction === null) return;
|
|
148
146
|
|
|
149
147
|
var sortField = "createdAt";
|
|
150
148
|
if (req.query.sort) {
|