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

Commit

Permalink
Add v3.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickRe committed Jul 8, 2020
1 parent 26b74d0 commit 25853df
Show file tree
Hide file tree
Showing 46 changed files with 1,388 additions and 370 deletions.

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

603 changes: 582 additions & 21 deletions core/frontend/apps/amp/lib/views/amp.hbs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion core/server/api/canary/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = {
labs: labs.getAll(),
clientExtensions: config.get('clientExtensions') || {},
enableDeveloperExperiments: config.get('enableDeveloperExperiments') || false,
stripeDirect: config.get('stripeDirect')
stripeDirect: config.get('stripeDirect'),
mailgunIsConfigured: config.get('bulkEmail') && config.get('bulkEmail').mailgun
};
if (billingUrl) {
response.billingUrl = billingUrl;
Expand Down
4 changes: 4 additions & 0 deletions core/server/api/canary/utils/serializers/input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ module.exports = {

get members() {
return require('./members');
},

get webhooks() {
return require('./webhooks');
}
};
2 changes: 1 addition & 1 deletion core/server/api/canary/utils/serializers/input/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ module.exports = {

async importCSV(apiConfig, frame) {
debug('importCSV');
frame.data.members = await parse(frame.file.path);
frame.data.members = await parse(frame.file.path, frame.data.mapping);
}
};
12 changes: 5 additions & 7 deletions core/server/api/canary/utils/serializers/input/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ module.exports = {
return !settingFlagsArr.includes('RO');
});

frame.data.settings = frame.data.settings.filter((setting) => {
return setting.key !== 'bulk_email_settings';
});

frame.data.settings.forEach((setting) => {
// CASE: transform objects/arrays into string (we store stringified objects in the db)
// @TODO: This belongs into the model layer. We should stringify before saving and parse when fetching from db.
Expand Down Expand Up @@ -87,15 +91,9 @@ module.exports = {
setting.key = 'lang';
}

if (['cover_image', 'icon', 'logo'].includes(setting.key)) {
if (['cover_image', 'icon', 'logo', 'portal_button_icon'].includes(setting.key)) {
setting = url.forSetting(setting);
}

//CASE: Ensure we don't store calculated fields `isEnabled/Config` in bulk email settings
if (setting.key === 'bulk_email_settings') {
const {apiKey = '', domain = '', baseUrl = '', provider = 'mailgun'} = setting.value ? JSON.parse(setting.value) : {};
setting.value = JSON.stringify({apiKey, domain, baseUrl, provider});
}
});
}
};
12 changes: 12 additions & 0 deletions core/server/api/canary/utils/serializers/input/webhooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const _ = require('lodash');
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:webhooks');

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

if (_.get(frame, 'options.context.api_key.id')) {
frame.data.webhooks[0].integration_id = frame.options.context.api_key.id;
}
}
};
22 changes: 0 additions & 22 deletions core/server/api/canary/utils/serializers/output/utils/clean.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const _ = require('lodash');
const localUtils = require('../../../index');
const config = require('../../../../../../../shared/config');

const tag = (attrs, frame) => {
if (localUtils.isContentAPI(frame)) {
Expand Down Expand Up @@ -143,28 +142,7 @@ const action = (attrs) => {
}
};

const settings = (attrs) => {
if (_.isArray(attrs)) {
attrs.forEach((attr) => {
if (attr.key === 'bulk_email_settings') {
const {provider, apiKey, domain, baseUrl} = attr.value ? JSON.parse(attr.value) : {};

const bulkEmailConfig = config.get('bulkEmail');
const hasMailgunConfig = !!(bulkEmailConfig && bulkEmailConfig.mailgun);
const hasMailgunSetting = !!(apiKey && baseUrl && domain);

attr.value = JSON.stringify({
provider, apiKey, domain, baseUrl,
isEnabled: (hasMailgunConfig || hasMailgunSetting),
isConfig: hasMailgunConfig
});
}
});
}
};

module.exports.post = post;
module.exports.tag = tag;
module.exports.author = author;
module.exports.action = action;
module.exports.settings = settings;
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const mapPage = (model, frame) => {
const mapSettings = (attrs, frame) => {
url.forSettings(attrs);
extraAttrs.forSettings(attrs, frame);
clean.settings(attrs, frame);

// NOTE: The cleanup of deprecated ghost_head/ghost_foot has to happen here
// because codeinjection_head/codeinjection_foot are assigned on a previous
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const forSettings = (attrs) => {
// @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) {
if (['cover_image', 'logo', 'icon', 'portal_button_icon'].includes(obj.key) && obj.value) {
obj.value = urlUtils.urlFor('image', {image: obj.value}, true);
}
});
Expand Down
43 changes: 43 additions & 0 deletions core/server/api/canary/utils/validators/input/schemas/tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,49 @@
"type": ["string", "null"],
"maxLength": 500
},
"og_image": {
"type": ["string", "null"],
"format": "uri-reference",
"maxLength": 2000
},
"og_title": {
"type": ["string", "null"],
"maxLength": 300
},
"og_description": {
"type": ["string", "null"],
"maxLength": 500
},
"twitter_image": {
"type": ["string", "null"],
"format": "uri-reference",
"maxLength": 2000
},
"twitter_title": {
"type": ["string", "null"],
"maxLength": 300
},
"twitter_description": {
"type": ["string", "null"],
"maxLength": 500
},
"codeinjection_head": {
"type": ["string", "null"],
"maxLength": 65535
},
"codeinjection_foot": {
"type": ["string", "null"],
"maxLength": 65535
},
"canonical_url": {
"type": ["string", "null"],
"format": "uri-reference",
"maxLength": 2000
},
"accent_color": {
"type": ["string", "null"],
"maxLength": 50
},
"id": {
"strip": true
},
Expand Down
40 changes: 38 additions & 2 deletions core/server/api/canary/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,25 @@ module.exports = {
},

edit: {
permissions: true,
permissions: {
before: (frame) => {
if (frame.options.context && frame.options.context.api_key && frame.options.context.api_key.id) {
return models.Webhook.findOne({id: frame.options.id})
.then((webhook) => {
if (webhook.get('integration_id') !== frame.options.context.api_key.id) {
throw new errors.NoPermissionError({
message: i18n.t('errors.api.webhooks.noPermissionToEdit.message', {
method: 'edit'
}),
context: i18n.t('errors.api.webhooks.noPermissionToEdit.context', {
method: 'edit'
})
});
}
});
}
}
},
data: [
'name',
'event',
Expand Down Expand Up @@ -82,7 +100,25 @@ module.exports = {
}
}
},
permissions: true,
permissions: {
before: (frame) => {
if (frame.options.context && frame.options.context.api_key && frame.options.context.api_key.id) {
return models.Webhook.findOne({id: frame.options.id})
.then((webhook) => {
if (webhook.get('integration_id') !== frame.options.context.api_key.id) {
throw new errors.NoPermissionError({
message: i18n.t('errors.api.webhooks.noPermissionToEdit.message', {
method: 'destory'
}),
context: i18n.t('errors.api.webhooks.noPermissionToEdit.context', {
method: 'destroy'
})
});
}
});
}
}
},
query(frame) {
frame.options.require = true;

Expand Down
4 changes: 4 additions & 0 deletions core/server/api/v2/utils/serializers/input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ module.exports = {

get tags() {
return require('./tags');
},

get webhooks() {
return require('./webhooks');
}
};
4 changes: 4 additions & 0 deletions core/server/api/v2/utils/serializers/input/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ module.exports = {
return !settingFlagsArr.includes('RO');
});

frame.data.settings = frame.data.settings.filter((setting) => {
return setting.key !== 'bulk_email_settings';
});

frame.data.settings.forEach((setting) => {
const settingType = settings[setting.key] ? settings[setting.key].type : '';

Expand Down
12 changes: 12 additions & 0 deletions core/server/api/v2/utils/serializers/input/webhooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const _ = require('lodash');
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:webhooks');

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

if (_.get(frame, 'options.context.api_key.id')) {
frame.data.webhooks[0].integration_id = frame.options.context.api_key.id;
}
}
};
42 changes: 30 additions & 12 deletions core/server/api/v2/utils/serializers/output/utils/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@ const localUtils = require('../../../index');

const tag = (attrs, frame) => {
if (localUtils.isContentAPI(frame)) {
delete attrs.created_at;
delete attrs.updated_at;
const contentAttrs = _.pick(attrs, [
'description',
'feature_image',
'id',
'meta_description',
'meta_title',
'name',
'slug',
'url',
'visibility'
]);

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

delete attrs.parent_id;
delete attrs.parent;

return attrs;
return _.pick(attrs, [
'created_at',
'description',
'feature_image',
'id',
'meta_description',
'meta_title',
'name',
'slug',
'updated_at',
'url',
'visibility'
]);
};

const author = (attrs, frame) => {
Expand Down
4 changes: 2 additions & 2 deletions core/server/api/v2/utils/serializers/output/utils/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const mapTag = (model, frame) => {
const jsonModel = model.toJSON ? model.toJSON(frame.options) : model;

url.forTag(model.id, jsonModel, frame.options);
clean.tag(jsonModel, frame);
const cleanedAttrs = clean.tag(jsonModel, frame);

return jsonModel;
return cleanedAttrs;
};

const mapPost = (model, frame) => {
Expand Down
40 changes: 38 additions & 2 deletions core/server/api/v2/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,25 @@ module.exports = {
},

edit: {
permissions: true,
permissions: {
before: (frame) => {
if (frame.options.context && frame.options.context.api_key && frame.options.context.api_key.id) {
return models.Webhook.findOne({id: frame.options.id})
.then((webhook) => {
if (webhook.get('integration_id') !== frame.options.context.api_key.id) {
throw new errors.NoPermissionError({
message: i18n.t('errors.api.webhooks.noPermissionToEdit.message', {
method: 'edit'
}),
context: i18n.t('errors.api.webhooks.noPermissionToEdit.context', {
method: 'edit'
})
});
}
});
}
}
},
data: [
'name',
'event',
Expand Down Expand Up @@ -82,7 +100,25 @@ module.exports = {
}
}
},
permissions: true,
permissions: {
before: (frame) => {
if (frame.options.context && frame.options.context.api_key && frame.options.context.api_key.id) {
return models.Webhook.findOne({id: frame.options.id})
.then((webhook) => {
if (webhook.get('integration_id') !== frame.options.context.api_key.id) {
throw new errors.NoPermissionError({
message: i18n.t('errors.api.webhooks.noPermissionToEdit.message', {
method: 'destory'
}),
context: i18n.t('errors.api.webhooks.noPermissionToEdit.context', {
method: 'destroy'
})
});
}
});
}
}
},
query(frame) {
frame.options.require = true;
return models.Webhook.destroy(frame.options)
Expand Down
2 changes: 1 addition & 1 deletion core/server/data/importer/importers/data/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class SettingsImporter extends BaseImporter {
});

this.dataToImport = _.filter(this.dataToImport, (data) => {
return !(['members_subscription_settings', 'stripe_connect_integration'].includes(data.key));
return !(['members_subscription_settings', 'stripe_connect_integration', 'bulk_email_settings'].includes(data.key));
});

// Only show warning if we are importing a private site into a non-private site.
Expand Down
Loading

0 comments on commit 25853df

Please sign in to comment.