summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-06-18 12:46:52 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-06-22 15:34:06 +0200
commit738b78f1b0eec61f4a55dd356d6b6a541ff56246 (patch)
treecba20da65582db0e389c2b7017c4ffd0a49ff7f5
parent2b7e5f841a016e8682d560643dce4797758a44c3 (diff)
downloadnextcloud-server-738b78f1b0eec61f4a55dd356d6b6a541ff56246.tar.gz
nextcloud-server-738b78f1b0eec61f4a55dd356d6b6a541ff56246.zip
Use \OC\HintException and translate the hint
-rw-r--r--apps/files_sharing/api/local.php4
-rw-r--r--core/ajax/share.php2
-rw-r--r--lib/private/share/exceptions/invalidfederatedcloudidexception.php30
-rw-r--r--lib/private/share/helper.php12
-rw-r--r--lib/private/share/share.php1
-rw-r--r--lib/public/share.php1
-rw-r--r--tests/lib/share/helper.php2
-rw-r--r--tests/lib/share/share.php29
8 files changed, 46 insertions, 35 deletions
diff --git a/apps/files_sharing/api/local.php b/apps/files_sharing/api/local.php
index 03812800c17..2d848f8b16e 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 e78d274815d..4de76b460cf 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 1f3e63c8800..00000000000
--- a/lib/private/share/exceptions/invalidfederatedcloudidexception.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-/**
- * @author Björn Schießle <schiessle@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 5081a517db7..1988324a996 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 6fcb020eeb3..d8c09bb0883 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 6c8b82f4293..797972bc1cb 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 c91d0bdde30..e37a3db8bf0 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 f03ed43e7fc..92f6b612688 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@server'),
+ array('us:er@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);