Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Add v2.10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickRe committed Jan 20, 2019
1 parent dcfe62b commit 2d2605b
Show file tree
Hide file tree
Showing 31 changed files with 702 additions and 400 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions core/server/api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const config = require('../config');
module.exports = require('./v0.1');
module.exports['v0.1'] = require('./v0.1');
module.exports.v2 = require('./v2');
module.exports.active = require(`./${config.get('api:versions:active')}`);
6 changes: 3 additions & 3 deletions core/server/api/shared/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ const disposition = {
}

return {
'Content-Disposition': value,
'Content-Disposition': `Attachment; filename="${value}"`,
'Content-Type': 'text/csv'
};
},

json(result, options = {}) {
return {
'Content-Disposition': options.value,
'Content-Disposition': `Attachment; filename="${options.value}"`,
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(JSON.stringify(result))
};
},

yaml(result, options = {}) {
return {
'Content-Disposition': options.value,
'Content-Disposition': `Attachment; filename="${options.value}"`,
'Content-Type': 'application/yaml',
'Content-Length': Buffer.byteLength(JSON.stringify(result))
};
Expand Down
2 changes: 2 additions & 0 deletions core/server/api/v2/settings-public.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = {
browse: {
permissions: true,
query() {
// @TODO: decouple settings cache from API knowledge
// The controller fetches models (or cached models) and the API frame for the target API version formats the response.
return settingsCache.getPublic();
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/v2/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ module.exports = {
headers: {
disposition: {
type: 'yaml',
value: 'Attachment; filename="routes.yaml"'
value: 'routes.yaml'
}
},
response: {
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/v2/subscribers.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const subscribers = {
type: 'csv',
value() {
const datetime = (new Date()).toJSON().substring(0, 10);
return `Attachment; filename="subscribers.${datetime}.csv"`;
return `subscribers.${datetime}.csv`;
}
}
},
Expand Down
26 changes: 26 additions & 0 deletions core/server/api/v2/utils/serializers/input/authors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:authors');
const utils = require('../../index');

function setDefaultOrder(frame) {
if (!frame.options.order) {
frame.options.order = 'name asc';
}
}

module.exports = {
browse(apiConfig, frame) {
debug('browse');

if (utils.isContentAPI(frame)) {
setDefaultOrder(frame);
}
},

read(apiConfig, frame) {
debug('read');

if (utils.isContentAPI(frame)) {
setDefaultOrder(frame);
}
}
};
18 changes: 18 additions & 0 deletions core/server/api/v2/utils/serializers/input/pages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('lodash');
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:pages');

function removeMobiledocFormat(frame) {
Expand All @@ -8,6 +9,19 @@ function removeMobiledocFormat(frame) {
}
}

function setDefaultOrder(frame) {
let includesOrderedRelations = false;

if (frame.options.withRelated) {
const orderedRelations = ['author', 'authors', 'tag', 'tags'];
includesOrderedRelations = _.intersection(orderedRelations, frame.options.withRelated).length > 0;
}

if (!frame.options.order && !includesOrderedRelations) {
frame.options.order = 'title asc';
}
}

module.exports = {
browse(apiConfig, frame) {
debug('browse');
Expand All @@ -28,6 +42,8 @@ module.exports = {

removeMobiledocFormat(frame);

setDefaultOrder(frame);

debug(frame.options);
},

Expand All @@ -37,6 +53,8 @@ module.exports = {
frame.data.page = true;
removeMobiledocFormat(frame);

setDefaultOrder(frame);

debug(frame.options);
}
};
17 changes: 17 additions & 0 deletions core/server/api/v2/utils/serializers/input/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ function includeTags(frame) {
}
}

function setDefaultOrder(frame) {
let includesOrderedRelations = false;

if (frame.options.withRelated) {
const orderedRelations = ['author', 'authors', 'tag', 'tags'];
includesOrderedRelations = _.intersection(orderedRelations, frame.options.withRelated).length > 0;
}

if (!frame.options.order && !includesOrderedRelations) {
frame.options.order = 'published_at desc';
}
}

module.exports = {
browse(apiConfig, frame) {
debug('browse');
Expand Down Expand Up @@ -53,6 +66,8 @@ module.exports = {
if (labs.isSet('members')) {
includeTags(frame);
}

setDefaultOrder(frame);
}

debug(frame.options);
Expand All @@ -76,6 +91,8 @@ module.exports = {
// CASE: Members needs to have the tags to check if its allowed access
includeTags(frame);
}

setDefaultOrder(frame);
}

debug(frame.options);
Expand Down
21 changes: 21 additions & 0 deletions core/server/api/v2/utils/serializers/input/tags.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:tags');
const url = require('./utils/url');
const utils = require('../../index');

function setDefaultOrder(frame) {
if (!frame.options.order) {
frame.options.order = 'name asc';
}
}

module.exports = {
browse(apiConfig, frame) {
debug('browse');

if (utils.isContentAPI(frame)) {
setDefaultOrder(frame);
}
},

read() {
debug('read');

this.browse(...arguments);
},

add(apiConfig, frame) {
debug('add');
frame.data.tags[0] = url.forTag(Object.assign({}, frame.data.tags[0]));
Expand Down
4 changes: 3 additions & 1 deletion core/server/api/v2/utils/serializers/output/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash');
const utils = require('../../index');
const mapper = require('./utils/mapper');
const _private = {};
const deprecatedSettings = ['force_i18n', 'permalinks'];

Expand All @@ -25,6 +26,7 @@ _private.settingsFilter = (settings, filter) => {
module.exports = {
browse(models, apiConfig, frame) {
let filteredSettings;

// If this is public, we already have the right data, we just need to add an Array wrapper
if (utils.isContentAPI(frame)) {
filteredSettings = models;
Expand All @@ -33,7 +35,7 @@ module.exports = {
}

frame.response = {
settings: filteredSettings,
settings: mapper.mapSettings(filteredSettings),
meta: {}
};

Expand Down
54 changes: 54 additions & 0 deletions core/server/api/v2/utils/serializers/output/utils/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ const tag = (attrs) => {
delete attrs.created_at;
delete attrs.updated_at;

// We are standardising on returning null from the Content API for any empty values
if (attrs.meta_title === '') {
attrs.meta_title = null;
}
if (attrs.meta_description === '') {
attrs.meta_description = null;
}
if (attrs.description === '') {
attrs.description = null;
}

return attrs;
};

Expand All @@ -24,6 +35,29 @@ const author = (attrs) => {
delete attrs.tour;
delete attrs.visibility;

// We are standardising on returning null from the Content API for any empty values
if (attrs.twitter === '') {
attrs.twitter = null;
}
if (attrs.bio === '') {
attrs.bio = null;
}
if (attrs.website === '') {
attrs.website = null;
}
if (attrs.facebook === '') {
attrs.facebook = null;
}
if (attrs.meta_title === '') {
attrs.meta_title = null;
}
if (attrs.meta_description === '') {
attrs.meta_description = null;
}
if (attrs.location === '') {
attrs.location = null;
}

return attrs;
};

Expand All @@ -37,6 +71,26 @@ const post = (attrs) => {
delete attrs.status;
delete attrs.visibility;

// We are standardising on returning null from the Content API for any empty values
if (attrs.twitter_title === '') {
attrs.twitter_title = null;
}
if (attrs.twitter_description === '') {
attrs.twitter_description = null;
}
if (attrs.meta_title === '') {
attrs.meta_title = null;
}
if (attrs.meta_description === '') {
attrs.meta_description = null;
}
if (attrs.og_title === '') {
attrs.og_title = null;
}
if (attrs.og_description === '') {
attrs.og_description = null;
}

return attrs;
};

Expand Down
25 changes: 25 additions & 0 deletions core/server/api/v2/utils/serializers/output/utils/extra-attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,28 @@ module.exports.forPost = (frame, model, attrs) => {
}
}
};

// @NOTE: ghost_head & ghost_foot are deprecated, remove in Ghost 3.0
module.exports.forSettings = (attrs) => {
const _ = require('lodash');

// @TODO: https://github.com/TryGhost/Ghost/issues/10106
// @NOTE: Admin & Content API return a different format, need to mappers
if (_.isArray(attrs)) {
const ghostHead = _.cloneDeep(_.find(attrs, {key: 'ghost_head'}));
const ghostFoot = _.cloneDeep(_.find(attrs, {key: 'ghost_foot'}));

if (ghostHead) {
ghostHead.key = 'codeinjection_head';
attrs.push(ghostHead);
}

if (ghostFoot) {
ghostFoot.key = 'codeinjection_foot';
attrs.push(ghostFoot);
}
} else {
attrs.codeinjection_head = attrs.ghost_head;
attrs.codeinjection_foot = attrs.ghost_foot;
}
};
14 changes: 14 additions & 0 deletions core/server/api/v2/utils/serializers/output/utils/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,23 @@ const mapPost = (model, frame) => {
});
}

/**
* Remove extra data attributes passed for filtering when used with columns/fields as bookshelf doesn't filter it out
*/
if (frame.options.columns && frame.options.columns.indexOf('page') < 0) {
delete jsonModel.page;
}

return jsonModel;
};

const mapSettings = (attrs) => {
url.forSettings(attrs);
extraAttrs.forSettings(attrs);
return attrs;
};

module.exports.mapPost = mapPost;
module.exports.mapUser = mapUser;
module.exports.mapTag = mapTag;
module.exports.mapSettings = mapSettings;
28 changes: 28 additions & 0 deletions core/server/api/v2/utils/serializers/output/utils/url.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('lodash');
const urlService = require('../../../../../../services/url');

const forPost = (id, attrs, options) => {
Expand Down Expand Up @@ -63,6 +64,33 @@ const forTag = (id, attrs) => {
return attrs;
};

const forSettings = (attrs) => {
// @TODO: https://github.com/TryGhost/Ghost/issues/10106
// @NOTE: Admin & Content API return a different format, need to mappers
if (_.isArray(attrs)) {
attrs.forEach((obj) => {
if (['cover_image', 'logo', 'icon'].includes(obj.key) && obj.value) {
obj.value = urlService.utils.urlFor('image', {image: obj.value}, true);
}
});
} else {
if (attrs.cover_image) {
attrs.cover_image = urlService.utils.urlFor('image', {image: attrs.cover_image}, true);
}

if (attrs.logo) {
attrs.logo = urlService.utils.urlFor('image', {image: attrs.logo}, true);
}

if (attrs.icon) {
attrs.icon = urlService.utils.urlFor('image', {image: attrs.icon}, true);
}
}

return attrs;
};

module.exports.forPost = forPost;
module.exports.forUser = forUser;
module.exports.forTag = forTag;
module.exports.forSettings = forSettings;
3 changes: 0 additions & 3 deletions core/server/config/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@
"api": {
"versions": {
"all": ["v0.1", "v2"],
"active": "v2",
"stable": "",
"deprecated": "v0.1",
"v2": {
"admin": "v2/admin",
"content": "v2/content",
Expand Down
Loading

0 comments on commit 2d2605b

Please sign in to comment.