Skip to content

Commit

Permalink
Allow specifying a default expiration date
Browse files Browse the repository at this point in the history
This overrides the max expiration date.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed May 1, 2020
1 parent cfd6f0b commit 7b0819c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/private/Share20/Manager.php
Expand Up @@ -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
Expand Down Expand Up @@ -468,7 +473,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
Expand Down
1 change: 1 addition & 0 deletions tests/lib/Share20/ManagerTest.php
Expand Up @@ -809,6 +809,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();
Expand Down

0 comments on commit 7b0819c

Please sign in to comment.