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 <louis@chmn.me>
  • Loading branch information
artonge committed Sep 25, 2024
1 parent dd206f8 commit a68a275
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
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>
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 a68a275

Please sign in to comment.