mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
add tests for blocked users teaser/unread
This commit is contained in:
@@ -133,17 +133,23 @@ module.exports = function (Topics) {
|
|||||||
const postsPerIteration = 5;
|
const postsPerIteration = 5;
|
||||||
let start = 0;
|
let start = 0;
|
||||||
let stop = start + postsPerIteration - 1;
|
let stop = start + postsPerIteration - 1;
|
||||||
|
let checkedAllReplies = false;
|
||||||
async.doWhilst(function (next) {
|
async.doWhilst(function (next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
db.getSortedSetRevRange('tid:' + postData.tid + ':posts', start, stop, next);
|
db.getSortedSetRevRange('tid:' + postData.tid + ':posts', start, stop, next);
|
||||||
},
|
},
|
||||||
function (pids, next) {
|
function (pids, next) {
|
||||||
if (!pids.length) {
|
if (pids.length) {
|
||||||
return callback(null, null);
|
return next(null, pids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkedAllReplies = true;
|
||||||
|
Topics.getTopicField(postData.tid, 'mainPid', function (err, mainPid) {
|
||||||
|
next(err, [mainPid]);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function (pids, next) {
|
||||||
posts.getPostsFields(pids, ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
|
posts.getPostsFields(pids, ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
|
||||||
},
|
},
|
||||||
function (prevPosts, next) {
|
function (prevPosts, next) {
|
||||||
@@ -158,7 +164,7 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
], next);
|
], next);
|
||||||
}, function () {
|
}, function () {
|
||||||
return isBlocked && prevPost && prevPost.pid;
|
return isBlocked && prevPost && prevPost.pid && !checkedAllReplies;
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
callback(err, prevPost);
|
callback(err, prevPost);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -213,6 +213,7 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (topic && topic.cid && cidMatch(topic.cid) && !blockedUids.includes(parseInt(topic.uid, 10))) {
|
if (topic && topic.cid && cidMatch(topic.cid) && !blockedUids.includes(parseInt(topic.uid, 10))) {
|
||||||
|
topic.tid = parseInt(topic.tid, 10);
|
||||||
if ((results.isTopicsFollowed[index] || !results.ignoredCids.includes(String(topic.cid)))) {
|
if ((results.isTopicsFollowed[index] || !results.ignoredCids.includes(String(topic.cid)))) {
|
||||||
counts[''] += 1;
|
counts[''] += 1;
|
||||||
tidsByFilter[''].push(topic.tid);
|
tidsByFilter[''].push(topic.tid);
|
||||||
|
|||||||
@@ -1350,6 +1350,34 @@ describe('Topic\'s', function () {
|
|||||||
},
|
},
|
||||||
], done);
|
], done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not return topic as unread if new post is from blocked user', function (done) {
|
||||||
|
var blockedUid;
|
||||||
|
var topic;
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
topics.post({ uid: adminUid, title: 'will not get as unread', content: 'not unread', cid: categoryObj.cid }, next);
|
||||||
|
},
|
||||||
|
function (result, next) {
|
||||||
|
topic = result.topicData;
|
||||||
|
User.create({ username: 'blockedunread' }, next);
|
||||||
|
},
|
||||||
|
function (uid, next) {
|
||||||
|
blockedUid = uid;
|
||||||
|
User.blocks.add(uid, adminUid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
topics.reply({ uid: blockedUid, content: 'post from blocked user', tid: topic.tid }, next);
|
||||||
|
},
|
||||||
|
function (result, next) {
|
||||||
|
topics.getUnreadTids({ cid: 0, uid: adminUid }, next);
|
||||||
|
},
|
||||||
|
function (unreadTids, next) {
|
||||||
|
assert(!unreadTids.includes(parseInt(topic.tid, 10)));
|
||||||
|
User.blocks.remove(blockedUid, adminUid, next);
|
||||||
|
},
|
||||||
|
], done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tags', function () {
|
describe('tags', function () {
|
||||||
@@ -1775,7 +1803,7 @@ describe('Topic\'s', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get teasers with first posts', function (done) {
|
it('should get teasers with last posts', function (done) {
|
||||||
meta.config.teaserPost = 'last-post';
|
meta.config.teaserPost = 'last-post';
|
||||||
topics.reply({ uid: adminUid, content: 'reply 1 content', tid: topic1.topicData.tid }, function (err, result) {
|
topics.reply({ uid: adminUid, content: 'reply 1 content', tid: topic1.topicData.tid }, function (err, result) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@@ -1816,6 +1844,29 @@ describe('Topic\'s', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not return teaser if user is blocked', function (done) {
|
||||||
|
var blockedUid;
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
User.create({ username: 'blocked' }, next);
|
||||||
|
},
|
||||||
|
function (uid, next) {
|
||||||
|
blockedUid = uid;
|
||||||
|
User.blocks.add(uid, adminUid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
topics.reply({ uid: blockedUid, content: 'post from blocked user', tid: topic2.topicData.tid }, next);
|
||||||
|
},
|
||||||
|
function (result, next) {
|
||||||
|
topics.getTeaser(topic2.topicData.tid, adminUid, next);
|
||||||
|
},
|
||||||
|
function (teaser, next) {
|
||||||
|
assert.equal(teaser.content, 'content 2');
|
||||||
|
User.blocks.remove(blockedUid, adminUid, next);
|
||||||
|
},
|
||||||
|
], done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tag privilege', function () {
|
describe('tag privilege', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user