diff --git a/core/server/api/canary/posts.js b/core/server/api/canary/posts.js index 7cc5561910..99676cacb2 100644 --- a/core/server/api/canary/posts.js +++ b/core/server/api/canary/posts.js @@ -1,7 +1,7 @@ const models = require('../../models'); const common = require('../../lib/common'); const urlUtils = require('../../lib/url-utils'); -const allowedIncludes = ['tags', 'authors', 'authors.roles']; +const allowedIncludes = ['tags', 'authors', 'authors.roles', 'email']; const unsafeAttrs = ['status', 'authors', 'visibility']; module.exports = { diff --git a/core/server/models/email.js b/core/server/models/email.js index 992839b6c5..41d8c0a2ef 100644 --- a/core/server/models/email.js +++ b/core/server/models/email.js @@ -33,6 +33,10 @@ const Email = ghostBookshelf.Model.extend({ model.emitChange('deleted', options); } +}, { + post() { + return this.belongsTo('Post'); + } }); const Emails = ghostBookshelf.Collection.extend({ diff --git a/core/server/models/post.js b/core/server/models/post.js index f067c1f1fe..b85796519b 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -576,6 +576,10 @@ Post = ghostBookshelf.Model.extend({ return this.hasOne('PostsMeta', 'post_id'); }, + email: function postsMeta() { + return this.hasOne('Email', 'post_id'); + }, + /** * @NOTE: * If you are requesting models with `columns`, you try to only receive some fields of the model/s. diff --git a/core/test/regression/api/canary/admin/posts_spec.js b/core/test/regression/api/canary/admin/posts_spec.js index eb22dc4d52..70757ed86a 100644 --- a/core/test/regression/api/canary/admin/posts_spec.js +++ b/core/test/regression/api/canary/admin/posts_spec.js @@ -20,7 +20,7 @@ describe('Posts API', function () { request = supertest.agent(config.get('url')); }) .then(function () { - return localUtils.doAuth(request, 'users:extra', 'posts'); + return localUtils.doAuth(request, 'users:extra', 'posts', 'emails'); }) .then(function (cookie) { ownerCookie = cookie; @@ -60,7 +60,7 @@ describe('Posts API', function () { }); it('combined fields, formats, include and non existing', function (done) { - request.get(localUtils.API.getApiQuery('posts/?formats=mobiledoc,html,plaintext&fields=id,title,primary_tag,doesnotexist&include=authors,tags')) + request.get(localUtils.API.getApiQuery('posts/?formats=mobiledoc,html,plaintext&fields=id,title,primary_tag,doesnotexist&include=authors,tags,email')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) @@ -81,7 +81,7 @@ describe('Posts API', function () { 'post', null, null, - ['mobiledoc', 'plaintext', 'id', 'title', 'html', 'authors', 'tags', 'primary_tag'] + ['mobiledoc', 'plaintext', 'id', 'title', 'html', 'authors', 'tags', 'primary_tag', 'email'] ); localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');