0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Members post gating options (#11160)

no issue

- Removed uses of `visibility` column in frontend url service configs
- The value of `visibility` is always set to 'public' in posts at the moment and doesn't serve any specific purpose when used with these filters.
- Allowed new visibility attributes in post model
- `posts.visibility` column is being repurposed for the needs of member content gating
- Added test for visibility editing in Admin API
- Corrected test schema checks for Admin API post/page responses
This commit is contained in:
Naz Gargol 2019-09-26 15:38:35 +02:00 committed by GitHub
parent 56493bed1a
commit ff13821b27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 66 additions and 15 deletions

View file

@ -8,7 +8,7 @@ module.exports = [
type: 'posts',
modelOptions: {
modelName: 'Post',
filter: 'visibility:public+status:published+page:false',
filter: 'status:published+page:false',
exclude: [
'title',
'mobiledoc',
@ -79,7 +79,7 @@ module.exports = [
'primary_tag',
'primary_author'
],
filter: 'visibility:public+status:published+page:true'
filter: 'status:published+page:true'
},
events: {
add: 'page.published',

View file

@ -8,7 +8,7 @@ module.exports = [
type: 'posts',
modelOptions: {
modelName: 'Post',
filter: 'visibility:public+status:published+page:false',
filter: 'status:published+page:false',
exclude: [
'title',
'mobiledoc',
@ -73,7 +73,7 @@ module.exports = [
'primary_tag',
'primary_author'
],
filter: 'visibility:public+status:published+page:true'
filter: 'status:published+page:true'
},
events: {
add: 'page.published',

View file

@ -8,7 +8,7 @@ module.exports = [
type: 'posts',
modelOptions: {
modelName: 'Post',
filter: 'visibility:public+status:published+page:false',
filter: 'status:published+page:false',
exclude: [
'title',
'mobiledoc',

View file

@ -98,6 +98,8 @@ const post = (attrs, frame) => {
if (attrs.og_description === '') {
attrs.og_description = null;
}
delete attrs.visibility;
} else {
delete attrs.page;
@ -111,7 +113,6 @@ const post = (attrs, frame) => {
}
delete attrs.locale;
delete attrs.visibility;
delete attrs.author;
return attrs;

View file

@ -43,7 +43,7 @@
},
"visibility": {
"type": ["string", "null"],
"enum": ["public"]
"enum": ["public", "members", "paid"]
},
"meta_title": {
"type": ["string", "null"],

View file

@ -43,7 +43,7 @@
},
"visibility": {
"type": ["string", "null"],
"enum": ["public"]
"enum": ["public", "members", "paid"]
},
"meta_title": {
"type": ["string", "null"],

View file

@ -98,6 +98,8 @@ const post = (attrs, frame) => {
if (attrs.og_description === '') {
attrs.og_description = null;
}
delete attrs.visibility;
} else {
delete attrs.page;
@ -111,7 +113,6 @@ const post = (attrs, frame) => {
}
delete attrs.locale;
delete attrs.visibility;
delete attrs.author;
return attrs;

View file

@ -43,7 +43,7 @@
},
"visibility": {
"type": ["string", "null"],
"enum": ["public"]
"enum": ["public", "members", "paid"]
},
"meta_title": {
"type": ["string", "null"],

View file

@ -43,7 +43,7 @@
},
"visibility": {
"type": ["string", "null"],
"enum": ["public"]
"enum": ["public", "members", "paid"]
},
"meta_title": {
"type": ["string", "null"],

View file

@ -27,7 +27,7 @@ module.exports = {
maxlength: 50,
nullable: false,
defaultTo: 'public',
validations: {isIn: [['public']]}
validations: {isIn: [['public', 'members', 'paid']]}
},
meta_title: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 300}}},
meta_description: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 500}}},

View file

@ -28,7 +28,6 @@ const expectedProperties = {
.keys()
// by default we only return mobildoc
.without('html', 'plaintext')
.without('visibility')
.without('locale')
.without('page')
// deprecated
@ -43,7 +42,6 @@ const expectedProperties = {
.keys()
// by default we only return mobildoc
.without('html', 'plaintext')
.without('visibility')
.without('locale')
.without('page')
// deprecated

View file

@ -342,6 +342,32 @@ describe('Posts API', function () {
res.body.posts[0].slug.should.equal('this-is-invisible');
});
});
it('accepts visibility parameter', function () {
return request
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[0].id}/`))
.set('Origin', config.get('url'))
.expect(200)
.then((res) => {
return request
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/'))
.set('Origin', config.get('url'))
.send({
posts: [{
visibility: 'members',
updated_at: res.body.posts[0].updated_at
}]
})
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200);
})
.then((res) => {
should.exist(res.body.posts);
should.exist(res.body.posts[0].visibility);
res.body.posts[0].visibility.should.equal('members');
});
});
});
describe('Destroy', function () {

View file

@ -22,7 +22,6 @@ const expectedProperties = {
.keys()
// by default we only return mobiledoc
.without('html', 'plaintext')
.without('visibility')
.without('locale')
.without('page')
.without('author_id')

View file

@ -342,6 +342,32 @@ describe('Posts API', function () {
res.body.posts[0].slug.should.equal('this-is-invisible');
});
});
it('accepts visibility parameter', function () {
return request
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[0].id}/`))
.set('Origin', config.get('url'))
.expect(200)
.then((res) => {
return request
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/'))
.set('Origin', config.get('url'))
.send({
posts: [{
visibility: 'members',
updated_at: res.body.posts[0].updated_at
}]
})
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200);
})
.then((res) => {
should.exist(res.body.posts);
should.exist(res.body.posts[0].visibility);
res.body.posts[0].visibility.should.equal('members');
});
});
});
describe('Destroy', function () {