move aliases route under mailbox
since aliases can now span domains fixes #577
This commit is contained in:
15
src/mail.js
15
src/mail.js
@@ -38,7 +38,6 @@ exports = module.exports = {
|
|||||||
updateMailboxOwner: updateMailboxOwner,
|
updateMailboxOwner: updateMailboxOwner,
|
||||||
removeMailbox: removeMailbox,
|
removeMailbox: removeMailbox,
|
||||||
|
|
||||||
listAliases: listAliases,
|
|
||||||
getAliases: getAliases,
|
getAliases: getAliases,
|
||||||
setAliases: setAliases,
|
setAliases: setAliases,
|
||||||
|
|
||||||
@@ -1127,19 +1126,6 @@ function removeMailbox(name, domain, auditSource, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function listAliases(domain, page, perPage, callback) {
|
|
||||||
assert.strictEqual(typeof domain, 'string');
|
|
||||||
assert.strictEqual(typeof page, 'number');
|
|
||||||
assert.strictEqual(typeof perPage, 'number');
|
|
||||||
assert.strictEqual(typeof callback, 'function');
|
|
||||||
|
|
||||||
mailboxdb.listAliases(domain, page, perPage, function (error, result) {
|
|
||||||
if (error) return callback(error);
|
|
||||||
|
|
||||||
callback(null, result);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAliases(name, domain, callback) {
|
function getAliases(name, domain, callback) {
|
||||||
assert.strictEqual(typeof name, 'string');
|
assert.strictEqual(typeof name, 'string');
|
||||||
assert.strictEqual(typeof domain, 'string');
|
assert.strictEqual(typeof domain, 'string');
|
||||||
@@ -1172,7 +1158,6 @@ function setAliases(name, domain, aliases, callback) {
|
|||||||
if (!validator.isEmail(`${name}@${domain}`)) return callback(new BoxError(BoxError.BAD_FIELD, `Invalid email: ${name}@${domain}`));
|
if (!validator.isEmail(`${name}@${domain}`)) return callback(new BoxError(BoxError.BAD_FIELD, `Invalid email: ${name}@${domain}`));
|
||||||
aliases[i] = { name, domain };
|
aliases[i] = { name, domain };
|
||||||
}
|
}
|
||||||
|
|
||||||
mailboxdb.setAliasesForName(name, domain, aliases, function (error) {
|
mailboxdb.setAliasesForName(name, domain, aliases, function (error) {
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ exports = module.exports = {
|
|||||||
updateList: updateList,
|
updateList: updateList,
|
||||||
del: del,
|
del: del,
|
||||||
|
|
||||||
listAliases: listAliases,
|
|
||||||
listMailboxes: listMailboxes,
|
listMailboxes: listMailboxes,
|
||||||
getLists: getLists,
|
getLists: getLists,
|
||||||
|
|
||||||
@@ -323,22 +322,6 @@ function getAliasesForName(name, domain, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function listAliases(domain, page, perPage, callback) {
|
|
||||||
assert.strictEqual(typeof domain, 'string');
|
|
||||||
assert.strictEqual(typeof page, 'number');
|
|
||||||
assert.strictEqual(typeof perPage, 'number');
|
|
||||||
assert.strictEqual(typeof callback, 'function');
|
|
||||||
|
|
||||||
database.query(`SELECT ${MAILBOX_FIELDS} FROM mailboxes WHERE domain = ? AND type = ? ORDER BY name LIMIT ${(page-1)*perPage},${perPage}`,
|
|
||||||
[ domain, exports.TYPE_ALIAS ], function (error, results) {
|
|
||||||
if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error));
|
|
||||||
|
|
||||||
results.forEach(function (result) { postProcess(result); });
|
|
||||||
|
|
||||||
callback(null, results);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAlias(name, domain, callback) {
|
function getAlias(name, domain, callback) {
|
||||||
assert.strictEqual(typeof name, 'string');
|
assert.strictEqual(typeof name, 'string');
|
||||||
assert.strictEqual(typeof domain, 'string');
|
assert.strictEqual(typeof domain, 'string');
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ exports = module.exports = {
|
|||||||
updateMailbox: updateMailbox,
|
updateMailbox: updateMailbox,
|
||||||
removeMailbox: removeMailbox,
|
removeMailbox: removeMailbox,
|
||||||
|
|
||||||
listAliases: listAliases,
|
|
||||||
getAliases: getAliases,
|
getAliases: getAliases,
|
||||||
setAliases: setAliases,
|
setAliases: setAliases,
|
||||||
|
|
||||||
@@ -215,22 +214,6 @@ function removeMailbox(req, res, next) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function listAliases(req, res, next) {
|
|
||||||
assert.strictEqual(typeof req.params.domain, 'string');
|
|
||||||
|
|
||||||
var page = typeof req.query.page !== 'undefined' ? parseInt(req.query.page) : 1;
|
|
||||||
if (!page || page < 0) return next(new HttpError(400, 'page query param has to be a positive number'));
|
|
||||||
|
|
||||||
var perPage = typeof req.query.per_page !== 'undefined'? parseInt(req.query.per_page) : 25;
|
|
||||||
if (!perPage || perPage < 0) return next(new HttpError(400, 'per_page query param has to be a positive number'));
|
|
||||||
|
|
||||||
mail.listAliases(req.params.domain, page, perPage, function (error, result) {
|
|
||||||
if (error) return next(BoxError.toHttpError(error));
|
|
||||||
|
|
||||||
next(new HttpSuccess(200, { aliases: result }));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAliases(req, res, next) {
|
function getAliases(req, res, next) {
|
||||||
assert.strictEqual(typeof req.params.domain, 'string');
|
assert.strictEqual(typeof req.params.domain, 'string');
|
||||||
assert.strictEqual(typeof req.params.name, 'string');
|
assert.strictEqual(typeof req.params.name, 'string');
|
||||||
|
|||||||
@@ -265,9 +265,9 @@ function initializeExpressSync() {
|
|||||||
router.post('/api/v1/mail/:domain/mailboxes', token, authorizeAdmin, routes.mail.addMailbox);
|
router.post('/api/v1/mail/:domain/mailboxes', token, authorizeAdmin, routes.mail.addMailbox);
|
||||||
router.post('/api/v1/mail/:domain/mailboxes/:name', token, authorizeAdmin, routes.mail.updateMailbox);
|
router.post('/api/v1/mail/:domain/mailboxes/:name', token, authorizeAdmin, routes.mail.updateMailbox);
|
||||||
router.del ('/api/v1/mail/:domain/mailboxes/:name', token, authorizeAdmin, routes.mail.removeMailbox);
|
router.del ('/api/v1/mail/:domain/mailboxes/:name', token, authorizeAdmin, routes.mail.removeMailbox);
|
||||||
router.get ('/api/v1/mail/:domain/aliases', token, authorizeAdmin, routes.mail.listAliases);
|
router.get ('/api/v1/mail/:domain/mailboxes/:name/aliases', token, authorizeAdmin, routes.mail.getAliases);
|
||||||
router.get ('/api/v1/mail/:domain/aliases/:name', token, authorizeAdmin, routes.mail.getAliases);
|
router.put ('/api/v1/mail/:domain/mailboxes/:name/aliases', token, authorizeAdmin, routes.mail.setAliases);
|
||||||
router.put ('/api/v1/mail/:domain/aliases/:name', token, authorizeAdmin, routes.mail.setAliases);
|
|
||||||
router.get ('/api/v1/mail/:domain/lists', token, authorizeAdmin, routes.mail.getLists);
|
router.get ('/api/v1/mail/:domain/lists', token, authorizeAdmin, routes.mail.getLists);
|
||||||
router.post('/api/v1/mail/:domain/lists', token, authorizeAdmin, routes.mail.addList);
|
router.post('/api/v1/mail/:domain/lists', token, authorizeAdmin, routes.mail.addList);
|
||||||
router.get ('/api/v1/mail/:domain/lists/:name', token, authorizeAdmin, routes.mail.getList);
|
router.get ('/api/v1/mail/:domain/lists/:name', token, authorizeAdmin, routes.mail.getList);
|
||||||
|
|||||||
@@ -1857,18 +1857,6 @@ describe('database', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can list aliases', function (done) {
|
|
||||||
mailboxdb.listAliases(DOMAIN_0.domain, 1, 10, function (error, results) {
|
|
||||||
expect(error).to.be(null);
|
|
||||||
expect(results.length).to.be(2);
|
|
||||||
expect(results[0].name).to.be('help');
|
|
||||||
expect(results[0].aliasName).to.be('support');
|
|
||||||
expect(results[0].aliasDomain).to.be(DOMAIN_0.domain);
|
|
||||||
expect(results[1].name).to.be('support2');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can get by owner id', function (done) {
|
it('can get by owner id', function (done) {
|
||||||
mailboxdb.getByOwnerId('osticket', function (error, results) {
|
mailboxdb.getByOwnerId('osticket', function (error, results) {
|
||||||
expect(error).to.be(null);
|
expect(error).to.be(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user