mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 08:25:46 +01:00
change user delete so it returns quickly
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var validator = require('validator');
|
var validator = require('validator');
|
||||||
|
var winston = require('winston');
|
||||||
|
|
||||||
var db = require('../../database');
|
var db = require('../../database');
|
||||||
var groups = require('../../groups');
|
var groups = require('../../groups');
|
||||||
@@ -146,17 +147,20 @@ function deleteUsers(socket, uids, method, callback) {
|
|||||||
if (!Array.isArray(uids)) {
|
if (!Array.isArray(uids)) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
groups.isMembers(uids, 'administrators', next);
|
||||||
|
},
|
||||||
|
function (isMembers, next) {
|
||||||
|
if (isMembers.includes(true)) {
|
||||||
|
return callback(new Error('[[error:cant-delete-other-admins]]'));
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
|
||||||
async.each(uids, function (uid, next) {
|
async.each(uids, function (uid, next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
user.isAdministrator(uid, next);
|
|
||||||
},
|
|
||||||
function (isAdmin, next) {
|
|
||||||
if (isAdmin) {
|
|
||||||
return next(new Error('[[error:cant-delete-other-admins]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
method(uid, next);
|
method(uid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -176,7 +180,13 @@ function deleteUsers(socket, uids, method, callback) {
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
], next);
|
], next);
|
||||||
}, callback);
|
}, next);
|
||||||
|
},
|
||||||
|
], function (err) {
|
||||||
|
if (err) {
|
||||||
|
winston.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
User.search = function (socket, data, callback) {
|
User.search = function (socket, data, callback) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
var db = require('../database');
|
|
||||||
var topics = require('../topics');
|
var topics = require('../topics');
|
||||||
var posts = require('../posts');
|
var posts = require('../posts');
|
||||||
var websockets = require('./index');
|
var websockets = require('./index');
|
||||||
@@ -73,22 +72,7 @@ SocketTopics.postcount = function (socket, tid, callback) {
|
|||||||
return next(new Error('[[no-privileges]]'));
|
return next(new Error('[[no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel({
|
topics.getTopicField(tid, 'postcount', next);
|
||||||
replyCount: function (next) {
|
|
||||||
db.sortedSetCard('tid:' + tid + ':posts', next);
|
|
||||||
},
|
|
||||||
topicData: function (next) {
|
|
||||||
topics.getTopicFields(tid, ['mainPid', 'postcount'], next);
|
|
||||||
},
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
if (results.topicData.mainPid && parseInt(results.topicData.postcount, 10) === parseInt(results.replyCount, 10) + 1) {
|
|
||||||
return next(null, results.topicData.postcount);
|
|
||||||
}
|
|
||||||
var postcount = results.replyCount + (results.topicData.mainPid ? 1 : 0);
|
|
||||||
topics.setTopicField(tid, 'postcount', postcount);
|
|
||||||
next(null, postcount);
|
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,12 +15,20 @@ var batch = require('../batch');
|
|||||||
var file = require('../file');
|
var file = require('../file');
|
||||||
|
|
||||||
module.exports = function (User) {
|
module.exports = function (User) {
|
||||||
|
var deletesInProgress = {};
|
||||||
|
|
||||||
User.delete = function (callerUid, uid, callback) {
|
User.delete = function (callerUid, uid, callback) {
|
||||||
if (!parseInt(uid, 10)) {
|
if (!parseInt(uid, 10)) {
|
||||||
return callback(new Error('[[error:invalid-uid]]'));
|
return setImmediate(callback, new Error('[[error:invalid-uid]]'));
|
||||||
}
|
}
|
||||||
|
if (deletesInProgress[uid]) {
|
||||||
|
return setImmediate(callback);
|
||||||
|
}
|
||||||
|
deletesInProgress[uid] = 'user.delete';
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
removeFromSortedSets(uid, next);
|
||||||
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
deletePosts(callerUid, uid, next);
|
deletePosts(callerUid, uid, next);
|
||||||
},
|
},
|
||||||
@@ -67,14 +75,38 @@ module.exports = function (User) {
|
|||||||
}, { alwaysStartAt: 0 }, callback);
|
}, { alwaysStartAt: 0 }, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeFromSortedSets(uid, callback) {
|
||||||
|
db.sortedSetsRemove([
|
||||||
|
'users:joindate',
|
||||||
|
'users:postcount',
|
||||||
|
'users:reputation',
|
||||||
|
'users:banned',
|
||||||
|
'users:banned:expire',
|
||||||
|
'users:flags',
|
||||||
|
'users:online',
|
||||||
|
'users:notvalidated',
|
||||||
|
'digest:day:uids',
|
||||||
|
'digest:week:uids',
|
||||||
|
'digest:month:uids',
|
||||||
|
], uid, callback);
|
||||||
|
}
|
||||||
|
|
||||||
User.deleteAccount = function (uid, callback) {
|
User.deleteAccount = function (uid, callback) {
|
||||||
|
if (deletesInProgress[uid] === 'user.deleteAccount') {
|
||||||
|
return setImmediate(callback);
|
||||||
|
}
|
||||||
|
deletesInProgress[uid] = 'user.deleteAccount';
|
||||||
var userData;
|
var userData;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
removeFromSortedSets(uid, next);
|
||||||
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
db.getObject('user:' + uid, next);
|
db.getObject('user:' + uid, next);
|
||||||
},
|
},
|
||||||
function (_userData, next) {
|
function (_userData, next) {
|
||||||
if (!_userData || !_userData.username) {
|
if (!_userData || !_userData.username) {
|
||||||
|
delete deletesInProgress[uid];
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
userData = _userData;
|
userData = _userData;
|
||||||
@@ -113,20 +145,6 @@ module.exports = function (User) {
|
|||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function (next) {
|
|
||||||
db.sortedSetsRemove([
|
|
||||||
'users:joindate',
|
|
||||||
'users:postcount',
|
|
||||||
'users:reputation',
|
|
||||||
'users:banned',
|
|
||||||
'users:banned:expire',
|
|
||||||
'users:online',
|
|
||||||
'users:notvalidated',
|
|
||||||
'digest:day:uids',
|
|
||||||
'digest:week:uids',
|
|
||||||
'digest:month:uids',
|
|
||||||
], uid, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
function (next) {
|
||||||
db.decrObjectField('global', 'userCount', next);
|
db.decrObjectField('global', 'userCount', next);
|
||||||
},
|
},
|
||||||
@@ -164,7 +182,10 @@ module.exports = function (User) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
db.deleteAll(['followers:' + uid, 'following:' + uid, 'user:' + uid], next);
|
db.deleteAll(['followers:' + uid, 'following:' + uid, 'user:' + uid], next);
|
||||||
},
|
},
|
||||||
], callback);
|
], function (err) {
|
||||||
|
delete deletesInProgress[uid];
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function deleteVotes(uid, callback) {
|
function deleteVotes(uid, callback) {
|
||||||
|
|||||||
@@ -198,11 +198,13 @@ describe('socket.io', function () {
|
|||||||
it('should delete users', function (done) {
|
it('should delete users', function (done) {
|
||||||
socketAdmin.user.deleteUsers({ uid: adminUid }, [uid], function (err) {
|
socketAdmin.user.deleteUsers({ uid: adminUid }, [uid], function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
setTimeout(function () {
|
||||||
groups.isMember(uid, 'registered-users', function (err, isMember) {
|
groups.isMember(uid, 'registered-users', function (err, isMember) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(!isMember);
|
assert(!isMember);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
}, 500);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user