move mailbox cleanup code from userdb to user businesslogic

This commit is contained in:
Johannes Zellner
2018-01-26 12:26:03 +01:00
parent 40f73f6c4b
commit ccdf926976
2 changed files with 10 additions and 6 deletions

View File

@@ -34,6 +34,7 @@ var assert = require('assert'),
groups = require('./groups.js'),
GroupError = groups.GroupError,
hat = require('hat'),
mailboxdb = require('./mailboxdb.js'),
mailer = require('./mailer.js'),
safe = require('safetydance'),
tokendb = require('./tokendb.js'),
@@ -261,15 +262,19 @@ function removeUser(userId, auditSource, callback) {
if (config.isDemo() && user.username === constants.DEMO_USERNAME) return callback(new UserError(UserError.BAD_FIELD, 'Not allowed in demo mode'));
userdb.del(userId, function (error) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND));
mailboxdb.delByOwnerId(userId, function (error) {
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
eventlog.add(eventlog.ACTION_USER_REMOVE, auditSource, { userId: userId });
userdb.del(userId, function (error) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND));
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
callback();
eventlog.add(eventlog.ACTION_USER_REMOVE, auditSource, { userId: userId });
mailer.userRemoved(user);
callback();
mailer.userRemoved(user);
});
});
});
}