mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
additional tests and proper handling for purged flag targets, #5232
This commit is contained in:
60
src/flags.js
60
src/flags.js
@@ -202,31 +202,6 @@ Flags.validate = function (payload, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
Flags.getTarget = function (type, id, uid, callback) {
|
||||
switch (type) {
|
||||
case 'post':
|
||||
async.waterfall([
|
||||
async.apply(posts.getPostsByPids, [id], uid),
|
||||
function (posts, next) {
|
||||
topics.addPostData(posts, uid, next);
|
||||
}
|
||||
], function (err, posts) {
|
||||
callback(err, posts[0]);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
user.getUsersData([id], function (err, users) {
|
||||
callback(err, users ? users[0] : undefined);
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
callback(new Error('[[error:invalid-data]]'));
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
Flags.getNotes = function (flagId, callback) {
|
||||
async.waterfall([
|
||||
async.apply(db.getSortedSetRevRangeWithScores.bind(db), 'flag:' + flagId + ':notes', 0, -1),
|
||||
@@ -348,6 +323,41 @@ Flags.exists = function (type, id, uid, callback) {
|
||||
db.isSortedSetMember('flags:hash', [type, id, uid].join(':'), callback);
|
||||
};
|
||||
|
||||
Flags.getTarget = function (type, id, uid, callback) {
|
||||
async.waterfall([
|
||||
async.apply(Flags.targetExists, type, id),
|
||||
function (exists, next) {
|
||||
if (exists) {
|
||||
switch (type) {
|
||||
case 'post':
|
||||
async.waterfall([
|
||||
async.apply(posts.getPostsByPids, [id], uid),
|
||||
function (posts, next) {
|
||||
topics.addPostData(posts, uid, next);
|
||||
}
|
||||
], function (err, posts) {
|
||||
next(err, posts[0]);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
user.getUsersData([id], function (err, users) {
|
||||
next(err, users ? users[0] : undefined);
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
next(new Error('[[error:invalid-data]]'));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Target used to exist (otherwise flag creation'd fail), but no longer
|
||||
next(null, {});
|
||||
}
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Flags.targetExists = function (type, id, callback) {
|
||||
switch (type) {
|
||||
case 'post':
|
||||
|
||||
Reference in New Issue
Block a user