Skip to content

Display error message for unauthorized court date visit attempt - #6460

Merged
compwron merged 5 commits into
rubyforgood:mainfrom
kanishk333gupta:handle-unauthorized-court-date-visit
Jul 23, 2025
Merged

Display error message for unauthorized court date visit attempt#6460
compwron merged 5 commits into
rubyforgood:mainfrom
kanishk333gupta:handle-unauthorized-court-date-visit

Conversation

@kanishk333gupta

Copy link
Copy Markdown
Contributor

What github issue is this PR for, if any?

Resolves #6457

What changed, and why?

Showing unauthorized message instead of 404 error. We were getting this error when user not authorized to view a court date either from an organization not containing the court date's parent casa case or a volunteer not assigned to the court date's parent casa case.

How is this tested? (please write rspec and jest tests!) 💖💪

Updated spec/requests/court_dates_spec.rb.

Screenshots

For fix, I have used similar pattern for errors as how it's used in app/controllers/casa_cases_controller.rb#set_casa_case .

  • Image before changes Screenshot from 2025-07-23 18-56-55
  • Image after changes Screenshot from 2025-07-23 18-58-55

@compwron
compwron requested a review from Copilot July 23, 2025 16:04
compwron
compwron previously approved these changes Jul 23, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces a 404 error with a more user-friendly unauthorized access message when users attempt to access court dates they don't have permission to view. The change improves the user experience by providing clearer feedback about authorization issues.

  • Added error handling in the set_casa_case method to catch unauthorized access attempts
  • Updated the response to redirect users to the casa cases page with an informative flash message
  • Modified tests to verify the new redirect behavior instead of expecting a 404 response

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/controllers/court_dates_controller.rb Added rescue block to handle unauthorized access with redirect and flash message
spec/requests/court_dates_spec.rb Updated test expectations to verify redirect behavior and flash message

Comment thread spec/requests/court_dates_spec.rb
Comment thread app/controllers/court_dates_controller.rb Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@compwron
compwron merged commit 52e1bdf into rubyforgood:main Jul 23, 2025
8 of 10 checks passed
@kanishk333gupta

Copy link
Copy Markdown
Contributor Author

Thanks @compwron for improving silly mistakes. I did my changes in local and pasted it in codespace, which was not working fine right now, for adding PR. So missed these completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Touches Ruby code 🧪 Tests Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gracefully handle unauthorized court date visit attempts

3 participants