From 1866ce5dfa2d82ff50317e9af504d9cd72fb7aa5 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 2 Dec 2022 21:42:52 -0800 Subject: [PATCH] preview: fix for shared album --- lib/Controller/ApiBase.php | 7 +++++-- lib/Db/TimelineQueryAlbums.php | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Controller/ApiBase.php b/lib/Controller/ApiBase.php index 8101d917..37025a90 100644 --- a/lib/Controller/ApiBase.php +++ b/lib/Controller/ApiBase.php @@ -190,11 +190,14 @@ class ApiBase extends Controller } $uid = $user->getUID(); - if (!$this->timelineQuery->albumHasUserFile($uid, $id)) { + $owner = $this->timelineQuery->albumHasUserFile($uid, $id); + if (!$owner) { return null; } - return $this->getOneFileFromFolder($this->rootFolder, $id); + $folder = $this->rootFolder->getUserFolder($owner); + + return $this->getOneFileFromFolder($folder, $id); } /** diff --git a/lib/Db/TimelineQueryAlbums.php b/lib/Db/TimelineQueryAlbums.php index bf3e2ff2..fb36a717 100644 --- a/lib/Db/TimelineQueryAlbums.php +++ b/lib/Db/TimelineQueryAlbums.php @@ -118,11 +118,13 @@ trait TimelineQueryAlbums /** * Check if a file belongs to a user through an album. + * + * @return bool|string owner of file */ public function albumHasUserFile(string $uid, int $fileId) { $query = $this->connection->getQueryBuilder(); - $query->select('paf.album_id')->from('photos_albums_files', 'paf')->where( + $query->select('paf.owner')->from('photos_albums_files', 'paf')->where( $query->expr()->andX( $query->expr()->eq('paf.file_id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)), $query->expr()->orX( @@ -144,7 +146,7 @@ trait TimelineQueryAlbums $query->expr()->eq('pc.collaborator_id', $query->createNamedParameter($uid)), )); - return false !== $query->executeQuery()->fetchOne(); + return $query->executeQuery()->fetchOne(); } /**