Skip to content

Commit 29f6f45

Browse files
committed
Merge pull request #22192 from owncloud/fix_19685
Only set the default expiration date on share creation
2 parents febe535 + 4972647 commit 29f6f45

4 files changed

Lines changed: 51 additions & 7 deletions

File tree

lib/private/share20/manager.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,14 @@ protected function validateExpirationDate(\OCP\Share\IShare $share) {
261261
}
262262

263263
// If expiredate is empty set a default one if there is a default
264-
if ($expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
264+
$fullId = null;
265+
try {
266+
$fullId = $share->getFullId();
267+
} catch (\UnexpectedValueException $e) {
268+
// This is a new share
269+
}
270+
271+
if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
265272
$expirationDate = new \DateTime();
266273
$expirationDate->setTime(0,0,0);
267274
$expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
@@ -315,8 +322,12 @@ protected function userCreateChecks(\OCP\Share\IShare $share) {
315322
$existingShares = $provider->getSharesByPath($share->getNode());
316323
foreach($existingShares as $existingShare) {
317324
// Ignore if it is the same share
318-
if ($existingShare->getFullId() === $share->getFullId()) {
319-
continue;
325+
try {
326+
if ($existingShare->getFullId() === $share->getFullId()) {
327+
continue;
328+
}
329+
} catch (\UnexpectedValueException $e) {
330+
//Shares are not identical
320331
}
321332

322333
// Identical share already existst
@@ -360,8 +371,12 @@ protected function groupCreateChecks(\OCP\Share\IShare $share) {
360371
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
361372
$existingShares = $provider->getSharesByPath($share->getNode());
362373
foreach($existingShares as $existingShare) {
363-
if ($existingShare->getFullId() === $share->getFullId()) {
364-
continue;
374+
try {
375+
if ($existingShare->getFullId() === $share->getFullId()) {
376+
continue;
377+
}
378+
} catch (\UnexpectedValueException $e) {
379+
//It is a new share so just continue
365380
}
366381

367382
if ($existingShare->getSharedWith() === $share->getSharedWith()) {
@@ -558,7 +573,11 @@ public function updateShare(\OCP\Share\IShare $share) {
558573
throw new \Exception('The Share API is disabled');
559574
}
560575

561-
$originalShare = $this->getShareById($share->getFullId());
576+
try {
577+
$originalShare = $this->getShareById($share->getFullId());
578+
} catch (\UnexpectedValueException $e) {
579+
throw new \InvalidArgumentException('Share does not have a full id');
580+
}
562581

563582
// We can't change the share type!
564583
if ($share->getShareType() !== $originalShare->getShareType()) {
@@ -673,10 +692,15 @@ protected function deleteChildren(\OCP\Share\IShare $share) {
673692
*
674693
* @param \OCP\Share\IShare $share
675694
* @throws ShareNotFound
695+
* @throws \InvalidArgumentException
676696
*/
677697
public function deleteShare(\OCP\Share\IShare $share) {
678698
// Just to make sure we have all the info
679-
$share = $this->getShareById($share->getFullId());
699+
try {
700+
$share = $this->getShareById($share->getFullId());
701+
} catch (\UnexpectedValueException $e) {
702+
throw new \InvalidArgumentException('Share does not have a full id');
703+
}
680704

681705
$formatHookParams = function(\OCP\Share\IShare $share) {
682706
// Prepare hook

lib/private/share20/share.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public function getId() {
9090
* @inheritdoc
9191
*/
9292
public function getFullId() {
93+
if ($this->providerId === null || $this->id === null) {
94+
throw new \UnexpectedValueException;
95+
}
9396
return $this->providerId . ':' . $this->id;
9497
}
9598

lib/public/share/ishare.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function getId();
4848
*
4949
* @return string
5050
* @since 9.0.0
51+
* @throws \UnexpectedValueException If the fullId could not be constructed
5152
*/
5253
public function getFullId();
5354

tests/lib/share20/managertest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,22 @@ public function testValidateExpirationDateHookException() {
890890
$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
891891
}
892892

893+
public function testValidateExpirationDateExistingShareNoDefault() {
894+
$share = $this->manager->newShare();
895+
896+
$share->setId('42')->setProviderId('foo');
897+
898+
$this->config->method('getAppValue')
899+
->will($this->returnValueMap([
900+
['core', 'shareapi_default_expire_date', 'no', 'yes'],
901+
['core', 'shareapi_expire_after_n_days', '7', '6'],
902+
]));
903+
904+
$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
905+
906+
$this->assertEquals(null, $share->getExpirationDate());
907+
}
908+
893909
/**
894910
* @expectedException Exception
895911
* @expectedExceptionMessage Only sharing with group members is allowed

0 commit comments

Comments
 (0)