Merge pull request #22646 from owncloud/fix_22642
Set default expiration date if none given on share creation
This commit is contained in:
commit
0795cc373d
2 changed files with 43 additions and 22 deletions
|
@ -224,7 +224,7 @@ class Manager implements IManager {
|
|||
* Validate if the expiration date fits the system settings
|
||||
*
|
||||
* @param \OCP\Share\IShare $share The share to validate the expiration date of
|
||||
* @return \OCP\Share\IShare The expiration date or null if $expireDate was null and it is not required
|
||||
* @return \OCP\Share\IShare The modified share object
|
||||
* @throws GenericShareException
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Exception
|
||||
|
@ -245,6 +245,20 @@ class Manager implements IManager {
|
|||
}
|
||||
}
|
||||
|
||||
// If expiredate is empty set a default one if there is a default
|
||||
$fullId = null;
|
||||
try {
|
||||
$fullId = $share->getFullId();
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
// This is a new share
|
||||
}
|
||||
|
||||
if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
|
||||
$expirationDate = new \DateTime();
|
||||
$expirationDate->setTime(0,0,0);
|
||||
$expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
|
||||
}
|
||||
|
||||
// If we enforce the expiration date check that is does not exceed
|
||||
if ($this->shareApiLinkDefaultExpireDateEnforced()) {
|
||||
if ($expirationDate === null) {
|
||||
|
@ -260,20 +274,6 @@ class Manager implements IManager {
|
|||
}
|
||||
}
|
||||
|
||||
// If expiredate is empty set a default one if there is a default
|
||||
$fullId = null;
|
||||
try {
|
||||
$fullId = $share->getFullId();
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
// This is a new share
|
||||
}
|
||||
|
||||
if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
|
||||
$expirationDate = new \DateTime();
|
||||
$expirationDate->setTime(0,0,0);
|
||||
$expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
|
||||
}
|
||||
|
||||
$accepted = true;
|
||||
$message = '';
|
||||
\OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [
|
||||
|
@ -289,7 +289,7 @@ class Manager implements IManager {
|
|||
|
||||
$share->setExpirationDate($expirationDate);
|
||||
|
||||
return $expirationDate;
|
||||
return $share;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -713,6 +713,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
*/
|
||||
public function testvalidateExpirationDateEnforceButNotSet() {
|
||||
$share = $this->manager->newShare();
|
||||
$share->setProviderId('foo')->setId('bar');
|
||||
|
||||
$this->config->method('getAppValue')
|
||||
->will($this->returnValueMap([
|
||||
|
@ -722,6 +723,26 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
|
||||
}
|
||||
|
||||
public function testvalidateExpirationDateEnforceButNotSetNewShare() {
|
||||
$share = $this->manager->newShare();
|
||||
|
||||
$this->config->method('getAppValue')
|
||||
->will($this->returnValueMap([
|
||||
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
|
||||
['core', 'shareapi_expire_after_n_days', '7', '3'],
|
||||
['core', 'shareapi_default_expire_date', 'no', 'yes'],
|
||||
]));
|
||||
|
||||
$expected = new \DateTime();
|
||||
$expected->setTime(0,0,0);
|
||||
$expected->add(new \DateInterval('P3D'));
|
||||
|
||||
$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
|
||||
|
||||
$this->assertNotNull($share->getExpirationDate());
|
||||
$this->assertEquals($expected, $share->getExpirationDate());
|
||||
}
|
||||
|
||||
public function testvalidateExpirationDateEnforceToFarIntoFuture() {
|
||||
// Expire date in the past
|
||||
$future = new \DateTime();
|
||||
|
@ -769,9 +790,9 @@ class ManagerTest extends \Test\TestCase {
|
|||
return $data['expirationDate'] == $future;
|
||||
}));
|
||||
|
||||
$future = $this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
|
||||
$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
|
||||
|
||||
$this->assertEquals($expected, $future);
|
||||
$this->assertEquals($expected, $share->getExpirationDate());
|
||||
}
|
||||
|
||||
public function testvalidateExpirationDateNoDateNoDefaultNull() {
|
||||
|
@ -790,9 +811,9 @@ class ManagerTest extends \Test\TestCase {
|
|||
return $data['expirationDate'] == $expected && $data['passwordSet'] === false;
|
||||
}));
|
||||
|
||||
$res = $this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
|
||||
$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
|
||||
|
||||
$this->assertEquals($expected, $res);
|
||||
$this->assertEquals($expected, $share->getExpirationDate());
|
||||
}
|
||||
|
||||
public function testvalidateExpirationDateNoDateNoDefault() {
|
||||
|
@ -805,9 +826,9 @@ class ManagerTest extends \Test\TestCase {
|
|||
$share = $this->manager->newShare();
|
||||
$share->setPassword('password');
|
||||
|
||||
$date = $this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
|
||||
$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
|
||||
|
||||
$this->assertNull($date);
|
||||
$this->assertNull($share->getExpirationDate());
|
||||
}
|
||||
|
||||
public function testvalidateExpirationDateNoDateDefault() {
|
||||
|
|
Loading…
Reference in a new issue