From cf29ed8c300aa273a57ab9da73acf6f8e735bca1 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 27 Apr 2021 16:22:43 +0100 Subject: [PATCH] Updated members `allowSelfSignup()` to take portal plans into account (#12909) refs https://github.com/TryGhost/Team/issues/579 `members_signup_access = 'invite'` now forces invite-only mode so both free and paid setups both use the `'all'` setting. To ensure we're properly allowing/disabling free (self signup) signups in the members API we need to update `allowSelfSignup()` to take additional settings into account. - `true` when Stripe is not connected. There are no paid plans available in this configuration so free signup is always enabled. To disable free signup on a site with no Stripe setup the members signup access should be set to `invite` or `none`. - `true` when Stripe is configured and free plan is enabled in portal, without it Members API would not send magic link emails to signup requests - `false` in all other situations such as invite-only and members-disabled signup access modes, or when the free plan has been disabled in portal configuration --- core/server/services/members/config.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/server/services/members/config.js b/core/server/services/members/config.js index a12ed9af3b..ed65ba8ea9 100644 --- a/core/server/services/members/config.js +++ b/core/server/services/members/config.js @@ -215,7 +215,25 @@ class MembersConfigProvider { } getAllowSelfSignup() { - return this._settingsCache.get('members_signup_access') === 'all'; + // 'invite' and 'none' members signup access disables all signup + if (this._settingsCache.get('members_signup_access') !== 'all') { + return false; + } + + // if stripe is not connected then selected plans mean nothing. + // disabling signup would be done by switching to "invite only" mode + if (!this.isStripeConnected()) { + return true; + } + + // self signup must be available for free plan signup to work + const hasFreePlan = this._settingsCache.get('portal_plans').includes('free'); + if (hasFreePlan) { + return true; + } + + // signup access is enabled but there's no free plan, don't allow self signup + return false; } getTokenConfig() {