fix(sharing): per-user calendar colour works for every sharing path

The recipient colour was stored on calendar_shares, so it only worked for
DIRECT shares. A calendar made visible through a group (a co-member's
group_visible_calendar_id) has no CalendarShare row, so the colour endpoint
returned 403 and nothing was saved — the reported "colour picker opens but the
colour stays the same" for a group-shared calendar.

Replace the share-scoped colour with a general per-user override table
(calendar_color_prefs, keyed by user+calendar). PUT /calendars/{id}/color now
accepts any calendar the user can read (readable_local_calendar_ids covers
direct shares, group calendars AND group-visible), and the merge read + calendar
list apply the override for all of them. Owners still set the shared colour.
The new table is created by create_all; the old calendar_shares.color is unused.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-06 21:38:16 +02:00
parent b8a578cf53
commit 1eecf834a3
4 changed files with 58 additions and 12 deletions

View File

@@ -367,6 +367,8 @@ def get_events(
models.GroupCalendar.calendar_id.in_(readable_ids)
)
} if readable_ids else set()
# Per-user colour overrides for calendars the user doesn't own (any share path).
color_prefs = permissions.color_prefs_for(db, current_user.id)
# Cache each owner's private-event visibility (one lookup per owner, not per event).
vis_cache: dict = {}
@@ -384,7 +386,7 @@ def get_events(
share = shares_by_cal.get(local_cal.id) if is_shared_personal else None
shared_owner_name = name_cache.get(local_cal.user_id) if is_shared_personal else None
shared_read_only = is_shared_personal and (share.permission if share else None) != "read_write"
shared_color = share.color if share else None
shared_color = color_prefs.get(local_cal.id)
local_events = (
db.query(models.LocalEvent)
.filter(