From 120f5802c011fa62eb417d5434c54f33506f6a69 Mon Sep 17 00:00:00 2001
From: CSDUMMI <31551856+CSDUMMI@users.noreply.github.com>
Date: Thu, 3 Aug 2023 16:43:15 +0200
Subject: [PATCH] Add direct link to the Single-Sign On provider if there is
only one sign up method available (#26083)
---
.rubocop_todo.yml | 2 +-
.../concerns/web_app_controller_concern.rb | 2 +-
.../features/interaction_modal/index.jsx | 45 ++++++++++++++-----
.../features/ui/components/header.jsx | 45 +++++++++++--------
.../features/ui/components/sign_in_banner.jsx | 13 +++++-
app/javascript/mastodon/initial_state.js | 2 +
app/javascript/mastodon/locales/en.json | 1 +
app/serializers/initial_state_serializer.rb | 5 +++
8 files changed, 82 insertions(+), 33 deletions(-)
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index b94216512..92c7f9cdc 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -135,7 +135,7 @@ Lint/UselessAssignment:
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
- Max: 143
+ Max: 146
# Configuration parameters: CountBlocks, Max.
Metrics/BlockNesting:
diff --git a/app/controllers/concerns/web_app_controller_concern.rb b/app/controllers/concerns/web_app_controller_concern.rb
index 6cd32a377..3a40ea382 100644
--- a/app/controllers/concerns/web_app_controller_concern.rb
+++ b/app/controllers/concerns/web_app_controller_concern.rb
@@ -11,7 +11,7 @@ module WebAppControllerConcern
end
def skip_csrf_meta_tags?
- current_user.nil?
+ !(ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1) && current_user.nil?
end
def set_app_body_class
diff --git a/app/javascript/mastodon/features/interaction_modal/index.jsx b/app/javascript/mastodon/features/interaction_modal/index.jsx
index 6b6768ac3..a8b86b721 100644
--- a/app/javascript/mastodon/features/interaction_modal/index.jsx
+++ b/app/javascript/mastodon/features/interaction_modal/index.jsx
@@ -13,7 +13,7 @@ import { openModal, closeModal } from 'mastodon/actions/modal';
import api from 'mastodon/api';
import Button from 'mastodon/components/button';
import { Icon } from 'mastodon/components/icon';
-import { registrationsOpen } from 'mastodon/initial_state';
+import { registrationsOpen, sso_redirect } from 'mastodon/initial_state';
const messages = defineMessages({
loginPrompt: { id: 'interaction_modal.login.prompt', defaultMessage: 'Domain of your home server, e.g. mastodon.social' },
@@ -331,18 +331,36 @@ class InteractionModal extends React.PureComponent {
}
let signupButton;
+ let signUpOrSignInButton;
- if (registrationsOpen) {
- signupButton = (
-
-
+ if (sso_redirect) {
+ signUpOrSignInButton = (
+
+
- );
+ )
} else {
- signupButton = (
-
+ if(registrationsOpen) {
+ signupButton = (
+
+
+
+ );
+ } else {
+ signupButton = (
+
+ );
+ }
+
+ signUpOrSignInButton = (
+ <>
+
+
+
+ {signupButton}
+ >
);
}
@@ -353,6 +371,13 @@ class InteractionModal extends React.PureComponent {
{actionDescription}
+
+
+
+ {signUpOrSignInButton}
+
+
+
diff --git a/app/javascript/mastodon/features/ui/components/header.jsx b/app/javascript/mastodon/features/ui/components/header.jsx
index 3d249e8d4..68484b59a 100644
--- a/app/javascript/mastodon/features/ui/components/header.jsx
+++ b/app/javascript/mastodon/features/ui/components/header.jsx
@@ -12,7 +12,7 @@ import { fetchServer } from 'mastodon/actions/server';
import { Avatar } from 'mastodon/components/avatar';
import { Icon } from 'mastodon/components/icon';
import { WordmarkLogo, SymbolLogo } from 'mastodon/components/logo';
-import { registrationsOpen, me } from 'mastodon/initial_state';
+import { registrationsOpen, me, sso_redirect } from 'mastodon/initial_state';
const Account = connect(state => ({
account: state.getIn(['accounts', me]),
@@ -73,28 +73,35 @@ class Header extends PureComponent {
>
);
} else {
- let signupButton;
- if (registrationsOpen) {
- signupButton = (
-
-
-
- );
+ if (sso_redirect) {
+ content = (
+
+ )
} else {
- signupButton = (
-
+ let signupButton;
+
+ if (registrationsOpen) {
+ signupButton = (
+
+
+
+ );
+ } else {
+ signupButton = (
+
+ );
+ }
+
+ content = (
+ <>
+ {signupButton}
+
+ >
);
}
-
- content = (
- <>
- {signupButton}
-
- >
- );
}
return (
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 e44b79769..db85c6cbf 100644
--- a/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx
+++ b/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx
@@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl';
import { openModal } from 'mastodon/actions/modal';
-import { registrationsOpen } from 'mastodon/initial_state';
+import { registrationsOpen, sso_redirect } from 'mastodon/initial_state';
import { useAppDispatch, useAppSelector } from 'mastodon/store';
const SignInBanner = () => {
@@ -17,7 +17,16 @@ const SignInBanner = () => {
let signupButton;
- const signupUrl = useAppSelector((state) => state.getIn(['server', 'server', 'registrations', 'url'], null) || '/auth/sign_up');
+ const signupUrl = useAppSelector((state) => state.getIn(['server', 'server', 'registrations', 'url'], null) || '/auth/sign_up');
+
+ if (sso_redirect) {
+ return (
+
+ )
+ }
if (registrationsOpen) {
signupButton = (
diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js
index 1ada5bfb9..85792a4ea 100644
--- a/app/javascript/mastodon/initial_state.js
+++ b/app/javascript/mastodon/initial_state.js
@@ -80,6 +80,7 @@
* @property {boolean} use_blurhash
* @property {boolean=} use_pending_items
* @property {string} version
+ * @property {string} sso_redirect
*/
/**
@@ -141,5 +142,6 @@ export const version = getMeta('version');
export const languages = initialState?.languages;
// @ts-expect-error
export const statusPageUrl = getMeta('status_page_url');
+export const sso_redirect = getMeta('sso_redirect');
export default initialState;
diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json
index 1457db329..2c901f3bd 100644
--- a/app/javascript/mastodon/locales/en.json
+++ b/app/javascript/mastodon/locales/en.json
@@ -598,6 +598,7 @@
"server_banner.server_stats": "Server stats:",
"sign_in_banner.create_account": "Create account",
"sign_in_banner.sign_in": "Login",
+ "sign_in_banner.sso_redirect": "Login or Register",
"sign_in_banner.text": "Login to follow profiles or hashtags, favorite, share and reply to posts. You can also interact from your account on a different server.",
"status.admin_account": "Open moderation interface for @{name}",
"status.admin_domain": "Open moderation interface for {domain}",
diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb
index bda06ef1f..9660c941d 100644
--- a/app/serializers/initial_state_serializer.rb
+++ b/app/serializers/initial_state_serializer.rb
@@ -32,6 +32,7 @@ class InitialStateSerializer < ActiveModel::Serializer
single_user_mode: Rails.configuration.x.single_user_mode,
trends_as_landing_page: Setting.trends_as_landing_page,
status_page_url: Setting.status_page_url,
+ sso_redirect: sso_redirect,
}
if object.current_account
@@ -108,4 +109,8 @@ class InitialStateSerializer < ActiveModel::Serializer
def instance_presenter
@instance_presenter ||= InstancePresenter.new
end
+
+ def sso_redirect
+ "/auth/auth/#{Devise.omniauth_providers[0]}" if ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1
+ end
end