Skip to content

Commit 55f6892

Browse files
committed
Fix missing owner
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent a900945 commit 55f6892

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

lib/Sabre/Album/AlbumPhoto.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\Files\Node;
3131
use OCP\Files\File;
3232
use OCP\Files\NotFoundException;
33+
use OCP\IUser;
3334
use Sabre\DAV\Exception\Forbidden;
3435
use Sabre\DAV\IFile;
3536

@@ -38,14 +39,16 @@ class AlbumPhoto implements IFile {
3839
private AlbumInfo $album;
3940
private AlbumFile $file;
4041
private IRootFolder $rootFolder;
42+
private IUser $user;
4143

4244
public const TAG_FAVORITE = '_$!<Favorite>!$_';
4345

44-
public function __construct(AlbumMapper $albumMapper, AlbumInfo $album, AlbumFile $file, IRootFolder $rootFolder) {
46+
public function __construct(AlbumMapper $albumMapper, AlbumInfo $album, AlbumFile $file, IRootFolder $rootFolder, IUser $user) {
4547
$this->albumMapper = $albumMapper;
4648
$this->album = $album;
4749
$this->file = $file;
4850
$this->rootFolder = $rootFolder;
51+
$this->user = $user;
4952
}
5053

5154
/**
@@ -86,8 +89,9 @@ public function put($data) {
8689
}
8790

8891
public function get() {
92+
$currentUserUID = $this->user->getUID();
8993
$nodes = $this->rootFolder
90-
->getUserFolder($this->file->getOwner())
94+
->getUserFolder($this->file->getOwner() ?: $currentUserUID)
9195
->getById($this->file->getFileId());
9296
$node = current($nodes);
9397
if ($node) {
@@ -107,8 +111,9 @@ public function getFileId(): int {
107111
}
108112

109113
public function getFileInfo(): Node {
114+
$currentUserUID = $this->user->getUID();
110115
$nodes = $this->rootFolder
111-
->getUserFolder($this->file->getOwner())
116+
->getUserFolder($this->file->getOwner() ?: $currentUserUID)
112117
->getById($this->file->getFileId());
113118
$node = current($nodes);
114119
if ($node) {

lib/Sabre/Album/AlbumRoot.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ public function createDirectory($name) {
121121

122122
public function getChildren(): array {
123123
return array_map(function (AlbumFile $file) {
124-
return new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder);
124+
return new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->user);
125125
}, $this->album->getFiles());
126126
}
127127

128128
public function getChild($name): AlbumPhoto {
129129
foreach ($this->album->getFiles() as $file) {
130130
if ($file->getFileId() . "-" . $file->getName() === $name) {
131-
return new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder);
131+
return new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->user);
132132
}
133133
}
134134
throw new NotFound("$name not found");
@@ -163,9 +163,9 @@ protected function addFile(int $sourceId, string $ownerUID): bool {
163163
throw new Conflict("File $sourceId is already in the folder");
164164
}
165165
if ($ownerUID === $uid) {
166-
$this->albumMapper->addFile($this->album->getAlbum()->getId(), $sourceId);
166+
$this->albumMapper->addFile($this->album->getAlbum()->getId(), $sourceId, $ownerUID);
167167
$node = current($this->userFolder->getById($sourceId));
168-
$this->album->addFile(new AlbumFile($sourceId, $node->getName(), $node->getMimetype(), $node->getSize(), $node->getMTime(), $node->getEtag(), $node->getCreationTime()));
168+
$this->album->addFile(new AlbumFile($sourceId, $node->getName(), $node->getMimetype(), $node->getSize(), $node->getMTime(), $node->getEtag(), $node->getCreationTime(), $ownerUID));
169169
return true;
170170
}
171171
return false;

0 commit comments

Comments
 (0)