Skip to content

Commit

Permalink
Redirect to home page when user unauthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Mar 18, 2022
1 parent f04e5fd commit 549b1f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/hyrax/citations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Hyrax
class CitationsController < ApplicationController
include WorksControllerBehavior
include DenyAccessOverrideBehavior
include Breadcrumbs

# Overrides decide_layout from WorksControllerBehavior
Expand Down
16 changes: 15 additions & 1 deletion spec/controllers/hyrax/citations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@
end

context "with an unauthenticated user" do
it "is not successful" do
let(:second_user) { FactoryBot.create(:user) }

before do
sign_in second_user
end

it "redirects to the home page" do
get :work, params: { id: work }
expect(response).to redirect_to main_app.root_path(locale: 'en')
expect(flash[:alert]).to eq "You are not authorized to access this page."
end
end

context "when a user is not logged in" do
it "redirects to the user login page" do
get :work, params: { id: work }
expect(response).to redirect_to main_app.new_user_session_path(locale: 'en')
expect(flash[:alert]).to eq "You are not authorized to access this page."
Expand Down

0 comments on commit 549b1f0

Please sign in to comment.