mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
🐛Fixed count.posts
respecting co authors (#9830)
closes #9822 - Fixed the post count issue for co authors - Corrected and refactored tests related to users post count - Consistency fix, because we return all posts where the author is primary or co author for the author page already
This commit is contained in:
parent
647fb1db62
commit
a0e7160fc9
@ -26,11 +26,12 @@ module.exports = function (Bookshelf) {
|
||||
}
|
||||
},
|
||||
users: {
|
||||
posts: function addPostCountToTags(model, options) {
|
||||
posts: function addPostCountToUsers(model, options) {
|
||||
model.query('columns', 'users.*', function (qb) {
|
||||
qb.count('posts.id')
|
||||
.from('posts')
|
||||
.whereRaw('posts.author_id = users.id')
|
||||
.join('posts_authors', 'posts.id', 'posts_authors.post_id')
|
||||
.whereRaw('posts_authors.author_id = users.id')
|
||||
.as('count__posts');
|
||||
|
||||
if (options.context && options.context.public) {
|
||||
|
@ -184,25 +184,19 @@ describe('Users API', function () {
|
||||
should.exist(response.users);
|
||||
response.users.should.have.length(9);
|
||||
|
||||
testUtils.API.checkResponse(response.users[0], 'user', 'count');
|
||||
testUtils.API.checkResponse(response.users[1], 'user', 'count');
|
||||
testUtils.API.checkResponse(response.users[2], 'user', 'count');
|
||||
testUtils.API.checkResponse(response.users[3], 'user', 'count');
|
||||
testUtils.API.checkResponse(response.users[4], 'user', 'count');
|
||||
testUtils.API.checkResponse(response.users[5], 'user', 'count');
|
||||
testUtils.API.checkResponse(response.users[6], 'user', 'count');
|
||||
testUtils.API.checkResponse(response.users[7], 'user', 'count');
|
||||
testUtils.API.checkResponse(response.users[8], 'user', 'count');
|
||||
response.users.map((user) => {
|
||||
testUtils.API.checkResponse(user, 'user', 'count');
|
||||
});
|
||||
|
||||
response.users[0].count.posts.should.eql(0);
|
||||
response.users[1].count.posts.should.eql(0);
|
||||
response.users[2].count.posts.should.eql(0);
|
||||
response.users[3].count.posts.should.eql(0);
|
||||
response.users[4].count.posts.should.eql(0);
|
||||
response.users[5].count.posts.should.eql(8);
|
||||
response.users[6].count.posts.should.eql(0);
|
||||
response.users[7].count.posts.should.eql(0);
|
||||
response.users[8].count.posts.should.eql(0);
|
||||
response.users.map((user) => {
|
||||
if (user.email === 'jbloggs@example.com') {
|
||||
user.count.posts.should.eql(8);
|
||||
} else if (user.email === 'jbOgendAth@example.com') {
|
||||
user.count.posts.should.eql(1);
|
||||
} else {
|
||||
response.users[1].count.posts.should.eql(0);
|
||||
}
|
||||
});
|
||||
|
||||
response.meta.pagination.should.have.property('page', 1);
|
||||
response.meta.pagination.should.have.property('limit', 15);
|
||||
|
@ -786,7 +786,7 @@ DataGenerator.forKnex = (function () {
|
||||
{
|
||||
id: ObjectId.generate(),
|
||||
post_id: DataGenerator.Content.posts[3].id,
|
||||
author_id: DataGenerator.Content.users[2].id,
|
||||
author_id: _.find(DataGenerator.Content.users, {email: 'jbOgendAth@example.com'}).id,
|
||||
sort_order: 1
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user