Work in progress on refactoring all mail sending to use the message sender an sender workers.

Some fixes related to subscriptions and password reset.
This commit is contained in:
Tomas Bures 2019-06-30 10:47:09 +02:00
parent 4e9f6bd57b
commit 450b930cc5
8 changed files with 95 additions and 76 deletions

View file

@ -125,8 +125,6 @@ async function listDTAjax(context, params) {
async function _validateAndPreprocess(tx, entity, isCreate, isOwnAccount) {
enforce(await tools.validateEmail(entity.email) === 0, 'Invalid email');
await namespaceHelpers.validateEntity(tx, entity);
const otherUserWithSameEmailQuery = tx('users').where('email', entity.email);
if (entity.id) {
otherUserWithSameEmailQuery.andWhereNot('id', entity.id);
@ -138,6 +136,9 @@ async function _validateAndPreprocess(tx, entity, isCreate, isOwnAccount) {
if (!isOwnAccount) {
await namespaceHelpers.validateEntity(tx, entity);
enforce(entity.role in config.roles.global, 'Unknown role');
const otherUserWithSameUsernameQuery = tx('users').where('username', entity.username);
if (!isCreate) {
otherUserWithSameUsernameQuery.andWhereNot('id', entity.id);
@ -148,8 +149,6 @@ async function _validateAndPreprocess(tx, entity, isCreate, isOwnAccount) {
}
}
enforce(entity.role in config.roles.global, 'Unknown role');
enforce(!isCreate || entity.password.length > 0, 'Password not set');
if (entity.password) {