0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

🐛 Fixed unexpected members-only content appearing in excerpt field (#12670)

closes https://github.com/TryGhost/Team/issues/468

- updated post-gating
  - clears excerpt if there's no access
  - rebuilds excerpt from free preview if paywall card is used and there's no custom excerpt
This commit is contained in:
Kevin Ansfield 2021-02-18 14:12:06 +00:00 committed by GitHub
parent 6d2b731379
commit c7a29b4e7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 10 deletions

View file

@ -16,8 +16,12 @@ const forPost = (attrs, frame) => {
if (paywallIndex !== -1) {
attrs.html = attrs.html.slice(0, paywallIndex);
attrs.plaintext = htmlToPlaintext(attrs.html);
if (!attrs.custom_excerpt && attrs.excerpt) {
attrs.excerpt = attrs.plaintext.substring(0, 500);
}
} else {
['plaintext', 'html'].forEach((field) => {
['plaintext', 'html', 'excerpt'].forEach((field) => {
if (attrs[field] !== undefined) {
attrs[field] = '';
}

View file

@ -35,6 +35,8 @@ const mapPost = (model, frame) => {
url.forPost(model.id, jsonModel, frame);
extraAttrs.forPost(frame, model, jsonModel);
if (utils.isContentAPI(frame)) {
// Content api v2 still expects page prop
if (!frame.options.columns || frame.options.columns.includes('page')) {
@ -48,7 +50,6 @@ const mapPost = (model, frame) => {
gating.forPost(jsonModel, frame);
}
extraAttrs.forPost(frame, model, jsonModel);
clean.post(jsonModel, frame);
if (frame.options && frame.options.withRelated) {

View file

@ -10,8 +10,12 @@ const forPost = (attrs, frame) => {
if (paywallIndex !== -1) {
attrs.html = attrs.html.slice(0, paywallIndex);
attrs.plaintext = htmlToPlaintext(attrs.html);
if (!attrs.custom_excerpt && attrs.excerpt) {
attrs.excerpt = attrs.plaintext.substring(0, 500);
}
} else {
['plaintext', 'html'].forEach((field) => {
['plaintext', 'html', 'excerpt'].forEach((field) => {
if (attrs[field] !== undefined) {
attrs[field] = '';
}

View file

@ -16,8 +16,12 @@ const forPost = (attrs, frame) => {
if (paywallIndex !== -1) {
attrs.html = attrs.html.slice(0, paywallIndex);
attrs.plaintext = htmlToPlaintext(attrs.html);
if (!attrs.custom_excerpt && attrs.excerpt) {
attrs.excerpt = attrs.plaintext.substring(0, 500);
}
} else {
['plaintext', 'html'].forEach((field) => {
['plaintext', 'html', 'excerpt'].forEach((field) => {
if (attrs[field] !== undefined) {
attrs[field] = '';
}

View file

@ -333,6 +333,7 @@ describe('api/canary/content/posts', function () {
localUtils.API.checkResponse(post, 'post', null, null);
post.slug.should.eql('thou-shalt-not-be-seen');
post.html.should.eql('');
post.excerpt.should.eql('');
});
});
@ -351,6 +352,7 @@ describe('api/canary/content/posts', function () {
localUtils.API.checkResponse(post, 'post', null, null);
post.slug.should.eql('thou-shalt-be-paid-for');
post.html.should.eql('');
post.excerpt.should.eql('');
});
});
@ -374,7 +376,7 @@ describe('api/canary/content/posts', function () {
it('can read "free" html and plaintext content of members post when using paywall card', function () {
return request
.get(localUtils.API.getApiQuery(`posts/${membersPostWithPaywallCard.id}/?key=${validKey}&formats=html,plaintext&fields=html,plaintext`))
.get(localUtils.API.getApiQuery(`posts/${membersPostWithPaywallCard.id}/?key=${validKey}&formats=html,plaintext`))
.set('Origin', testUtils.API.getURL())
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
@ -384,9 +386,10 @@ describe('api/canary/content/posts', function () {
should.exist(jsonResponse.posts);
const post = jsonResponse.posts[0];
localUtils.API.checkResponse(post, 'post', null, null, ['id', 'html', 'plaintext']);
localUtils.API.checkResponse(post, 'post', ['plaintext']);
post.html.should.eql('<p>Free content</p>');
post.plaintext.should.eql('Free content');
post.excerpt.should.eql('Free content');
});
});
@ -422,6 +425,12 @@ describe('api/canary/content/posts', function () {
jsonResponse.posts[3].html.should.not.eql('');
jsonResponse.posts[8].html.should.not.eql('');
jsonResponse.posts[0].excerpt.should.eql('');
jsonResponse.posts[1].excerpt.should.eql('');
jsonResponse.posts[2].excerpt.should.not.eql('');
jsonResponse.posts[3].excerpt.should.not.eql('');
jsonResponse.posts[8].excerpt.should.not.eql('');
// check meta response for this test
jsonResponse.meta.pagination.page.should.eql(1);
jsonResponse.meta.pagination.limit.should.eql(15);

View file

@ -283,6 +283,7 @@ describe('api/v2/content/posts', function () {
localUtils.API.checkResponse(post, 'post', null, null);
post.slug.should.eql('thou-shalt-not-be-seen');
post.html.should.eql('');
post.excerpt.should.eql('');
});
});
@ -301,6 +302,7 @@ describe('api/v2/content/posts', function () {
localUtils.API.checkResponse(post, 'post', null, null);
post.slug.should.eql('thou-shalt-be-paid-for');
post.html.should.eql('');
post.excerpt.should.eql('');
});
});
@ -324,7 +326,7 @@ describe('api/v2/content/posts', function () {
it('can read "free" html and plaintext content of members post when using paywall card', function () {
return request
.get(localUtils.API.getApiQuery(`posts/${membersPostWithPaywallCard.id}/?key=${validKey}&formats=html,plaintext&fields=html,plaintext`))
.get(localUtils.API.getApiQuery(`posts/${membersPostWithPaywallCard.id}/?key=${validKey}&formats=html,plaintext`))
.set('Origin', testUtils.API.getURL())
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
@ -334,9 +336,10 @@ describe('api/v2/content/posts', function () {
should.exist(jsonResponse.posts);
const post = jsonResponse.posts[0];
localUtils.API.checkResponse(post, 'post', null, null, ['id', 'html', 'plaintext']);
localUtils.API.checkResponse(post, 'post', ['plaintext']);
post.html.should.eql('<p>Free content</p>');
post.plaintext.should.eql('Free content');
post.excerpt.should.eql('Free content');
});
});
@ -372,6 +375,12 @@ describe('api/v2/content/posts', function () {
jsonResponse.posts[3].html.should.not.eql('');
jsonResponse.posts[8].html.should.not.eql('');
jsonResponse.posts[0].excerpt.should.eql('');
jsonResponse.posts[1].excerpt.should.eql('');
jsonResponse.posts[2].excerpt.should.not.eql('');
jsonResponse.posts[3].excerpt.should.not.eql('');
jsonResponse.posts[8].excerpt.should.not.eql('');
// check meta response for this test
jsonResponse.meta.pagination.page.should.eql(1);
jsonResponse.meta.pagination.limit.should.eql(15);

View file

@ -333,6 +333,7 @@ describe('api/v3/content/posts', function () {
localUtils.API.checkResponse(post, 'post', null, null);
post.slug.should.eql('thou-shalt-not-be-seen');
post.html.should.eql('');
post.excerpt.should.eql('');
});
});
@ -351,6 +352,7 @@ describe('api/v3/content/posts', function () {
localUtils.API.checkResponse(post, 'post', null, null);
post.slug.should.eql('thou-shalt-be-paid-for');
post.html.should.eql('');
post.excerpt.should.eql('');
});
});
@ -374,7 +376,7 @@ describe('api/v3/content/posts', function () {
it('can read "free" html and plaintext content of members post when using paywall card', function () {
return request
.get(localUtils.API.getApiQuery(`posts/${membersPostWithPaywallCard.id}/?key=${validKey}&formats=html,plaintext&fields=html,plaintext`))
.get(localUtils.API.getApiQuery(`posts/${membersPostWithPaywallCard.id}/?key=${validKey}&formats=html,plaintext`))
.set('Origin', testUtils.API.getURL())
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
@ -384,7 +386,7 @@ describe('api/v3/content/posts', function () {
should.exist(jsonResponse.posts);
const post = jsonResponse.posts[0];
localUtils.API.checkResponse(post, 'post', null, null, ['id', 'html', 'plaintext']);
localUtils.API.checkResponse(post, 'post', ['plaintext']);
post.html.should.eql('<p>Free content</p>');
post.plaintext.should.eql('Free content');
});
@ -421,6 +423,12 @@ describe('api/v3/content/posts', function () {
jsonResponse.posts[2].html.should.not.eql('');
jsonResponse.posts[8].html.should.not.eql('');
jsonResponse.posts[0].excerpt.should.eql('');
jsonResponse.posts[1].excerpt.should.eql('');
jsonResponse.posts[2].excerpt.should.not.eql('');
jsonResponse.posts[3].excerpt.should.not.eql('');
jsonResponse.posts[8].excerpt.should.not.eql('');
// check meta response for this test
jsonResponse.meta.pagination.page.should.eql(1);
jsonResponse.meta.pagination.limit.should.eql(15);