Skip to content

Commit

Permalink
Merge pull request rubyforgood#2559 from josearmandojacq/modify_court…
Browse files Browse the repository at this point in the history
…_mandates

Allows volunteers to modify court orders/court mandates
  • Loading branch information
compwron authored Sep 14, 2021
2 parents ea7c020 + 60a23d8 commit 54ac993
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
38 changes: 19 additions & 19 deletions app/policies/casa_case_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def initialize(user, scope)

def resolve
case @user
when CasaAdmin, Supervisor
scope.by_organization(@user.casa_org)
when Volunteer
scope.actively_assigned_to(user)
else
raise "unrecognized user type #{@user.type}"
when CasaAdmin, Supervisor
scope.by_organization(@user.casa_org)
when Volunteer
scope.actively_assigned_to(user)
else
raise "unrecognized user type #{@user.type}"
end
end
end
Expand Down Expand Up @@ -43,11 +43,11 @@ def can_see_filters?

alias_method :update_case_number?, :is_admin?
alias_method :update_case_status?, :is_admin?
alias_method :update_court_date?, :admin_or_supervisor?
alias_method :update_hearing_type?, :admin_or_supervisor?
alias_method :update_judge?, :admin_or_supervisor?
alias_method :update_court_report_due_date?, :admin_or_supervisor?
alias_method :update_court_mandates?, :admin_or_supervisor?
alias_method :update_court_date?, :admin_or_supervisor_or_volunteer?
alias_method :update_hearing_type?, :admin_or_supervisor_or_volunteer?
alias_method :update_judge?, :admin_or_supervisor_or_volunteer?
alias_method :update_court_report_due_date?, :admin_or_supervisor_or_volunteer?
alias_method :update_court_mandates?, :admin_or_supervisor_or_volunteer?

def permitted_attributes
common_attrs = [
Expand All @@ -57,14 +57,14 @@ def permitted_attributes
]

case @user
when CasaAdmin
common_attrs.concat(%i[case_number birth_month_year_youth court_date court_report_due_date hearing_type_id judge_id])
common_attrs << case_court_mandates_attributes
when Supervisor
common_attrs.concat(%i[court_date court_report_due_date hearing_type_id judge_id])
common_attrs << case_court_mandates_attributes
else
common_attrs
when CasaAdmin
common_attrs.concat(%i[case_number birth_month_year_youth court_date court_report_due_date hearing_type_id judge_id])
common_attrs << case_court_mandates_attributes
when Supervisor, Volunteer
common_attrs.concat(%i[court_date court_report_due_date hearing_type_id judge_id])
common_attrs << case_court_mandates_attributes
else
common_attrs
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/policies/casa_case_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@
end

context "when user is a volunteer" do
it "does not allow update" do
is_expected.not_to permit(volunteer, casa_case)
it "allows to update" do
is_expected.to permit(volunteer, casa_case)
end
end
end

permissions :update_birth_month_year_youth? do
permissions :update_hearing_type?, :update_judge?, :update_court_mandates? do
context "when user is an admin" do
it "allow update" do
it "allows to update" do
is_expected.to permit(casa_admin, casa_case)
end
end

context "when user is a supervisor" do
it "does not allow update" do
is_expected.not_to permit(supervisor, casa_case)
it "allows to update" do
is_expected.to permit(supervisor, casa_case)
end
end

context "when user is a volunteer" do
it "does not allow update" do
is_expected.not_to permit(volunteer, casa_case)
it "allows to update" do
is_expected.to permit(volunteer, casa_case)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/casa_cases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@

# Not permitted
expect(casa_case.case_number).to eq "111"
expect(casa_case.hearing_type).to_not eq hearing_type
expect(casa_case.judge).to_not eq judge
expect(casa_case.case_court_mandates.size).to be 0
expect(casa_case.hearing_type).to eq hearing_type
expect(casa_case.judge).to eq judge
expect(casa_case.case_court_mandates.size).to be 2
end

it "redirects to the casa_case" do
Expand Down
8 changes: 4 additions & 4 deletions spec/system/casa_cases/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,12 @@ def sign_in_and_assign_volunteer
click_on "Update CASA Case"
end

expect(page).not_to have_text("Day")
expect(page).not_to have_text("Month")
expect(page).not_to have_text("Year")
expect(page).to have_text("Day")
expect(page).to have_text("Month")
expect(page).to have_text("Year")
expect(page).not_to have_text("Deactivate Case")

expect(page).not_to have_css("#add-mandate-button")
expect(page).to have_css("#add-mandate-button")

visit casa_case_path(casa_case)
expect(page).to have_text("Court Report Status: Submitted")
Expand Down

0 comments on commit 54ac993

Please sign in to comment.