diff --git a/lib/Album/AlbumMapper.php b/lib/Album/AlbumMapper.php index 575c4da0..815238b9 100644 --- a/lib/Album/AlbumMapper.php +++ b/lib/Album/AlbumMapper.php @@ -332,6 +332,40 @@ class AlbumMapper { return array_values(array_filter($collaborators, fn ($c) => $c !== null)); } + + /** + * @param int $albumId + * @param string $userId + * @return bool + */ + public function isCollaborator(int $albumId, string $userId): bool { + $query = $this->connection->getQueryBuilder(); + $query->select("collaborator_id", "collaborator_type") + ->from("photos_albums_collabs") + ->where($query->expr()->eq('album_id', $query->createNamedParameter($albumId, IQueryBuilder::PARAM_INT))); + + $rows = $query->executeQuery()->fetchAll(); + + foreach ($rows as $row) { + switch ($row['collaborator_type']) { + case self::TYPE_USER: + if ($row['collaborator_id'] === $userId) { + return true; + } + break; + case self::TYPE_GROUP: + if ($this->groupManager->isInGroup($userId, $row['collaborator_id'])) { + return true; + } + break; + default: + break; + } + } + + return false; + } + /** * @param int $albumId * @param array{'id': string, 'type': int} $collaborators diff --git a/lib/Sabre/Album/SharedAlbumRoot.php b/lib/Sabre/Album/SharedAlbumRoot.php index d5dc9909..a6f84510 100644 --- a/lib/Sabre/Album/SharedAlbumRoot.php +++ b/lib/Sabre/Album/SharedAlbumRoot.php @@ -25,7 +25,6 @@ namespace OCA\Photos\Sabre\Album; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Conflict; -use OCA\Photos\Album\AlbumMapper; class SharedAlbumRoot extends AlbumRoot { /** @@ -47,11 +46,7 @@ class SharedAlbumRoot extends AlbumRoot { throw new Conflict("File $sourceId is already in the folder"); } - $collaboratorIds = array_map( - fn ($collaborator) => $collaborator['type'].':'.$collaborator['id'], - $this->albumMapper->getCollaborators($this->album->getAlbum()->getId()), - ); - if (!in_array(AlbumMapper::TYPE_USER.':'.$this->userId, $collaboratorIds)) { + if (!$this->albumMapper->isCollaborator($this->album->getAlbum()->getId(), $this->userId)) { return false; }