Skip to content

Commit

Permalink
fix session management
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaelvilleneuve committed Feb 4, 2025
1 parent f0af949 commit 475208e
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
respond_to :json

include Agents::SignInWithRdvSolidarites
before_action :validate_rdv_solidarites_credentials!, :retrieve_agent!, :mark_agent_as_logged_in!,
before_action :retrieve_agent!, :mark_agent_as_logged_in!,
:set_current_agent

include AuthorizationConcern
Expand Down
10 changes: 1 addition & 9 deletions app/controllers/concerns/agents/sign_in_with_rdv_solidarites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@ class RdvSolidarites::InvalidCredentialsError < StandardError; end
module Agents::SignInWithRdvSolidarites
extend ActiveSupport::Concern

included do
rescue_from RdvSolidarites::InvalidCredentialsError, with: :invalid_credentials
end

private

def validate_rdv_solidarites_credentials!
raise RdvSolidarites::InvalidCredentialsError unless rdv_solidarites_credentials.valid?
end

def rdv_solidarites_credentials
@rdv_solidarites_credentials ||= RdvSolidaritesCredentials.new(request)
OpenStruct.new(request.env["omniauth.auth"]["info"]["agent"])
end

def invalid_credentials
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/concerns/authenticated_controller_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def authenticate_agent!

clear_session
session[:agent_return_to] = request.env["PATH_INFO"]
redirect_to sign_in_path
flash[:notice] = "Veuillez vous connecter"
redirect_to root_path
end

def clear_session
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class SessionsController < ApplicationController
respond_to :json, only: :create

include Agents::SignInWithRdvSolidarites
before_action :validate_rdv_solidarites_credentials!, :retrieve_agent!, :mark_agent_as_logged_in!,
before_action :retrieve_agent!, :mark_agent_as_logged_in!,
:set_agent_return_to_url,
only: [:create]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
href: super_admins_agent_impersonation_path(agent_id: other_agent.id))
click_link("Se logger en tant que")
# it disconnects the agent
expect(page).to have_current_path(sign_in_path)
expect(page).to have_current_path(root_path)
end
end
end
Expand Down
8 changes: 0 additions & 8 deletions spec/features/agent_can_change_navigation_level_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@
expect(page).to have_no_css("button#btn-organisation-navigation")
end
end

context "on login page" do
it "does not show the organisation navigation button in header" do
visit sign_in_path

expect(page).to have_no_css("button#btn-organisation-navigation")
end
end
end

context "when agent is logged in" do
Expand Down

0 comments on commit 475208e

Please sign in to comment.