diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-03 13:36:14 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-03 13:36:14 +0100 |
commit | aaf7299d2813c1b1b206459b2d7997d3e1cd0526 (patch) | |
tree | 4e9905b450d762fcc3abe7a1e8643aedc0c15310 /lib | |
parent | cf81574e877a6468358cc4a1e52cc078b6b01823 (diff) | |
parent | dc32f49c6ee25770b461f11287fd9695f2429c91 (diff) | |
download | nextcloud-server-aaf7299d2813c1b1b206459b2d7997d3e1cd0526.tar.gz nextcloud-server-aaf7299d2813c1b1b206459b2d7997d3e1cd0526.zip |
Merge pull request #22070 from owncloud/share2_exceptions
Add sharing exceptions to OCP
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/share20/defaultshareprovider.php | 2 | ||||
-rw-r--r-- | lib/private/share20/manager.php | 23 | ||||
-rw-r--r-- | lib/public/share/exceptions/genericshareexception.php | 28 | ||||
-rw-r--r-- | lib/public/share/exceptions/sharenotfound.php (renamed from lib/private/share20/exception/sharenotfound.php) | 11 |
4 files changed, 50 insertions, 14 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 224dddf4019..7b78be2b61d 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -24,7 +24,7 @@ use OCP\Files\File; use OCP\Share\IShareProvider; use OC\Share20\Exception\InvalidShare; use OC\Share20\Exception\ProviderException; -use OC\Share20\Exception\ShareNotFound; +use OCP\Share\Exceptions\ShareNotFound; use OC\Share20\Exception\BackendError; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\NotFoundException; diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index b22b81bb404..520b5a53762 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -36,8 +36,8 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\IUser; -use OC\Share20\Exception\ShareNotFound; -use OC\HintException; +use OCP\Share\Exceptions\ShareNotFound; +use OCP\Share\Exceptions\GenericShareException; /** * This class is the communication hub for all sharing related operations. @@ -144,7 +144,8 @@ class Manager implements IManager { * Check for generic requirements before creating a share * * @param \OCP\Share\IShare $share - * @throws \Exception + * @throws \InvalidArgumentException + * @throws GenericShareException */ protected function generalCreateChecks(\OCP\Share\IShare $share) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { @@ -190,7 +191,7 @@ class Manager implements IManager { // Check if we actually have share permissions if (!$share->getNode()->isShareable()) { $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); - throw new HintException($message_t, $message_t, 404); + throw new GenericShareException($message_t, $message_t, 404); } // Permissions should be set @@ -201,7 +202,7 @@ class Manager implements IManager { // Check that we do not share with more permissions than we have if ($share->getPermissions() & ~$share->getNode()->getPermissions()) { $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]); - throw new HintException($message_t, $message_t, 404); + throw new GenericShareException($message_t, $message_t, 404); } // Check that read permissions are always set @@ -213,9 +214,11 @@ class Manager implements IManager { /** * Validate if the expiration date fits the system settings * - * @param \DateTime $expirationDate The current expiration date (can be null) + * @param \OCP\Share\IShare $share The share to validate the expiration date of * @return \DateTime|null The expiration date or null if $expireDate was null and it is not required - * @throws \OC\HintException + * @throws GenericShareException + * @throws \InvalidArgumentException + * @throws \Exception */ protected function validateExpirationDate(\OCP\Share\IShare $share) { @@ -229,7 +232,7 @@ class Manager implements IManager { $date->setTime(0, 0, 0); if ($date >= $expirationDate) { $message = $this->l->t('Expiration date is in the past'); - throw new \OC\HintException($message, $message, 404); + throw new GenericShareException($message, $message, 404); } } @@ -244,7 +247,7 @@ class Manager implements IManager { $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); if ($date < $expirationDate) { $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); - throw new \OC\HintException($message, $message, 404); + throw new GenericShareException($message, $message, 404); } } @@ -638,8 +641,6 @@ class Manager implements IManager { * * @param \OCP\Share\IShare $share * @throws ShareNotFound - * @throws BackendError - * @throws ShareNotFound */ public function deleteShare(\OCP\Share\IShare $share) { // Just to make sure we have all the info diff --git a/lib/public/share/exceptions/genericshareexception.php b/lib/public/share/exceptions/genericshareexception.php new file mode 100644 index 00000000000..83dfa12dbfc --- /dev/null +++ b/lib/public/share/exceptions/genericshareexception.php @@ -0,0 +1,28 @@ +<?php + +namespace OCP\Share\Exceptions; +use OC\HintException; + +/** + * Class GenericEncryptionException + * + * @package OCP\Share\Exceptions + * @since 9.0.0 + */ +class GenericShareException extends HintException { + + /** + * @param string $message + * @param string $hint + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', $hint = '', $code = 0, \Exception $previous = null) { + if (empty($message)) { + $message = 'Unspecified share exception'; + } + parent::__construct($message, $hint, $code, $previous); + } + +} diff --git a/lib/private/share20/exception/sharenotfound.php b/lib/public/share/exceptions/sharenotfound.php index b59f185939a..96e7c096492 100644 --- a/lib/private/share20/exception/sharenotfound.php +++ b/lib/public/share/exceptions/sharenotfound.php @@ -18,8 +18,15 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -namespace OC\Share20\Exception; -class ShareNotFound extends \Exception { +namespace OCP\Share\Exceptions; + +/** + * Class ShareNotFound + * + * @package OCP\Share\Exceptions + * @since 9.0.0 + */ +class ShareNotFound extends GenericShareException { } |