mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
Added email_only property in Posts Admin API v4
https://github.com/TryGhost/Team/issues/893 - The property is only added to Admin API v4 and is invisible in all Content APIs as well as v2/v3 Posts APIs
This commit is contained in:
parent
9081877996
commit
838e94e535
@ -77,6 +77,7 @@ const post = (attrs, frame) => {
|
||||
// @TODO: https://github.com/TryGhost/Ghost/issues/10335
|
||||
// delete attrs.page;
|
||||
delete attrs.status;
|
||||
delete attrs.email_only;
|
||||
|
||||
// We are standardising on returning null from the Content API for any empty values
|
||||
if (attrs.twitter_title === '') {
|
||||
|
@ -96,6 +96,7 @@ const post = (attrs, frame) => {
|
||||
// @TODO: https://github.com/TryGhost/Ghost/issues/10335
|
||||
// delete attrs.page;
|
||||
delete attrs.status;
|
||||
delete attrs.email_only;
|
||||
|
||||
// We are standardising on returning null from the Content API for any empty values
|
||||
if (attrs.twitter_title === '') {
|
||||
|
@ -55,7 +55,9 @@ const mapPost = (model, frame) => {
|
||||
_(metaAttrs).filter((k) => {
|
||||
return (!frame.options.columns || (frame.options.columns && frame.options.columns.includes(k)));
|
||||
}).each((attr) => {
|
||||
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
|
||||
if (!(attr === 'email_only')) {
|
||||
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
|
||||
}
|
||||
});
|
||||
delete jsonModel.posts_meta;
|
||||
|
||||
|
@ -76,6 +76,7 @@ const post = (attrs, frame) => {
|
||||
// @TODO: https://github.com/TryGhost/Ghost/issues/10335
|
||||
// delete attrs.page;
|
||||
delete attrs.status;
|
||||
delete attrs.email_only;
|
||||
|
||||
// We are standardising on returning null from the Content API for any empty values
|
||||
if (attrs.twitter_title === '') {
|
||||
|
@ -60,7 +60,9 @@ const mapPost = (model, frame) => {
|
||||
_(metaAttrs).filter((k) => {
|
||||
return (!frame.options.columns || (frame.options.columns && frame.options.columns.includes(k)));
|
||||
}).each((attr) => {
|
||||
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
|
||||
if (!(attr === 'email_only')) {
|
||||
jsonModel[attr] = _.get(jsonModel.posts_meta, attr) || null;
|
||||
}
|
||||
});
|
||||
delete jsonModel.posts_meta;
|
||||
|
||||
|
@ -600,6 +600,35 @@ describe('Posts API (canary)', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can edit post_meta field that has default value and no previously created posts_meta relation', function () {
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[0].id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
should.equal(res.body.posts[0].email_only, false);
|
||||
|
||||
return request
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[1].id + '/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
posts: [{
|
||||
email_only: true,
|
||||
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.headers['x-cache-invalidate']);
|
||||
|
||||
should.exist(res.body.posts);
|
||||
should.equal(res.body.posts[0].email_only, true);
|
||||
});
|
||||
});
|
||||
|
||||
it('saving post with no modbiledoc content doesn\t trigger cache invalidation', function () {
|
||||
return request
|
||||
.post(localUtils.API.getApiQuery('posts/'))
|
||||
|
@ -64,7 +64,8 @@ const expectedProperties = {
|
||||
'meta_title',
|
||||
'meta_description',
|
||||
'email_subject',
|
||||
'frontmatter'
|
||||
'frontmatter',
|
||||
'email_only'
|
||||
],
|
||||
user: [
|
||||
'id',
|
||||
|
@ -399,6 +399,29 @@ describe('Posts API (v2)', function () {
|
||||
res.body.posts[0].visibility.should.equal('members');
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot edit post_meta field that was introduced in API v4', function () {
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[0].id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
should.equal(res.body.posts[0].email_only, undefined);
|
||||
|
||||
return request
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[1].id + '/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
posts: [{
|
||||
email_only: true,
|
||||
updated_at: res.body.posts[0].updated_at
|
||||
}]
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(422);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Destroy', function () {
|
||||
|
@ -592,6 +592,29 @@ describe('Posts API (v3)', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot edit post_meta field that was introduced in API v4', function () {
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[0].id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
should.equal(res.body.posts[0].email_only, undefined);
|
||||
|
||||
return request
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[1].id + '/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
posts: [{
|
||||
email_only: true,
|
||||
updated_at: res.body.posts[0].updated_at
|
||||
}]
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(422);
|
||||
});
|
||||
});
|
||||
|
||||
it('saving post with no modbiledoc content doesn\t trigger cache invalidation', function () {
|
||||
return request
|
||||
.post(localUtils.API.getApiQuery('posts/'))
|
||||
|
Loading…
Reference in New Issue
Block a user