Remove alias handling from user logic to mail logic

This commit is contained in:
Johannes Zellner
2018-01-25 18:03:26 +01:00
parent 647582a246
commit aab175ea05
3 changed files with 10 additions and 91 deletions
+1 -33
View File
@@ -9,9 +9,7 @@ exports = module.exports = {
verifyPassword: verifyPassword,
requireAdmin: requireAdmin,
sendInvite: sendInvite,
setGroups: setGroups,
setAliases: setAliases,
getAliases: getAliases
setGroups: setGroups
};
var assert = require('assert'),
@@ -198,33 +196,3 @@ function setGroups(req, res, next) {
next(new HttpSuccess(204));
});
}
function setAliases(req, res, next) {
assert.strictEqual(typeof req.params.userId, 'string');
if (!util.isArray(req.body.aliases)) return next(new HttpError(400, 'aliases must be an array'));
for (var i = 0; i < req.body.aliases.length; i++) {
if (typeof req.body.aliases[i] !== 'string') return next(new HttpError(400, 'alias must be a string'));
}
user.setAliases(req.params.userId, req.body.aliases, function (error) {
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'No such user'));
if (error && error.reason === UserError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error && error.reason === UserError.ALREADY_EXISTS) return next(new HttpError(409, 'One or more aliases already exist'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200));
});
}
function getAliases(req, res, next) {
assert.strictEqual(typeof req.params.userId, 'string');
user.getAliases(req.params.userId, function (error, aliases) {
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'No such user'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, { aliases: aliases }));
});
}