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 26, 2024
1 parent dd206f8 commit 3e7db48
Show file tree
Hide file tree
Showing 19 changed files with 366 additions and 35 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.

1 change: 1 addition & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function index(): TemplateResponse {
$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', $this->rootFolder->getUserFolder($user->getUid())->get($this->userConfig->getUserConfig('photosLocation'))->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 @@ -62,26 +62,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 @@ -106,6 +112,7 @@ export default {
ImagePlus,
NcButton,
NcLoadingIcon,
NcNoteCard,
UploadPicker,
},
Expand Down Expand Up @@ -151,6 +158,7 @@ export default {
uploadContext: {
route: 'albumpicker',
},
currentUser: getCurrentUser().uid,
}
},
Expand Down Expand Up @@ -268,9 +276,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>
Loading

0 comments on commit 3e7db48

Please sign in to comment.