From 148817f28737e471b18c7a9322bf986c8c6a832e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Bol=C3=ADvar?= Date: Thu, 16 May 2024 13:54:48 +0200 Subject: [PATCH 1/2] Change sign out page for odoo users --- .../devise/sessions_controller_override.rb | 27 +++++++++++++++++++ config/initializers/decidim_overrides.rb | 1 + spec/lib/overrides_spec.rb | 1 + 3 files changed, 29 insertions(+) create mode 100644 app/controllers/concerns/decidim/devise/sessions_controller_override.rb diff --git a/app/controllers/concerns/decidim/devise/sessions_controller_override.rb b/app/controllers/concerns/decidim/devise/sessions_controller_override.rb new file mode 100644 index 0000000..ae2a56e --- /dev/null +++ b/app/controllers/concerns/decidim/devise/sessions_controller_override.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Decidim + module Devise + module SessionsControllerOverride + extend ActiveSupport::Concern + + included do + alias_method :original_after_sign_out_path_for, :after_sign_out_path_for + alias_method :original_destroy, :destroy + + def destroy + @user = current_user + original_destroy + end + + def after_sign_out_path_for(resource) + if @user.odoo_identity? + "https://oficinavirtual.somconnexio.coop" + else + original_after_sign_out_path_for(resource) + end + end + end + end + end +end diff --git a/config/initializers/decidim_overrides.rb b/config/initializers/decidim_overrides.rb index 838978f..77e8c0c 100644 --- a/config/initializers/decidim_overrides.rb +++ b/config/initializers/decidim_overrides.rb @@ -4,6 +4,7 @@ Decidim::ActionDelegator::Verifications::DelegationsVerifier::AuthorizationsController.include( Decidim::ActionDelegator::Verifications::DelegationsVerifier::AuthorizationsControllerOverride ) + Decidim::Devise::SessionsController.include(Decidim::Devise::SessionsControllerOverride) Decidim::ActionDelegator::Setting.include(Decidim::ActionDelegator::SettingOverride) Decidim::ActionDelegator::Verifications::DelegationsAuthorizer.include(Decidim::ActionDelegator::Verifications::DelegationsAuthorizerOverride) Decidim::Odoo::Verifications::OdooMember.include(Decidim::Odoo::Verifications::OdooMemberOverride) diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index a546be9..9865796 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -9,6 +9,7 @@ { package: "decidim-core", files: { + "/app/controllers/decidim/devise/sessions_controller.rb" => "235cbe9844cdd39f65c72d3dc87f5f23", "/app/views/layouts/decidim/_head_extra.html.erb" => "1b8237357754cf519f4e418135f78440" } }, From 0838c292eac48ec7e93ae3c4b6e90080a831dc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Bol=C3=ADvar?= Date: Thu, 16 May 2024 14:01:47 +0200 Subject: [PATCH 2/2] Use ENV variable for Odoo sign out custom URL --- .../concerns/decidim/devise/sessions_controller_override.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/decidim/devise/sessions_controller_override.rb b/app/controllers/concerns/decidim/devise/sessions_controller_override.rb index ae2a56e..bf5f0aa 100644 --- a/app/controllers/concerns/decidim/devise/sessions_controller_override.rb +++ b/app/controllers/concerns/decidim/devise/sessions_controller_override.rb @@ -15,8 +15,9 @@ def destroy end def after_sign_out_path_for(resource) - if @user.odoo_identity? - "https://oficinavirtual.somconnexio.coop" + url = ENV.fetch("ODOO_SIGN_OUT_URL", nil) + if @user.odoo_identity? && url + url else original_after_sign_out_path_for(resource) end