Skip to content

Commit 73c31a9

Browse files
authored
Merge pull request #48936 from nextcloud/backport/48918/stable29
2 parents f3029ce + e4603a7 commit 73c31a9

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
188188
if ($isOwnShare) {
189189
$result['item_permissions'] = $node->getPermissions();
190190
}
191-
191+
192192
// If we're on the recipient side, the node permissions
193193
// are bound to the share permissions. So we need to
194194
// adjust the permissions to the share permissions if necessary.
@@ -674,7 +674,7 @@ public function createShare(
674674
$expireDateTime = $this->parseDate($expireDate);
675675
$share->setExpirationDate($expireDateTime);
676676
} catch (\Exception $e) {
677-
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
677+
throw new OCSNotFoundException($e->getMessage(), $e);
678678
}
679679
} else {
680680
// Client sent empty string for expire date.
@@ -825,12 +825,11 @@ public function createShare(
825825
try {
826826
$share = $this->shareManager->createShare($share);
827827
} catch (GenericShareException $e) {
828-
$this->logger->error($e->getMessage(), ['exception' => $e]);
829828
$code = $e->getCode() === 0 ? 403 : $e->getCode();
830829
throw new OCSException($e->getHint(), $code);
831830
} catch (\Exception $e) {
832831
$this->logger->error($e->getMessage(), ['exception' => $e]);
833-
throw new OCSForbiddenException($e->getMessage(), $e);
832+
throw new OCSForbiddenException('Failed to create share.', $e);
834833
}
835834

836835
$output = $this->formatShare($share);
@@ -1350,11 +1349,11 @@ public function updateShare(
13501349
$share->setExpirationDate(null);
13511350
} elseif ($expireDate !== null) {
13521351
try {
1353-
$expireDate = $this->parseDate($expireDate);
1352+
$expireDateTime = $this->parseDate($expireDate);
1353+
$share->setExpirationDate($expireDateTime);
13541354
} catch (\Exception $e) {
13551355
throw new OCSBadRequestException($e->getMessage(), $e);
13561356
}
1357-
$share->setExpirationDate($expireDate);
13581357
}
13591358

13601359
try {
@@ -1363,7 +1362,8 @@ public function updateShare(
13631362
$code = $e->getCode() === 0 ? 403 : $e->getCode();
13641363
throw new OCSException($e->getHint(), (int)$code);
13651364
} catch (\Exception $e) {
1366-
throw new OCSBadRequestException($e->getMessage(), $e);
1365+
$this->logger->error($e->getMessage(), ['exception' => $e]);
1366+
throw new OCSBadRequestException('Failed to update share.', $e);
13671367
}
13681368

13691369
return new DataResponse($this->formatShare($share));
@@ -1452,7 +1452,8 @@ public function acceptShare(string $id): DataResponse {
14521452
$code = $e->getCode() === 0 ? 403 : $e->getCode();
14531453
throw new OCSException($e->getHint(), (int)$code);
14541454
} catch (\Exception $e) {
1455-
throw new OCSBadRequestException($e->getMessage(), $e);
1455+
$this->logger->error($e->getMessage(), ['exception' => $e]);
1456+
throw new OCSBadRequestException('Failed to accept share.', $e);
14561457
}
14571458

14581459
return new DataResponse();

apps/files_sharing/tests/ApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ public function testPublicLinkExpireDate($date, $valid) {
13171317
$this->assertTrue($valid);
13181318
} catch (OCSNotFoundException $e) {
13191319
$this->assertFalse($valid);
1320-
$this->assertEquals('Invalid date, date format must be YYYY-MM-DD', $e->getMessage());
1320+
$this->assertEquals('Invalid date. Format must be YYYY-MM-DD', $e->getMessage());
13211321
$ocs->cleanup();
13221322
return;
13231323
}

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ public function testCreateShareValidExpireDate() {
22232223

22242224
public function testCreateShareInvalidExpireDate() {
22252225
$this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class);
2226-
$this->expectExceptionMessage('Invalid date, date format must be YYYY-MM-DD');
2226+
$this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD');
22272227

22282228
$ocs = $this->mockFormatShare();
22292229

0 commit comments

Comments
 (0)