-
Notifications
You must be signed in to change notification settings - Fork 166
fix: Handle AnonymousUser in has_event_perm template tag and ScheduleView #1504
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
base: enext
Are you sure you want to change the base?
fix: Handle AnonymousUser in has_event_perm template tag and ScheduleView #1504
Conversation
…View Fixed AttributeError when anonymous users access public pages like CFP: - Added is_authenticated check in has_event_perm template tag before calling User.has_perm(), which requires permission_cache attribute - Added is_authenticated check in ScheduleView.dispatch before checking has_perm for featured submissions redirect This bug occurred because AnonymousUser doesn't have the permission_cache attribute that is initialized in the custom User model's __init__ method. Fixes: AnonymousUser object has no attribute 'permission_cache'
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsure permission checks for schedule viewing and template tag usage safely handle AnonymousUser instances by gating permission logic behind is_authenticated checks. Sequence diagram for updated ScheduleView.dispatch permission handlingsequenceDiagram
actor AnonymousUser as AnonymousUser
participant Browser as Browser
participant ScheduleView as ScheduleView
participant PermissionSystem as PermissionSystem
participant Messages as Messages
AnonymousUser->>Browser: Request schedule page
Browser->>ScheduleView: HTTP GET /schedule
ScheduleView->>ScheduleView: has_permission()
alt has_permission returns false
ScheduleView->>ScheduleView: check request.user.is_authenticated
alt user is authenticated
ScheduleView->>PermissionSystem: has_perm(list_featured_submission, event)
alt user has permission
ScheduleView->>Messages: messages.success("Our schedule is not live yet.")
ScheduleView-->>Browser: Redirect to featured submissions
else user lacks permission
ScheduleView-->>Browser: Normal response without redirect
end
else user is AnonymousUser
ScheduleView-->>Browser: Normal response without redirect
end
else has_permission returns true
ScheduleView-->>Browser: Normal schedule response
end
Sequence diagram for updated has_event_perm template tagsequenceDiagram
participant Template as DjangoTemplate
participant Tag as has_event_perm
participant AdminMode as is_admin_mode_active
participant UserClass as User
Template->>Tag: has_event_perm(perm, user, request, obj)
Tag->>Tag: check user.is_authenticated
alt user is not authenticated
Tag-->>Template: False
else user is authenticated
Tag->>AdminMode: is_admin_mode_active(request)
alt admin mode active
Tag-->>Template: True
else admin mode not active
Tag->>UserClass: has_perm(user, perm, obj)
UserClass-->>Tag: permission_result
Tag-->>Template: permission_result
end
end
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- In
ScheduleView.dispatch, the condition mixesrequest.userandself.request.user; consider using a single source consistently (e.g.,request.user) to avoid subtle discrepancies or future confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ScheduleView.dispatch`, the condition mixes `request.user` and `self.request.user`; consider using a single source consistently (e.g., `request.user`) to avoid subtle discrepancies or future confusion.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Earlier AnonymousUser doesn't have the permission_cache attribute

Fixes #1503
Summary by Sourcery
Handle anonymous users safely in permission checks for schedule view and event permission template tag.
Bug Fixes: