diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5093f4a1c6..cfc4e2786f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -75,7 +75,7 @@ def dashboard_path_from_current_role elsif current_user.organization dashboard_path(current_user.organization) else - root_path + "/403" end end diff --git a/public/403.html b/public/403.html new file mode 100644 index 0000000000..e3af451eb5 --- /dev/null +++ b/public/403.html @@ -0,0 +1,66 @@ + + + + The page you were looking for is forbidden (403) + + + + + + +
+
+

The page you were looking for is forbidden.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/spec/requests/static_requests_spec.rb b/spec/requests/static_requests_spec.rb index 529e9f2b7e..b2958d98c5 100644 --- a/spec/requests/static_requests_spec.rb +++ b/spec/requests/static_requests_spec.rb @@ -34,6 +34,21 @@ end end + describe "Non super user without org signed in" do + let(:user_no_org) { User.create(email: "no-org-user@example.org2", password: "password!") } + before do + user_no_org.add_role(:org_user) + sign_in(user_no_org) + end + + describe "GET #index" do + it "redirects to a public/403.html page" do + get root_path + expect(response).to redirect_to("/403") + end + end + end + describe "Super user without org signed in" do before do sign_in(@super_admin_no_org) diff --git a/spec/system/sign_in_system_spec.rb b/spec/system/sign_in_system_spec.rb index 4f03c49ecf..26d282c637 100644 --- a/spec/system/sign_in_system_spec.rb +++ b/spec/system/sign_in_system_spec.rb @@ -40,13 +40,19 @@ end context "when users are valid and don't belong to an organization" do - it "redirects to home " do - user_no_org = create(:user, organization: nil) + let(:user_no_org) { User.create(email: 'no-org-user@example.org2', password: 'password!') } + + before do + user_no_org.add_role(:org_user) + visit new_user_session_path + fill_in "Email", with: user_no_org.email fill_in "Password", with: user_no_org.password click_button "Log in" + end - expect(page).to have_current_path(root_path) + it "redirects to 403" do + expect(page).to have_current_path("/403") end end end