mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
Added email relation to post and allowed include for /posts
endpoint
This commit is contained in:
parent
97e2af9a06
commit
4e1caa8b08
@ -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 = {
|
||||
|
@ -33,6 +33,10 @@ const Email = ghostBookshelf.Model.extend({
|
||||
|
||||
model.emitChange('deleted', options);
|
||||
}
|
||||
}, {
|
||||
post() {
|
||||
return this.belongsTo('Post');
|
||||
}
|
||||
});
|
||||
|
||||
const Emails = ghostBookshelf.Collection.extend({
|
||||
|
@ -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.
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user