-
Notifications
You must be signed in to change notification settings - Fork 95
fix: Google calendar my starred sessions #394
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
fix: Google calendar my starred sessions #394
Conversation
Reviewer's GuideThis PR implements a signed‐token mechanism for “my starred” ICS exports to resolve Google Calendar failures by embedding user‐scoped, expiring tokens in URLs, extending the ExporterView to consume these tokens without requiring a login, managing token issuance and renewal in session, and exposing a new tokenized export route. Sequence diagram for tokenized ICS export for Google CalendarsequenceDiagram
actor User
participant Browser
participant ExporterView
participant Session
participant GoogleCalendar
User->>Browser: Clicks 'Export to Google Calendar'
Browser->>ExporterView: GET /export.my-google-calendar
ExporterView->>Session: Check for existing token
alt Token valid and not expiring soon
ExporterView->>Browser: Respond with webcal:// URL containing token
else Token missing or expiring soon
ExporterView->>ExporterView: Generate new token
ExporterView->>Session: Store new token
ExporterView->>Browser: Respond with webcal:// URL containing new token
end
Browser->>GoogleCalendar: Subscribes using webcal:// URL with token
GoogleCalendar->>ExporterView: GET /export/schedule-my.ics/<token>/
ExporterView->>ExporterView: Parse and validate token
alt Token valid
ExporterView->>ExporterView: Fetch starred sessions for user
ExporterView->>GoogleCalendar: Return ICS file
else Token invalid
ExporterView->>GoogleCalendar: Return 404
end
Entity relationship diagram for tokenized ICS exporterDiagram
USER ||--o{ SUBMISSIONFAVOURITE : has
SUBMISSIONFAVOURITE {
int id
int user
int submission_id
}
ICS_TOKEN {
int user_id
int exp
}
Class diagram for updated ExporterView and ScheduleMixinclassDiagram
class ScheduleMixin {
+generate_ics_token(user_id)
+parse_ics_token(token)
+check_token_expiry(token)
}
class ExporterView {
+get_context_data(**kwargs)
+get_exporter(public=True)
+get(request, *args, **kwargs)
}
ExporterView --|> ScheduleMixin
File-Level Changes
Possibly 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 @Saksham-Sirohi - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/pretalx/agenda/views/schedule.py:90` </location>
<code_context>
+ return None
+
+ @staticmethod
+ def check_token_expiry(token):
+ """Check if a token exists and has more than 4 days until expiry
+
+ Returns:
+ - None if token is invalid
+ - False if token is valid but expiring soon (< 4 days)
+ - True if token is valid and not expiring soon (>= 4 days)
+ """
+ try:
+ value = signing.loads(token, salt="my-starred-ics")
+ expiry_date = timezone.datetime.fromtimestamp(value["exp"], tz=timezone.utc)
+ days_until_expiry = (expiry_date - timezone.now()).days
+
+ # Token is valid but check if it's expiring soon
+ if days_until_expiry < 4:
+ return False # Valid but expiring soon
+ return True # Valid and not expiring soon
+ except Exception:
+ return None # Invalid token
</code_context>
<issue_to_address>
Token expiry calculation may be inaccurate due to use of .days.
Using .days truncates partial days, which may cause tokens to be flagged as 'expiring soon' prematurely. For more accurate results, use total_seconds() or compare the timedelta directly to timedelta(days=4).
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
@staticmethod
def check_token_expiry(token):
"""Check if a token exists and has more than 4 days until expiry
Returns:
- None if token is invalid
- False if token is valid but expiring soon (< 4 days)
- True if token is valid and not expiring soon (>= 4 days)
"""
try:
value = signing.loads(token, salt="my-starred-ics")
expiry_date = timezone.datetime.fromtimestamp(value["exp"], tz=timezone.utc)
days_until_expiry = (expiry_date - timezone.now()).days
# Token is valid but check if it's expiring soon
if days_until_expiry < 4:
return False # Valid but expiring soon
return True # Valid and not expiring soon
except Exception:
return None # Invalid token
=======
@staticmethod
def check_token_expiry(token):
"""Check if a token exists and has more than 4 days until expiry
Returns:
- None if token is invalid
- False if token is valid but expiring soon (< 4 days)
- True if token is valid and not expiring soon (>= 4 days)
"""
try:
value = signing.loads(token, salt="my-starred-ics")
expiry_date = timezone.datetime.fromtimestamp(value["exp"], tz=timezone.utc)
time_until_expiry = expiry_date - timezone.now()
# Token is valid but check if it's expiring soon
if time_until_expiry < timedelta(days=4):
return False # Valid but expiring soon
return True # Valid and not expiring soon
except Exception:
return None # Invalid token
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Please test the changes. The starred webcal file can now be accessed without authentication or tokens, as intended. This will require verification in a working environment. All other export formats remain unchanged and continue to function as before. |
8c2864c to
8b7057f
Compare
Fixes google calander starred export failure
Fixes #172
Summary by Sourcery
Support token-based iCal exports for starred sessions to enable Google Calendar integration without forcing user login.
New Features:
Enhancements: