Sharing:
- New HeapShare and FolderShare models with read/write permissions
- Sharing API router (CRUD for heap and folder shares)
- Heap endpoints accept shared access (photo_ids, add/remove with write)
- Photo list drops user_id filter in shared context, adds owner_username
- Media serving (thumb/original/proxy) falls back to share check on 404
- ShareDialog component for managing shares from kebab menus
- HeapsPanel shows "Shared with me" section for shared heaps
- LeftSidebar shows "Shared with me" section for shared folders
- Owner badge on PhotoThumbnail for photos from other users
Auth:
- Access token default bumped to 1 year, refresh to 10 years
- Refresh token persisted in localStorage (survives page reload)
- Timer-based refresh replaced with 401 axios interceptor
Vision pipeline fixes:
- Bootstrap sets Redis ready key even on partial export failure
- Export functions run conditionally (only for actually missing models)
- _load_thumb handles multi-user path (/data/thumbs/{user_id}/{photo_id}/)
- can_access_photo_via_share uses single subquery instead of N+1 loop
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
"""
|
|
Sharing models — cross-user access to heaps and folders.
|
|
|
|
HeapShare grants another user read or read+write access to a heap.
|
|
FolderShare does the same for a folder (or source root).
|
|
"""
|
|
import uuid
|
|
|
|
from sqlalchemy import (
|
|
Column, DateTime, ForeignKey, Index, String, UniqueConstraint, func,
|
|
)
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class HeapShare(Base):
|
|
__tablename__ = "heap_shares"
|
|
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
heap_id = Column(
|
|
String, ForeignKey("heaps.id", ondelete="CASCADE"), nullable=False,
|
|
)
|
|
# Denormalized from heap.user_id for fast "shares I own" lookups.
|
|
owner_id = Column(String, ForeignKey("users.id"), nullable=False)
|
|
shared_with_id = Column(String, ForeignKey("users.id"), nullable=False)
|
|
permission = Column(String, nullable=False, default="read") # 'read' | 'write'
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("heap_id", "shared_with_id", name="uq_heap_share"),
|
|
Index("ix_heap_shares_shared_with", "shared_with_id"),
|
|
Index("ix_heap_shares_heap_id", "heap_id"),
|
|
)
|
|
|
|
|
|
class FolderShare(Base):
|
|
__tablename__ = "folder_shares"
|
|
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
# Can reference either a Folder.id or a SourceRoot.id.
|
|
folder_id = Column(String, nullable=False)
|
|
folder_type = Column(String, nullable=False, default="folder") # 'folder' | 'source_root'
|
|
owner_id = Column(String, ForeignKey("users.id"), nullable=False)
|
|
shared_with_id = Column(String, ForeignKey("users.id"), nullable=False)
|
|
permission = Column(String, nullable=False, default="read") # 'read' | 'write'
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("folder_id", "shared_with_id", name="uq_folder_share"),
|
|
Index("ix_folder_shares_shared_with", "shared_with_id"),
|
|
Index("ix_folder_shares_folder_id", "folder_id"),
|
|
)
|