Skip to content

Commit 5c6fd77

Browse files
skjnldsvbackportbot[bot]
authored andcommitted
fix(files_sharing): fix share creation error handling
Signed-off-by: skjnldsv <skjnldsv@protonmail.com> [skip ci]
1 parent c00d619 commit 5c6fd77

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
use OCP\Lock\ILockingProvider;
8282
use OCP\Lock\LockedException;
8383
use OCP\Server;
84+
use OCP\Share\Exceptions\GenericShareException;
8485
use OCP\Share\Exceptions\ShareNotFound;
8586
use OCP\Share\IManager;
8687
use OCP\Share\IShare;
@@ -804,6 +805,9 @@ public function createShare(
804805
} catch (HintException $e) {
805806
$code = $e->getCode() === 0 ? 403 : $e->getCode();
806807
throw new OCSException($e->getHint(), $code);
808+
} catch (GenericShareException|\InvalidArgumentException $e) {
809+
$this->logger->error($e->getMessage(), ['exception' => $e]);
810+
throw new OCSForbiddenException($e->getMessage(), $e);
807811
} catch (\Exception $e) {
808812
$this->logger->error($e->getMessage(), ['exception' => $e]);
809813
throw new OCSForbiddenException('Failed to create share.', $e);

apps/files_sharing/src/mixins/ShareRequests.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
// TODO: remove when ie not supported
2727
import 'url-search-params-polyfill'
2828

29+
import { emit } from '@nextcloud/event-bus'
30+
import { showError } from '@nextcloud/dialogs'
2931
import { generateOcsUrl } from '@nextcloud/router'
3032
import axios from '@nextcloud/axios'
3133
import Share from '../models/Share.js'
@@ -65,7 +67,7 @@ export default {
6567
} catch (error) {
6668
console.error('Error while creating share', error)
6769
const errorMessage = error?.response?.data?.ocs?.meta?.message
68-
OC.Notification.showTemporary(
70+
showError(
6971
errorMessage ? t('files_sharing', 'Error creating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error creating the share'),
7072
{ type: 'error' },
7173
)

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
</NcButton>
231231
<NcButton type="primary"
232232
data-cy-files-sharing-share-editor-action="save"
233+
:disabled="creating"
233234
@click="saveShare">
234235
{{ shareButtonText }}
235236
<template v-if="creating" #icon>
@@ -899,8 +900,16 @@ export default {
899900
incomingShare.password = this.share.password
900901
}
901902
902-
this.creating = true
903-
const share = await this.addShare(incomingShare)
903+
let share
904+
try {
905+
this.creating = true
906+
share = await this.addShare(incomingShare)
907+
} catch (error) {
908+
this.creating = false
909+
// Error is already handled by ShareRequests mixin
910+
return
911+
}
912+
904913
// 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
905914
this.share._share.id = share.id
906915
await this.queueUpdate(...permissionsAndAttributes)
@@ -914,6 +923,7 @@ export default {
914923
}
915924
}
916925
}
926+
917927
this.share = share
918928
this.creating = false
919929
this.$emit('add:share', this.share)

tests/lib/Share20/ManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ public function testLinkCreateChecksReadOnly() {
22732273

22742274
public function testPathCreateChecksContainsSharedMount() {
22752275
$this->expectException(\InvalidArgumentException::class);
2276-
$this->expectExceptionMessage('Path contains files shared with you');
2276+
$this->expectExceptionMessage('You cannot share a folder that contains other shares');
22772277

22782278
$path = $this->createMock(Folder::class);
22792279
$path->method('getPath')->willReturn('path');

0 commit comments

Comments
 (0)