Skip to content

Commit

Permalink
feat: Check upload directory share state
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Sep 30, 2024
1 parent 45af930 commit 3919e49
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 28 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.

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.

7 changes: 7 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ 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 {
$userFolder->get($this->userConfig->getUserConfig('photosLocation'));
} catch (NotFoundException $e) {
$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);
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
49 changes: 36 additions & 13 deletions src/components/PhotosPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,25 @@

<!-- The actions on the bottom -->
<template #actions>
<UploadPicker :accept="allowedMimes"
:context="uploadContext"
:destination="photosLocationFolder"
:multiple="true"
@uploaded="refreshFiles" />
<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="photos-picker__actions">
<div class="photos-picker__actions__buttons">
<UploadPicker :accept="allowedMimes"
:context="uploadContext"
:destination="photosLocationFolder"
:multiple="true"
@uploaded="refreshFiles" />
<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="photosLocationFolder.attributes['owner-id'] !== currentUser" type="warning">
{{ t('photos', 'The destination folder is owned by {owner}', { owner: photosLocationFolder.attributes['owner-id'] }) }}
</NcNoteCard>
</div>
</template>

<FilesListViewer class="photos-picker__file-list"
Expand Down Expand Up @@ -107,11 +114,12 @@

<script>
import { UploadPicker } from '@nextcloud/upload'
import { NcButton, NcDialog, NcLoadingIcon, NcSelect, useIsMobile } from '@nextcloud/vue'
import { NcButton, NcDialog, NcLoadingIcon, NcSelect, NcNoteCard, useIsMobile } from '@nextcloud/vue'
import { defineComponent } from 'vue'
import { mapGetters } from 'vuex'

import moment from '@nextcloud/moment'
import { getCurrentUser } from '@nextcloud/auth'

import ImagePlus from 'vue-material-design-icons/ImagePlus.vue'

Expand All @@ -135,6 +143,7 @@ export default defineComponent({
NcDialog,
NcLoadingIcon,
NcSelect,
NcNoteCard,
UploadPicker,
},

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

Expand Down Expand Up @@ -296,5 +306,18 @@ export default defineComponent({
justify-content: center;
}
}

&__actions {
display: flex;
flex-direction: column;
flex-grow: 1;

&__buttons {
display: flex;
align-items: center;
justify-content: end;
gap: 16px;
}
}
}
</style>

0 comments on commit 3919e49

Please sign in to comment.