From 0d8a9f5ec36174e29af88e3a95f0ea28b947f2bd Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Mon, 17 Oct 2022 15:20:59 +0200 Subject: [PATCH] switch devise laypout for extranet --- .../application_controller/with_domain.rb | 5 +++ .../concerns/users/layout_choice.rb | 20 ++++++++++ .../users/confirmations_controller.rb | 1 + .../users/omniauth_callbacks_controller.rb | 2 + app/controllers/users/passwords_controller.rb | 1 + .../users/registrations_controller.rb | 3 +- app/controllers/users/sessions_controller.rb | 3 +- .../two_factor_authentication_controller.rb | 2 + app/controllers/users/unlocks_controller.rb | 1 + .../extranet/application/_footer.html.erb | 10 +++-- app/views/extranet/layouts/devise.html.erb | 40 +++++++++++++++++++ db/schema.rb | 2 +- 12 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 app/controllers/concerns/users/layout_choice.rb create mode 100644 app/views/extranet/layouts/devise.html.erb diff --git a/app/controllers/application_controller/with_domain.rb b/app/controllers/application_controller/with_domain.rb index 6311d132c..95edbff9d 100644 --- a/app/controllers/application_controller/with_domain.rb +++ b/app/controllers/application_controller/with_domain.rb @@ -26,5 +26,10 @@ module ApplicationController::WithDomain end end helper_method :current_context + + def current_mode + current_extranet.present? ? 'extranet' : 'university' + end + helper_method :current_mode end end diff --git a/app/controllers/concerns/users/layout_choice.rb b/app/controllers/concerns/users/layout_choice.rb new file mode 100644 index 000000000..2721bd54c --- /dev/null +++ b/app/controllers/concerns/users/layout_choice.rb @@ -0,0 +1,20 @@ +module Users::LayoutChoice + extend ActiveSupport::Concern + + included do + layout :extranet_or_default + end + + private + + def extranet_or_default + # extranet have their custom devise layout + # university osuny sessions have an "admin" layout for registration edit/update, else default devise layout. + case current_mode + when 'extranet' + 'extranet/layouts/devise' + when 'university' + (controller_path == 'users/registrations' && ['edit', 'update'].include?(action_name)) ? 'admin/layouts/application' : 'devise' + end + end +end diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 663067dd4..2d4b6116e 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -1,5 +1,6 @@ class Users::ConfirmationsController < Devise::ConfirmationsController include Users::AddUniversityToRequestParams + include Users::LayoutChoice def resend unless signed_in_resource.confirmed? diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 47b36fc4d..924bb3429 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -1,7 +1,9 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController # include Users::AddBrandToRequestParams + # include Users::LayoutChoice # include I18nHelper + protect_from_forgery except: :saml before_action :redirect_unless_university_has_sso skip_before_action :verify_authenticity_token, only: :saml diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index c0334ec48..49d967b4a 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -1,5 +1,6 @@ class Users::PasswordsController < Devise::PasswordsController include Users::AddUniversityToRequestParams + include Users::LayoutChoice def update super do |resource| diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 4e22f2bc2..8ce23d804 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,7 +1,6 @@ class Users::RegistrationsController < Devise::RegistrationsController include Users::AddUniversityToRequestParams - - layout 'admin/layouts/application', only: [:edit, :update] + include Users::LayoutChoice before_action :configure_sign_up_params, only: :create before_action :configure_account_update_params, only: :update diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 719343815..41758961c 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -1,10 +1,11 @@ class Users::SessionsController < Devise::SessionsController include Users::AddUniversityToRequestParams + include Users::LayoutChoice # DELETE /resource/sign_out def destroy current_user.invalidate_all_sessions! super end - + end diff --git a/app/controllers/users/two_factor_authentication_controller.rb b/app/controllers/users/two_factor_authentication_controller.rb index 1ab0e9e27..bc2df1827 100644 --- a/app/controllers/users/two_factor_authentication_controller.rb +++ b/app/controllers/users/two_factor_authentication_controller.rb @@ -1,2 +1,4 @@ class Users::TwoFactorAuthenticationController < Devise::TwoFactorAuthenticationController + include Users::LayoutChoice + end diff --git a/app/controllers/users/unlocks_controller.rb b/app/controllers/users/unlocks_controller.rb index b1ef88921..47d30a6a5 100644 --- a/app/controllers/users/unlocks_controller.rb +++ b/app/controllers/users/unlocks_controller.rb @@ -1,3 +1,4 @@ class Users::UnlocksController < Devise::UnlocksController include Users::AddUniversityToRequestParams + include Users::LayoutChoice end diff --git a/app/views/extranet/application/_footer.html.erb b/app/views/extranet/application/_footer.html.erb index 0ea2da91e..ccb9d2c54 100644 --- a/app/views/extranet/application/_footer.html.erb +++ b/app/views/extranet/application/_footer.html.erb @@ -1,8 +1,12 @@ +<% hide_logo ||= false %> + <footer class="pt-5"> <div class="container"> - <div class="footer-logo pb-5 mb-5 text-center"> - <%= render 'logo' %> - </div> + <% unless hide_logo %> + <div class="footer-logo pb-5 mb-5 text-center"> + <%= render 'logo' %> + </div> + <% end %> <div class="row justify-space-between"> <% if current_extranet.about.is_a?(Education::School) %> <address class="col-md-6" itemscope itemtype="https://schema.org/CollegeOrUniversity"> diff --git a/app/views/extranet/layouts/devise.html.erb b/app/views/extranet/layouts/devise.html.erb new file mode 100644 index 000000000..993387982 --- /dev/null +++ b/app/views/extranet/layouts/devise.html.erb @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> + <title><%= yield :title %></title> + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + <%= stylesheet_link_tag 'admin', media: 'all' %> + <%= javascript_include_tag 'admin' %> + <%= favicon_link_tag 'favicon.png' %> + </head> + <body class="<%= body_classes %>"> + <div class="container"> + <div class="row"> + <div class="col-sm-10 mx-auto"> + <h1 class="my-5 py-5 text-center"> + <%= link_to root_path do %> + <%= render 'logo' %> + <% end %> + </h1> + <div class="card"> + <div class="card-body text-start"> + <% unless notice.blank? %> + <div class="alert alert-success mt-2" role="alert"><%= notice.html_safe %></div> + <% end %> + <% unless alert.blank? %> + <div class="alert alert-danger mt-2" role="alert"><%= alert.html_safe %></div> + <% end %> + <%= yield %> + </div> + </div> + </div> + </div> + </div> + <%= render 'extranet/application/footer', hide_logo: true %> + <%= render 'gdpr/cookie_consent' %> + <%= render 'bugsnag' %> + </body> +</html> diff --git a/db/schema.rb b/db/schema.rb index cb9d994e1..776268905 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -44,7 +44,7 @@ ActiveRecord::Schema.define(version: 2022_10_11_070402) do t.text "metadata" t.string "service_name", null: false t.bigint "byte_size", null: false - t.string "checksum" + t.string "checksum", null: false t.datetime "created_at", null: false t.uuid "university_id" t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true -- GitLab