2019-08-09 17:25:12 +03:00
|
|
|
const url = require('url');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const testUtils = require('../../../../utils');
|
2020-03-30 18:26:47 +03:00
|
|
|
const schema = require('../../../../../core/server/data/schema').tables;
|
2019-08-09 17:25:12 +03:00
|
|
|
const API_URL = '/ghost/api/canary/admin/';
|
|
|
|
|
|
|
|
const expectedProperties = {
|
|
|
|
// API top level
|
|
|
|
posts: ['posts', 'meta'],
|
|
|
|
tags: ['tags', 'meta'],
|
|
|
|
users: ['users', 'meta'],
|
|
|
|
settings: ['settings', 'meta'],
|
|
|
|
subscribers: ['subscribers', 'meta'],
|
|
|
|
roles: ['roles'],
|
|
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
|
|
|
slugs: ['slugs'],
|
|
|
|
slug: ['slug'],
|
|
|
|
invites: ['invites', 'meta'],
|
|
|
|
themes: ['themes'],
|
2020-05-28 12:14:02 +03:00
|
|
|
members: ['members', 'meta'],
|
2019-08-09 17:25:12 +03:00
|
|
|
|
|
|
|
post: _(schema.posts)
|
|
|
|
.keys()
|
|
|
|
// by default we only return mobiledoc
|
|
|
|
.without('html', 'plaintext')
|
|
|
|
.without('locale')
|
|
|
|
.without('page')
|
2019-09-17 18:26:23 +03:00
|
|
|
.without('author_id', 'author')
|
2020-09-24 04:32:40 +03:00
|
|
|
.without('type')
|
2019-08-09 17:25:12 +03:00
|
|
|
// always returns computed properties
|
2019-09-02 14:51:43 +03:00
|
|
|
// primary_tag and primary_author properties are included
|
|
|
|
// only because authors and tags are always included
|
2019-08-09 17:25:12 +03:00
|
|
|
.concat('url', 'primary_tag', 'primary_author', 'excerpt')
|
2020-09-24 04:32:40 +03:00
|
|
|
.concat('authors', 'tags', 'email')
|
2019-09-16 11:45:55 +03:00
|
|
|
// returns meta fields from `posts_meta` schema
|
|
|
|
.concat(
|
|
|
|
..._(schema.posts_meta).keys().without('post_id', 'id')
|
|
|
|
)
|
Fixed backward compatibility for `send_email_when_published` (#12357)
no-issue
* Handled send_email_when_published in Posts API
This restores backwards compatibility of the Posts API allowing existing
clients to continue to use the `send_email_when_published` flag. This
change uses two edits, which is unfortunate. The reason being is that
this is an API compatibility issue, not a model issue, so we shouldn't
introduce code to the model layer to handle it. The visibility property
of the model is used to determine how to fall back, and because it can
be left out of the API request, and relies on a default in the settings,
we require that the model decide on the `visibility` before we run our
fallback logic (or we duplicate the `visibility` default at the cost of
maintenance in the future)
* Dropped send_email_when_published column from posts
Since this column is not used any more, we can drop it from the table.
We include an extra migration to repopulate the column in the event of
a rollback
* Updated importer to handle send_email_when_published
Because we currently export this value from Ghost, we should correctly
import it. This follows the same logic as the migrations for this value.
* Included send_email_when_published in API response
As our v3 API documentation includes `send_email_when_published` we must
retain backward compatibility by calculating the property.
* Fixed fields filter with send_email_when_published
* Added safety checks to frame properties
Some parts of the code pass a manually created "frame" which is missing
lots of properties, so we check for the existence of all of them before
using them.
* Fixed 3.1 migration to include columnDefinition
We require that migrations have all the information they need contained
within them as they run in an unknown state of the codebase, which could
be from the commit they are introduced, to any future commit. In this
case the column definition is removed from the schema in 3.38 and the
migration would fail when run in this version or later.
2020-11-11 16:03:41 +03:00
|
|
|
.concat('send_email_when_published')
|
2019-08-09 17:25:12 +03:00
|
|
|
,
|
|
|
|
user: _(schema.users)
|
|
|
|
.keys()
|
|
|
|
.without('visibility')
|
|
|
|
.without('password')
|
|
|
|
.without('locale')
|
|
|
|
.concat('url')
|
|
|
|
,
|
|
|
|
tag: _(schema.tags)
|
|
|
|
.keys()
|
|
|
|
// unused field
|
|
|
|
.without('parent_id')
|
|
|
|
,
|
|
|
|
setting: _(schema.settings)
|
|
|
|
.keys()
|
|
|
|
,
|
|
|
|
subscriber: _(schema.subscribers)
|
|
|
|
.keys()
|
|
|
|
,
|
2019-10-03 12:15:50 +03:00
|
|
|
member: _(schema.members)
|
|
|
|
.keys()
|
2020-02-19 13:49:21 +03:00
|
|
|
.concat('avatar_image')
|
2020-01-28 07:25:00 +03:00
|
|
|
.concat('comped')
|
2020-02-14 13:36:25 +03:00
|
|
|
.concat('labels')
|
2019-10-03 12:15:50 +03:00
|
|
|
,
|
2020-02-27 06:48:02 +03:00
|
|
|
member_signin_url: ['member_id', 'url'],
|
2019-08-09 17:25:12 +03:00
|
|
|
role: _(schema.roles)
|
|
|
|
.keys()
|
|
|
|
,
|
|
|
|
permission: _(schema.permissions)
|
|
|
|
.keys()
|
|
|
|
,
|
|
|
|
notification: ['type', 'message', 'status', 'id', 'dismissible', 'location', 'custom'],
|
|
|
|
theme: ['name', 'package', 'active'],
|
|
|
|
invite: _(schema.invites)
|
|
|
|
.keys()
|
|
|
|
.without('token')
|
|
|
|
,
|
|
|
|
webhook: _(schema.webhooks)
|
2019-08-19 14:41:09 +03:00
|
|
|
.keys()
|
2019-11-05 08:13:53 +03:00
|
|
|
,
|
2019-11-08 07:37:53 +03:00
|
|
|
email_preview: ['html', 'subject', 'plaintext']
|
2019-08-09 17:25:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
_.each(expectedProperties, (value, key) => {
|
|
|
|
if (!value.__wrapped__) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated: x_by
|
|
|
|
*/
|
|
|
|
expectedProperties[key] = value
|
|
|
|
.without(
|
|
|
|
'created_by',
|
|
|
|
'updated_by',
|
|
|
|
'published_by'
|
|
|
|
)
|
|
|
|
.value();
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
API: {
|
|
|
|
getApiQuery(route) {
|
|
|
|
return url.resolve(API_URL, route);
|
|
|
|
},
|
|
|
|
|
|
|
|
checkResponse(...args) {
|
|
|
|
this.expectedProperties = expectedProperties;
|
|
|
|
return testUtils.API.checkResponse.call(this, ...args);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
doAuth(...args) {
|
|
|
|
return testUtils.API.doAuth(`${API_URL}session/`, ...args);
|
|
|
|
},
|
|
|
|
|
|
|
|
getValidAdminToken(endpoint, key) {
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
key = key || testUtils.DataGenerator.Content.api_keys[0];
|
|
|
|
|
|
|
|
const JWT_OPTIONS = {
|
|
|
|
keyid: key.id,
|
|
|
|
algorithm: 'HS256',
|
|
|
|
expiresIn: '5m',
|
|
|
|
audience: endpoint
|
|
|
|
};
|
|
|
|
|
|
|
|
return jwt.sign(
|
|
|
|
{},
|
|
|
|
Buffer.from(key.secret, 'hex'),
|
|
|
|
JWT_OPTIONS
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|