]> source.dussan.org Git - nextcloud-server.git/commitdiff
Emit hook for expirationDate verification
authorRoeland Jago Douma <rullzer@owncloud.com>
Fri, 29 Jan 2016 21:42:59 +0000 (22:42 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Sat, 30 Jan 2016 14:40:31 +0000 (15:40 +0100)
lib/private/share20/manager.php

index d6245f4beac27907dfb4d7065df7a84901f2a794..0f658d83fa6df30ebd3f5478b563cb5b94cb3eea 100644 (file)
@@ -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;
                        }
                }