Skip to content

Commit f4b8623

Browse files
committed
Allow specifying a default expiration date
This overrides the max expiration date. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 4114bce commit f4b8623

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/private/Share20/Manager.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,12 @@ protected function validateExpirationDateInternal(\OCP\Share\IShare $share) {
396396
if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) {
397397
$expirationDate = new \DateTime();
398398
$expirationDate->setTime(0,0,0);
399-
$expirationDate->add(new \DateInterval('P'.$this->shareApiInternalDefaultExpireDays().'D'));
399+
400+
$days = (int)$this->config->getAppValue('core', 'internal_defaultExpDays', $this->shareApiLinkDefaultExpireDays());
401+
if ($days > $this->shareApiLinkDefaultExpireDays()) {
402+
$days = $this->shareApiLinkDefaultExpireDays();
403+
}
404+
$expirationDate->add(new \DateInterval('P'.$days.'D'));
400405
}
401406

402407
// If we enforce the expiration date check that is does not exceed
@@ -467,7 +472,12 @@ protected function validateExpirationDate(\OCP\Share\IShare $share) {
467472
if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
468473
$expirationDate = new \DateTime();
469474
$expirationDate->setTime(0,0,0);
470-
$expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
475+
476+
$days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', $this->shareApiLinkDefaultExpireDays());
477+
if ($days > $this->shareApiLinkDefaultExpireDays()) {
478+
$days = $this->shareApiLinkDefaultExpireDays();
479+
}
480+
$expirationDate->add(new \DateInterval('P'.$days.'D'));
471481
}
472482

473483
// If we enforce the expiration date check that is does not exceed

tests/lib/Share20/ManagerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ public function testvalidateExpirationDateEnforceButNotSetNewShare() {
808808
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
809809
['core', 'shareapi_expire_after_n_days', '7', '3'],
810810
['core', 'shareapi_default_expire_date', 'no', 'yes'],
811+
['core', 'link_defaultExpDays', 3, '3'],
811812
]);
812813

813814
$expected = new \DateTime();

0 commit comments

Comments
 (0)