Skip to content

Guard against nil user in Mentor::Discussion#viewable_by?#8623

Merged
iHiD merged 1 commit into
mainfrom
fix/8622
Feb 12, 2026
Merged

Guard against nil user in Mentor::Discussion#viewable_by?#8623
iHiD merged 1 commit into
mainfrom
fix/8622

Conversation

@iHiD
Copy link
Copy Markdown
Member

@iHiD iHiD commented Feb 12, 2026

Closes #8622

Summary

  • Use safe navigation operator (&.) in Mentor::Discussion#viewable_by? and #viewable_by_mentor? to prevent NoMethodError when user is nil
  • This occurs when an unauthenticated user subscribes to DiscussionPostListChannel — the ActionCable connection allows nil current_user, which gets passed to viewable_by?
  • Added test for nil user case

Test plan

  • bundle exec rails test test/models/mentor/discussion_test.rb — all 19 tests pass
  • New test verifies viewable_by?(nil) returns false

🤖 Generated with Claude Code

When an unauthenticated user subscribes to DiscussionPostListChannel,
current_user is nil. Use safe navigation operator (&.) to prevent
NoMethodError when calling admin? on nil.

Closes #8622

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@iHiD iHiD merged commit 89b85fa into main Feb 12, 2026
41 checks passed
@iHiD iHiD deleted the fix/8622 branch February 12, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NoMethodError: undefined method 'admin?' for nil (NoMethodError)

1 participant