refactor: simplify ICS calendar API to return only duty shifts
All checks were successful
CI / lint-and-test (push) Successful in 24s
All checks were successful
CI / lint-and-test (push) Successful in 24s
- Removed the ability to specify multiple event types in the ICS calendar generation API, ensuring it only returns duty shifts. - Updated the associated test to reflect the change in behavior, confirming that unknown query parameters are ignored. - Revised documentation to clarify the API's focus on duty shifts only, enhancing clarity for users.
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
import logging
|
||||
import re
|
||||
from datetime import date, timedelta
|
||||
from typing import Literal
|
||||
|
||||
import duty_teller.config as config
|
||||
from fastapi import Depends, FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -100,20 +98,16 @@ def list_calendar_events(
|
||||
"/api/calendar/ical/{token}.ics",
|
||||
summary="Personal calendar ICS",
|
||||
description=(
|
||||
"Returns an ICS calendar with the subscribing user's events. "
|
||||
"By default only duty shifts are included; use query parameter events=all "
|
||||
"for all event types (duty, unavailable, vacation). "
|
||||
"Returns an ICS calendar with the subscribing user's duty shifts only. "
|
||||
"No Telegram auth; access is by secret token in the URL."
|
||||
),
|
||||
)
|
||||
def get_personal_calendar_ical(
|
||||
token: str,
|
||||
events: Literal["duty", "all"] = "duty",
|
||||
session: Session = Depends(get_db_session),
|
||||
) -> Response:
|
||||
"""
|
||||
Return ICS calendar with the subscribing user's events.
|
||||
Default: only duty shifts. Use ?events=all for duty, unavailable, vacation.
|
||||
Return ICS calendar with the subscribing user's duty shifts only.
|
||||
No Telegram auth; access is by secret token in the URL.
|
||||
"""
|
||||
if not _is_valid_calendar_token(token):
|
||||
@@ -124,9 +118,8 @@ def get_personal_calendar_ical(
|
||||
today = date.today()
|
||||
from_date = (today - timedelta(days=365)).strftime("%Y-%m-%d")
|
||||
to_date = (today + timedelta(days=365 * 2)).strftime("%Y-%m-%d")
|
||||
event_types = ["duty"] if events == "duty" else None
|
||||
duties_with_name = get_duties_for_user(
|
||||
session, user.id, from_date=from_date, to_date=to_date, event_types=event_types
|
||||
session, user.id, from_date=from_date, to_date=to_date, event_types=["duty"]
|
||||
)
|
||||
ics_bytes = build_personal_ics(duties_with_name)
|
||||
return Response(
|
||||
|
||||
Reference in New Issue
Block a user