mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
Disabled portal and stripe in {{ghost_head}}
when signup access is none
refs https://github.com/TryGhost/Team/issues/579 - skips insertion of members-related scripts and styles when `members_signup_access` setting is set to `'none'` - adds `id="gh-members-styles"` to the inserted style script tag for reference in tests and JS
This commit is contained in:
parent
fff6a04c54
commit
4a8352c418
@ -37,13 +37,17 @@ function finaliseStructuredData(meta) {
|
||||
}
|
||||
|
||||
function getMembersHelper(data) {
|
||||
if (settingsCache.get('members_signup_access') === 'none') {
|
||||
return '';
|
||||
}
|
||||
|
||||
const stripeDirectSecretKey = settingsCache.get('stripe_secret_key');
|
||||
const stripeDirectPublishableKey = settingsCache.get('stripe_publishable_key');
|
||||
const stripeConnectAccountId = settingsCache.get('stripe_connect_account_id');
|
||||
const colorString = _.has(data, 'site._preview') && data.site.accent_color ? ` data-accent-color="${data.site.accent_color}"` : '';
|
||||
const portalUrl = config.get('portal:url');
|
||||
let membersHelper = `<script defer src="${portalUrl}" data-ghost="${urlUtils.getSiteUrl()}"${colorString}></script>`;
|
||||
membersHelper += (`<style> ${templateStyles}</style>`);
|
||||
membersHelper += (`<style id="gh-members-styles">${templateStyles}</style>`);
|
||||
if ((!!stripeDirectSecretKey && !!stripeDirectPublishableKey) || !!stripeConnectAccountId) {
|
||||
membersHelper += '<script async src="https://js.stripe.com/v3/"></script>';
|
||||
}
|
||||
|
@ -1684,4 +1684,122 @@ describe('{{ghost_head}} helper', function () {
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('members scripts', function () {
|
||||
it('includes portal when signup is "all"', function (done) {
|
||||
settingsCache.get.withArgs('members_signup_access').returns('all');
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
relativeUrl: '/',
|
||||
context: ['home', 'index'],
|
||||
safeVersion: '4.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.containEql('<script defer src="https://unpkg.com/@tryghost/portal');
|
||||
rendered.string.should.containEql('<style id="gh-members-styles">');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('includes portal when signup is "invite"', function (done) {
|
||||
settingsCache.get.withArgs('members_signup_access').returns('invite');
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
relativeUrl: '/',
|
||||
context: ['home', 'index'],
|
||||
safeVersion: '4.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.containEql('<script defer src="https://unpkg.com/@tryghost/portal');
|
||||
rendered.string.should.containEql('<style id="gh-members-styles">');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('includes stripe when set up as direct', function (done) {
|
||||
settingsCache.get.withArgs('members_signup_access').returns('all');
|
||||
settingsCache.get.withArgs('stripe_secret_key').returns('secret');
|
||||
settingsCache.get.withArgs('stripe_publishable_key').returns('publishable');
|
||||
settingsCache.get.withArgs('stripe_connect_account_id').returns(null);
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
relativeUrl: '/',
|
||||
context: ['home', 'index'],
|
||||
safeVersion: '4.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.containEql('<script defer src="https://unpkg.com/@tryghost/portal');
|
||||
rendered.string.should.containEql('<style id="gh-members-styles">');
|
||||
rendered.string.should.containEql('<script async src="https://js.stripe.com');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('includes stripe when set up as connect', function (done) {
|
||||
settingsCache.get.withArgs('members_signup_access').returns('all');
|
||||
settingsCache.get.withArgs('stripe_secret_key').returns(null);
|
||||
settingsCache.get.withArgs('stripe_publishable_key').returns(null);
|
||||
settingsCache.get.withArgs('stripe_connect_account_id').returns('connect_account');
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
relativeUrl: '/',
|
||||
context: ['home', 'index'],
|
||||
safeVersion: '4.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.containEql('<script defer src="https://unpkg.com/@tryghost/portal');
|
||||
rendered.string.should.containEql('<style id="gh-members-styles">');
|
||||
rendered.string.should.containEql('<script async src="https://js.stripe.com');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('skips portal and stripe when signup is "none"', function (done) {
|
||||
settingsCache.get.withArgs('members_signup_access').returns('none');
|
||||
settingsCache.get.withArgs('stripe_connect_account_id').returns('connect_account');
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
relativeUrl: '/',
|
||||
context: ['home', 'index'],
|
||||
safeVersion: '4.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.not.containEql('<script defer src="https://unpkg.com/@tryghost/portal');
|
||||
rendered.string.should.not.containEql('<style id="gh-members-styles">');
|
||||
rendered.string.should.not.containEql('<script async src="https://js.stripe.com');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('skips stripe if not set up', function (done) {
|
||||
settingsCache.get.withArgs('members_signup_access').returns('all');
|
||||
settingsCache.get.withArgs('stripe_secret_key', null);
|
||||
settingsCache.get.withArgs('stripe_publishable_key', null);
|
||||
settingsCache.get.withArgs('stripe_connect_account_id', null);
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
relativeUrl: '/',
|
||||
context: ['home', 'index'],
|
||||
safeVersion: '4.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.containEql('<script defer src="https://unpkg.com/@tryghost/portal');
|
||||
rendered.string.should.containEql('<style id="gh-members-styles">');
|
||||
rendered.string.should.not.containEql('<script async src="https://js.stripe.com');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user