[Pkg-owncloud-commits] [owncloud] 70/205: Use \OC\HintException and translate the hint

David Prévot taffit at moszumanska.debian.org
Thu Jul 2 17:36:57 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 738b78f1b0eec61f4a55dd356d6b6a541ff56246
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Thu Jun 18 12:46:52 2015 +0200

    Use \OC\HintException and translate the hint
---
 apps/files_sharing/api/local.php                   |  4 +++
 core/ajax/share.php                                |  2 ++
 .../invalidfederatedcloudidexception.php           | 30 ----------------------
 lib/private/share/helper.php                       | 12 ++++++---
 lib/private/share/share.php                        |  1 +
 lib/public/share.php                               |  1 +
 tests/lib/share/helper.php                         |  2 +-
 tests/lib/share/share.php                          | 29 +++++++++++++++++++++
 8 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/apps/files_sharing/api/local.php b/apps/files_sharing/api/local.php
index 0381280..2d848f8 100644
--- a/apps/files_sharing/api/local.php
+++ b/apps/files_sharing/api/local.php
@@ -27,6 +27,8 @@
 
 namespace OCA\Files_Sharing\API;
 
+use OC\HintException;
+
 class Local {
 
 	/**
@@ -294,6 +296,8 @@ class Local {
 					$shareWith,
 					$permissions
 					);
+		} catch (HintException $e) {
+			return new \OC_OCS_Result(null, 400, $e->getHint());
 		} catch (\Exception $e) {
 			return new \OC_OCS_Result(null, 403, $e->getMessage());
 		}
diff --git a/core/ajax/share.php b/core/ajax/share.php
index e78d274..4de76b4 100644
--- a/core/ajax/share.php
+++ b/core/ajax/share.php
@@ -66,6 +66,8 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
 					} else {
 						OC_JSON::success();
 					}
+				} catch (\OC\HintException $exception) {
+					OC_JSON::error(array('data' => array('message' => $exception->getHint())));
 				} catch (Exception $exception) {
 					OC_JSON::error(array('data' => array('message' => $exception->getMessage())));
 				}
diff --git a/lib/private/share/exceptions/invalidfederatedcloudidexception.php b/lib/private/share/exceptions/invalidfederatedcloudidexception.php
deleted file mode 100644
index 1f3e63c..0000000
--- a/lib/private/share/exceptions/invalidfederatedcloudidexception.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-/**
- * @author Björn Schießle <schiessle at owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-
-namespace OC\Share\Exceptions;
-
-
-use OC\HintException;
-
-class InvalidFederatedCloudIdException extends HintException {
-
-}
diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php
index 5081a51..1988324 100644
--- a/lib/private/share/helper.php
+++ b/lib/private/share/helper.php
@@ -27,7 +27,7 @@
 
 namespace OC\Share;
 
-use OC\Share\Exceptions\InvalidFederatedCloudIdException;
+use OC\HintException;
 
 class Helper extends \OC\Share\Constants {
 
@@ -244,11 +244,13 @@ class Helper extends \OC\Share\Constants {
 	 *
 	 * @param string $id
 	 * @return array
-	 * @throws InvalidFederatedCloudIdException
+	 * @throws HintException
 	 */
 	public static function splitUserRemote($id) {
 		if (strpos($id, '@') === false) {
-			throw new InvalidFederatedCloudIdException('invalid Federated Cloud ID');
+			$l = \OC::$server->getL10N('core');
+			$hint = $l->t('Invalid Federated Cloud ID');
+			throw new HintException('Invalid Federated Cloud ID', $hint);
 		}
 
 		// Find the first character that is not allowed in user names
@@ -282,6 +284,8 @@ class Helper extends \OC\Share\Constants {
 			}
 		}
 
-		throw new InvalidFederatedCloudIdException('invalid Federated Cloud ID');
+		$l = \OC::$server->getL10N('core');
+		$hint = $l->t('Invalid Federated Cloud ID');
+		throw new HintException('Invalid Fededrated Cloud ID', $hint);
 	}
 }
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 6fcb020..d8c09bb 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -554,6 +554,7 @@ class Share extends Constants {
 	 * @param string $itemSourceName
 	 * @param \DateTime $expirationDate
 	 * @return boolean|string Returns true on success or false on failure, Returns token on success for links
+	 * @throws \OC\HintException when the share type is remote and the shareWith is invalid
 	 * @throws \Exception
 	 */
 	public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null) {
diff --git a/lib/public/share.php b/lib/public/share.php
index 6c8b82f..797972b 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -255,6 +255,7 @@ class Share extends \OC\Share\Constants {
 	 * @param string $itemSourceName
 	 * @param \DateTime $expirationDate
 	 * @return bool|string Returns true on success or false on failure, Returns token on success for links
+	 * @throws \OC\HintException when the share type is remote and the shareWith is invalid
 	 * @throws \Exception
 	 * @since 5.0.0 - parameter $itemSourceName was added in 6.0.0, parameter $expirationDate was added in 7.0.0
 	 */
diff --git a/tests/lib/share/helper.php b/tests/lib/share/helper.php
index c91d0bd..e37a3db 100644
--- a/tests/lib/share/helper.php
+++ b/tests/lib/share/helper.php
@@ -116,7 +116,7 @@ class Test_Share_Helper extends \Test\TestCase {
 	 * @dataProvider dataTestSplitUserRemoteError
 	 *
 	 * @param string $id
-	 * @expectedException \OC\Share\Exceptions\InvalidFederatedCloudIdException
+	 * @expectedException \OC\HintException
 	 */
 	public function testSplitUserRemoteError($id) {
 		\OC\Share\Helper::splitUserRemote($id);
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index f03ed43..92f6b61 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -968,6 +968,35 @@ class Test_Share extends \Test\TestCase {
 
 	}
 
+	public function dataShareWithRemoteUserAndRemoteIsInvalid() {
+		return [
+			// Invalid path
+			array('user@'),
+
+			// Invalid user
+			array('@server'),
+			array('us/er at server'),
+			array('us:er at server'),
+
+			// Invalid splitting
+			array('user'),
+			array(''),
+			array('us/erserver'),
+			array('us:erserver'),
+		];
+	}
+
+	/**
+	 * @dataProvider dataShareWithRemoteUserAndRemoteIsInvalid
+	 *
+	 * @param string $remoteId
+	 * @expectedException \OC\HintException
+	 */
+	public function testShareWithRemoteUserAndRemoteIsInvalid($remoteId) {
+		OC_User::setUserId($this->user1);
+		OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_REMOTE, $remoteId, \OCP\Constants::PERMISSION_ALL);
+	}
+
 	public function testUnshareAll() {
 		$this->shareUserTestFileWithUser($this->user1, $this->user2);
 		$this->shareUserTestFileWithUser($this->user2, $this->user3);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list