notifications: add back app down and app oom mails
This commit is contained in:
19
src/users.js
19
src/users.js
@@ -90,6 +90,7 @@ const appPasswords = require('./apppasswords.js'),
|
||||
mail = require('./mail.js'),
|
||||
mailer = require('./mailer.js'),
|
||||
mysql = require('mysql'),
|
||||
notifications = require('./notifications'),
|
||||
qrcode = require('qrcode'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('./settings.js'),
|
||||
@@ -213,6 +214,7 @@ async function add(email, data, auditSource) {
|
||||
let fallbackEmail = data.fallbackEmail || '';
|
||||
const source = data.source || ''; // empty is local user
|
||||
const role = data.role || exports.ROLE_USER;
|
||||
const notificationConfig = 'notificationConfig' in data ? data.notificationConfig : null;
|
||||
|
||||
let error;
|
||||
|
||||
@@ -264,11 +266,12 @@ async function add(email, data, auditSource) {
|
||||
source,
|
||||
role,
|
||||
avatar: constants.AVATAR_NONE,
|
||||
language: ''
|
||||
language: '',
|
||||
notificationConfigJson: notificationConfig ? JSON.stringify(notificationConfig) : null
|
||||
};
|
||||
|
||||
const query = 'INSERT INTO users (id, username, password, email, fallbackEmail, salt, resetToken, inviteToken, displayName, source, role, avatar, language) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
const args = [ user.id, user.username, user.password, user.email, user.fallbackEmail, user.salt, user.resetToken, user.inviteToken, user.displayName, user.source, user.role, user.avatar, user.language ];
|
||||
const query = 'INSERT INTO users (id, username, password, email, fallbackEmail, salt, resetToken, inviteToken, displayName, source, role, avatar, language, notificationConfigJson) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
const args = [ user.id, user.username, user.password, user.email, user.fallbackEmail, user.salt, user.resetToken, user.inviteToken, user.displayName, user.source, user.role, user.avatar, user.language, user.notificationConfigJson ];
|
||||
|
||||
[error] = await safe(database.query(query, args));
|
||||
if (error && error.code === 'ER_DUP_ENTRY' && error.sqlMessage.indexOf('users_email') !== -1) throw new BoxError(BoxError.ALREADY_EXISTS, 'email already exists');
|
||||
@@ -631,8 +634,8 @@ async function update(user, data, auditSource) {
|
||||
if (k === 'twoFactorAuthenticationEnabled' || k === 'active') {
|
||||
fields.push(k + ' = ?');
|
||||
args.push(data[k] ? 1 : 0);
|
||||
} else if (k === 'loginLocations') {
|
||||
fields.push('loginLocationsJson = ?');
|
||||
} else if (k === 'loginLocations' || k === 'notificationConfig') {
|
||||
fields.push(`${k}Json = ?`);
|
||||
args.push(JSON.stringify(data[k]));
|
||||
} else {
|
||||
fields.push(k + ' = ?');
|
||||
@@ -819,7 +822,8 @@ async function createOwner(email, username, password, displayName, auditSource)
|
||||
const activated = await isActivated();
|
||||
if (activated) throw new BoxError(BoxError.ALREADY_EXISTS, 'Cloudron already activated');
|
||||
|
||||
return await add(email, { username, password, fallbackEmail: '', displayName, role: exports.ROLE_OWNER }, auditSource);
|
||||
const notificationConfig = [notifications.TYPE_BACKUP_FAILED, notifications.TYPE_CERTIFICATE_RENEWAL_FAILED, notifications.TYPE_MANUAL_APP_UPDATE_NEEDED, notifications.TYPE_APP_DOWN ];
|
||||
return await add(email, { username, password, fallbackEmail: '', displayName, role: exports.ROLE_OWNER, notificationConfig }, auditSource);
|
||||
}
|
||||
|
||||
async function getInviteLink(user, auditSource) {
|
||||
@@ -980,8 +984,7 @@ async function setNotificationConfig(user, notificationConfig, auditSource) {
|
||||
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');
|
||||
await update(user, { notificationConfig }, auditSource);
|
||||
}
|
||||
|
||||
async function resetSources() {
|
||||
|
||||
Reference in New Issue
Block a user