Skip to content

Commit

Permalink
Merge pull request #18 from llaske/fix/11
Browse files Browse the repository at this point in the history
Allow special characters in deployment description
  • Loading branch information
NikhilM98 authored Nov 22, 2020
2 parents 4b9f884 + cb61018 commit 1446514
Show file tree
Hide file tree
Showing 6 changed files with 5,172 additions and 61 deletions.
8 changes: 5 additions & 3 deletions api/controller/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Helm = require("nodejs-helm").Helm,
nodemailer = require('nodemailer'),
fs = require('fs'),
mongo = require('mongodb'),
validator = require('validator'),
exec = require('child_process').exec;

var db;
Expand Down Expand Up @@ -123,6 +124,7 @@ exports.findById = function(req, res) {
collection.findOne({
'_id': new mongo.ObjectID(req.params.did)
}, function(err, item) {
item.deployment_description = validator.unescape(item.deployment_description);
res.send(item);
});
});
Expand Down Expand Up @@ -228,7 +230,7 @@ exports.getAllDeployments = function(query, options, callback) {
insensitive: { "$toLower": "$name" }
}
},
{
{
$sort: {
"insensitive": 1
}
Expand Down Expand Up @@ -455,7 +457,7 @@ exports.updateDeployment = function(req, res) {

var did = req.params.did;
var deployment = JSON.parse(req.body.deployment);

deployment.timestamp = +new Date(); // Update timestamp
delete deployment.school_short_name; // Disable school_short_name change
delete deployment.deployed; // Disable deployed state change
Expand Down Expand Up @@ -666,7 +668,7 @@ exports.updateStatus = function(req, res) {
</div>`,
subject: statusTitle
};

var smtpTransporter = nodemailer.createTransport({
port: smtp_port,
host: smtp_host,
Expand Down
13 changes: 6 additions & 7 deletions dashboard/controller/deployments/editDeployment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// include libraries
var superagent = require('superagent'),
common = require('../../../helper/common'),
validator = require('validator'),
regexValidate = require('../../../helper/regexValidate');

var deployments = require('./index');
Expand All @@ -9,7 +10,7 @@ module.exports = function editDeployment(req, res) {
if (req.params.did) {
if (req.method == 'POST') {
// validate

delete req.body.school_short_name;
delete req.body.deployed;
delete req.body.status;
Expand Down Expand Up @@ -70,13 +71,11 @@ module.exports = function editDeployment(req, res) {
delete req.body.device_info;
}

req.body.deployment_description = req.body.deployment_description ? req.body.deployment_description.trim() : '';
if (req.body.deployment_description) {
req.assert('deployment_description', {text: 'deployment-description-invalid'}).matches(regexValidate('deployment-description'));
} else {
req.body.deployment_description = req.body.deployment_description ? validator.escape(req.body.deployment_description.trim()) : '';
if (!req.body.deployment_description) {
delete req.body.deployment_description;
}

if (Object.keys(req.body).length === 0) {
req.flash('errors', {
msg: {
Expand Down Expand Up @@ -149,7 +148,7 @@ module.exports = function editDeployment(req, res) {
}
});
return res.redirect('/deployments');
}
}
});
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/controller/deployments/requestDeployment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// include libraries
var superagent = require('superagent'),
validator = require('validator'),
common = require('../../../helper/common'),
regexValidate = require('../../../helper/regexValidate');

Expand Down Expand Up @@ -37,12 +38,11 @@ module.exports = function requestDeployment(req, res) {
req.body.device_info = req.body.device_info ? req.body.device_info.trim() : '';
req.assert('device_info', {text: 'device-info-invalid'}).matches(regexValidate('devices'));

req.body.deployment_description = req.body.deployment_description ? req.body.deployment_description.trim() : '';
req.assert('deployment_description', {text: 'deployment-description-invalid'}).matches(regexValidate('deployment-description'));
req.body.deployment_description = req.body.deployment_description ? validator.escape(req.body.deployment_description.trim()) : '';

// get errors
var errors = req.validationErrors();

if (!errors) {
superagent
.post(common.getAPIUrl(req) + 'api/v1/deployments')
Expand Down
2 changes: 0 additions & 2 deletions helper/regexValidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module.exports = function(type) {
return /^en$|^es$|^fr$|^hi$/;
case "address":
return /^[^!@$^%+={}|<>?"`;:&]+$/;
case "deployment-description":
return /^[^@$^%+={}|<>"'`;:&]{3,1024}$/i;
case "number":
return /^[0-9]+$/i;
case "devices":
Expand Down
Loading

0 comments on commit 1446514

Please sign in to comment.