Skip to content

Commit 3cd5a7f

Browse files
committed
fix(shareApiController): avoid duplicated expiryDate operations
`expireDate` can be set once and used anywhere needed, the current implementation, duplicates this behavior which leads to `parseDate` receiving an a date object it parsed and returend earlier in the createShare method. Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
1 parent abd24c8 commit 3cd5a7f

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,16 @@ public function createShare(
647647
$share = $this->setShareAttributes($share, $attributes);
648648
}
649649

650+
//Expire date
651+
if ($expireDate !== '') {
652+
try {
653+
$expireDate = $this->parseDate($expireDate);
654+
$share->setExpirationDate($expireDate);
655+
} catch (\Exception $e) {
656+
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
657+
}
658+
}
659+
650660
$share->setSharedBy($this->currentUser);
651661
$this->checkInheritedAttributes($share);
652662

@@ -733,15 +743,6 @@ public function createShare(
733743

734744
$share->setSharedWith($shareWith);
735745
$share->setPermissions($permissions);
736-
if ($expireDate !== '') {
737-
try {
738-
$expireDate = $this->parseDate($expireDate);
739-
$share->setExpirationDate($expireDate);
740-
} catch (\Exception $e) {
741-
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
742-
}
743-
}
744-
745746
$share->setSharedWithDisplayName($this->getCachedFederatedDisplayName($shareWith, false));
746747
} elseif ($shareType === IShare::TYPE_REMOTE_GROUP) {
747748
if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
@@ -754,14 +755,6 @@ public function createShare(
754755

755756
$share->setSharedWith($shareWith);
756757
$share->setPermissions($permissions);
757-
if ($expireDate !== '') {
758-
try {
759-
$expireDate = $this->parseDate($expireDate);
760-
$share->setExpirationDate($expireDate);
761-
} catch (\Exception $e) {
762-
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
763-
}
764-
}
765758
} elseif ($shareType === IShare::TYPE_CIRCLE) {
766759
if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
767760
throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
@@ -797,16 +790,6 @@ public function createShare(
797790
throw new OCSBadRequestException($this->l->t('Unknown share type'));
798791
}
799792

800-
//Expire date
801-
if ($expireDate !== '') {
802-
try {
803-
$expireDate = $this->parseDate($expireDate);
804-
$share->setExpirationDate($expireDate);
805-
} catch (\Exception $e) {
806-
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
807-
}
808-
}
809-
810793
$share->setShareType($shareType);
811794

812795
if ($note !== '') {

0 commit comments

Comments
 (0)