From 4173270b3b30df47a171c4fbe716b35f894b7bf2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Mon, 31 Oct 2022 17:08:23 +0100
Subject: [PATCH] sso button label

---
 app/controllers/admin/communication/extranets_controller.rb | 2 +-
 app/controllers/server/universities_controller.rb           | 2 +-
 app/models/communication/extranet.rb                        | 1 +
 app/models/university.rb                                    | 1 +
 app/views/admin/communication/extranets/_form.html.erb      | 1 +
 app/views/devise/sessions/new.html.erb                      | 3 ++-
 app/views/server/universities/_form.html.erb                | 1 +
 config/locales/communication/en.yml                         | 3 +++
 config/locales/communication/fr.yml                         | 3 +++
 config/locales/university/en.yml                            | 2 ++
 config/locales/university/fr.yml                            | 2 ++
 db/migrate/20221031155827_add_sso_button_label.rb           | 6 ++++++
 db/schema.rb                                                | 6 ++++--
 test/fixtures/communication/extranets.yml                   | 1 +
 test/fixtures/universities.yml                              | 1 +
 test/models/communication/extranet_test.rb                  | 1 +
 16 files changed, 31 insertions(+), 5 deletions(-)
 create mode 100644 db/migrate/20221031155827_add_sso_button_label.rb

diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb
index b9e807a79..ed971661f 100644
--- a/app/controllers/admin/communication/extranets_controller.rb
+++ b/app/controllers/admin/communication/extranets_controller.rb
@@ -67,7 +67,7 @@ class Admin::Communication::ExtranetsController < Admin::Communication::Applicat
           .permit(:name, :host, :about_type, :about_id,
             :registration_contact, :logo, :logo_delete,
             :terms, :privacy_policy, :cookies_policy, :color,
-            :has_sso, :sso_target_url, :sso_cert, :sso_name_identifier_format, :sso_mapping
+            :has_sso, :sso_target_url, :sso_cert, :sso_name_identifier_format, :sso_mapping, :sso_button_label
           )
   end
 end
diff --git a/app/controllers/server/universities_controller.rb b/app/controllers/server/universities_controller.rb
index 7993a87cf..5628d8d2b 100644
--- a/app/controllers/server/universities_controller.rb
+++ b/app/controllers/server/universities_controller.rb
@@ -62,7 +62,7 @@ class Server::UniversitiesController < Server::ApplicationController
     params.require(:university).permit(:name,
       :address, :zipcode, :city, :country,
       :private, :identifier, :logo, :logo_delete, :sms_sender_name,
-      :has_sso, :sso_target_url, :sso_cert, :sso_name_identifier_format, :sso_mapping,
+      :has_sso, :sso_target_url, :sso_cert, :sso_name_identifier_format, :sso_mapping, :sso_button_label,
       :invoice_date, :invoice_amount)
   end
 end
diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb
index cd9c9bd78..fecf94505 100644
--- a/app/models/communication/extranet.rb
+++ b/app/models/communication/extranet.rb
@@ -11,6 +11,7 @@
 #  name                       :string
 #  privacy_policy             :text
 #  registration_contact       :string
+#  sso_button_label           :string
 #  sso_cert                   :text
 #  sso_mapping                :jsonb
 #  sso_name_identifier_format :string
diff --git a/app/models/university.rb b/app/models/university.rb
index 8780933af..a8c36a091 100644
--- a/app/models/university.rb
+++ b/app/models/university.rb
@@ -16,6 +16,7 @@
 #  name                       :string
 #  private                    :boolean
 #  sms_sender_name            :string
+#  sso_button_label           :string
 #  sso_cert                   :text
 #  sso_mapping                :jsonb
 #  sso_name_identifier_format :string
diff --git a/app/views/admin/communication/extranets/_form.html.erb b/app/views/admin/communication/extranets/_form.html.erb
index db051c124..0a84a5f7e 100644
--- a/app/views/admin/communication/extranets/_form.html.erb
+++ b/app/views/admin/communication/extranets/_form.html.erb
@@ -51,6 +51,7 @@
         <%= f.input :sso_target_url, required: true %>
         <%= f.input :sso_cert, required: true %>
         <%= f.input :sso_name_identifier_format, required: true %>
+        <%= f.input :sso_button_label %>
       </div>
     </div>
     <div class="col-md-6 sso-inputs">
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb
index f83922661..6e3fe9e20 100644
--- a/app/views/devise/sessions/new.html.erb
+++ b/app/views/devise/sessions/new.html.erb
@@ -2,7 +2,8 @@
   <div class="col-md-6 mb-5">
     <h2 class="mb-4"><%= t('login.already_registered') %></h2>
     <% if current_context.has_sso? %>
-      <p><%= link_to t('login.sign_in_with_sso'), omniauth_authorize_path(resource_name, current_university.sso_provider), method: :post, class: 'btn btn-primary' %></p>
+      <% button_label = current_context.sso_button_label.blank? ? t('login.sign_in_with_sso') : current_context.sso_button_label %>
+      <p><%= link_to button_label, omniauth_authorize_path(resource_name, current_context.sso_provider), method: :post, class: 'btn btn-primary' %></p>
       <p><%= t('login.or') %></p>
       <a href="#collapseLoginForm" class="btn btn-primary mb-3" data-bs-toggle="collapse"><%= t('login.sign_in_with_credentials') %></a>
     <% end %>
diff --git a/app/views/server/universities/_form.html.erb b/app/views/server/universities/_form.html.erb
index 9dfd61fc2..90b60f85f 100644
--- a/app/views/server/universities/_form.html.erb
+++ b/app/views/server/universities/_form.html.erb
@@ -39,6 +39,7 @@
         <%= f.input :sso_target_url, required: true %>
         <%= f.input :sso_cert, required: true %>
         <%= f.input :sso_name_identifier_format, required: true %>
+        <%= f.input :sso_button_label %>
       </div>
     </div>
     <div class="col-md-6 sso-inputs">
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index cd80a8eff..608e49d99 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -56,6 +56,7 @@ en:
         host: Domain
         name: Name
         registration_contact: Contact mail for registrations problems
+        sso_button_label: Sign in button's label
         sso_cert: Certificate
         sso_inherit_from_university: SSO inherited from University
         sso_mapping: Mapping
@@ -662,6 +663,8 @@ en:
               url: URL
   simple_form:
     hints:
+      communication_extranet:
+        sso_button_label: "Default: Sign in via SSO"
       communication_website:
         git_branch: 'If blank, default branch will be used'
         git_endpoint: 'If blank, default will be used (https://github.com or https://gitlab.com/api/v4)'
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 708e029d0..9a527d1ec 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -55,6 +55,7 @@ fr:
         name: Nom
         privacy_policy: Politique de confidentialité
         registration_contact: Mail de contact pour les problèmes d'inscription
+        sso_button_label: Libellé du bouton de connexion
         sso_cert: Certificat
         sso_inherit_from_university: SSO hérité de l'Université
         sso_mapping: Mapping
@@ -667,6 +668,8 @@ fr:
               url: URL
   simple_form:
     hints:
+      communication_extranet:
+        sso_button_label: "Par défaut : Se connecter en SSO"
       communication_website:
         git_branch: 'Laisser vide pour la branche par défaut'
         git_endpoint: 'Laisser vide pour les valeurs par défaut (https://github.com ou https://gitlab.com/api/v4)'
diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml
index cfb308921..268dfdd47 100644
--- a/config/locales/university/en.yml
+++ b/config/locales/university/en.yml
@@ -15,6 +15,7 @@ en:
         public: Public
         public_or_private: Public/private
         sms_sender_name: SMS sender name
+        sso_button_label: Sign in button's label
         sso_cert: Certificate
         sso_mapping: Mapping
         sso_name_identifier_format: Name Identifier Format
@@ -130,6 +131,7 @@ en:
     hints:
       university:
         sms_sender_name: "11 characters max. Only alphanumeric chars ([A-Z][a-z][0-9])."
+        sso_button_label: "Default: Sign in via SSO"
       university_organization:
         description: If this field is empty the main text's begining will be used.
       university_person:
diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml
index 823b655ae..a2845536b 100644
--- a/config/locales/university/fr.yml
+++ b/config/locales/university/fr.yml
@@ -15,6 +15,7 @@ fr:
         public: Public
         public_or_private: Public/privé
         sms_sender_name: Nom de l'expéditeur SMS
+        sso_button_label: Libellé du bouton de connexion
         sso_cert: Certificat
         sso_mapping: Mapping
         sso_name_identifier_format: Name Identifier Format
@@ -130,6 +131,7 @@ fr:
     hints:
       university:
         sms_sender_name: "11 caractères maximum. Que des caractères alphadécimaux ([A-Z][a-z][0-9])."
+        sso_button_label: "Par défaut : Se connecter en SSO"
       university_organization:
         description: Si ce champ est vide le début du texte principal sera utilisé.
       university_person:
diff --git a/db/migrate/20221031155827_add_sso_button_label.rb b/db/migrate/20221031155827_add_sso_button_label.rb
new file mode 100644
index 000000000..475bef3a8
--- /dev/null
+++ b/db/migrate/20221031155827_add_sso_button_label.rb
@@ -0,0 +1,6 @@
+class AddSsoButtonLabel < ActiveRecord::Migration[6.1]
+  def change
+    add_column :universities, :sso_button_label, :string
+    add_column :communication_extranets, :sso_button_label, :string
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 0664d124b..e6595bf33 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2022_10_24_145426) do
+ActiveRecord::Schema.define(version: 2022_10_31_155827) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -44,7 +44,7 @@ ActiveRecord::Schema.define(version: 2022_10_24_145426) do
     t.text "metadata"
     t.string "service_name", null: false
     t.bigint "byte_size", null: false
-    t.string "checksum", null: false
+    t.string "checksum"
     t.datetime "created_at", null: false
     t.uuid "university_id"
     t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
@@ -113,6 +113,7 @@ ActiveRecord::Schema.define(version: 2022_10_24_145426) do
     t.text "privacy_policy"
     t.text "cookies_policy"
     t.string "color"
+    t.string "sso_button_label"
     t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about"
     t.index ["university_id"], name: "index_communication_extranets_on_university_id"
   end
@@ -672,6 +673,7 @@ ActiveRecord::Schema.define(version: 2022_10_24_145426) do
     t.text "sso_cert"
     t.string "sso_name_identifier_format"
     t.jsonb "sso_mapping"
+    t.string "sso_button_label"
   end
 
   create_table "university_organizations", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
diff --git a/test/fixtures/communication/extranets.yml b/test/fixtures/communication/extranets.yml
index 096e5b66c..fa530b05d 100644
--- a/test/fixtures/communication/extranets.yml
+++ b/test/fixtures/communication/extranets.yml
@@ -11,6 +11,7 @@
 #  name                       :string
 #  privacy_policy             :text
 #  registration_contact       :string
+#  sso_button_label           :string
 #  sso_cert                   :text
 #  sso_mapping                :jsonb
 #  sso_name_identifier_format :string
diff --git a/test/fixtures/universities.yml b/test/fixtures/universities.yml
index 112c47a9b..e51e10e50 100644
--- a/test/fixtures/universities.yml
+++ b/test/fixtures/universities.yml
@@ -16,6 +16,7 @@
 #  name                       :string
 #  private                    :boolean
 #  sms_sender_name            :string
+#  sso_button_label           :string
 #  sso_cert                   :text
 #  sso_mapping                :jsonb
 #  sso_name_identifier_format :string
diff --git a/test/models/communication/extranet_test.rb b/test/models/communication/extranet_test.rb
index 69be8d1cd..0b396fd48 100644
--- a/test/models/communication/extranet_test.rb
+++ b/test/models/communication/extranet_test.rb
@@ -11,6 +11,7 @@
 #  name                       :string
 #  privacy_policy             :text
 #  registration_contact       :string
+#  sso_button_label           :string
 #  sso_cert                   :text
 #  sso_mapping                :jsonb
 #  sso_name_identifier_format :string
-- 
GitLab