Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for authorize after security breach Dec 2022 #3097

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/contributors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def edit
# rubocop:disable Metrics/AbcSize
# POST /plans/:plan_id/contributors
def create
authorize @plan
# to create a contributor you need to be able to edit the plan
authorize @plan, :edit?

args = translate_roles(hash: contributor_params)
args = process_org(hash: args)
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def create
@note = Note.new
# take user id from current user rather than form as form can be spoofed
@note.user_id = current_user.id
# ensure user has access to plan BEFORE creating/finding answer
unless Plan.find_by(id: note_params[:plan_id]).readable_by?(@note.user_id)
raise Pundit::NotAuthorizedError
end

Answer.transaction do
@answer = Answer.find_by(
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/org_admin/phase_versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class OrgAdmin::PhaseVersionsController < ApplicationController
# POST /org_admin/templates/:template_id/phases/:phase_id/versions
def create
@phase = Phase.find(params[:phase_id])
authorize @phase, :create?
authorize @phase
@new_phase = get_modifiable(@phase)
flash[:notice] = if @new_phase == @phase
"This template is already a draft"
Expand Down
8 changes: 2 additions & 6 deletions app/controllers/paginable/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ class Paginable::PlansController < ApplicationController

# /paginable/plans/privately_visible/:page
def privately_visible
unless Paginable::PlanPolicy.new(current_user).privately_visible?
raise Pundit::NotAuthorizedError
end
authorize Plan

paginable_renderise(
partial: "privately_visible",
Expand All @@ -20,9 +18,7 @@ def privately_visible

# GET /paginable/plans/organisationally_or_publicly_visible/:page
def organisationally_or_publicly_visible
unless Paginable::PlanPolicy.new(current_user).organisationally_or_publicly_visible?
raise Pundit::NotAuthorizedError
end
authorize Plan

paginable_renderise(
partial: "organisationally_or_publicly_visible",
Expand Down
5 changes: 5 additions & 0 deletions app/policies/department_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def initialize(user, department)
@department = department
end

def index?
(@user.can_org_admin? && @user.org.id == @department.org_id) ||
@user.can_super_admin?
end

def new?
@user.can_org_admin? || @user.can_super_admin?
end
Expand Down
21 changes: 0 additions & 21 deletions app/policies/paginable/plan_policy.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/policies/phase_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def preview?
user.can_modify_templates? && (phase.template.org_id == user.org_id)
end

def edit?
user.can_modify_templates? && (phase.template.org_id == user.org_id)
end

def update?
user.can_modify_templates? && (phase.template.org_id == user.org_id)
end
Expand Down
12 changes: 12 additions & 0 deletions app/policies/plan_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def initialize(user, plan)
@plan = plan
end

def index?
@user.present?
end

def show?
@plan.readable_by?(@user.id)
end
Expand Down Expand Up @@ -82,4 +86,12 @@ def update_guidances_list?
@plan.editable_by?(@user.id)
end

def privately_visible?
@user.present?
end

def organisationally_or_publicly_visible?
@user.present?
end

end
4 changes: 2 additions & 2 deletions app/policies/section_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def initialize(user, section)
##

def index?
user.present?
@user.present?
end

def show?
user.present?
@user.present?
end

def edit?
Expand Down