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

Commit 91b010b

Browse files
committed
Add v2.20.1
1 parent a048bd7 commit 91b010b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+623
-335
lines changed

content/settings/routes.yaml

-10
This file was deleted.

core/built/assets/ghost-dark-394b326a3ce924e57089bb0afc4a3b62.css

-1
This file was deleted.

core/built/assets/ghost-dark-73414ae9099bf2837244be76964c3b76.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/built/assets/ghost.min-36f6ee722222b21f27a4cc1bed53434d.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/built/assets/ghost.min-e99c34c338db469b1d5fde30cb1006f5.js core/built/assets/ghost.min-3d890d4d1611b7eaf06ea4a26d9a43a2.js

+53-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/built/assets/ghost.min-ea8c00eaf0b14ad500f73569099bbc4f.css

-1
This file was deleted.

core/server/api/v2/members.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const memberUserObject = require('../../services/members').api.memberUserObject;
1+
const memberUserObject = require('../../services/members').api.members;
22

33
const members = {
44
docName: 'members',

core/server/api/v2/notifications.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,25 @@ module.exports = {
3030
allNotifications = _.orderBy(allNotifications, 'addedAt', 'desc');
3131

3232
allNotifications = allNotifications.filter((notification) => {
33+
// NOTE: Filtering by version below is just a patch for bigger problem - notifications are not removed
34+
// after Ghost update. Logic below should be removed when Ghost upgrade detection
35+
// is done (https://github.com/TryGhost/Ghost/issues/10236) and notifications are
36+
// be removed permanently on upgrade event.
37+
const ghost20RegEx = /Ghost 2.0 is now available/gi;
38+
3339
// CASE: do not return old release notification
34-
if (!notification.custom && notification.message) {
35-
const notificationVersion = notification.message.match(/(\d+\.)(\d+\.)(\d+)/),
36-
blogVersion = ghostVersion.full.match(/^(\d+\.)(\d+\.)(\d+)/);
40+
if (notification.message && (!notification.custom || notification.message.match(ghost20RegEx))) {
41+
let notificationVersion = notification.message.match(/(\d+\.)(\d+\.)(\d+)/);
42+
43+
if (notification.message.match(ghost20RegEx)) {
44+
notificationVersion = '2.0.0';
45+
} else if (notificationVersion){
46+
notificationVersion = notificationVersion[0];
47+
}
48+
49+
const blogVersion = ghostVersion.full.match(/^(\d+\.)(\d+\.)(\d+)/);
3750

38-
if (notificationVersion && blogVersion && semver.gt(notificationVersion[0], blogVersion[0])) {
51+
if (notificationVersion && blogVersion && semver.gt(notificationVersion, blogVersion[0])) {
3952
return true;
4053
} else {
4154
return false;

core/server/api/v2/settings.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ const urlService = require('../../services/url');
99
const common = require('../../lib/common');
1010
const settingsCache = require('../../services/settings/cache');
1111

12+
const SETTINGS_BLACKLIST = [
13+
'members_public_key',
14+
'members_private_key',
15+
'members_session_secret'
16+
];
17+
1218
module.exports = {
1319
docName: 'settings',
1420

@@ -28,7 +34,9 @@ module.exports = {
2834
// CASE: omit core settings unless internal request
2935
if (!frame.options.context.internal) {
3036
settings = _.filter(settings, (setting) => {
31-
return setting.type !== 'core';
37+
const isCore = setting.type === 'core';
38+
const isBlacklisted = SETTINGS_BLACKLIST.includes(setting.key);
39+
return !isBlacklisted && !isCore;
3240
});
3341
}
3442

core/server/data/schema/default-settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
},
1212
"session_secret": {
1313
"defaultValue": null
14+
},
15+
"theme_session_secret": {
16+
"defaultValue": null
1417
}
1518
},
1619
"blog": {

core/server/lib/members/index.js

+63-31
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ module.exports = function MembersApi({
1414
privateKey,
1515
publicKey,
1616
sessionSecret,
17-
ssoOrigin
17+
ssoOrigin,
18+
accessControl
1819
},
1920
paymentConfig,
20-
validateAudience,
2121
createMember,
2222
validateMember,
2323
updateMember,
@@ -53,6 +53,20 @@ module.exports = function MembersApi({
5353
/* session */
5454
const {getCookie, setCookie, removeCookie} = Cookies(sessionSecret);
5555

56+
function validateAccess({audience, origin}) {
57+
const audienceLookup = accessControl[origin] || {
58+
[origin]: accessControl['*']
59+
};
60+
61+
const tokenSettings = audienceLookup[audience];
62+
63+
if (tokenSettings) {
64+
return Promise.resolve(tokenSettings);
65+
}
66+
67+
return Promise.reject();
68+
}
69+
5670
/* token */
5771
apiRouter.post('/token', getData('audience'), (req, res) => {
5872
const {signedin} = getCookie(req);
@@ -65,19 +79,16 @@ module.exports = function MembersApi({
6579

6680
const {audience, origin} = req.data;
6781

68-
validateAudience({audience, origin, id: signedin})
69-
.then(() => {
70-
return users.get({id: signedin});
82+
validateAccess({audience, origin})
83+
.then(({tokenLength}) => {
84+
return users.get({id: signedin})
85+
.then(member => encodeToken({
86+
sub: member.id,
87+
plans: member.subscriptions.map(sub => sub.plan),
88+
exp: tokenLength,
89+
aud: audience
90+
}));
7191
})
72-
.then(member => encodeToken({
73-
sub: member.id,
74-
plans: member.subscriptions.map(sub => sub.plan),
75-
exp: member.subscriptions
76-
.map(sub => sub.validUntil)
77-
.reduce((a, b) => Math.min(a, b),
78-
Math.floor((Date.now() / 1000) + (60 * 60 * 24 * 30))),
79-
aud: audience
80-
}))
8192
.then(token => res.end(token))
8293
.catch(handleError(403, res));
8394
});
@@ -89,9 +100,10 @@ module.exports = function MembersApi({
89100
return subscriptions.getPublicConfig(adapter);
90101
}));
91102
})
92-
.then(data => res.json({
93-
paymentConfig: data,
94-
siteConfig: siteConfig
103+
.then(paymentConfig => res.json({
104+
paymentConfig,
105+
issuer,
106+
siteConfig
95107
}))
96108
.catch(handleError(500, res));
97109
});
@@ -106,7 +118,7 @@ module.exports = function MembersApi({
106118
}
107119

108120
/* subscriptions */
109-
apiRouter.post('/subscription', getData('adapter', 'plan', 'stripeToken'), ssoOriginCheck, (req, res) => {
121+
apiRouter.post('/subscription', getData('adapter', 'plan', 'stripeToken', {name: 'coupon', required: false}), ssoOriginCheck, (req, res) => {
110122
const {signedin} = getCookie(req);
111123
if (!signedin) {
112124
res.writeHead(401, {
@@ -115,7 +127,7 @@ module.exports = function MembersApi({
115127
return res.end();
116128
}
117129

118-
const {plan, adapter, stripeToken} = req.data;
130+
const {plan, adapter, stripeToken, coupon} = req.data;
119131

120132
subscriptions.getAdapters()
121133
.then((adapters) => {
@@ -128,7 +140,8 @@ module.exports = function MembersApi({
128140
return subscriptions.createSubscription(member, {
129141
adapter,
130142
plan,
131-
stripeToken
143+
stripeToken,
144+
coupon
132145
});
133146
})
134147
.then(() => {
@@ -195,9 +208,19 @@ module.exports = function MembersApi({
195208
/* http */
196209
const staticRouter = Router();
197210
staticRouter.use('/static', static(require('path').join(__dirname, './static/auth/dist')));
198-
staticRouter.use('/gateway', static(require('path').join(__dirname, './static/gateway')));
211+
staticRouter.get('/gateway', (req, res) => {
212+
res.status(200).send(`
213+
<script>
214+
window.membersApiUrl = "${issuer}";
215+
</script>
216+
<script src="bundle.js"></script>
217+
`);
218+
});
219+
staticRouter.get('/bundle.js', (req, res) => {
220+
res.status(200).sendFile(require('path').join(__dirname, './static/gateway/bundle.js'));
221+
});
199222
staticRouter.get('/*', (req, res) => {
200-
res.sendFile(require('path').join(__dirname, './static/auth/dist/index.html'));
223+
res.status(200).sendFile(require('path').join(__dirname, './static/auth/dist/index.html'));
201224
});
202225

203226
/* http */
@@ -210,14 +233,23 @@ module.exports = function MembersApi({
210233
});
211234
});
212235

213-
function httpHandler(req, res, next) {
214-
return router.handle(req, res, next);
215-
}
216-
217-
httpHandler.staticRouter = staticRouter;
218-
httpHandler.apiRouter = apiRouter;
219-
httpHandler.memberUserObject = users;
220-
httpHandler.reconfigureSettings = function (data) {
236+
const apiInstance = {
237+
staticRouter,
238+
apiRouter
239+
};
240+
apiInstance.members = users;
241+
apiInstance.getPublicConfig = function () {
242+
return Promise.resolve({
243+
publicKey,
244+
issuer
245+
});
246+
};
247+
apiInstance.getMember = function (id, token) {
248+
return decodeToken(token).then(() => {
249+
return users.get({id});
250+
});
251+
};
252+
apiInstance.reconfigureSettings = function (data) {
221253
subscriptions = new Subscriptions(data.paymentConfig);
222254
users = Users({
223255
subscriptions,
@@ -233,5 +265,5 @@ module.exports = function MembersApi({
233265
siteConfig = data.siteConfig;
234266
};
235267

236-
return httpHandler;
268+
return apiInstance;
237269
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import FormInput from './FormInput';
2+
import { IconName } from './icons';
3+
4+
export default ({value, disabled, error, children, onInput, className}) => (
5+
<FormInput
6+
type="text"
7+
name="coupon"
8+
label="coupon"
9+
value={value}
10+
error={error}
11+
icon={IconName}
12+
placeholder="Coupon..."
13+
required={false}
14+
disabled={disabled}
15+
className={className}
16+
onInput={onInput}>
17+
{children}
18+
</FormInput>
19+
);

core/server/lib/members/static/auth/components/Form.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export default class Form extends Component {
5656
return (e) => {
5757
e.preventDefault();
5858

59-
const requiredFields = children.map(c => c.attributes.bindTo).filter(x => !!x)
60-
if (!requiredFields.some(x => !data[x])) {
59+
const requiredFields = children.map(c => c.attributes && c.attributes.bindTo).filter(x => !!x)
60+
if (!requiredFields.some(x => data[x] == null)) {
6161
onSubmit(this.state.data)
6262
}
6363
this.setState({

core/server/lib/members/static/auth/components/FormInput.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default ({type, name, placeholder, value = '', error, onInput, required, className, children, icon}) => (
1+
export default ({type, name, placeholder, value = '', error, onInput, required, disabled = false, className, children, icon}) => (
22
<div className="gm-form-element">
33
<div className={[
44
(className ? className : ""),
@@ -12,6 +12,7 @@ export default ({type, name, placeholder, value = '', error, onInput, required,
1212
value={ value }
1313
onInput={ (e) => onInput(e, name) }
1414
required={ required }
15+
disabled={ disabled }
1516
className={[
1617
(value ? "gm-input-filled" : ""),
1718
(error ? "gm-error" : "")

0 commit comments

Comments
 (0)