From c902c22d163c6e96172f1cb270d5dfb8062956a1 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Mon, 15 Apr 2024 21:38:55 +0100 Subject: [PATCH] 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 --- .../lib/Controller/ShareAPIController.php | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 5c9786d831d02..ce19be6286aa3 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -618,6 +618,16 @@ public function createShare( $share = $this->setShareAttributes($share, $attributes); } + //Expire date + if ($expireDate !== '') { + try { + $expireDate = $this->parseDate($expireDate); + $share->setExpirationDate($expireDate); + } catch (\Exception $e) { + throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); + } + } + $share->setSharedBy($this->currentUser); $this->checkInheritedAttributes($share); @@ -704,15 +714,6 @@ public function createShare( $share->setSharedWith($shareWith); $share->setPermissions($permissions); - if ($expireDate !== '') { - try { - $expireDate = $this->parseDate($expireDate); - $share->setExpirationDate($expireDate); - } catch (\Exception $e) { - throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); - } - } - $share->setSharedWithDisplayName($this->getCachedFederatedDisplayName($shareWith, false)); } elseif ($shareType === IShare::TYPE_REMOTE_GROUP) { if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { @@ -725,14 +726,6 @@ public function createShare( $share->setSharedWith($shareWith); $share->setPermissions($permissions); - if ($expireDate !== '') { - try { - $expireDate = $this->parseDate($expireDate); - $share->setExpirationDate($expireDate); - } catch (\Exception $e) { - throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); - } - } } elseif ($shareType === IShare::TYPE_CIRCLE) { if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); @@ -768,16 +761,6 @@ public function createShare( throw new OCSBadRequestException($this->l->t('Unknown share type')); } - //Expire date - if ($expireDate !== '') { - try { - $expireDate = $this->parseDate($expireDate); - $share->setExpirationDate($expireDate); - } catch (\Exception $e) { - throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); - } - } - $share->setShareType($shareType); if ($note !== '') {