From 1efe877d000dbaee321b37bd75dfe9cae93c801a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 29 Jan 2016 22:42:59 +0100 Subject: Emit hook for expirationDate verification --- lib/private/share20/manager.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'lib/private/share20') diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index d6245f4beac..0f658d83fa6 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -216,7 +216,9 @@ class Manager implements IManager { * @return \DateTime|null The expiration date or null if $expireDate was null and it is not required * @throws \OC\HintException */ - protected function validateExpirationDate($expirationDate) { + protected function validateExpirationDate(\OCP\Share\IShare $share) { + + $expirationDate = $share->getExpirationDate(); if ($expirationDate !== null) { //Make sure the expiration date is a date @@ -243,18 +245,30 @@ class Manager implements IManager { $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); throw new \OC\HintException($message, $message, 404); } - - return $expirationDate; } // If expiredate is empty set a default one if there is a default if ($expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { - $date = new \DateTime(); - $date->setTime(0,0,0); - $date->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); - return $date; + $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', [ + 'expirationDate' => &$expirationDate, + 'accepted' => &$accepted, + 'message' => &$message, + 'passwordSet' => $share->getPassword() === null, + ]); + + if (!$accepted) { + throw new \Exception($message); } + $share->setExpirationDate($expirationDate); + return $expirationDate; } @@ -435,7 +449,7 @@ class Manager implements IManager { ); //Verify the expiration date - $share->setExpirationDate($this->validateExpirationDate($share->getExpirationDate())); + $this->validateExpirationDate($share); //Verify the password $this->verifyPassword($share->getPassword()); @@ -572,7 +586,7 @@ class Manager implements IManager { if ($share->getExpirationDate() !== $originalShare->getExpirationDate()) { //Verify the expiration date - $share->setExpirationDate($this->validateExpirationDate($share->getExpirationDate())); + $this->validateExpirationDate($share); $expirationDateUpdated = true; } } -- cgit v1.2.3