notifications: per user email prefs
This commit is contained in:
@@ -15,6 +15,7 @@ exports = module.exports = {
|
||||
setTwoFactorAuthenticationSecret,
|
||||
enableTwoFactorAuthentication,
|
||||
disableTwoFactorAuthentication,
|
||||
setNotificationConfig
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
@@ -70,6 +71,7 @@ async function get(req, res, next) {
|
||||
source: req.user.source,
|
||||
hasBackgroundImage: !!backgroundImage,
|
||||
language: req.user.language,
|
||||
notificationConfig: req.user.notificationConfig,
|
||||
avatarUrl: `https://${dashboardFqdn}/api/v1/profile/avatar/${req.user.id}`,
|
||||
avatarType: avatarType.toString() // this is a Buffer
|
||||
}));
|
||||
@@ -245,3 +247,16 @@ async function disableTwoFactorAuthentication(req, res, next) {
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
}
|
||||
|
||||
async function setNotificationConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
if (!Array.isArray(req.body.notificationConfig)) return next(new HttpError(400, 'notificationConfig must be an array of strings'));
|
||||
if (req.body.notificationConfig.some(k => typeof k !== 'string')) return next(new HttpError(400, 'notificationConfig must be an array of strings'));
|
||||
|
||||
const [error] = await safe(users.setNotificationConfig(req.user, req.body.notificationConfig, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user