diff --git a/backend/app/routers/library.py b/backend/app/routers/library.py index 5c3acb3..a460905 100644 --- a/backend/app/routers/library.py +++ b/backend/app/routers/library.py @@ -34,6 +34,17 @@ def _owner_filter(user: User, scope: str | None): return sa_true() return Photo.user_id == user.id + +async def _active_source_root_paths( + db: AsyncSession, user: User, scope: str | None +) -> list[str]: + """Active SourceRoot.path values visible to this user, honouring the + admin ?scope=global escape hatch.""" + q = select(SourceRoot.path).where(SourceRoot.is_active.is_(True)) + if not (scope == "global" and user.role == "admin"): + q = q.where(SourceRoot.user_id == user.id) + return (await db.execute(q)).scalars().all() + # Media types we accept in the regenerate-thumbnails request body. Mirrors # the values produced by `app.tasks.scan.get_media_type`. _VALID_MEDIA_TYPES = {'photo', 'raw', 'heic', 'video'} @@ -114,15 +125,7 @@ async def get_library_stats( size = (await db.execute(select(func.sum(Photo.file_size)).where(owner))).scalar() or 0 - # Source root directories (active ones only). Scoped to the - # requesting user unless they're an admin asking for global view — - # otherwise the Settings panel would leak other users' NC paths. - sr_query = select(SourceRoot.path).where(SourceRoot.is_active.is_(True)) - if not (scope == "global" and current_user.role == "admin"): - sr_query = sr_query.where(SourceRoot.user_id == current_user.id) - roots = ( - await db.execute(sr_query.order_by(SourceRoot.path)) - ).scalars().all() + roots = sorted(await _active_source_root_paths(db, current_user, scope)) return { "all_photos": all_photos_count, @@ -731,28 +734,18 @@ async def get_duplicate_groups( """ owner = _owner_filter(current_user, scope) - # Restrict to photos that actually live under an active SourceRoot - # in the user's settings. The folder→source_root link alone is not - # enough: Nextcloud's "move to trash" flow can leave a Folder row at - # a path like `…/files/.delete/purge-1` still wired to the original - # source_root_id, which then leaks its photos into the duplicates - # view even though that path is outside everything the user - # configured. Filtering on the folder's path being a descendant of - # the active root's path matches what the user actually expects to - # see in Settings → Source folders. - sr_path_query = select(SourceRoot.path).where(SourceRoot.is_active.is_(True)) - if not (scope == "global" and current_user.role == "admin"): - sr_path_query = sr_path_query.where(SourceRoot.user_id == current_user.id) - active_root_paths = (await db.execute(sr_path_query)).scalars().all() + # Restrict to photos under an active SourceRoot in the user's + # settings. Folder.source_root_id alone isn't trustworthy: Nextcloud's + # "move to trash" flow leaves Folder rows like `…/files/.delete/ + # purge-1` still wired to the original source_root_id, leaking their + # photos into this view as ghost paths the user never configured. + active_root_paths = await _active_source_root_paths(db, current_user, scope) if not active_root_paths: return {"groups": [], "total_groups": 0, "total_members": 0} - # Match the source root path itself OR a strict child (path + '/'). - # `startswith` alone would accept `/files/Photos2` for a `/files/Photos` - # root. folder_in_scope = or_( *[ - (Folder.path == p) | (Folder.path.like(p.rstrip('/') + '/%')) + (Folder.path == p) | (Folder.path.like(p + '/%')) for p in active_root_paths ] ) diff --git a/frontend/src/components/timeline/Timeline.tsx b/frontend/src/components/timeline/Timeline.tsx index b0716fb..418a655 100644 --- a/frontend/src/components/timeline/Timeline.tsx +++ b/frontend/src/components/timeline/Timeline.tsx @@ -199,10 +199,6 @@ export function Timeline() { // Shared photos query — both Timeline and PreviewView use the same hook so // they share one cache entry, regardless of filter state. const { data: photos = [], isLoading } = usePhotosQuery() - // Background cursor loop (after the initial page resolves) still - // streaming more photos? Drives the bottom-of-grid spinner so the - // user has a signal that more results are on the way and a sudden - // "end of list" is real rather than mid-fetch. const isLoadingMore = usePhotosLoadingMore() // Tracks the previous viewMode so the "preview just closed" scroll @@ -736,8 +732,9 @@ export function Timeline() { if (isLoading) { return ( -