notifications: per user email prefs
This commit is contained in:
18
src/users.js
18
src/users.js
@@ -51,6 +51,8 @@ exports = module.exports = {
|
||||
getBackgroundImage,
|
||||
setBackgroundImage,
|
||||
|
||||
setNotificationConfig,
|
||||
|
||||
resetSources,
|
||||
|
||||
parseDisplayName,
|
||||
@@ -70,7 +72,7 @@ const ORDERED_ROLES = [ exports.ROLE_USER, exports.ROLE_USER_MANAGER, exports.RO
|
||||
|
||||
// the avatar and backgroundImage fields are special and not added here to reduce response sizes
|
||||
const USERS_FIELDS = [ 'id', 'username', 'email', 'fallbackEmail', 'password', 'salt', 'creationTime', 'inviteToken', 'resetToken', 'displayName', 'language',
|
||||
'twoFactorAuthenticationEnabled', 'twoFactorAuthenticationSecret', 'active', 'source', 'role', 'resetTokenCreationTime', 'loginLocationsJson' ].join(',');
|
||||
'twoFactorAuthenticationEnabled', 'twoFactorAuthenticationSecret', 'active', 'source', 'role', 'resetTokenCreationTime', 'loginLocationsJson', 'notificationConfigJson' ].join(',');
|
||||
|
||||
const DEFAULT_GHOST_LIFETIME = 6 * 60 * 60 * 1000; // 6 hours
|
||||
|
||||
@@ -120,6 +122,9 @@ function postProcess(result) {
|
||||
if (!Array.isArray(result.loginLocations)) result.loginLocations = [];
|
||||
delete result.loginLocationsJson;
|
||||
|
||||
result.notificationConfig = safe.JSON.parse(result.notificationConfigJson) || [];
|
||||
delete result.notificationConfigJson;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -185,7 +190,7 @@ function validatePassword(password) {
|
||||
|
||||
// remove all fields that should never be sent out via REST API
|
||||
function removePrivateFields(user) {
|
||||
const result = _.pick(user, 'id', 'username', 'email', 'fallbackEmail', 'displayName', 'groupIds', 'active', 'source', 'role', 'createdAt', 'twoFactorAuthenticationEnabled');
|
||||
const result = _.pick(user, 'id', 'username', 'email', 'fallbackEmail', 'displayName', 'groupIds', 'active', 'source', 'role', 'createdAt', 'twoFactorAuthenticationEnabled', 'notificationConfig');
|
||||
|
||||
// invite status indicator
|
||||
result.inviteAccepted = !user.inviteToken;
|
||||
@@ -970,6 +975,15 @@ async function setBackgroundImage(id, backgroundImage) {
|
||||
if (result.length === 0) throw new BoxError(BoxError.NOT_FOUND, 'User not found');
|
||||
}
|
||||
|
||||
async function setNotificationConfig(user, notificationConfig, auditSource) {
|
||||
assert.strictEqual(typeof user, 'object');
|
||||
assert(Array.isArray(notificationConfig));
|
||||
assert(auditSource && typeof auditSource === 'object');
|
||||
|
||||
const result = await database.query('UPDATE users SET notificationConfigJson=? WHERE id = ?', [ JSON.stringify(notificationConfig), user.id ]);
|
||||
if (result.length === 0) throw new BoxError(BoxError.NOT_FOUND, 'User not found');
|
||||
}
|
||||
|
||||
async function resetSources() {
|
||||
await database.query('UPDATE users SET source = ?', [ '' ]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user