From 289c1b3e8a5c03b868dde1a76f62661197e302d4 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 6 Jul 2020 13:00:15 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Updated=20access=20to=20be=20tru?= =?UTF-8?q?e=20by=20default=20in=20v3=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #11990 - access should be a members feature, but it was already accidentally exposed to the theme layer - it has now been added to the API even if members is disabled - access defaults to true, unless members is enabled - when members is enabled, access is set to the currently logged in members' access --- .../canary/utils/serializers/output/utils/post-gating.js | 7 +++++++ test/api-acceptance/content/utils.js | 2 ++ test/regression/api/canary/content/posts_spec.js | 7 +++---- test/regression/api/canary/content/utils.js | 2 ++ test/regression/api/v3/content/posts_spec.js | 7 +++---- test/regression/api/v3/content/utils.js | 2 ++ 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/core/server/api/canary/utils/serializers/output/utils/post-gating.js b/core/server/api/canary/utils/serializers/output/utils/post-gating.js index d73f41e5e3..92c14e4546 100644 --- a/core/server/api/canary/utils/serializers/output/utils/post-gating.js +++ b/core/server/api/canary/utils/serializers/output/utils/post-gating.js @@ -3,6 +3,12 @@ const labs = require('../../../../../../services/labs'); // @TODO: reconsider the location of this - it's part of members and adds a property to the API const forPost = (attrs, frame) => { + // CASE: Access always defaults to true, unless members is enabled and the member does not have access + if (!Object.prototype.hasOwnProperty.call(frame.options, 'columns') || (frame.options.columns.includes('access'))) { + attrs.access = true; + } + + // Handle members being enabled if (labs.isSet('members')) { const memberHasAccess = membersService.contentGating.checkPostAccess(attrs, frame.original.context.member); @@ -18,6 +24,7 @@ const forPost = (attrs, frame) => { attrs.access = memberHasAccess; } } + return attrs; }; diff --git a/test/api-acceptance/content/utils.js b/test/api-acceptance/content/utils.js index b4a654c678..7e56248ecf 100644 --- a/test/api-acceptance/content/utils.js +++ b/test/api-acceptance/content/utils.js @@ -29,6 +29,8 @@ const expectedProperties = { // .without('page') // v2 returns a calculated excerpt field .concat('excerpt') + // Access is a calculated property in >= v3 + .concat('access') // returns meta fields from `posts_meta` schema .concat( ..._(schema.posts_meta).keys().without('post_id', 'id') diff --git a/test/regression/api/canary/content/posts_spec.js b/test/regression/api/canary/content/posts_spec.js index dd7bf5a371..6fea281264 100644 --- a/test/regression/api/canary/content/posts_spec.js +++ b/test/regression/api/canary/content/posts_spec.js @@ -227,7 +227,6 @@ describe('api/canary/content/posts', function () { let publicPost; let membersPost; let paidPost; - let contentGatingFields = ['access']; before(function () { // NOTE: ideally this would be set through Admin API request not a stub @@ -291,7 +290,7 @@ describe('api/canary/content/posts', function () { should.exist(jsonResponse.posts); const post = jsonResponse.posts[0]; - localUtils.API.checkResponse(post, 'post', contentGatingFields, null); + localUtils.API.checkResponse(post, 'post', null, null); post.slug.should.eql('thou-shalt-not-be-seen'); post.html.should.eql(''); }); @@ -309,7 +308,7 @@ describe('api/canary/content/posts', function () { should.exist(jsonResponse.posts); const post = jsonResponse.posts[0]; - localUtils.API.checkResponse(post, 'post', contentGatingFields, null); + localUtils.API.checkResponse(post, 'post', null, null); post.slug.should.eql('thou-shalt-be-paid-for'); post.html.should.eql(''); }); @@ -348,7 +347,7 @@ describe('api/canary/content/posts', function () { should.exist(jsonResponse.posts); localUtils.API.checkResponse(jsonResponse, 'posts'); jsonResponse.posts.should.have.length(14); - localUtils.API.checkResponse(jsonResponse.posts[0], 'post', contentGatingFields, null); + localUtils.API.checkResponse(jsonResponse.posts[0], 'post', null, null); localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination'); _.isBoolean(jsonResponse.posts[0].featured).should.eql(true); diff --git a/test/regression/api/canary/content/utils.js b/test/regression/api/canary/content/utils.js index 3b0df72970..4fac2a65ca 100644 --- a/test/regression/api/canary/content/utils.js +++ b/test/regression/api/canary/content/utils.js @@ -28,6 +28,8 @@ const expectedProperties = { .without('type') // canary returns a calculated excerpt field .concat('excerpt') + // Access is a calculated property in >= v3 + .concat('access') // returns meta fields from `posts_meta` schema .concat( ..._(schema.posts_meta).keys().without('post_id', 'id') diff --git a/test/regression/api/v3/content/posts_spec.js b/test/regression/api/v3/content/posts_spec.js index ba333e4b81..e551284474 100644 --- a/test/regression/api/v3/content/posts_spec.js +++ b/test/regression/api/v3/content/posts_spec.js @@ -227,7 +227,6 @@ describe('api/v3/content/posts', function () { let publicPost; let membersPost; let paidPost; - let contentGatingFields = ['access']; before(function () { // NOTE: ideally this would be set through Admin API request not a stub @@ -291,7 +290,7 @@ describe('api/v3/content/posts', function () { should.exist(jsonResponse.posts); const post = jsonResponse.posts[0]; - localUtils.API.checkResponse(post, 'post', contentGatingFields, null); + localUtils.API.checkResponse(post, 'post', null, null); post.slug.should.eql('thou-shalt-not-be-seen'); post.html.should.eql(''); }); @@ -309,7 +308,7 @@ describe('api/v3/content/posts', function () { should.exist(jsonResponse.posts); const post = jsonResponse.posts[0]; - localUtils.API.checkResponse(post, 'post', contentGatingFields, null); + localUtils.API.checkResponse(post, 'post', null, null); post.slug.should.eql('thou-shalt-be-paid-for'); post.html.should.eql(''); }); @@ -348,7 +347,7 @@ describe('api/v3/content/posts', function () { should.exist(jsonResponse.posts); localUtils.API.checkResponse(jsonResponse, 'posts'); jsonResponse.posts.should.have.length(14); - localUtils.API.checkResponse(jsonResponse.posts[0], 'post', contentGatingFields, null); + localUtils.API.checkResponse(jsonResponse.posts[0], 'post', null, null); localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination'); _.isBoolean(jsonResponse.posts[0].featured).should.eql(true); diff --git a/test/regression/api/v3/content/utils.js b/test/regression/api/v3/content/utils.js index c50d0571fa..5895ad0fc9 100644 --- a/test/regression/api/v3/content/utils.js +++ b/test/regression/api/v3/content/utils.js @@ -28,6 +28,8 @@ const expectedProperties = { .without('type') // v3 returns a calculated excerpt field .concat('excerpt') + // Access is a calculated property in >= v3 + .concat('access') // returns meta fields from `posts_meta` schema .concat( ..._(schema.posts_meta).keys().without('post_id', 'id')