2018-10-07 17:36:02 +03:00
|
|
|
const url = require('url');
|
|
|
|
const _ = require('lodash');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2021-05-12 17:15:54 +03:00
|
|
|
|
|
|
|
// NOTE: the dependance on the schema here is wrong! It is a design flaw which is causing problems for API maintenance and compatibility
|
|
|
|
// whenever you need to modify any of the below property lists using schema - rework them into an "allowlist" array like it's done in
|
|
|
|
// the commit introducing this comment.
|
2020-03-30 18:26:47 +03:00
|
|
|
const schema = require('../../../core/server/data/schema').tables;
|
2021-05-12 17:15:54 +03:00
|
|
|
|
2022-03-03 08:20:03 +03:00
|
|
|
const API_URL = '/ghost/api/admin/';
|
2018-10-07 17:36:02 +03:00
|
|
|
|
2018-12-17 18:14:36 +03:00
|
|
|
const expectedProperties = {
|
|
|
|
// API top level
|
|
|
|
posts: ['posts', 'meta'],
|
2019-02-22 06:17:14 +03:00
|
|
|
pages: ['pages', 'meta'],
|
2018-12-17 18:14:36 +03:00
|
|
|
tags: ['tags', 'meta'],
|
|
|
|
users: ['users', 'meta'],
|
|
|
|
settings: ['settings', 'meta'],
|
|
|
|
roles: ['roles'],
|
|
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
|
|
|
slugs: ['slugs'],
|
|
|
|
slug: ['slug'],
|
2018-12-17 19:45:07 +03:00
|
|
|
invites: ['invites', 'meta'],
|
|
|
|
themes: ['themes'],
|
2019-01-29 21:52:05 +03:00
|
|
|
actions: ['actions', 'meta'],
|
2020-05-21 20:44:35 +03:00
|
|
|
members: ['members', 'meta'],
|
2020-10-16 20:02:58 +03:00
|
|
|
snippets: ['snippets', 'meta'],
|
2019-01-29 21:52:05 +03:00
|
|
|
|
2022-08-23 18:37:09 +03:00
|
|
|
action: ['id', 'resource_type', 'actor_type', 'event', 'created_at', 'actor', 'context', 'resource_id', 'actor_id'],
|
2018-12-17 19:45:07 +03:00
|
|
|
|
2022-07-19 16:23:29 +03:00
|
|
|
config: [
|
|
|
|
'version',
|
|
|
|
'environment',
|
|
|
|
'database',
|
|
|
|
'mail',
|
|
|
|
'labs',
|
|
|
|
'clientExtensions',
|
|
|
|
'enableDeveloperExperiments',
|
|
|
|
'useGravatar',
|
|
|
|
'stripeDirect',
|
|
|
|
'emailAnalytics',
|
|
|
|
'tenor',
|
|
|
|
'mailgunIsConfigured',
|
2023-05-16 10:39:49 +03:00
|
|
|
'editor',
|
|
|
|
'adminX'
|
2022-07-19 16:23:29 +03:00
|
|
|
],
|
2019-02-24 20:37:11 +03:00
|
|
|
|
2021-05-12 17:15:54 +03:00
|
|
|
post: [
|
|
|
|
'id',
|
|
|
|
'uuid',
|
|
|
|
'title',
|
|
|
|
'slug',
|
|
|
|
'mobiledoc',
|
|
|
|
'comment_id',
|
|
|
|
'feature_image',
|
2021-06-10 22:35:56 +03:00
|
|
|
'feature_image_alt',
|
|
|
|
'feature_image_caption',
|
2021-05-12 17:15:54 +03:00
|
|
|
'featured',
|
|
|
|
'status',
|
|
|
|
'visibility',
|
Renamed newsletter_id and email_recipient_filter options (#14798)
refs https://github.com/TryGhost/Team/issues/1596
- Renamed `newsletter_id` to `newsletter` option, the `newsletter` option expects a slug instead of an id
- Renamed `email_recipient_filter` to `email_segment` option
- Default `email_segment` to `all`. Ignored if no newsletter is set
- `email_segment` is ignored if no newsletter is set
- When reverting a post to a draft, both `newsletter` and `email_segment` are reset to their default values (null, all)
- Removed legacy mapping from old email_recipient_filter values 'paid' and 'free' (already a migration in place)
- Dropped legacy throwing errors when email_recipient_filter is paid or free in transformEmailRecipientFilter
- Reorganized transformEmailRecipientFilter parameters for the now required newsletter parameter
- Fixed an issue where the newsletter filter wasn't working because it wasn't in permittedoptions
- Fixed an issue where you could send to an archived newsletter
- Added an extra protection when scheduling to an active, and later archiving the newsletter
- Dropped support for `send_email_when_published` in API
- When importing posts we currently don't have a system in place to set the newsletter_id to map the `send_email_when_published` behaviour. Since this was already the case, I won't include a fix in this PR.
- Stripped `email_recipient_filter`/`email_segment` from Content API (https://ghost.slack.com/archives/C02G9E68C/p1652363211841359?thread_ts=1650623650.233229&cid=C02G9E68C)
- Updated `admin-api-schema` to 3.2.0, which includes the new email_segment property
- Contains a temporary fix for https://github.com/TryGhost/Team/issues/1626, where the `.related('newsletter').fetch` call fails when the newsletter relation is already loaded, because of the overridden `formatOnWrite` method.
Since the `email_recipient_filter` is no longer used without a newsletter, the `none` value is no longer used. A migration transforms all those values to `all`. This should be safe, because we only send an email now when newsletter_id is not null (scheduled posts should already have a newsletter_id, even if at the time of scheduling they didn't add the newsletter_id option, because at that time, we defaulted to the default newsletter).
Admin changes to make this work: https://github.com/TryGhost/Admin/pull/2380
2022-05-16 11:18:04 +03:00
|
|
|
'email_segment',
|
2021-05-12 17:15:54 +03:00
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
'published_at',
|
|
|
|
'custom_excerpt',
|
|
|
|
'codeinjection_head',
|
|
|
|
'codeinjection_foot',
|
|
|
|
'custom_template',
|
|
|
|
'canonical_url',
|
|
|
|
'url',
|
|
|
|
'primary_tag',
|
|
|
|
'primary_author',
|
|
|
|
'excerpt',
|
|
|
|
'tags',
|
|
|
|
'authors',
|
|
|
|
'email',
|
|
|
|
'og_image',
|
|
|
|
'og_title',
|
|
|
|
'og_description',
|
|
|
|
'twitter_image',
|
|
|
|
'twitter_title',
|
|
|
|
'twitter_description',
|
|
|
|
'meta_title',
|
|
|
|
'meta_description',
|
|
|
|
'email_subject',
|
2021-08-03 09:15:49 +03:00
|
|
|
'frontmatter',
|
2022-01-26 14:26:33 +03:00
|
|
|
'email_only',
|
2022-04-26 14:01:27 +03:00
|
|
|
'tiers',
|
2022-08-25 22:25:01 +03:00
|
|
|
'newsletter',
|
2023-04-18 13:12:35 +03:00
|
|
|
'count',
|
|
|
|
'post_revisions'
|
2021-05-12 17:15:54 +03:00
|
|
|
],
|
2019-02-22 06:17:14 +03:00
|
|
|
|
2021-05-13 14:40:17 +03:00
|
|
|
page: [
|
|
|
|
'id',
|
|
|
|
'uuid',
|
|
|
|
'title',
|
|
|
|
'slug',
|
|
|
|
'mobiledoc',
|
|
|
|
'comment_id',
|
|
|
|
'feature_image',
|
2021-06-10 22:35:56 +03:00
|
|
|
'feature_image_alt',
|
|
|
|
'feature_image_caption',
|
2021-05-13 14:40:17 +03:00
|
|
|
'featured',
|
|
|
|
'status',
|
|
|
|
'visibility',
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
'published_at',
|
|
|
|
'custom_excerpt',
|
|
|
|
'codeinjection_head',
|
|
|
|
'codeinjection_foot',
|
|
|
|
'custom_template',
|
|
|
|
'canonical_url',
|
|
|
|
'url',
|
|
|
|
'primary_tag',
|
|
|
|
'primary_author',
|
|
|
|
'excerpt',
|
|
|
|
'tags',
|
|
|
|
'authors',
|
|
|
|
'og_image',
|
|
|
|
'og_title',
|
|
|
|
'og_description',
|
|
|
|
'twitter_image',
|
|
|
|
'twitter_title',
|
|
|
|
'twitter_description',
|
|
|
|
'meta_title',
|
|
|
|
'meta_description',
|
2022-01-26 14:26:33 +03:00
|
|
|
'frontmatter',
|
2022-08-25 22:25:01 +03:00
|
|
|
'tiers',
|
|
|
|
'count'
|
2021-05-13 14:40:17 +03:00
|
|
|
],
|
2019-02-22 06:17:14 +03:00
|
|
|
|
2018-12-17 19:45:07 +03:00
|
|
|
user: _(schema.users)
|
|
|
|
.keys()
|
2019-02-13 13:41:14 +03:00
|
|
|
.without('visibility')
|
2018-12-17 19:45:07 +03:00
|
|
|
.without('password')
|
2019-02-13 13:41:14 +03:00
|
|
|
.without('locale')
|
2019-03-06 12:17:41 +03:00
|
|
|
.concat('url')
|
2018-12-17 19:45:07 +03:00
|
|
|
,
|
|
|
|
tag: _(schema.tags)
|
|
|
|
.keys()
|
2019-02-12 21:26:31 +03:00
|
|
|
// unused field
|
|
|
|
.without('parent_id')
|
2018-12-17 19:45:07 +03:00
|
|
|
,
|
|
|
|
setting: _(schema.settings)
|
|
|
|
.keys()
|
|
|
|
,
|
2022-02-07 18:04:38 +03:00
|
|
|
member: [
|
|
|
|
'id',
|
|
|
|
'uuid',
|
|
|
|
'email',
|
|
|
|
'status',
|
|
|
|
'name',
|
|
|
|
'note',
|
|
|
|
'geolocation',
|
|
|
|
'subscribed',
|
|
|
|
'email_count',
|
|
|
|
'email_opened_count',
|
|
|
|
'email_open_rate',
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
'avatar_image',
|
|
|
|
'comped',
|
2022-02-22 21:20:31 +03:00
|
|
|
'last_seen_at',
|
2022-02-07 18:04:38 +03:00
|
|
|
'labels'
|
|
|
|
],
|
2020-05-21 20:05:47 +03:00
|
|
|
member_signin_url: ['member_id', 'url'],
|
2018-12-17 19:45:07 +03:00
|
|
|
role: _(schema.roles)
|
|
|
|
.keys()
|
|
|
|
,
|
|
|
|
permission: _(schema.permissions)
|
|
|
|
.keys()
|
|
|
|
,
|
2018-12-17 18:14:36 +03:00
|
|
|
notification: ['type', 'message', 'status', 'id', 'dismissible', 'location', 'custom'],
|
|
|
|
theme: ['name', 'package', 'active'],
|
2018-12-17 19:45:07 +03:00
|
|
|
invite: _(schema.invites)
|
|
|
|
.keys()
|
|
|
|
.without('token')
|
|
|
|
,
|
2018-12-17 18:14:36 +03:00
|
|
|
webhook: _(schema.webhooks)
|
2019-08-19 14:41:09 +03:00
|
|
|
.keys()
|
2019-11-06 09:11:06 +03:00
|
|
|
,
|
|
|
|
email: _(schema.emails)
|
2019-11-08 07:37:53 +03:00
|
|
|
.keys(),
|
2022-04-25 20:38:46 +03:00
|
|
|
email_previews: ['html', 'subject', 'plaintext'],
|
2020-12-11 21:45:35 +03:00
|
|
|
email_recipient: _(schema.email_recipients)
|
|
|
|
.keys()
|
|
|
|
.filter(key => key.indexOf('@@') === -1),
|
2020-10-16 20:02:58 +03:00
|
|
|
snippet: _(schema.snippets).keys()
|
2018-12-17 18:14:36 +03:00
|
|
|
};
|
|
|
|
|
2018-12-17 19:45:07 +03:00
|
|
|
_.each(expectedProperties, (value, key) => {
|
|
|
|
if (!value.__wrapped__) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated: x_by
|
|
|
|
*/
|
|
|
|
expectedProperties[key] = value
|
|
|
|
.without(
|
|
|
|
'created_by',
|
|
|
|
'updated_by',
|
|
|
|
'published_by'
|
|
|
|
)
|
|
|
|
.value();
|
|
|
|
});
|
|
|
|
|
2018-10-07 17:36:02 +03:00
|
|
|
module.exports = {
|
|
|
|
API: {
|
|
|
|
getApiQuery(route) {
|
|
|
|
return url.resolve(API_URL, route);
|
2018-12-17 18:14:36 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
checkResponse(...args) {
|
|
|
|
this.expectedProperties = expectedProperties;
|
|
|
|
return testUtils.API.checkResponse.call(this, ...args);
|
2018-10-07 17:36:02 +03:00
|
|
|
}
|
2018-10-09 06:24:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
doAuth(...args) {
|
|
|
|
return testUtils.API.doAuth(`${API_URL}session/`, ...args);
|
2019-01-18 19:36:11 +03:00
|
|
|
},
|
|
|
|
|
2022-08-09 13:15:30 +03:00
|
|
|
getValidAdminToken(audience, keyid = 0) {
|
2019-01-18 19:36:11 +03:00
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
const JWT_OPTIONS = {
|
2022-08-09 13:15:30 +03:00
|
|
|
keyid: testUtils.DataGenerator.Content.api_keys[keyid].id,
|
2019-01-23 15:22:47 +03:00
|
|
|
algorithm: 'HS256',
|
2019-01-23 20:08:57 +03:00
|
|
|
expiresIn: '5m',
|
2019-02-23 14:51:21 +03:00
|
|
|
audience: audience
|
2019-01-18 19:36:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return jwt.sign(
|
2019-02-26 07:03:47 +03:00
|
|
|
{},
|
2022-08-09 13:15:30 +03:00
|
|
|
Buffer.from(testUtils.DataGenerator.Content.api_keys[keyid].secret, 'hex'),
|
2019-01-23 15:22:47 +03:00
|
|
|
JWT_OPTIONS
|
2019-01-18 19:36:11 +03:00
|
|
|
);
|
2021-11-18 11:38:55 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
async startGhost(overrides = {}) {
|
|
|
|
const defaults = {
|
2021-11-22 09:51:54 +03:00
|
|
|
backend: true,
|
|
|
|
frontend: false
|
2021-11-18 11:38:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return await testUtils.startGhost(Object.assign(defaults, overrides));
|
2018-10-07 17:36:02 +03:00
|
|
|
}
|
|
|
|
};
|