Skip to content

Commit

Permalink
✨ Enabled Portal (#12317)
Browse files Browse the repository at this point in the history
no refs

[Portal](https://github.com/TryGhost/Portal) is a new drop-in script to make the bulk of Ghost membership features work on any theme out of the box, which was under a developer flag so far. This release removes the flag for Portal and makes it included as default for any members-enabled Ghost site. The Portal script is backward compatible with old public members script and existing Members-enabled themes should notice no change.

- Removes Portal config flag as Portal is now enabled by default
- Removes old members script as Portal is backward compatible with it
- Changes `{{content}}` helper to show default CTA in case of restricted content access
- `accent_color` setting is no more behind the dev experiment flag and included by default
- Adds migration to switch off Portal button setting for all existing sites which don't have Portal enabled in beta
  • Loading branch information
rishabhgrg committed Nov 3, 2020
1 parent 4ebebd1 commit 8ad11fe
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 384 deletions.
13 changes: 1 addition & 12 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,6 @@ const configureGrunt = function (grunt) {
}
},

uglify: {
prod: {
options: {
sourceMap: false
},
files: {
'core/server/public/members.min.js': 'core/server/public/members.js'
}
}
},

postcss: {
prod: {
options: {
Expand Down Expand Up @@ -548,7 +537,7 @@ const configureGrunt = function (grunt) {
//
// It is otherwise the same as running `grunt`, but is only used when running Ghost in the `production` env.
grunt.registerTask('prod', 'Build JS & templates for production',
['subgrunt:prod', 'uglify:prod', 'postcss:prod']);
['subgrunt:prod', 'postcss:prod']);

// ### Live reload
// `grunt dev` - build assets on the fly whilst developing
Expand Down
4 changes: 2 additions & 2 deletions core/frontend/helpers/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
// Dev flag feature: In case of restricted content access for member-only posts, shows CTA box

const {templates, hbs, config, SafeString} = require('../services/proxy');
const {templates, hbs, SafeString} = require('../services/proxy');
const downsize = require('downsize');
const _ = require('lodash');
const createFrame = hbs.handlebars.createFrame;
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = function content(options = {}) {
this.html = '';
}

if (!this.access && (!!config.get('enableDeveloperExperiments') || !!config.get('portal'))) {
if (!_.isUndefined(this.access) && !this.access) {
return restrictedCta.apply(self, args);
}

Expand Down
8 changes: 2 additions & 6 deletions core/frontend/helpers/ghost_head.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const debug = require('ghost-ignition').debug('ghost_head');
const templateStyles = require('./tpl/styles');

const getMetaData = metaData.get;
const getAssetUrl = metaData.getAssetUrl;

function writeMetaTag(property, content, type) {
type = type || property.substring(0, 7) === 'twitter' ? 'name' : 'property';
Expand Down Expand Up @@ -42,11 +41,8 @@ function getMembersHelper() {
const stripeDirectPublishableKey = settingsCache.get('stripe_publishable_key');
const stripeConnectAccountId = settingsCache.get('stripe_connect_account_id');

let membersHelper = `<script defer src="${getAssetUrl('public/members.js', true)}"></script>`;
if (config.get('enableDeveloperExperiments') || config.get('portal')) {
membersHelper = `<script defer src="https://unpkg.com/@tryghost/portal@latest/umd/portal.min.js" data-ghost="${urlUtils.getSiteUrl()}"></script>`;
membersHelper += (`<style type='text/css'> ${templateStyles}</style>`);
}
let membersHelper = `<script defer src="https://unpkg.com/@tryghost/portal@latest/umd/portal.min.js" data-ghost="${urlUtils.getSiteUrl()}"></script>`;
membersHelper += (`<style type='text/css'> ${templateStyles}</style>`);
if ((!!stripeDirectSecretKey && !!stripeDirectPublishableKey) || !!stripeConnectAccountId) {
membersHelper += '<script async src="https://js.stripe.com/v3/"></script>';
}
Expand Down
3 changes: 1 addition & 2 deletions core/server/api/canary/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ module.exports = {
clientExtensions: config.get('clientExtensions') || {},
enableDeveloperExperiments: config.get('enableDeveloperExperiments') || false,
stripeDirect: config.get('stripeDirect'),
mailgunIsConfigured: config.get('bulkEmail') && config.get('bulkEmail').mailgun,
portal: config.get('portal')
mailgunIsConfigured: config.get('bulkEmail') && config.get('bulkEmail').mailgun
};
if (billingUrl) {
response.billingUrl = billingUrl;
Expand Down
6 changes: 0 additions & 6 deletions core/server/api/canary/site.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const ghostVersion = require('../../lib/ghost-version');
const settingsCache = require('../../services/settings/cache');
const urlUtils = require('../../../shared/url-utils');
const config = require('../../../shared/config');

const site = {
docName: 'site',
Expand All @@ -18,11 +17,6 @@ const site = {
version: ghostVersion.safe
};

// accent_color is currently an experimental feature
if (!config.get('enableDeveloperExperiments') && !config.get('portal')) {
delete response.accent_color;
}

return response;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const gating = require('./post-gating');
const clean = require('./clean');
const extraAttrs = require('./extra-attrs');
const postsMetaSchema = require('../../../../../../data/schema').tables.posts_meta;
const config = require('../../../../../../../shared/config');
const mega = require('../../../../../../services/mega');

const mapUser = (model, frame) => {
Expand Down Expand Up @@ -104,15 +103,8 @@ const mapSettings = (attrs, frame) => {
// fields completely.
if (_.isArray(attrs)) {
attrs = _.filter(attrs, (o) => {
if (o.key === 'accent_color' && !config.get('enableDeveloperExperiments') && !config.get('portal')) {
return false;
}
return o.key !== 'ghost_head' && o.key !== 'ghost_foot';
});
} else {
if (!config.get('enableDeveloperExperiments') && !config.get('portal')) {
delete attrs.accent_color;
}
}

return attrs;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const logging = require('../../../../../shared/logging');
const config = require('../../../../../shared/config');

module.exports = {
config: {
transaction: true
},

async up(options) {
// update portal button setting to false
const isPortalEnabled = config.get('portal');
if (!isPortalEnabled) {
logging.info(`Updating portal button setting to false`);
return await options
.transacting('settings')
.where('key', 'portal_button')
.update({
value: 'false'
});
}
logging.info(`Portal is enabled, ignoring portal button update`);
return Promise.resolve();
},

// `up` is only run to fix previously set default value for portal button,
// it doesn't make sense to be revert it back as `true` as feature is still behind dev flag
async down() {
return Promise.resolve();
}
};

0 comments on commit 8ad11fe

Please sign in to comment.