Fix error when partially upding a filter

This commit is contained in:
Louis Laureys 2020-10-19 00:33:24 +02:00
parent 3271064044
commit 9dd3ed0e65

View file

@ -774,7 +774,7 @@ module.exports = (db, server) => {
* @apiParam {String} user Users unique ID. * @apiParam {String} user Users unique ID.
* @apiParam {String} filter Filters unique ID. * @apiParam {String} filter Filters unique ID.
* @apiParam {String} [name] Name of the Filter * @apiParam {String} [name] Name of the Filter
* @apiParam {Object} query Rules that a message must match * @apiParam {Object} [query] Rules that a message must match
* @apiParam {String} [query.from] Partial match for the From: header (case insensitive) * @apiParam {String} [query.from] Partial match for the From: header (case insensitive)
* @apiParam {String} [query.to] Partial match for the To:/Cc: headers (case insensitive) * @apiParam {String} [query.to] Partial match for the To:/Cc: headers (case insensitive)
* @apiParam {String} [query.subject] Partial match for the Subject: header (case insensitive) * @apiParam {String} [query.subject] Partial match for the Subject: header (case insensitive)
@ -782,7 +782,7 @@ module.exports = (db, server) => {
* @apiParam {String} [query.text] Fulltext search against message text * @apiParam {String} [query.text] Fulltext search against message text
* @apiParam {Boolean} [query.ha] Does a message have to have an attachment or not * @apiParam {Boolean} [query.ha] Does a message have to have an attachment or not
* @apiParam {Number} [query.size] Message size in bytes. If the value is a positive number then message needs to be larger, if negative then message needs to be smaller than abs(size) value * @apiParam {Number} [query.size] Message size in bytes. If the value is a positive number then message needs to be larger, if negative then message needs to be smaller than abs(size) value
* @apiParam {Object} action Action to take with a matching message * @apiParam {Object} [action] Action to take with a matching message
* @apiParam {Boolean} [action.seen] If true then mark matching messages as Seen * @apiParam {Boolean} [action.seen] If true then mark matching messages as Seen
* @apiParam {Boolean} [action.flag] If true then mark matching messages as Flagged * @apiParam {Boolean} [action.flag] If true then mark matching messages as Flagged
* @apiParam {Boolean} [action.delete] If true then do not store matching messages * @apiParam {Boolean} [action.delete] If true then do not store matching messages
@ -906,6 +906,7 @@ module.exports = (db, server) => {
hasChanges = true; hasChanges = true;
} }
if (req.params.query) {
['from', 'to', 'subject', 'listId'].forEach(key => { ['from', 'to', 'subject', 'listId'].forEach(key => {
if (result.value.query[key]) { if (result.value.query[key]) {
$set['query.headers.' + key] = result.value.query[key].replace(/\s+/g, ' '); $set['query.headers.' + key] = result.value.query[key].replace(/\s+/g, ' ');
@ -940,7 +941,9 @@ module.exports = (db, server) => {
$unset['query.size'] = true; $unset['query.size'] = true;
hasChanges = true; hasChanges = true;
} }
}
if (req.params.action) {
['seen', 'flag', 'delete', 'spam'].forEach(key => { ['seen', 'flag', 'delete', 'spam'].forEach(key => {
if (typeof result.value.action[key] === 'boolean') { if (typeof result.value.action[key] === 'boolean') {
$set['action.' + key] = result.value.action[key]; $set['action.' + key] = result.value.action[key];
@ -1025,10 +1028,11 @@ module.exports = (db, server) => {
hasChanges = true; hasChanges = true;
} }
} }
}
if (!hasChanges) { if (!hasChanges) {
res.json({ res.json({
error: 'No changes' success: true
}); });
return next(); return next();
} }