Skip to content

Commit 2aca23a

Browse files
committed
feat: Add log when file could not be created in an album
Signed-off-by: Louis Chemineau <[email protected]> [skip ci]
1 parent 20291ff commit 2aca23a

7 files changed

+64
-57
lines changed

lib/Sabre/Album/AlbumRoot.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCP\Files\InvalidDirectoryException;
1818
use OCP\Files\IRootFolder;
1919
use OCP\Files\NotFoundException;
20+
use Psr\Log\LoggerInterface;
2021
use Sabre\DAV\Exception\Conflict;
2122
use Sabre\DAV\Exception\Forbidden;
2223
use Sabre\DAV\Exception\NotFound;
@@ -29,13 +30,15 @@ class AlbumRoot implements ICollection, ICopyTarget {
2930
protected AlbumWithFiles $album;
3031
protected IRootFolder $rootFolder;
3132
protected string $userId;
33+
private UserConfigService $userConfigService;
3234

3335
public function __construct(
3436
AlbumMapper $albumMapper,
3537
AlbumWithFiles $album,
3638
IRootFolder $rootFolder,
3739
string $userId,
38-
UserConfigService $userConfigService
40+
UserConfigService $userConfigService,
41+
protected LoggerInterface $logger,
3942
) {
4043
$this->albumMapper = $albumMapper;
4144
$this->album = $album;
@@ -106,6 +109,7 @@ public function createFile($name, $data = null) {
106109
\header('OC-FileId: ' . $node->getId());
107110
return '"' . $node->getEtag() . '"';
108111
} catch (\Exception $e) {
112+
$this->logger->error('Could not create file', ['exception' => $e]);
109113
throw new Forbidden('Could not create file');
110114
}
111115
}

lib/Sabre/Album/AlbumsHome.php

+15-17
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313
use OCA\Photos\Album\AlbumWithFiles;
1414
use OCA\Photos\Service\UserConfigService;
1515
use OCP\Files\IRootFolder;
16+
use Psr\Log\LoggerInterface;
1617
use Sabre\DAV\Exception\Forbidden;
1718
use Sabre\DAV\Exception\NotFound;
1819
use Sabre\DAV\ICollection;
1920

2021
class AlbumsHome implements ICollection {
21-
protected AlbumMapper $albumMapper;
22-
protected array $principalInfo;
23-
protected string $userId;
24-
protected IRootFolder $rootFolder;
25-
protected UserConfigService $userConfigService;
26-
2722
public const NAME = 'albums';
2823

2924
/**
@@ -32,17 +27,13 @@ class AlbumsHome implements ICollection {
3227
protected ?array $children = null;
3328

3429
public function __construct(
35-
array $principalInfo,
36-
AlbumMapper $albumMapper,
37-
string $userId,
38-
IRootFolder $rootFolder,
39-
UserConfigService $userConfigService
30+
protected array $principalInfo,
31+
protected AlbumMapper $albumMapper,
32+
protected string $userId,
33+
protected IRootFolder $rootFolder,
34+
protected UserConfigService $userConfigService,
35+
protected LoggerInterface $logger,
4036
) {
41-
$this->principalInfo = $principalInfo;
42-
$this->albumMapper = $albumMapper;
43-
$this->userId = $userId;
44-
$this->rootFolder = $rootFolder;
45-
$this->userConfigService = $userConfigService;
4637
}
4738

4839
/**
@@ -91,7 +82,14 @@ public function getChildren(): array {
9182
if ($this->children === null) {
9283
$albumInfos = $this->albumMapper->getForUser($this->userId);
9384
$this->children = array_map(function (AlbumInfo $albumInfo) {
94-
return new AlbumRoot($this->albumMapper, new AlbumWithFiles($albumInfo, $this->albumMapper), $this->rootFolder, $this->userId, $this->userConfigService);
85+
return new AlbumRoot(
86+
$this->albumMapper,
87+
new AlbumWithFiles($albumInfo, $this->albumMapper),
88+
$this->rootFolder,
89+
$this->userId,
90+
$this->userConfigService,
91+
$this->logger,
92+
);
9593
}, $albumInfos);
9694
}
9795

lib/Sabre/Album/SharedAlbumRoot.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,27 @@
1313
use OCA\Photos\Service\UserConfigService;
1414
use OCP\Files\IRootFolder;
1515
use OCP\IUserManager;
16+
use Psr\Log\LoggerInterface;
1617
use Sabre\DAV\Exception\Conflict;
1718
use Sabre\DAV\Exception\Forbidden;
1819

1920
class SharedAlbumRoot extends AlbumRoot {
20-
private IUserManager $userManager;
21-
2221
public function __construct(
2322
AlbumMapper $albumMapper,
2423
AlbumWithFiles $album,
2524
IRootFolder $rootFolder,
2625
string $userId,
2726
UserConfigService $userConfigService,
28-
IUserManager $userManager
27+
LoggerInterface $logger,
2928
) {
3029
parent::__construct(
3130
$albumMapper,
3231
$album,
3332
$rootFolder,
3433
$userId,
3534
$userConfigService,
36-
$userManager
35+
$logger
3736
);
38-
39-
$this->userManager = $userManager;
4037
}
4138

4239
/**

lib/Sabre/Album/SharedAlbumsHome.php

+17-11
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,31 @@
1414
use OCP\Files\IRootFolder;
1515
use OCP\IGroupManager;
1616
use OCP\IUserManager;
17+
use Psr\Log\LoggerInterface;
1718
use Sabre\DAV\Exception\Forbidden;
1819

1920
class SharedAlbumsHome extends AlbumsHome {
20-
private IUserManager $userManager;
21-
private IGroupManager $groupManager;
22-
2321
public const NAME = 'sharedalbums';
2422

2523
public function __construct(
2624
array $principalInfo,
2725
AlbumMapper $albumMapper,
2826
string $userId,
2927
IRootFolder $rootFolder,
30-
IUserManager $userManager,
31-
IGroupManager $groupManager,
32-
UserConfigService $userConfigService
28+
private IUserManager $userManager,
29+
private IGroupManager $groupManager,
30+
UserConfigService $userConfigService,
31+
LoggerInterface $logger,
32+
3333
) {
3434
parent::__construct(
3535
$principalInfo,
3636
$albumMapper,
3737
$userId,
3838
$rootFolder,
39-
$userConfigService
39+
$userConfigService,
40+
$logger,
4041
);
41-
42-
$this->userManager = $userManager;
43-
$this->groupManager = $groupManager;
4442
}
4543

4644
/**
@@ -66,7 +64,15 @@ public function getChildren(): array {
6664
}
6765

6866
$this->children = array_map(function (AlbumWithFiles $album) {
69-
return new SharedAlbumRoot($this->albumMapper, $album, $this->rootFolder, $this->userId, $this->userConfigService, $this->userManager);
67+
return new SharedAlbumRoot(
68+
$this->albumMapper,
69+
$album,
70+
$this->rootFolder,
71+
$this->userId,
72+
$this->userConfigService,
73+
$this->logger,
74+
$this->userManager,
75+
);
7076
}, $albums);
7177
}
7278

lib/Sabre/PhotosHome.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\Files\IRootFolder;
1919
use OCP\IGroupManager;
2020
use OCP\IUserManager;
21+
use Psr\Log\LoggerInterface;
2122
use Sabre\DAV\Exception\Forbidden;
2223
use Sabre\DAV\Exception\NotFound;
2324
use Sabre\DAV\ICollection;
@@ -33,6 +34,7 @@ public function __construct(
3334
private IUserManager $userManager,
3435
private IGroupManager $groupManager,
3536
private UserConfigService $userConfigService,
37+
private LoggerInterface $logger,
3638
) {
3739
}
3840

@@ -69,9 +71,9 @@ public function createDirectory($name) {
6971
public function getChild($name) {
7072
switch ($name) {
7173
case AlbumsHome::NAME:
72-
return new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService);
74+
return new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService, $this->logger);
7375
case SharedAlbumsHome::NAME:
74-
return new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService);
76+
return new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger);
7577
case PlacesHome::NAME:
7678
return new PlacesHome($this->userId, $this->rootFolder, $this->reverseGeoCoderService, $this->placeMapper);
7779
}
@@ -84,8 +86,8 @@ public function getChild($name) {
8486
*/
8587
public function getChildren(): array {
8688
return [
87-
new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService),
88-
new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService),
89+
new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService, $this->logger),
90+
new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger),
8991
new PlacesHome($this->userId, $this->rootFolder, $this->reverseGeoCoderService, $this->placeMapper),
9092
];
9193
}

lib/Sabre/PublicRootCollection.php

+15-17
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,24 @@
1414
use OCP\Files\IRootFolder;
1515
use OCP\IRequest;
1616
use OCP\Security\Bruteforce\IThrottler;
17+
use Psr\Log\LoggerInterface;
1718
use Sabre\DAV\Exception\NotFound;
1819
use Sabre\DAVACL\AbstractPrincipalCollection;
1920
use Sabre\DAVACL\PrincipalBackend;
2021

2122
class PublicRootCollection extends AbstractPrincipalCollection {
2223
private const BRUTEFORCE_ACTION = 'publicphotos_webdav_auth';
23-
private AlbumMapper $albumMapper;
24-
private IRootFolder $rootFolder;
25-
private UserConfigService $userConfigService;
26-
private IRequest $request;
27-
private IThrottler $throttler;
2824

2925
public function __construct(
30-
AlbumMapper $albumMapper,
31-
IRootFolder $rootFolder,
26+
private AlbumMapper $albumMapper,
27+
private IRootFolder $rootFolder,
3228
PrincipalBackend\BackendInterface $principalBackend,
33-
UserConfigService $userConfigService,
34-
IRequest $request,
35-
IThrottler $throttler
29+
private UserConfigService $userConfigService,
30+
private IRequest $request,
31+
private IThrottler $throttler,
32+
private LoggerInterface $logger,
3633
) {
3734
parent::__construct($principalBackend, 'principals/token');
38-
39-
$this->albumMapper = $albumMapper;
40-
$this->rootFolder = $rootFolder;
41-
$this->userConfigService = $userConfigService;
42-
$this->request = $request;
43-
$this->throttler = $throttler;
4435
}
4536

4637
public function getName(): string {
@@ -79,6 +70,13 @@ public function getChild($name) {
7970
throw new NotFound("Unable to find public album");
8071
}
8172

82-
return new PublicAlbumRoot($this->albumMapper, $albums[0], $this->rootFolder, $albums[0]->getAlbum()->getUserId(), $this->userConfigService);
73+
return new PublicAlbumRoot(
74+
$this->albumMapper,
75+
$albums[0],
76+
$this->rootFolder,
77+
$albums[0]->getAlbum()->getUserId(),
78+
$this->userConfigService,
79+
$this->logger,
80+
);
8381
}
8482
}

lib/Sabre/RootCollection.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\IGroupManager;
1717
use OCP\IUserManager;
1818
use OCP\IUserSession;
19+
use Psr\Log\LoggerInterface;
1920
use Sabre\DAVACL\AbstractPrincipalCollection;
2021
use Sabre\DAVACL\PrincipalBackend;
2122

@@ -30,6 +31,7 @@ public function __construct(
3031
private IUserManager $userManager,
3132
private IGroupManager $groupManager,
3233
private UserConfigService $userConfigService,
34+
private LoggerInterface $logger,
3335
) {
3436
parent::__construct($principalBackend, 'principals/users');
3537
}
@@ -49,7 +51,7 @@ public function getChildForPrincipal(array $principalInfo): PhotosHome {
4951
if (is_null($user) || $name !== $user->getUID()) {
5052
throw new \Sabre\DAV\Exception\Forbidden();
5153
}
52-
return new PhotosHome($principalInfo, $this->albumMapper, $this->placeMapper, $this->reverseGeoCoderService, $name, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService);
54+
return new PhotosHome($principalInfo, $this->albumMapper, $this->placeMapper, $this->reverseGeoCoderService, $name, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger);
5355
}
5456

5557
public function getName(): string {

0 commit comments

Comments
 (0)