Skip to content

Node.js based forum software built for the modern web

closes #4354

barisusakli2869b3c0685b
diff --git a/src/socket.io/admin/user.js b/src/socket.io/admin/user.js
index c46e01a99c..2633425dc4 100644
--- a/src/socket.io/admin/user.js
+++ b/src/socket.io/admin/user.js
@@ -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({
diff --git a/src/topics/delete.js b/src/topics/delete.js
index 8f2794fa17..97d617d878 100644
--- a/src/topics/delete.js
+++ b/src/topics/delete.js
@@ -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([
diff --git a/src/topics/tools.js b/src/topics/tools.js
index 3deea91b46..1cb02ae514 100644
--- a/src/topics/tools.js
+++ b/src/topics/tools.js
@@ -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;
diff --git a/src/user/delete.js b/src/user/delete.js
index 921bb62d32..3ab5176725 100644
--- a/src/user/delete.js
+++ b/src/user/delete.js
@@ -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 deleteTopics(uid, callback) {
- deleteSortedSetElements('uid:' + uid + ':topics', topics.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 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);
}
diff --git a/tests/topics.js b/tests/topics.js
index bf30147573..fe00db7646 100644
--- a/tests/topics.js
+++ b/tests/topics.js
@@ -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();
});
diff --git a/tests/user.js b/tests/user.js
index f9423a62aa..570b002808 100644
--- a/tests/user.js
+++ b/tests/user.js
@@ -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);