Skip to content

Commit 367ef8d

Browse files
committed
fix(files_sharing): fix share creation error handling
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 3808f86 commit 367ef8d

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OCP\Lock\LockedException;
5353
use OCP\Mail\IMailer;
5454
use OCP\Server;
55+
use OCP\Share\Exceptions\GenericShareException;
5556
use OCP\Share\Exceptions\ShareNotFound;
5657
use OCP\Share\Exceptions\ShareTokenException;
5758
use OCP\Share\IManager;
@@ -800,6 +801,9 @@ public function createShare(
800801
} catch (HintException $e) {
801802
$code = $e->getCode() === 0 ? 403 : $e->getCode();
802803
throw new OCSException($e->getHint(), $code);
804+
} catch (GenericShareException|\InvalidArgumentException $e) {
805+
$this->logger->error($e->getMessage(), ['exception' => $e]);
806+
throw new OCSForbiddenException($e->getMessage(), $e);
803807
} catch (\Exception $e) {
804808
$this->logger->error($e->getMessage(), ['exception' => $e]);
805809
throw new OCSForbiddenException('Failed to create share.', $e);

apps/files_sharing/src/mixins/ShareRequests.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
// TODO: remove when ie not supported
77
import 'url-search-params-polyfill'
88

9+
import { emit } from '@nextcloud/event-bus'
10+
import { showError } from '@nextcloud/dialogs'
911
import { generateOcsUrl } from '@nextcloud/router'
1012
import axios from '@nextcloud/axios'
13+
1114
import Share from '../models/Share.ts'
12-
import { emit } from '@nextcloud/event-bus'
1315

1416
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
1517

@@ -45,7 +47,7 @@ export default {
4547
} catch (error) {
4648
console.error('Error while creating share', error)
4749
const errorMessage = error?.response?.data?.ocs?.meta?.message
48-
OC.Notification.showTemporary(
50+
showError(
4951
errorMessage ? t('files_sharing', 'Error creating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error creating the share'),
5052
{ type: 'error' },
5153
)

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
</NcButton>
252252
<NcButton type="primary"
253253
data-cy-files-sharing-share-editor-action="save"
254+
:disabled="creating"
254255
@click="saveShare">
255256
{{ shareButtonText }}
256257
<template v-if="creating" #icon>
@@ -1003,8 +1004,16 @@ export default {
10031004
incomingShare.password = this.share.password
10041005
}
10051006
1006-
this.creating = true
1007-
const share = await this.addShare(incomingShare)
1007+
let share
1008+
try {
1009+
this.creating = true
1010+
share = await this.addShare(incomingShare)
1011+
} catch (error) {
1012+
this.creating = false
1013+
// Error is already handled by ShareRequests mixin
1014+
return
1015+
}
1016+
10081017
// ugly hack to make code work - we need the id to be set but at the same time we need to keep values we want to update
10091018
this.share._share.id = share.id
10101019
await this.queueUpdate(...permissionsAndAttributes)
@@ -1018,6 +1027,7 @@ export default {
10181027
}
10191028
}
10201029
}
1030+
10211031
this.share = share
10221032
this.creating = false
10231033
this.$emit('add:share', this.share)

lib/private/Share20/Manager.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,11 @@ protected function pathCreateChecks($path) {
597597
$mounts = $this->mountManager->findIn($path->getPath());
598598
foreach ($mounts as $mount) {
599599
if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
600-
throw new \InvalidArgumentException($this->l->t('Path contains files shared with you'));
600+
// Using a flat sharing model ensures the file owner can always see who has access.
601+
// Allowing parent folder sharing would require tracking inherited access, which adds complexity
602+
// and hurts performance/scalability.
603+
// So we forbid sharing a parent folder of a share you received.
604+
throw new \InvalidArgumentException($this->l->t('You cannot share a folder that contains other shares'));
601605
}
602606
}
603607
}

0 commit comments

Comments
 (0)