From ca66e61b933b97a74f1f79b820a2fa3bd5ffc5f2 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 23 May 2023 15:17:09 +0200 Subject: [PATCH] Add support for custom sign-up URLs (#25014) --- app/helpers/application_helper.rb | 2 +- .../mastodon/features/interaction_modal/index.jsx | 6 ++++-- .../mastodon/features/ui/components/header.jsx | 11 ++++++++--- .../features/ui/components/sign_in_banner.jsx | 8 +++++--- app/serializers/rest/instance_serializer.rb | 1 + 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 19d297725e..cdd5927c40 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -52,7 +52,7 @@ module ApplicationHelper if closed_registrations? || omniauth_only? 'https://joinmastodon.org/#getting-started' else - new_user_registration_path + ENV.fetch('SSO_ACCOUNT_SIGN_UP', new_user_registration_path) end end diff --git a/app/javascript/mastodon/features/interaction_modal/index.jsx b/app/javascript/mastodon/features/interaction_modal/index.jsx index 0f3b36122b..b1ff72b0ef 100644 --- a/app/javascript/mastodon/features/interaction_modal/index.jsx +++ b/app/javascript/mastodon/features/interaction_modal/index.jsx @@ -9,6 +9,7 @@ import { openModal, closeModal } from 'mastodon/actions/modal'; const mapStateToProps = (state, { accountId }) => ({ displayNameHtml: state.getIn(['accounts', accountId, 'display_name_html']), + signupUrl: state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up'), }); const mapDispatchToProps = (dispatch) => ({ @@ -81,6 +82,7 @@ class InteractionModal extends PureComponent { url: PropTypes.string, type: PropTypes.oneOf(['reply', 'reblog', 'favourite', 'follow']), onSignupClick: PropTypes.func.isRequired, + signupUrl: PropTypes.string.isRequired, }; handleSignupClick = () => { @@ -88,7 +90,7 @@ class InteractionModal extends PureComponent { }; render () { - const { url, type, displayNameHtml } = this.props; + const { url, type, displayNameHtml, signupUrl } = this.props; const name = ; @@ -121,7 +123,7 @@ class InteractionModal extends PureComponent { if (registrationsOpen) { signupButton = ( - + ); diff --git a/app/javascript/mastodon/features/ui/components/header.jsx b/app/javascript/mastodon/features/ui/components/header.jsx index 79b43ecb60..c73626865c 100644 --- a/app/javascript/mastodon/features/ui/components/header.jsx +++ b/app/javascript/mastodon/features/ui/components/header.jsx @@ -16,6 +16,10 @@ const Account = connect(state => ({ )); +const mapStateToProps = (state) => ({ + signupUrl: state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up'), +}); + const mapDispatchToProps = (dispatch) => ({ openClosedRegistrationsModal() { dispatch(openModal('CLOSED_REGISTRATIONS')); @@ -31,11 +35,12 @@ class Header extends PureComponent { static propTypes = { openClosedRegistrationsModal: PropTypes.func, location: PropTypes.object, + signupUrl: PropTypes.string.isRequired, }; render () { const { signedIn } = this.context.identity; - const { location, openClosedRegistrationsModal } = this.props; + const { location, openClosedRegistrationsModal, signupUrl } = this.props; let content; @@ -51,7 +56,7 @@ class Header extends PureComponent { if (registrationsOpen) { signupButton = ( - + ); @@ -87,4 +92,4 @@ class Header extends PureComponent { } -export default withRouter(connect(null, mapDispatchToProps)(Header)); +export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Header)); diff --git a/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx b/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx index 984a574e56..53aefd34cc 100644 --- a/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx +++ b/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx @@ -1,11 +1,11 @@ import { useCallback } from 'react'; import { FormattedMessage } from 'react-intl'; -import { useDispatch } from 'react-redux'; +import { useAppDispatch, useAppSelector } from 'mastodon/store'; import { registrationsOpen } from 'mastodon/initial_state'; import { openModal } from 'mastodon/actions/modal'; const SignInBanner = () => { - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const openClosedRegistrationsModal = useCallback( () => dispatch(openModal('CLOSED_REGISTRATIONS')), @@ -14,9 +14,11 @@ const SignInBanner = () => { let signupButton; + const signupUrl = useAppSelector((state) => state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up')); + if (registrationsOpen) { signupButton = ( - + ); diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index a07840f0ca..14aeda9462 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -85,6 +85,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer enabled: registrations_enabled?, approval_required: Setting.registrations_mode == 'approved', message: registrations_enabled? ? nil : registrations_message, + url: ENV.fetch('SSO_ACCOUNT_SIGN_UP', nil), } end