Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow album owner to get file added by collaborators
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Sep 20, 2022
commit b1e99c1d08106131df544554e31eb98d28401399
40 changes: 40 additions & 0 deletions lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ public function getForFile(int $fileId): array {
}, $rows);
}

/**
* @param string $userId
* @param int $fileId
* @return AlbumInfo[]
*/
public function getForUserAndFile(string $userId, int $fileId): array {
$query = $this->connection->getQueryBuilder();
$query->select("a.album_id", "name", "user", "location", "created", "last_added_photo")
->from("photos_albums", "a")
->leftJoin("a", "photos_albums_files", "p", $query->expr()->eq("a.album_id", "p.album_id"))
->where($query->expr()->eq('user', $query->createNamedParameter($userId)))
->andWhere($query->expr()->eq('file_id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$rows = $query->executeQuery()->fetchAll();
return array_map(function (array $row) {
return new AlbumInfo((int)$row['album_id'], $row['user'], $row['name'], $row['location'], (int)$row['created'], (int)$row['last_added_photo']);
}, $rows);
}

public function rename(int $id, string $newName): void {
$query = $this->connection->getQueryBuilder();
$query->update("photos_albums")
Expand Down Expand Up @@ -195,6 +213,28 @@ public function getForUserWithFiles(string $userId): array {
return $result;
}

/**
* @param int $albumId
* @param int $fileId
* @return AlbumFile
*/
public function getForAlbumIdAndFileId(int $albumId, int $fileId): AlbumFile {
$query = $this->connection->getQueryBuilder();
$query->select("fileid", "mimetype", "a.album_id", "user", "size", "mtime", "etag", "location", "created", "last_added_photo", "added", "owner")
->selectAlias("f.name", "file_name")
->selectAlias("a.name", "album_name")
->from("photos_albums", "a")
->leftJoin("a", "photos_albums_files", "p", $query->expr()->eq("a.album_id", "p.album_id"))
->leftJoin("p", "filecache", "f", $query->expr()->eq("p.file_id", "f.fileid"))
->where($query->expr()->eq('a.album_id', $query->createNamedParameter($albumId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('file_id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$row = $query->executeQuery()->fetchAll()[0];

$mimeId = $row['mimetype'];
$mimeType = $this->mimeTypeLoader->getMimetypeById($mimeId);
return new AlbumFile((int)$row['fileid'], $row['file_name'], $mimeType, (int)$row['size'], (int)$row['mtime'], $row['etag'], (int)$row['added'], $row['owner']);
}

public function addFile(int $albumId, int $fileId, string $owner): void {
$added = $this->timeFactory->getTime();
try {
Expand Down
7 changes: 5 additions & 2 deletions lib/Controller/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public function index(
$nodes = $this->userFolder->getById($fileId);

if (\count($nodes) === 0) {
$albums = $this->albumMapper->getAlbumForCollaboratorIdAndFileId($user->getUID(), AlbumMapper::TYPE_USER, $fileId);
$albums = $this->albumMapper->getForUserAndFile($user->getUID(), $fileId);
$receivedAlbums = $this->albumMapper->getAlbumForCollaboratorIdAndFileId($user->getUID(), AlbumMapper::TYPE_USER, $fileId);
$albums = array_merge($albums, $receivedAlbums);

$userGroups = $this->groupManager->getUserGroupIds($user);
foreach ($userGroups as $groupId) {
Expand All @@ -98,8 +100,9 @@ public function index(
}

foreach ($albums as $album) {
$albumFile = $this->albumMapper->getForAlbumIdAndFileId($album->getId(), $fileId);
$nodes = $this->rootFolder
->getUserFolder($album->getUserId())
->getUserFolder($albumFile->getOwner())
->getById($fileId);
if (\count($nodes) !== 0) {
break;
Expand Down