From c3ea7596afc497e200f313fc51781295e323bbba Mon Sep 17 00:00:00 2001 From: Melissa Autumn Date: Tue, 22 Oct 2024 09:53:22 -0700 Subject: [PATCH] Specify a default calendar colour so we don't accidentally crash --- backend/src/appointment/controller/calendar.py | 4 ++-- backend/src/appointment/database/schemas.py | 4 +++- backend/src/appointment/defines.py | 3 +++ backend/src/appointment/routes/api.py | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/src/appointment/controller/calendar.py b/backend/src/appointment/controller/calendar.py index 65faeb4e..1d5e7c0b 100644 --- a/backend/src/appointment/controller/calendar.py +++ b/backend/src/appointment/controller/calendar.py @@ -26,7 +26,7 @@ from .. import utils from ..database.schemas import CalendarConnection -from ..defines import REDIS_REMOTE_EVENTS_KEY, DATEFMT +from ..defines import REDIS_REMOTE_EVENTS_KEY, DATEFMT, DEFAULT_CALENDAR_COLOUR from .apis.google_client import GoogleClient from ..database.models import CalendarProvider, BookingStatus from ..database import schemas, models, repo @@ -341,7 +341,7 @@ def sync_calendars(self): user=self.user, password=self.password, provider=CalendarProvider.caldav, - color='#c276c5' # Pick a default colour for now! + color=DEFAULT_CALENDAR_COLOUR # Pick a default colour for now! ) # add calendar diff --git a/backend/src/appointment/database/schemas.py b/backend/src/appointment/database/schemas.py index 840e1a0d..4de4e135 100644 --- a/backend/src/appointment/database/schemas.py +++ b/backend/src/appointment/database/schemas.py @@ -11,6 +11,8 @@ from pydantic import BaseModel, Field, EmailStr, model_validator from pydantic_core import PydanticCustomError + +from ..defines import DEFAULT_CALENDAR_COLOUR from ..l10n import l10n @@ -243,7 +245,7 @@ class ScheduleSlug(BaseModel): class CalendarBase(BaseModel): title: str | None = None - color: str | None = None + color: str | None = DEFAULT_CALENDAR_COLOUR connected: bool | None = None diff --git a/backend/src/appointment/defines.py b/backend/src/appointment/defines.py index bf33d024..6d439d12 100644 --- a/backend/src/appointment/defines.py +++ b/backend/src/appointment/defines.py @@ -18,3 +18,6 @@ # Custom pydantic error types END_TIME_BEFORE_START_TIME_ERR = 'end_time_before_start_time' + +# CalDAV doesn't provide colours afaik +DEFAULT_CALENDAR_COLOUR = '#c276c5' diff --git a/backend/src/appointment/routes/api.py b/backend/src/appointment/routes/api.py index 098edcbf..5801dfa0 100644 --- a/backend/src/appointment/routes/api.py +++ b/backend/src/appointment/routes/api.py @@ -27,6 +27,7 @@ from ..controller.auth import signed_url_by_subscriber, schedule_links_by_subscriber from ..database.models import Subscriber, CalendarProvider, MeetingLinkProviderType, ExternalConnectionType, \ InviteStatus +from ..defines import DEFAULT_CALENDAR_COLOUR from ..dependencies.google import get_google_client from ..dependencies.auth import get_subscriber from ..dependencies.database import get_db, get_redis @@ -102,7 +103,7 @@ def read_my_appointments(db: Session = Depends(get_db), subscriber: Subscriber = # Note because we `__dict__` any relationship values won't be carried over, so don't forget to manually add those! appointments = map( lambda x: schemas.AppointmentWithCalendarOut( - **x.__dict__, calendar_title=x.calendar.title, calendar_color=x.calendar.color + **x.__dict__, calendar_title=x.calendar.title, calendar_color=x.calendar.color or DEFAULT_CALENDAR_COLOUR ), appointments, )