notifications: per user email prefs

This commit is contained in:
Girish Ramakrishnan
2024-12-11 18:24:20 +01:00
parent 746e694d7e
commit 6004cd17bf
12 changed files with 130 additions and 27 deletions
+15
View File
@@ -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, {}));
}