mail: quota support
This commit is contained in:
@@ -177,6 +177,11 @@ async function addMailbox(req, res, next) {
|
||||
if (typeof req.body.ownerType !== 'string') return next(new HttpError(400, 'ownerType must be a string'));
|
||||
if (typeof req.body.active !== 'boolean') return next(new HttpError(400, 'active must be a boolean'));
|
||||
|
||||
if (!Number.isInteger(req.body.storageQuota)) return next(new HttpError(400, 'storageQuota must be an integer'));
|
||||
if (req.body.storageQuota < 0) return next(new HttpError(400, 'storageQuota must be a postive integer or zero'));
|
||||
if (!Number.isInteger(req.body.messagesQuota)) return next(new HttpError(400, 'messagesQuota must be an integer'));
|
||||
if (req.body.messagesQuota < 0) return next(new HttpError(400, 'messagesQuota must be a positive integer or zero'));
|
||||
|
||||
const [error] = await safe(mail.addMailbox(req.body.name, req.params.domain, req.body, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
@@ -192,6 +197,11 @@ async function updateMailbox(req, res, next) {
|
||||
if (typeof req.body.active !== 'boolean') return next(new HttpError(400, 'active must be a boolean'));
|
||||
if (typeof req.body.enablePop3 !== 'boolean') return next(new HttpError(400, 'enablePop3 must be a boolean'));
|
||||
|
||||
if (!Number.isInteger(req.body.storageQuota)) return next(new HttpError(400, 'storageQuota must be an integer'));
|
||||
if (req.body.storageQuota < 0) return next(new HttpError(400, 'storageQuota must be a postive integer or zero'));
|
||||
if (!Number.isInteger(req.body.messagesQuota)) return next(new HttpError(400, 'messagesQuota must be an integer'));
|
||||
if (req.body.messagesQuota < 0) return next(new HttpError(400, 'messagesQuota must be a positive integer or zero'));
|
||||
|
||||
const [error] = await safe(mail.updateMailbox(req.params.name, req.params.domain, req.body, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
|
||||
@@ -422,7 +422,7 @@ describe('Mail API', function () {
|
||||
|
||||
it('add succeeds', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`)
|
||||
.send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true })
|
||||
.send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, storageQuota: 10, messagesQuota: 20 })
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(201);
|
||||
@@ -430,7 +430,7 @@ describe('Mail API', function () {
|
||||
|
||||
it('cannot add again', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`)
|
||||
.send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true })
|
||||
.send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, storageQuota: 10, messagesQuota: 20 })
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
|
||||
@@ -457,6 +457,8 @@ describe('Mail API', function () {
|
||||
expect(response.body.mailbox.aliasName).to.equal(null);
|
||||
expect(response.body.mailbox.aliasDomain).to.equal(null);
|
||||
expect(response.body.mailbox.domain).to.equal(dashboardDomain);
|
||||
expect(response.body.mailbox.storageQuota).to.equal(10);
|
||||
expect(response.body.mailbox.messagesQuota).to.equal(20);
|
||||
});
|
||||
|
||||
it('listing succeeds', async function () {
|
||||
@@ -471,6 +473,8 @@ describe('Mail API', function () {
|
||||
expect(response.body.mailboxes[0].ownerType).to.equal('user');
|
||||
expect(response.body.mailboxes[0].aliases).to.eql([]);
|
||||
expect(response.body.mailboxes[0].domain).to.equal(dashboardDomain);
|
||||
expect(response.body.mailboxes[0].storageQuota).to.equal(10);
|
||||
expect(response.body.mailboxes[0].messagesQuota).to.equal(20);
|
||||
});
|
||||
|
||||
it('disable fails even if not exist', async function () {
|
||||
@@ -505,7 +509,7 @@ describe('Mail API', function () {
|
||||
|
||||
it('add the mailbox', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`)
|
||||
.send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true })
|
||||
.send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, storageQuota: 10, messagesQuota: 20 })
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(201);
|
||||
|
||||
Reference in New Issue
Block a user