Decouple mailbox deletion from user delete

This commit is contained in:
Girish Ramakrishnan
2018-04-02 09:45:46 -07:00
parent 602291895c
commit 255a5a12a5

View File

@@ -36,7 +36,6 @@ 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'),
@@ -268,19 +267,15 @@ 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'));
mailboxdb.delByOwnerId(userId, function (error) {
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));
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));
eventlog.add(eventlog.ACTION_USER_REMOVE, auditSource, { userId: userId, user: removePrivateFields(user) });
eventlog.add(eventlog.ACTION_USER_REMOVE, auditSource, { userId: userId, user: removePrivateFields(user) });
callback();
callback();
mailer.userRemoved(user);
});
mailer.userRemoved(user);
});
});
}