mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 08:55:47 +01:00
closes #4354
This commit is contained in:
@@ -156,7 +156,7 @@ User.deleteUsers = function(socket, uids, callback) {
|
||||
return next(new Error('[[error:cant-delete-other-admins]]'));
|
||||
}
|
||||
|
||||
user.delete(uid, next);
|
||||
user.delete(socket.uid, uid, next);
|
||||
},
|
||||
function (next) {
|
||||
events.log({
|
||||
|
||||
@@ -11,7 +11,7 @@ var async = require('async'),
|
||||
|
||||
module.exports = function(Topics) {
|
||||
|
||||
Topics.delete = function(tid, callback) {
|
||||
Topics.delete = function(tid, uid, callback) {
|
||||
Topics.getTopicFields(tid, ['cid'], function(err, topicData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -38,7 +38,7 @@ module.exports = function(Topics) {
|
||||
});
|
||||
};
|
||||
|
||||
Topics.restore = function(tid, callback) {
|
||||
Topics.restore = function(tid, uid, callback) {
|
||||
Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount', 'viewcount'], function(err, topicData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -103,12 +103,12 @@ module.exports = function(Topics) {
|
||||
posts.purge(mainPid, uid, next);
|
||||
},
|
||||
function (next) {
|
||||
Topics.purge(tid, next);
|
||||
Topics.purge(tid, uid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Topics.purge = function(tid, callback) {
|
||||
Topics.purge = function(tid, uid, callback) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.deleteAll([
|
||||
|
||||
@@ -49,7 +49,7 @@ module.exports = function(Topics) {
|
||||
return callback(new Error('[[error:topic-already-restored]]'));
|
||||
}
|
||||
|
||||
Topics[isDelete ? 'delete' : 'restore'](tid, next);
|
||||
Topics[isDelete ? 'delete' : 'restore'](tid, uid, next);
|
||||
},
|
||||
function (next) {
|
||||
topicData.deleted = isDelete ? 1 : 0;
|
||||
|
||||
@@ -11,16 +11,16 @@ var async = require('async'),
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
User.delete = function(uid, callback) {
|
||||
User.delete = function(callerUid, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback(new Error('[[error:invalid-uid]]'));
|
||||
}
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
deletePosts(uid, next);
|
||||
deletePosts(callerUid, uid, next);
|
||||
},
|
||||
function(next) {
|
||||
deleteTopics(uid, next);
|
||||
deleteTopics(callerUid, uid, next);
|
||||
},
|
||||
function(next) {
|
||||
User.deleteAccount(uid, next);
|
||||
@@ -28,17 +28,19 @@ module.exports = function(User) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
function deletePosts(uid, callback) {
|
||||
deleteSortedSetElements('uid:' + uid + ':posts', posts.purge, callback);
|
||||
function deletePosts(callerUid, uid, callback) {
|
||||
batch.processSortedSet('uid:' + uid + ':posts', function(ids, next) {
|
||||
async.eachSeries(ids, function(pid, netx) {
|
||||
posts.purge(pid, callerUid, next);
|
||||
}, next);
|
||||
}, {alwaysStartAt: 0}, callback);
|
||||
}
|
||||
|
||||
function deleteTopics(uid, callback) {
|
||||
deleteSortedSetElements('uid:' + uid + ':topics', topics.purge, callback);
|
||||
}
|
||||
|
||||
function deleteSortedSetElements(set, deleteMethod, callback) {
|
||||
batch.processSortedSet(set, function(ids, next) {
|
||||
async.eachLimit(ids, 10, deleteMethod, next);
|
||||
function deleteTopics(callerUid, uid, callback) {
|
||||
batch.processSortedSet('uid:' + uid + ':topics', function(ids, next) {
|
||||
async.eachSeries(ids, function(tid, next) {
|
||||
topics.purge(tid, callerUid, next);
|
||||
}, next);
|
||||
}, {alwaysStartAt: 0}, callback);
|
||||
}
|
||||
|
||||
@@ -145,7 +147,7 @@ module.exports = function(User) {
|
||||
return pid && array.indexOf(pid) === index;
|
||||
});
|
||||
|
||||
async.eachLimit(pids, 50, function(pid, next) {
|
||||
async.eachSeries(pids, function(pid, next) {
|
||||
favourites.unvote(pid, uid, next);
|
||||
}, next);
|
||||
}
|
||||
|
||||
@@ -173,14 +173,14 @@ describe('Topic\'s', function() {
|
||||
});
|
||||
|
||||
it('should delete the topic', function(done) {
|
||||
topics.delete(newTopic.tid, function(err) {
|
||||
topics.delete(newTopic.tid, 1, function(err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should purge the topic', function(done) {
|
||||
topics.purge(newTopic.tid, function(err) {
|
||||
topics.purge(newTopic.tid, 1, function(err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -184,7 +184,7 @@ describe('User', function() {
|
||||
});
|
||||
|
||||
it('should delete a user account', function(done) {
|
||||
User.delete(uid, function(err) {
|
||||
User.delete(1, uid, function(err) {
|
||||
assert.ifError(err);
|
||||
User.existsBySlug('usertodelete', function(err, exists) {
|
||||
assert.ifError(err);
|
||||
|
||||
Reference in New Issue
Block a user