mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-17 19:36:28 +02:00
feat(projects): URL field + cover photo on project cards (#1155)
Two new project fields: a free-text URL rendered as a one-click
external-link button beside the project name on every card (opens in a
new tab, click is e.stopPropagation()-guarded so it doesn't enter the
project), and a cover photo that replaces the status-icon box with a
square thumbnail.
URL is plumbed through ProjectCreate/Update/Response/ListResponse,
including from-template + create-template flows so it inherits between
a project and its template. Cover photo is not inherited because the
file would be shared on disk between source and copy.
Schema validator rejects anything other than http:// or https://
prefixes -- <a href> rendering would otherwise execute javascript:
/ data: / file: URLs even with React's default escaping. PATCH uses
model_fields_set for the URL field so users can clear it by sending
{"url": null}.
Cover image storage: Project.cover_image_filename references a file
Cover image storage: Project.cover_image_filename references a file
inside the existing archives/projects/{id}/attachments/ dir, but it's
tracked separately from the attachments JSON list so swap/delete on
the cover doesn't perturb the user's other attachments. Three routes
(POST/GET/DELETE /projects/{id}/cover-image) accept only .jpg/.jpeg/
.png/.gif/.webp (no SVG -- SVG can carry script payloads), replace in
place (prior file deleted before the new one lands so repeat uploads
can't accumulate orphans), and self-heal when a DB reference points at
a vanished disk file by clearing the column and 404'ing.
GET cover-image is gated by RequireCameraStreamTokenIfAuthEnabled
(accepts ?token=... query string) -- not the bearer-token gate -- so
<img src> requests work in both auth-on and auth-off configurations.
The frontend wraps getProjectCoverImageUrl with withStreamToken(),
matching the existing pattern from getArchiveThumbnail.
Permissions: PROJECTS_UPDATE for upload/delete/PATCH, PROJECTS_READ
gate is implicit via the stream-token credential. Migration: 2
idempotent ALTER TABLE projects ADD COLUMN. Localised across all 8
UI languages.
This commit is contained in:
@@ -32,6 +32,23 @@ def manager():
|
||||
return PrinterManager()
|
||||
|
||||
|
||||
def _close_unawaited(coro):
|
||||
"""Side effect for mocked ``_schedule_async``.
|
||||
|
||||
``set_awaiting_plate_clear`` evaluates the coroutine expressions
|
||||
``self._persist_awaiting_plate_clear(...)`` and
|
||||
``self._broadcast_status_change(...)`` before passing them to
|
||||
``_schedule_async``. When that target is patched, the coroutine objects
|
||||
leak — Python's ``__del__`` then emits ``coroutine was never awaited``
|
||||
during GC, and when GC runs late enough that warning hits the interpreter
|
||||
shutdown path with ``KeyError: '__import__'``. Closing the coroutine here
|
||||
prevents both. Returns ``None`` so the mock's call signature is unchanged.
|
||||
"""
|
||||
if asyncio.iscoroutine(coro):
|
||||
coro.close()
|
||||
return None
|
||||
|
||||
|
||||
def _fake_state(**overrides):
|
||||
"""Minimal stand-in for a ``PrinterState`` — only the attributes
|
||||
``printer_state_to_dict`` reads. We use a SimpleNamespace rather than
|
||||
@@ -58,7 +75,7 @@ class TestSchedulingFromSetAwaitingPlateClear:
|
||||
manager._loop = MagicMock()
|
||||
manager._loop.is_running.return_value = True
|
||||
|
||||
with patch.object(manager, "_schedule_async") as scheduled:
|
||||
with patch.object(manager, "_schedule_async", side_effect=_close_unawaited) as scheduled:
|
||||
manager.set_awaiting_plate_clear(7, True)
|
||||
|
||||
# Two coroutines: persist + broadcast. Order doesn't matter.
|
||||
@@ -96,7 +113,7 @@ class TestSchedulingFromSetAwaitingPlateClear:
|
||||
manager._loop = MagicMock()
|
||||
manager._loop.is_running.return_value = True
|
||||
|
||||
with patch.object(manager, "_schedule_async") as scheduled:
|
||||
with patch.object(manager, "_schedule_async", side_effect=_close_unawaited) as scheduled:
|
||||
manager.set_awaiting_plate_clear(7, True)
|
||||
scheduled.reset_mock()
|
||||
manager.set_awaiting_plate_clear(7, False)
|
||||
|
||||
Reference in New Issue
Block a user