Skip to content

Commit e747392

Browse files
authored
Merge pull request #5089 from coalest/4511-need-a-graceful-landing-if-someone-goes-to-a-screen-they-dont-have-access-to-while-logged-in
Redirect to partners dashboard with flash message for org-related pages
2 parents 98ab422 + f142747 commit e747392

17 files changed

+108
-12
lines changed

app/controllers/account_requests_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class AccountRequestsController < ApplicationController
22
skip_before_action :authorize_user
33
skip_before_action :authenticate_user!
4+
skip_before_action :require_organization
45

56
before_action :set_account_request_from_token, only: [:received, :confirmation, :confirm]
67

app/controllers/admin_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# [Super Admin] This is the parent controller for the Admin namespace, and also provides the Dashboard data for SuperAdmins.
22
class AdminController < ApplicationController
33
before_action :require_admin
4+
skip_before_action :require_organization
45

56
def require_admin
67
verboten! unless current_user.has_cached_role?(Role::SUPER_ADMIN)

app/controllers/application_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
66
protect_from_forgery with: :exception
77
before_action :authenticate_user!
88
before_action :authorize_user
9+
before_action :require_organization, unless: :devise_controller?
910
before_action :log_active_user
1011
before_action :swaddled
1112
before_action :configure_permitted_parameters, if: :devise_controller?
@@ -82,6 +83,15 @@ def authorize_admin
8283
current_user.has_cached_role?(Role::ORG_ADMIN, current_organization)
8384
end
8485

86+
def require_organization
87+
return if current_organization
88+
89+
respond_to do |format|
90+
format.html { redirect_to dashboard_path_from_current_role, flash: {error: "That screen is not available. Please try again as a bank."} }
91+
format.json { render body: nil, status: :forbidden }
92+
end
93+
end
94+
8595
def log_active_user
8696
if current_user && should_update_last_request_at?
8797
# we don't want the user record to validate or run callbacks when we're tracking activity

app/controllers/distributions_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DistributionsController < ApplicationController
1010
before_action :enable_turbo!, only: %i[new show]
1111
skip_before_action :authenticate_user!, only: %i(calendar)
1212
skip_before_action :authorize_user, only: %i(calendar)
13+
skip_before_action :require_organization, only: %i(calendar)
1314

1415
def print
1516
@distribution = Distribution.find(params[:id])

app/controllers/partners/base_controller.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class BaseController < ApplicationController
33
layout 'partners/application'
44

55
before_action :require_partner
6+
skip_before_action :require_organization
67

78
private
89

@@ -11,11 +12,11 @@ def redirect_to_root
1112
end
1213

1314
def require_partner
14-
unless current_partner
15-
respond_to do |format|
16-
format.html { redirect_to dashboard_path, flash: {error: "Logged in user is not set up as a 'partner'."} }
17-
format.json { render body: nil, status: :forbidden }
18-
end
15+
return if current_partner
16+
17+
respond_to do |format|
18+
format.html { redirect_to dashboard_path, flash: {error: "That screen is not available. Please try again as a partner."} }
19+
format.json { render body: nil, status: :forbidden }
1920
end
2021
end
2122

app/controllers/partners/requests_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def require_partner_or_org_admin
103103

104104
def redirect_invalid_user
105105
respond_to do |format|
106-
format.html { redirect_to dashboard_path, flash: {error: "Logged in user is not set up as a 'partner'."} }
106+
format.html { redirect_to dashboard_path, flash: {error: "That screen is not available. Please try again as a partner."} }
107107
format.json { render body: nil, status: :forbidden }
108108
end
109109
end

app/controllers/partners_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class PartnersController < ApplicationController
55
include Importable
66
before_action :validate_user_role, only: :show
7+
skip_before_action :require_organization, only: :show
78

89
def index
910
@partners = current_organization.partners.includes(:partner_group).alphabetized

app/controllers/static_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
class StaticController < ApplicationController
33
skip_before_action :authorize_user
44
skip_before_action :authenticate_user!
5+
skip_before_action :require_organization
56
skip_before_action :log_active_user
67

78
layout false

app/controllers/users_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Provides scope-limited access to viewing the data of other users
22
class UsersController < ApplicationController
3+
skip_before_action :require_organization, only: [:switch_to_role]
4+
35
def index
46
@users = current_organization.users
57
end

spec/requests/adjustments_requests_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
expect(subject).to be_successful
4949
end
5050

51+
include_examples "restricts access to organization users/admins"
52+
5153
context 'when filtering by date' do
5254
let!(:old_adjustment) { create(:adjustment, created_at: 7.days.ago) }
5355
let!(:new_adjustment) { create(:adjustment, created_at: 1.day.ago) }

0 commit comments

Comments
 (0)