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]]'));
|
return next(new Error('[[error:cant-delete-other-admins]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
user.delete(uid, next);
|
user.delete(socket.uid, uid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
events.log({
|
events.log({
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var async = require('async'),
|
|||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
|
|
||||||
Topics.delete = function(tid, callback) {
|
Topics.delete = function(tid, uid, callback) {
|
||||||
Topics.getTopicFields(tid, ['cid'], function(err, topicData) {
|
Topics.getTopicFields(tid, ['cid'], function(err, topicData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(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) {
|
Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount', 'viewcount'], function(err, topicData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -103,12 +103,12 @@ module.exports = function(Topics) {
|
|||||||
posts.purge(mainPid, uid, next);
|
posts.purge(mainPid, uid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
Topics.purge(tid, next);
|
Topics.purge(tid, uid, next);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.purge = function(tid, callback) {
|
Topics.purge = function(tid, uid, callback) {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function(next) {
|
function(next) {
|
||||||
db.deleteAll([
|
db.deleteAll([
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ module.exports = function(Topics) {
|
|||||||
return callback(new Error('[[error:topic-already-restored]]'));
|
return callback(new Error('[[error:topic-already-restored]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics[isDelete ? 'delete' : 'restore'](tid, next);
|
Topics[isDelete ? 'delete' : 'restore'](tid, uid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
topicData.deleted = isDelete ? 1 : 0;
|
topicData.deleted = isDelete ? 1 : 0;
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ var async = require('async'),
|
|||||||
|
|
||||||
module.exports = function(User) {
|
module.exports = function(User) {
|
||||||
|
|
||||||
User.delete = function(uid, callback) {
|
User.delete = function(callerUid, uid, callback) {
|
||||||
if (!parseInt(uid, 10)) {
|
if (!parseInt(uid, 10)) {
|
||||||
return callback(new Error('[[error:invalid-uid]]'));
|
return callback(new Error('[[error:invalid-uid]]'));
|
||||||
}
|
}
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
deletePosts(uid, next);
|
deletePosts(callerUid, uid, next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
deleteTopics(uid, next);
|
deleteTopics(callerUid, uid, next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
User.deleteAccount(uid, next);
|
User.deleteAccount(uid, next);
|
||||||
@@ -28,17 +28,19 @@ module.exports = function(User) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function deletePosts(uid, callback) {
|
function deletePosts(callerUid, uid, callback) {
|
||||||
deleteSortedSetElements('uid:' + uid + ':posts', posts.purge, 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) {
|
function deleteTopics(callerUid, uid, callback) {
|
||||||
deleteSortedSetElements('uid:' + uid + ':topics', topics.purge, callback);
|
batch.processSortedSet('uid:' + uid + ':topics', function(ids, next) {
|
||||||
}
|
async.eachSeries(ids, function(tid, next) {
|
||||||
|
topics.purge(tid, callerUid, next);
|
||||||
function deleteSortedSetElements(set, deleteMethod, callback) {
|
}, next);
|
||||||
batch.processSortedSet(set, function(ids, next) {
|
|
||||||
async.eachLimit(ids, 10, deleteMethod, next);
|
|
||||||
}, {alwaysStartAt: 0}, callback);
|
}, {alwaysStartAt: 0}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +147,7 @@ module.exports = function(User) {
|
|||||||
return pid && array.indexOf(pid) === index;
|
return pid && array.indexOf(pid) === index;
|
||||||
});
|
});
|
||||||
|
|
||||||
async.eachLimit(pids, 50, function(pid, next) {
|
async.eachSeries(pids, function(pid, next) {
|
||||||
favourites.unvote(pid, uid, next);
|
favourites.unvote(pid, uid, next);
|
||||||
}, next);
|
}, next);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,14 +173,14 @@ describe('Topic\'s', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should delete the topic', function(done) {
|
it('should delete the topic', function(done) {
|
||||||
topics.delete(newTopic.tid, function(err) {
|
topics.delete(newTopic.tid, 1, function(err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should purge the topic', function(done) {
|
it('should purge the topic', function(done) {
|
||||||
topics.purge(newTopic.tid, function(err) {
|
topics.purge(newTopic.tid, 1, function(err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ describe('User', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should delete a user account', function(done) {
|
it('should delete a user account', function(done) {
|
||||||
User.delete(uid, function(err) {
|
User.delete(1, uid, function(err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
User.existsBySlug('usertodelete', function(err, exists) {
|
User.existsBySlug('usertodelete', function(err, exists) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user