Skip to content

Commit

Permalink
Revert using display name in shared albums' name
Browse files Browse the repository at this point in the history
+ Improve rendering of cover and header of shared albums

Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed May 16, 2023
1 parent 47e06b5 commit fb15d54
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ vendor

cypress/videos
cypress/snapshots
cypress/downloads
cypress/downloads

js/*hot-update.*
191 changes: 191 additions & 0 deletions cypress/e2e/shared_albums.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@

import { randHash } from '../utils'
/**
* @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me>
*
* @author Louis Chmn <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { User } from '@nextcloud/cypress'
import {
addCollaborators,
addFilesToAlbumFromAlbum,
createAnAlbumFromAlbums,
goToAlbum,
removeCollaborators,
removeSelectionFromAlbum,
} from './albumsUtils'
import {
downloadAllFiles,
downloadSelection,
goToSharedAlbum,
removeSharedAlbums,
selectMedia,
uploadTestMedia,
} from './photosUtils'

import { randHash } from '../utils'

const alice = new User(`alice_${randHash()}`)
const bob = new User(`bob_${randHash()}`)
const charlie = new User(`charlie_${randHash()}`)

const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
Cypress.on('uncaught:exception', (err) => {
/* returning false here prevents Cypress from failing the test */
if (resizeObserverLoopErrRe.test(err.message)) {
return false
}
})

describe('Manage shared albums', () => {
before(() => {
cy.createUser(alice)
cy.createUser(bob).then(() => {
uploadTestMedia(bob)
})
cy.createUser(charlie)

})

context('Adding and removing files in a shared album', () => {
before(() => {
cy.login(alice)
cy.visit('apps/photos/albums')
createAnAlbumFromAlbums('shared_album_test1')
addCollaborators([bob.userId])
})

it('Add and remove a file to a shared album from a shared album', () => {
cy.login(bob)
cy.visit('apps/photos/albums')
goToSharedAlbum('shared_album_test1')
cy.get('[data-test="media"]').should('have.length', 0)
addFilesToAlbumFromAlbum('shared_album_test1', [0])
cy.get('[data-test="media"]').should('have.length', 1)
selectMedia([0])
removeSelectionFromAlbum()
cy.get('[data-test="media"]').should('have.length', 0)
})

it('Add and remove multiple files to a shared album from a shared album', () => {
goToSharedAlbum('shared_album_test1')
cy.get('[data-test="media"]').should('have.length', 0)
addFilesToAlbumFromAlbum('shared_album_test1', [1, 2])
cy.get('[data-test="media"]').should('have.length', 2)
selectMedia([0, 1])
removeSelectionFromAlbum()
cy.get('[data-test="media"]').should('have.length', 0)
})
})

context('Download files from a shared album', () => {
before(() => {
cy.login(alice)
cy.visit('apps/photos/albums')
createAnAlbumFromAlbums('shared_album_test2')
addCollaborators([bob.userId])

cy.login(bob)
cy.visit('apps/photos/sharedalbums')
goToSharedAlbum('shared_album_test2')
addFilesToAlbumFromAlbum('shared_album_test2', [0, 1, 2])
})

xit('Download a file from a shared album', () => {
goToSharedAlbum('shared_album_test2')
selectMedia([0])
downloadSelection()
selectMedia([0])
})

xit('Download multiple files from a shared album', () => {
goToSharedAlbum('shared_album_test2')
selectMedia([1, 2])
downloadSelection()
selectMedia([1, 2])
})

xit('Download all files from a shared album', () => {
goToSharedAlbum('shared_album_test2')
downloadAllFiles()
})
})

context('Delete a received shared album', () => {
before(() => {
cy.login(alice)
cy.visit('apps/photos/albums')
createAnAlbumFromAlbums('shared_album_test3')
addCollaborators([bob.userId])
})

it('Remove shared album', () => {
cy.login(bob)
cy.visit('apps/photos/albums')
goToSharedAlbum('shared_album_test3')
removeSharedAlbums()
})
})

context('Remove a collaborator from an album', () => {
before(() => {
cy.login(alice)
cy.visit('/apps/photos/albums')
createAnAlbumFromAlbums('shared_album_test4')
addCollaborators([bob.userId])
})

it('Remove collaborator from an album', () => {
cy.login(bob)
cy.visit('apps/photos/sharedalbums')
cy.get(`[data-test="shared_album_test4 (${alice.userId})"]`).should('have.length', 1)

cy.login(alice)
cy.visit('/apps/photos')
goToAlbum('shared_album_test4')
removeCollaborators([bob.userId])

cy.login(bob)
cy.visit('/apps/photos/sharedalbums')
cy.get('body')
.should('not.contain', `shared_album_test4 (${alice.userId})`)
})
})

context('Two shared albums with the same name', () => {
before(() => {
cy.login(alice)
cy.visit('apps/photos/albums')
createAnAlbumFromAlbums('shared_album_test5')
addCollaborators([bob.userId])

cy.login(charlie)
cy.visit('apps/photos/albums')
createAnAlbumFromAlbums('shared_album_test5')
addCollaborators([bob.userId])
})

it('It should display two shared albums', () => {
cy.login(bob)
cy.visit('/apps/photos/sharedalbums')
cy.get(`[data-test="shared_album_test5 (${alice.userId})"]`).should('have.length', 1)
cy.get(`[data-test="shared_album_test5 (${charlie.userId})"]`).should('have.length', 1)
})
})
})
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.

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.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
use OCP\Files\IMimeTypeLoader;
use OCP\Security\ISecureRandom;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IGroupManager;
use OCP\IL10N;
Expand Down Expand Up @@ -350,7 +348,7 @@ public function getCollaborators(int $albumId): array {
$rows = $query->executeQuery()->fetchAll();

$collaborators = array_map(function (array $row) {
/** @var IUser|IGroup|null */
/** @var string|null */
$displayName = null;

switch ($row['collaborator_type']) {
Expand Down Expand Up @@ -535,7 +533,7 @@ public function getSharedAlbumsForCollaboratorWithFiles(string $collaboratorId,
// Suffix album name with the album owner to prevent duplicates.
// Not done for public link as it would like owner's uid.
if ($collaboratorType !== self::TYPE_LINK) {
$albumName = $row['album_name'].' ('.$this->userManager->get($row['album_user'])->getDisplayName().')';
$albumName = $row['album_name'].' ('.$row['album_user'].')';
}
$albumsById[$albumId] = new AlbumInfo($albumId, $row['album_user'], $albumName, $row['location'], (int)$row['created'], (int)$row['last_added_photo']);
}
Expand Down
38 changes: 35 additions & 3 deletions lib/Sabre/Album/SharedAlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,35 @@

use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\Conflict;
use OCA\Photos\Album\AlbumMapper;
use OCA\Photos\Album\AlbumWithFiles;
use OCA\Photos\Service\UserConfigService;
use OCP\Files\IRootFolder;
use OCP\IUserManager;

class SharedAlbumRoot extends AlbumRoot {
private IUserManager $userManager;

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

$this->userManager = $userManager;
}

/**
* @return void
*/
Expand Down Expand Up @@ -55,11 +82,16 @@ protected function addFile(int $sourceId, string $ownerUID): bool {
}

/**
* Do not reveal collaborators for shared albums.
* Return only the owner, and do not reveal other collaborators.
*/
public function getCollaborators(): array {
/** @var array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}} */
return [];
return [[
'nc:collaborator' => [
'id' => $this->album->getAlbum()->getUserId(),
'label' => $this->userManager->get($this->album->getAlbum()->getUserId())->getDisplayName(),
'type' => 1,
],
]];
}

public function setCollaborators($collaborators): array {
Expand Down
2 changes: 1 addition & 1 deletion lib/Sabre/Album/SharedAlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getChildren(): array {
}

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

Expand Down
18 changes: 15 additions & 3 deletions src/views/SharedAlbumContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@
:loading="loadingFiles"
:params="{ albumName }"
:path="'/' + albumName"
:title="albumName"
:title="albumOriginalName"
@refresh="fetchAlbumContent">
<!-- <UploadPicker :accept="allowedMimes"
:destination="folder.filename"
:multiple="true"
@uploaded="onUpload" /> -->

<div v-if="album.location !== ''" slot="subtitle" class="album__location">
<MapMarker />{{ album.location }}
<MapMarker />{{ album.location }} ⸱ {{ t('photos', 'Shared by') }}&nbsp;<NcUserBubble :display-name="album.collaborators[0].label" :user="album.collaborators[0].id" />
</div>
<template v-if="album !== undefined" slot="right">
<NcButton v-if="album.nbItems !== 0"
Expand Down Expand Up @@ -123,7 +124,7 @@ import Close from 'vue-material-design-icons/Close'
// import Download from 'vue-material-design-icons/Download'
// import DownloadMultiple from 'vue-material-design-icons/DownloadMultiple'

import { NcActions, NcActionButton, NcButton, NcModal, NcEmptyContent, NcActionSeparator, isMobile } from '@nextcloud/vue'
import { NcActions, NcActionButton, NcButton, NcModal, NcEmptyContent, NcActionSeparator, NcUserBubble, isMobile } from '@nextcloud/vue'
import { getCurrentUser } from '@nextcloud/auth'

import FetchSharedAlbumsMixin from '../mixins/FetchSharedAlbumsMixin.js'
Expand All @@ -137,6 +138,7 @@ import logger from '../services/logger.js'
import client from '../services/DavClient.js'
import DavRequest from '../services/DavRequest.js'
import { genFileInfo } from '../utils/fileUtils.js'
import { translate } from '@nextcloud/l10n'

export default {
name: 'SharedAlbumContent',
Expand All @@ -154,6 +156,7 @@ export default {
NcActionSeparator,
NcButton,
NcModal,
NcUserBubble,
CollectionContent,
// ActionDownload,
FilesPicker,
Expand Down Expand Up @@ -201,6 +204,13 @@ export default {
albumFileIds() {
return this.sharedAlbumsFiles[this.albumName] || []
},

/**
* @return {string} The album name without the userId between parentheses.
*/
albumOriginalName() {
return this.albumName.replace(new RegExp(`\\(${this.album.collaborators[0].id}\\)$`), '')
},
},

watch: {
Expand Down Expand Up @@ -289,6 +299,8 @@ export default {
await this.deleteSharedAlbum({ albumName: this.albumName })
this.$router.push('/sharedalbums')
},

t: translate,
},
}
</script>
Expand Down
Loading

0 comments on commit fb15d54

Please sign in to comment.