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

Commit

Permalink
Add v3.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickRe committed Jun 22, 2020
1 parent 2eb0af6 commit 2fb0400
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 251 deletions.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

54 changes: 18 additions & 36 deletions core/server/api/canary/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const membersService = require('../../services/members');
const settingsCache = require('../../services/settings/cache');
const {i18n} = require('../../lib/common');
const logging = require('../../../shared/logging');
const fsLib = require('../../lib/fs');
const db = require('../../data/db');
const _ = require('lodash');

Expand Down Expand Up @@ -123,6 +122,19 @@ const createLabels = async (labels, options) => {

const members = {
docName: 'members',

hasActiveStripeSubscriptions: {
permissions: {
method: 'browse'
},
async query() {
const hasActiveStripeSubscriptions = await membersService.api.hasActiveStripeSubscriptions();
return {
hasActiveStripeSubscriptions
};
}
},

browse: {
options: [
'limit',
Expand Down Expand Up @@ -387,7 +399,6 @@ const members = {
method: 'add'
},
async query(frame) {
let filePath = frame.file.path;
let imported = {
count: 0
};
Expand All @@ -397,43 +408,14 @@ const members = {
};
let duplicateStripeCustomerIdCount = 0;

const columnsToExtract = [{
name: 'email',
lookup: /^email/i
}, {
name: 'name',
lookup: /name/i
}, {
name: 'note',
lookup: /note/i
}, {
name: 'subscribed_to_emails',
lookup: /subscribed_to_emails/i
}, {
name: 'stripe_customer_id',
lookup: /stripe_customer_id/i
}, {
name: 'complimentary_plan',
lookup: /complimentary_plan/i
}, {
name: 'labels',
lookup: /labels/i
}, {
name: 'created_at',
lookup: /created_at/i
}];

// NOTE: custom labels have to be created in advance otherwise there are conflicts
// when processing member creation in parallel later on in import process
const importSetLabels = serializeMemberLabels(frame.data.labels);
await createLabels(importSetLabels, frame.options);

return fsLib.readCSV({
path: filePath,
columnsToExtract: columnsToExtract
}).then((result) => {
const sanitized = sanitizeInput(result);
duplicateStripeCustomerIdCount = result.length - sanitized.length;
return Promise.resolve().then(() => {
const sanitized = sanitizeInput(frame.data.members);
duplicateStripeCustomerIdCount = frame.data.members.length - sanitized.length;
invalid.count += duplicateStripeCustomerIdCount;

if (duplicateStripeCustomerIdCount) {
Expand Down Expand Up @@ -488,13 +470,13 @@ const members = {
// for this reason we have to make sure any unexpected errors are logged here
if (Array.isArray(error)) {
logging.error(error[0]);
invalid.errors.push(...error);
} else {
logging.error(error);
invalid.errors.push(error);
}

invalid.count = invalid.count + 1;

invalid.errors.push(error);
}
});
}).then(() => {
Expand Down
19 changes: 19 additions & 0 deletions core/server/api/canary/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ module.exports = {
}
},

disconnectStripeConnectIntegration: {
permissions: {
method: 'edit'
},
async query(frame) {
const hasActiveStripeSubscriptions = await membersService.api.hasActiveStripeSubscriptions();
if (hasActiveStripeSubscriptions) {
throw new BadRequestError({
message: 'Cannot disconnect Stripe whilst you have active subscriptions.'
});
}

return models.Settings.edit({
key: 'stripe_connect_integration',
value: '{}'
}, frame.options);
}
},

edit: {
headers: {
cacheInvalidate: true
Expand Down
6 changes: 6 additions & 0 deletions core/server/api/canary/utils/serializers/input/members.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash');
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:members');
const {parse} = require('@tryghost/members-csv');

function defaultRelations(frame) {
if (frame.options.withRelated) {
Expand Down Expand Up @@ -42,5 +43,10 @@ module.exports = {
edit(apiConfig, frame) {
debug('edit');
this.add(apiConfig, frame);
},

async importCSV(apiConfig, frame) {
debug('importCSV');
frame.data.members = await parse(frame.file.path);
}
};
32 changes: 6 additions & 26 deletions core/server/api/canary/utils/serializers/output/members.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const _ = require('lodash');
const {i18n} = require('../../../../../lib/common');
const errors = require('@tryghost/errors');
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:output:members');
const mapper = require('./utils/mapper');
const papaparse = require('papaparse');
const {unparse} = require('@tryghost/members-csv');

module.exports = {
hasActiveStripeSubscriptions(data, apiConfig, frame) {
frame.response = data;
},
browse(data, apiConfig, frame) {
debug('browse');

Expand Down Expand Up @@ -49,32 +51,10 @@ module.exports = {
debug('exportCSV');

const members = data.members.map((member) => {
member = mapper.mapMember(member, frame);
let stripeCustomerId;

if (member.stripe) {
stripeCustomerId = _.get(member, 'stripe.subscriptions[0].customer.id');
}
let labels = [];
if (member.labels) {
labels = `${member.labels.map(l => l.name).join(',')}`;
}

return {
id: member.id,
email: member.email,
name: member.name,
note: member.note,
subscribed_to_emails: member.subscribed,
complimentary_plan: member.comped,
stripe_customer_id: stripeCustomerId,
created_at: member.created_at,
deleted_at: member.deleted_at,
labels: labels
};
return mapper.mapMember(member, frame);
});

frame.response = papaparse.unparse(members);
frame.response = unparse(members);
},

importCSV(data, apiConfig, frame) {
Expand Down
19 changes: 19 additions & 0 deletions core/server/data/schema/default-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@
"defaultValue": "{}"
}
},
"portal" : {
"portal_name": {
"defaultValue": "true",
"validations": {
"isEmpty": false,
"isIn": [["true", "false"]]
}
},
"portal_button": {
"defaultValue": "true",
"validations": {
"isEmpty": false,
"isIn": [["true", "false"]]
}
},
"portal_plans": {
"defaultValue": "[\"free\", \"monthly\", \"yearly\"]"
}
},
"bulk_email": {
"bulk_email_settings": {
"defaultValue": "{\"provider\":\"mailgun\", \"apiKey\": \"\", \"domain\": \"\", \"baseUrl\": \"\"}"
Expand Down
2 changes: 1 addition & 1 deletion core/server/data/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ module.exports = {
maxlength: 50,
nullable: false,
defaultTo: 'core',
validations: {isIn: [['core', 'blog', 'theme', 'private', 'members', 'bulk_email']]}
validations: {isIn: [['core', 'blog', 'theme', 'private', 'members', 'bulk_email', 'portal']]}
},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
Expand Down
5 changes: 0 additions & 5 deletions core/server/lib/fs/index.js

This file was deleted.

56 changes: 0 additions & 56 deletions core/server/lib/fs/read-csv.js

This file was deleted.

11 changes: 8 additions & 3 deletions core/server/services/members/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ const getMemberSiteData = async function (req, res) {
);
const stripeSecretToken = stripePaymentProcessor && stripePaymentProcessor.config.secret_token;
const stripePublicToken = stripePaymentProcessor && stripePaymentProcessor.config.public_token;
const isStripeConfigured = (!!stripeSecretToken && stripeSecretToken !== '' && !!stripePublicToken && stripePublicToken !== '');
const stripeConnectIntegration = settingsCache.get('stripe_connect_integration');

const isStripeConfigured = (!!stripeSecretToken && !!stripePublicToken) || !!(stripeConnectIntegration && stripeConnectIntegration.account_id);
const response = {
title: settingsCache.get('title'),
description: settingsCache.get('description'),
Expand All @@ -98,8 +100,11 @@ const getMemberSiteData = async function (req, res) {
url: urlUtils.urlFor('home', true),
version: ghostVersion.safe,
plans: membersService.config.getPublicPlans(),
allowSelfSignup: membersService.config.getAllowSelfSignup(),
isStripeConfigured
allow_self_signup: membersService.config.getAllowSelfSignup(),
is_stripe_configured: isStripeConfigured,
portal_button: settingsCache.get('portal_button'),
portal_name: settingsCache.get('portal_name'),
portal_plans: settingsCache.get('portal_plans')
};

// Brand is currently an experimental feature
Expand Down
6 changes: 3 additions & 3 deletions core/server/web/admin/views/default-prod.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title>Ghost Admin</title>


<meta name="ghost-admin/config/environment" content="%7B%22modulePrefix%22%3A%22ghost-admin%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22trailing-hash%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%2C%22Array%22%3Atrue%2C%22String%22%3Atrue%2C%22Function%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_JQUERY_INTEGRATION%22%3Atrue%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22version%22%3A%223.20%22%2C%22name%22%3A%22ghost-admin%22%7D%2C%22ember-simple-auth%22%3A%7B%7D%2C%22moment%22%3A%7B%22includeTimezone%22%3A%22all%22%7D%2C%22ember-cli-mirage%22%3A%7B%22usingProxy%22%3Afalse%2C%22useDefaultPassthroughs%22%3Atrue%7D%2C%22exportApplicationGlobal%22%3Afalse%2C%22ember-load%22%3A%7B%22loadingIndicatorClass%22%3A%22ember-load-indicator%22%7D%7D" />
<meta name="ghost-admin/config/environment" content="%7B%22modulePrefix%22%3A%22ghost-admin%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22trailing-hash%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%2C%22Array%22%3Atrue%2C%22String%22%3Atrue%2C%22Function%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_JQUERY_INTEGRATION%22%3Atrue%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22version%22%3A%223.21%22%2C%22name%22%3A%22ghost-admin%22%7D%2C%22ember-simple-auth%22%3A%7B%7D%2C%22moment%22%3A%7B%22includeTimezone%22%3A%22all%22%7D%2C%22ember-cli-mirage%22%3A%7B%22usingProxy%22%3Afalse%2C%22useDefaultPassthroughs%22%3Atrue%7D%2C%22exportApplicationGlobal%22%3Afalse%2C%22ember-load%22%3A%7B%22loadingIndicatorClass%22%3A%22ember-load-indicator%22%7D%7D" />

<meta name="HandheldFriendly" content="True" />
<meta name="MobileOptimized" content="320" />
Expand All @@ -34,7 +34,7 @@


<link rel="stylesheet" href="assets/vendor.min-59d06862d7441e413f92fcc5c41f807e.css">
<link rel="stylesheet" href="assets/ghost.min-07263cc90498d80408a31e18b48a10a8.css" title="light">
<link rel="stylesheet" href="assets/ghost.min-91b0f63b70e88354c76448098edb6c3e.css" title="light">



Expand All @@ -53,7 +53,7 @@


<script src="assets/vendor.min-f56780de5125e2a9ff22d96dd6d15441.js"></script>
<script src="assets/ghost.min-c678601d8dc76853547c6bf8a0b0f1b1.js"></script>
<script src="assets/ghost.min-3c26713e823b994471ac83f5b1685522.js"></script>

</body>
</html>
6 changes: 3 additions & 3 deletions core/server/web/admin/views/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title>Ghost Admin</title>


<meta name="ghost-admin/config/environment" content="%7B%22modulePrefix%22%3A%22ghost-admin%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22trailing-hash%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%2C%22Array%22%3Atrue%2C%22String%22%3Atrue%2C%22Function%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_JQUERY_INTEGRATION%22%3Atrue%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22version%22%3A%223.20%22%2C%22name%22%3A%22ghost-admin%22%7D%2C%22ember-simple-auth%22%3A%7B%7D%2C%22moment%22%3A%7B%22includeTimezone%22%3A%22all%22%7D%2C%22ember-cli-mirage%22%3A%7B%22usingProxy%22%3Afalse%2C%22useDefaultPassthroughs%22%3Atrue%7D%2C%22exportApplicationGlobal%22%3Afalse%2C%22ember-load%22%3A%7B%22loadingIndicatorClass%22%3A%22ember-load-indicator%22%7D%7D" />
<meta name="ghost-admin/config/environment" content="%7B%22modulePrefix%22%3A%22ghost-admin%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22trailing-hash%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%2C%22Array%22%3Atrue%2C%22String%22%3Atrue%2C%22Function%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_JQUERY_INTEGRATION%22%3Atrue%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22version%22%3A%223.21%22%2C%22name%22%3A%22ghost-admin%22%7D%2C%22ember-simple-auth%22%3A%7B%7D%2C%22moment%22%3A%7B%22includeTimezone%22%3A%22all%22%7D%2C%22ember-cli-mirage%22%3A%7B%22usingProxy%22%3Afalse%2C%22useDefaultPassthroughs%22%3Atrue%7D%2C%22exportApplicationGlobal%22%3Afalse%2C%22ember-load%22%3A%7B%22loadingIndicatorClass%22%3A%22ember-load-indicator%22%7D%7D" />

<meta name="HandheldFriendly" content="True" />
<meta name="MobileOptimized" content="320" />
Expand All @@ -34,7 +34,7 @@


<link rel="stylesheet" href="assets/vendor.min-59d06862d7441e413f92fcc5c41f807e.css">
<link rel="stylesheet" href="assets/ghost.min-07263cc90498d80408a31e18b48a10a8.css" title="light">
<link rel="stylesheet" href="assets/ghost.min-91b0f63b70e88354c76448098edb6c3e.css" title="light">



Expand All @@ -53,7 +53,7 @@


<script src="assets/vendor.min-f56780de5125e2a9ff22d96dd6d15441.js"></script>
<script src="assets/ghost.min-c678601d8dc76853547c6bf8a0b0f1b1.js"></script>
<script src="assets/ghost.min-3c26713e823b994471ac83f5b1685522.js"></script>

</body>
</html>
3 changes: 3 additions & 0 deletions core/server/web/api/canary/admin/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = function apiRoutes() {
router.put('/settings', mw.authAdminApi, http(apiCanary.settings.edit));
router.get('/settings/members/email', http(apiCanary.settings.validateMembersFromEmail));
router.post('/settings/members/email', mw.authAdminApi, http(apiCanary.settings.updateMembersFromEmail));
router.del('/settings/stripe/connect', mw.authAdminApi, http(apiCanary.settings.disconnectStripeConnectIntegration));

// ## Users
router.get('/users', mw.authAdminApi, http(apiCanary.users.browse));
Expand Down Expand Up @@ -100,6 +101,8 @@ module.exports = function apiRoutes() {
http(apiCanary.members.importCSV)
);

router.get('/members/hasActiveStripeSubscriptions', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.hasActiveStripeSubscriptions));

router.get('/members/stripe_connect', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.membersStripeConnect.auth));

router.get('/members/:id', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.read));
Expand Down
Loading

0 comments on commit 2fb0400

Please sign in to comment.