Skip to content

Commit

Permalink
fix: Redirect to login page if logged out on the page
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Jan 4, 2024
1 parent 18dd98d commit 5d85778
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ module CommitteeRequestsControllerExtends
def new
return if authorized?(current_user)

authorization_method = Decidim::Verifications::Adapter.from_element(current_initiative.document_number_authorization_handler)
redirect_url = new_initiative_committee_request_path(current_initiative)
redirect_to authorization_method.root_path(redirect_url: redirect_url)
if current_user.nil?
redirect_to decidim.new_user_session_path
else
authorization_method = Decidim::Verifications::Adapter.from_element(current_initiative.document_number_authorization_handler)
redirect_url = new_initiative_committee_request_path(current_initiative)
redirect_to authorization_method.root_path(redirect_url: redirect_url)
end
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ module Initiatives
end
end

context "when not logged in" do
let(:current_user) { nil }
let(:authorized) { false }

it "redirects to login page" do
allow(controller).to receive(:new_initiative_committee_request_path).with(initiative).and_return(committee_request_path)

get :new, params: { initiative_slug: initiative.slug }

expect(response).to have_http_status(:found)
expect(URI.parse(response.location).path).to eq("/users/sign_in")
end
end

context "when authorized" do
let(:authorized) { true }

Expand Down

0 comments on commit 5d85778

Please sign in to comment.