Skip to content

Commit d8d51f0

Browse files
committed
WIP: check org membership before displaying report
1 parent 64d20c1 commit d8d51f0

5 files changed

+13
-8
lines changed

app/controllers/application_controller.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def authorize_user
6565
current_user.has_role?(Role::PARTNER, current_partner)
6666
end
6767

68+
def authorize_org_user
69+
verboten! unless current_user.has_role?(Role::SUPER_ADMIN) ||
70+
current_user.has_role?(Role::ORG_USER, current_organization)
71+
end
72+
6873
def authorize_admin
6974
verboten! unless current_user.has_role?(Role::SUPER_ADMIN) ||
7075
current_user.has_role?(Role::ORG_ADMIN, current_organization)
@@ -97,9 +102,9 @@ def not_found!
97102
end
98103
end
99104

100-
def verboten!
105+
def verboten!(message: 'Access Denied.')
101106
respond_to do |format|
102-
format.html { redirect_to dashboard_path_from_current_role, flash: { error: "Access Denied." } }
107+
format.html { redirect_to dashboard_path_from_current_role, flash: { error: message } }
103108
format.json { render body: nil, status: :forbidden }
104109
end
105110
end

app/controllers/organizations_controller.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Provides limited R/W to a scope-limited organization resource (member-routes-only)
22
class OrganizationsController < ApplicationController
33
before_action :authorize_admin, except: [:show]
4-
before_action :authorize_user, only: [:show]
4+
before_action :authorize_org_user, only: [:show]
55

66
def show
77
@organization = current_organization
@@ -80,11 +80,6 @@ def remove_user
8080

8181
private
8282

83-
def authorize_user
84-
verboten! unless current_user.has_role?(Role::SUPER_ADMIN) ||
85-
current_user.has_role?(Role::ORG_USER, current_organization)
86-
end
87-
8883
def organization_params
8984
request_type_formatter(params)
9085

app/controllers/reports/annual_reports_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Reports::AnnualReportsController < ApplicationController
22
before_action :validate_show_params, only: [:show, :recalculate]
3+
before_action :authorize_org_user
34

45
def index
56
# 2813_update_annual_report -- changed to earliest_reporting_year

app/controllers/reports_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class ReportsController < ApplicationController
22
before_action :setup_date_range_picker
3+
before_action :authorize_org_user
34

45
def donations_summary
56
@donations = current_organization.donations.during(helpers.selected_range)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RSpec.describe ReportsController do
2+
let(:organization) { create(:organization) }
3+
end

0 commit comments

Comments
 (0)