Skip to content

Commit

Permalink
Merge pull request #2787 from nextcloud/backport/2772/stable31
Browse files Browse the repository at this point in the history
[stable31] feat: Ease opening photos picker in album content view
  • Loading branch information
AndyScherzinger authored Jan 29, 2025
2 parents 470ef15 + 5870c44 commit 59e1b48
Show file tree
Hide file tree
Showing 26 changed files with 90 additions and 173 deletions.
3 changes: 1 addition & 2 deletions cypress/e2e/albums.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
addFilesToAlbumFromAlbum,
addFilesToAlbumFromAlbumFromHeader,
createAnAlbumFromAlbums,
deleteAnAlbumFromAlbumContent,
goToAlbum,
removeSelectionFromAlbum,
} from './albumsUtils'
Expand All @@ -28,7 +27,7 @@ Cypress.on('uncaught:exception', (err) => {
}
})

describe('Manage albums', { testIsolation: true }, () => {
describe('Manage albums', () => {
let user = null

beforeEach(function () {
Expand Down
1 change: 0 additions & 1 deletion cypress/e2e/albumsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export function addFilesToAlbumFromAlbum(albumName: string, itemsIndex: number[]
}

export function addFilesToAlbumFromAlbumFromHeader(albumName: string, itemsIndex: number[]) {
cy.contains('New').click()
cy.contains('Add photos to this album').click()
cy.get('.photos-picker__file-list').within(() => {
selectMedia(itemsIndex)
Expand Down
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@ This file is generated from multiple sources. Included packages:
- date-format-parse
- version: 0.2.7
- license: MIT
- debounce
- version: 1.2.1
- license: MIT
- decode-named-character-reference
- version: 1.0.2
- license: MIT
Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-public.js.map

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ SPDX-License-Identifier: MIT
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: omahlama
SPDX-FileCopyrightText: debounce developers
SPDX-FileCopyrightText: Rob Cresswell <[email protected]>
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Christoph Wurst
Expand All @@ -19,9 +18,6 @@ This file is generated from multiple sources. Included packages:
- blurhash
- version: 2.0.5
- license: MIT
- debounce
- version: 1.2.1
- license: MIT
- vue-loader
- version: 15.11.1
- license: MIT
Expand Down

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion lib/Sabre/Album/AlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\Files\InvalidDirectoryException;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\Conflict;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
Expand All @@ -30,7 +31,8 @@ public function __construct(
protected AlbumWithFiles $album,
protected IRootFolder $rootFolder,
protected string $userId,
protected UserConfigService $userConfigService
protected UserConfigService $userConfigService,
protected LoggerInterface $logger,
) {
}

Expand Down Expand Up @@ -96,6 +98,7 @@ public function createFile($name, $data = null) {
\header('OC-FileId: ' . $node->getId());
return '"' . $node->getEtag() . '"';
} catch (\Exception $e) {
$this->logger->error('Could not create file', ['exception' => $e]);
throw new Forbidden('Could not create file');
}
}
Expand Down
32 changes: 15 additions & 17 deletions lib/Sabre/Album/AlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@
use OCA\Photos\Album\AlbumWithFiles;
use OCA\Photos\Service\UserConfigService;
use OCP\Files\IRootFolder;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;

class AlbumsHome implements ICollection {
protected AlbumMapper $albumMapper;
protected array $principalInfo;
protected string $userId;
protected IRootFolder $rootFolder;
protected UserConfigService $userConfigService;

public const NAME = 'albums';

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

public function __construct(
array $principalInfo,
AlbumMapper $albumMapper,
string $userId,
IRootFolder $rootFolder,
UserConfigService $userConfigService
protected array $principalInfo,
protected AlbumMapper $albumMapper,
protected string $userId,
protected IRootFolder $rootFolder,
protected UserConfigService $userConfigService,
protected LoggerInterface $logger,
) {
$this->principalInfo = $principalInfo;
$this->albumMapper = $albumMapper;
$this->userId = $userId;
$this->rootFolder = $rootFolder;
$this->userConfigService = $userConfigService;
}

/**
Expand Down Expand Up @@ -91,7 +82,14 @@ public function getChildren(): array {
if ($this->children === null) {
$albumInfos = $this->albumMapper->getForUser($this->userId);
$this->children = array_map(function (AlbumInfo $albumInfo) {
return new AlbumRoot($this->albumMapper, new AlbumWithFiles($albumInfo, $this->albumMapper), $this->rootFolder, $this->userId, $this->userConfigService);
return new AlbumRoot(
$this->albumMapper,
new AlbumWithFiles($albumInfo, $this->albumMapper),
$this->rootFolder,
$this->userId,
$this->userConfigService,
$this->logger,
);
}, $albumInfos);
}

Expand Down
9 changes: 4 additions & 5 deletions lib/Sabre/Album/SharedAlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@
use OCA\Photos\Service\UserConfigService;
use OCP\Files\IRootFolder;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\Conflict;
use Sabre\DAV\Exception\Forbidden;

class SharedAlbumRoot extends AlbumRoot {
private IUserManager $userManager;

public function __construct(
AlbumMapper $albumMapper,
AlbumWithFiles $album,
IRootFolder $rootFolder,
string $userId,
UserConfigService $userConfigService,
IUserManager $userManager
LoggerInterface $logger,
private IUserManager $userManager,
) {
parent::__construct(
$albumMapper,
$album,
$rootFolder,
$userId,
$userConfigService,
$logger,
);

$this->userManager = $userManager;
}

/**
Expand Down
28 changes: 17 additions & 11 deletions lib/Sabre/Album/SharedAlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,31 @@
use OCP\Files\IRootFolder;
use OCP\IGroupManager;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\Forbidden;

class SharedAlbumsHome extends AlbumsHome {
private IUserManager $userManager;
private IGroupManager $groupManager;

public const NAME = 'sharedalbums';

public function __construct(
array $principalInfo,
AlbumMapper $albumMapper,
string $userId,
IRootFolder $rootFolder,
IUserManager $userManager,
IGroupManager $groupManager,
UserConfigService $userConfigService
private IUserManager $userManager,
private IGroupManager $groupManager,
UserConfigService $userConfigService,
LoggerInterface $logger,

) {
parent::__construct(
$principalInfo,
$albumMapper,
$userId,
$rootFolder,
$userConfigService
$userConfigService,
$logger,
);

$this->userManager = $userManager;
$this->groupManager = $groupManager;
}

/**
Expand All @@ -66,7 +64,15 @@ public function getChildren(): array {
}

$this->children = array_map(function (AlbumWithFiles $album) {
return new SharedAlbumRoot($this->albumMapper, $album, $this->rootFolder, $this->userId, $this->userConfigService, $this->userManager);
return new SharedAlbumRoot(
$this->albumMapper,
$album,
$this->rootFolder,
$this->userId,
$this->userConfigService,
$this->logger,
$this->userManager,
);
}, $albums);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/Sabre/PhotosHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\Files\IRootFolder;
use OCP\IGroupManager;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
Expand All @@ -33,6 +34,7 @@ public function __construct(
private IUserManager $userManager,
private IGroupManager $groupManager,
private UserConfigService $userConfigService,
private LoggerInterface $logger,
) {
}

Expand Down Expand Up @@ -69,9 +71,9 @@ public function createDirectory($name) {
public function getChild($name) {
switch ($name) {
case AlbumsHome::NAME:
return new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService);
return new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService, $this->logger);
case SharedAlbumsHome::NAME:
return new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService);
return new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger);
case PlacesHome::NAME:
return new PlacesHome($this->userId, $this->rootFolder, $this->reverseGeoCoderService, $this->placeMapper);
}
Expand All @@ -84,8 +86,8 @@ public function getChild($name) {
*/
public function getChildren(): array {
return [
new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService),
new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService),
new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService, $this->logger),
new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger),
new PlacesHome($this->userId, $this->rootFolder, $this->reverseGeoCoderService, $this->placeMapper),
];
}
Expand Down
32 changes: 15 additions & 17 deletions lib/Sabre/PublicRootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,24 @@
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\Security\Bruteforce\IThrottler;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAVACL\AbstractPrincipalCollection;
use Sabre\DAVACL\PrincipalBackend;

class PublicRootCollection extends AbstractPrincipalCollection {
private const BRUTEFORCE_ACTION = 'publicphotos_webdav_auth';
private AlbumMapper $albumMapper;
private IRootFolder $rootFolder;
private UserConfigService $userConfigService;
private IRequest $request;
private IThrottler $throttler;

public function __construct(
AlbumMapper $albumMapper,
IRootFolder $rootFolder,
private AlbumMapper $albumMapper,
private IRootFolder $rootFolder,
PrincipalBackend\BackendInterface $principalBackend,
UserConfigService $userConfigService,
IRequest $request,
IThrottler $throttler
private UserConfigService $userConfigService,
private IRequest $request,
private IThrottler $throttler,
private LoggerInterface $logger,
) {
parent::__construct($principalBackend, 'principals/token');

$this->albumMapper = $albumMapper;
$this->rootFolder = $rootFolder;
$this->userConfigService = $userConfigService;
$this->request = $request;
$this->throttler = $throttler;
}

public function getName(): string {
Expand Down Expand Up @@ -79,6 +70,13 @@ public function getChild($name) {
throw new NotFound('Unable to find public album');
}

return new PublicAlbumRoot($this->albumMapper, $albums[0], $this->rootFolder, $albums[0]->getAlbum()->getUserId(), $this->userConfigService);
return new PublicAlbumRoot(
$this->albumMapper,
$albums[0],
$this->rootFolder,
$albums[0]->getAlbum()->getUserId(),
$this->userConfigService,
$this->logger,
);
}
}
4 changes: 3 additions & 1 deletion lib/Sabre/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAVACL\AbstractPrincipalCollection;
use Sabre\DAVACL\PrincipalBackend;

Expand All @@ -30,6 +31,7 @@ public function __construct(
private IUserManager $userManager,
private IGroupManager $groupManager,
private UserConfigService $userConfigService,
private LoggerInterface $logger,
) {
parent::__construct($principalBackend, 'principals/users');
}
Expand All @@ -49,7 +51,7 @@ public function getChildForPrincipal(array $principalInfo): PhotosHome {
if (is_null($user) || $name !== $user->getUID()) {
throw new \Sabre\DAV\Exception\Forbidden();
}
return new PhotosHome($principalInfo, $this->albumMapper, $this->placeMapper, $this->reverseGeoCoderService, $name, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService);
return new PhotosHome($principalInfo, $this->albumMapper, $this->placeMapper, $this->reverseGeoCoderService, $name, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger);
}

public function getName(): string {
Expand Down
Loading

0 comments on commit 59e1b48

Please sign in to comment.