Skip to content

Commit

Permalink
fix: Use user uid to compare in PhotosPicker
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Sep 30, 2024
1 parent 4f45c0a commit 053366c
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 38 deletions.
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.

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.

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-src_views_AlbumContent_vue.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,20 @@ public function index(): TemplateResponse {
$this->eventDispatcher->dispatch(LoadSidebar::class, new LoadSidebar());
$this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());

$userFolder = $this->rootFolder->getUserFolder($user->getUid());
try {
$photosFolder = $userFolder->get($this->userConfig->getUserConfig('photosLocation'));
} catch (NotFoundException $e) {
$photosFolder = $userFolder->newFolder($this->userConfig->getUserConfig('photosLocation'));
}

$this->initialState->provideInitialState('image-mimes', Application::IMAGE_MIMES);
$this->initialState->provideInitialState('video-mimes', Application::VIDEO_MIMES);
$this->initialState->provideInitialState('maps', $this->appManager->isEnabledForUser('maps') === true);
$this->initialState->provideInitialState('recognize', $this->appManager->isEnabledForUser('recognize') === true);
$this->initialState->provideInitialState('systemtags', $this->appManager->isEnabledForUser('systemtags') === true);
$this->initialState->provideInitialState('showPeopleMenuEntry', $this->config->getAppValue('photos', 'showPeopleMenuEntry', 'true') === 'true');
$this->initialState->provideInitialState('photosLocationOwner', $photosFolder->getOwner()->getUid());

// Provide user config
foreach (array_keys(UserConfigService::DEFAULT_CONFIGS) as $key) {
Expand Down
5 changes: 5 additions & 0 deletions lib/Sabre/Album/AlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\Photos\Album\AlbumWithFiles;
use OCA\Photos\Service\UserConfigService;
use OCP\Files\Folder;
use OCP\Files\InvalidDirectoryException;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use Sabre\DAV\Exception\Conflict;
Expand Down Expand Up @@ -106,6 +107,10 @@ public function createFile($name, $data = null) {
throw new Conflict('The destination exists and is not a folder');
}

if ($photosFolder->isShared()) {
throw new InvalidDirectoryException('The destination is a received share');
}

// Check for conflict and rename the file accordingly
$newName = \basename(\OC_Helper::buildNotExistingFileName($photosLocation, $name));

Expand Down
45 changes: 31 additions & 14 deletions src/components/FilesPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,32 @@
</div>

<div class="file-picker__actions">
<UploadPicker :accept="allowedMimes"
:context="uploadContext"
:destination="photosLocation"
:multiple="true"
@uploaded="refreshFiles"
@failed="handleFailure" />
<NcButton type="primary" :disabled="loading || selectedFileIds.length === 0" @click="emitPickedEvent">
<template #icon>
<ImagePlus v-if="!loading" />
<NcLoadingIcon v-if="loading" />
</template>
{{ t('photos', 'Add to {destination}', { destination }) }}
</NcButton>
<div class="file-picker__actions__buttons">
<UploadPicker :accept="allowedMimes"
:context="uploadContext"
:destination="photosLocation"
:multiple="true"
@uploaded="refreshFiles"
@failed="handleFailure" />
<NcButton type="primary" :disabled="loading || selectedFileIds.length === 0" @click="emitPickedEvent">
<template #icon>
<ImagePlus v-if="!loading" />
<NcLoadingIcon v-if="loading" />
</template>
{{ t('photos', 'Add to {destination}', { destination }) }}
</NcButton>
</div>
<NcNoteCard v-if="photosLocationOwner !== currentUser" type="warning">
{{ t('photos', 'The destination folder is owned by {owner}', { owner: photosLocationOwner }) }}
</NcNoteCard>
</div>
</div>
</template>

<script>
import { mapGetters } from 'vuex'
import { NcButton, NcLoadingIcon } from '@nextcloud/vue'
import { NcButton, NcLoadingIcon, NcNoteCard } from '@nextcloud/vue'
import { getCurrentUser } from '@nextcloud/auth'
import { UploadPicker } from '@nextcloud/upload'
import moment from '@nextcloud/moment'

Expand All @@ -107,6 +113,7 @@ export default {
ImagePlus,
NcButton,
NcLoadingIcon,
NcNoteCard,
UploadPicker,
},

Expand Down Expand Up @@ -152,6 +159,7 @@ export default {
uploadContext: {
route: 'albumpicker',
},
currentUser: getCurrentUser().uid,
}
},

Expand Down Expand Up @@ -269,9 +277,18 @@ export default {

&__actions {
display: flex;
flex-direction: column;
justify-content: space-between;
justify-items: center;
padding-top: 16px;
flex-grow: 1;

&__buttons {
display: flex;
align-items: center;
justify-content: end;
gap: 16px;
}
}
}
</style>
1 change: 1 addition & 0 deletions src/mixins/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default {
? croppedLayoutLocalStorage === 'true'
: loadState('photos', 'croppedLayout', 'false') === 'true',
photosLocation: loadState('photos', 'photosLocation', ''),
photosLocationOwner: loadState('photos', 'photosLocationOwner', ''),
}
},

Expand Down

0 comments on commit 053366c

Please sign in to comment.