From f4b8623d330dcde02f07fa58d7134698744ee790 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 21 Apr 2020 14:10:33 +0200 Subject: [PATCH] Allow specifying a default expiration date This overrides the max expiration date. Signed-off-by: Roeland Jago Douma --- lib/private/Share20/Manager.php | 14 ++++++++++++-- tests/lib/Share20/ManagerTest.php | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index becf29e4cc7ba..eae26645b55c7 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -396,7 +396,12 @@ protected function validateExpirationDateInternal(\OCP\Share\IShare $share) { if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) { $expirationDate = new \DateTime(); $expirationDate->setTime(0,0,0); - $expirationDate->add(new \DateInterval('P'.$this->shareApiInternalDefaultExpireDays().'D')); + + $days = (int)$this->config->getAppValue('core', 'internal_defaultExpDays', $this->shareApiLinkDefaultExpireDays()); + if ($days > $this->shareApiLinkDefaultExpireDays()) { + $days = $this->shareApiLinkDefaultExpireDays(); + } + $expirationDate->add(new \DateInterval('P'.$days.'D')); } // If we enforce the expiration date check that is does not exceed @@ -467,7 +472,12 @@ protected function validateExpirationDate(\OCP\Share\IShare $share) { if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { $expirationDate = new \DateTime(); $expirationDate->setTime(0,0,0); - $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); + + $days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', $this->shareApiLinkDefaultExpireDays()); + if ($days > $this->shareApiLinkDefaultExpireDays()) { + $days = $this->shareApiLinkDefaultExpireDays(); + } + $expirationDate->add(new \DateInterval('P'.$days.'D')); } // If we enforce the expiration date check that is does not exceed diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 4a7b0e9ae4b4a..b8364cfdc4669 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -808,6 +808,7 @@ public function testvalidateExpirationDateEnforceButNotSetNewShare() { ['core', 'shareapi_enforce_expire_date', 'no', 'yes'], ['core', 'shareapi_expire_after_n_days', '7', '3'], ['core', 'shareapi_default_expire_date', 'no', 'yes'], + ['core', 'link_defaultExpDays', 3, '3'], ]); $expected = new \DateTime();