Skip to content

Commit 52e1bdf

Browse files
authored
Merge pull request #6460 from kanishk333gupta/handle-unauthorized-court-date-visit
Display error message for unauthorized court date visit attempt
2 parents acf9c61 + 00f9c93 commit 52e1bdf

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/controllers/court_dates_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def destroy
6565

6666
def set_casa_case
6767
@casa_case = current_organization.casa_cases.friendly.find(params[:casa_case_id])
68+
rescue ActiveRecord::RecordNotFound
69+
respond_to do |format|
70+
format.html { redirect_to casa_cases_path, notice: "Sorry, you are not authorized to perform this action." }
71+
format.json { render json: {error: "Sorry, you are not authorized to perform this action."}, status: :unauthorized }
72+
end
6873
end
6974

7075
def set_court_date

spec/requests/court_dates_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@
182182
other_case = create(:casa_case, casa_org: other_org)
183183

184184
get edit_casa_case_court_date_path(other_case, court_date)
185-
expect(response).to be_not_found
185+
expect(response).to redirect_to(casa_cases_path)
186+
expect(response.status).to match 302
187+
expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
186188
end
187189
end
188190

0 commit comments

Comments
 (0)