summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-08-13 10:13:21 +0200
committerVincent Petry <pvince81@owncloud.com>2015-08-13 10:13:21 +0200
commit55dc74bba48704cc2478530300aece9396b7b191 (patch)
tree232d162e9dd71f3f50e6c943a35340ea72c07893 /apps/files_sharing
parentb811124aac3cf308b5c011d4c32554d145fe4d10 (diff)
parent77b6e3d5ec8a5bf6ae0fd3cbb24486ee828c5d89 (diff)
downloadnextcloud-server-55dc74bba48704cc2478530300aece9396b7b191.tar.gz
nextcloud-server-55dc74bba48704cc2478530300aece9396b7b191.zip
Merge pull request #16543 from rullzer/files_sharing_proper_function_args
files_sharing private function to proper signature
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/api/local.php47
-rw-r--r--apps/files_sharing/tests/api.php48
2 files changed, 70 insertions, 25 deletions
diff --git a/apps/files_sharing/api/local.php b/apps/files_sharing/api/local.php
index 2b2b475466f..eb0e0e0d846 100644
--- a/apps/files_sharing/api/local.php
+++ b/apps/files_sharing/api/local.php
@@ -42,20 +42,20 @@ class Local {
}
// if a file is specified, get the share for this file
if (isset($_GET['path'])) {
- $params['itemSource'] = self::getFileId($_GET['path']);
- $params['path'] = $_GET['path'];
- $params['itemType'] = self::getItemType($_GET['path']);
-
if ( isset($_GET['reshares']) && $_GET['reshares'] !== 'false' ) {
- $params['reshares'] = true;
+ $reshares = true;
} else {
- $params['reshares'] = false;
+ $reshares = false;
}
if (isset($_GET['subfiles']) && $_GET['subfiles'] !== 'false') {
- return self::getSharesFromFolder($params);
+ return self::getSharesFromFolder($_GET['path']);
}
- return self::collectShares($params);
+ return self::collectShares(self::getFileId($_GET['path']),
+ self::getItemType($_GET['path']),
+ false,
+ $_GET['path'],
+ $reshares);
}
$shares = \OCP\Share::getItemShared('file', null);
@@ -89,38 +89,36 @@ class Local {
public static function getShare($params) {
$s = self::getShareFromId($params['id']);
- $params['itemSource'] = $s['file_source'];
- $params['itemType'] = $s['item_type'];
- $params['specificShare'] = true;
- return self::collectShares($params);
+ return self::collectShares($s['file_source'], $s['item_type'], true, null, false, (int)$params['id']);
}
/**
* collect all share information, either of a specific share or all
* shares for a given path
- * @param array $params
+ *
+ * @param string $itemSource
+ * @param string $itemType
+ * @param bool $getSpecificShare
+ * @param string $path
+ * @param bool $reshares
+ * @param int $id
+ *
* @return \OC_OCS_Result
*/
- private static function collectShares($params) {
-
- $itemSource = $params['itemSource'];
- $itemType = $params['itemType'];
- $getSpecificShare = isset($params['specificShare']) ? $params['specificShare'] : false;
-
+ private static function collectShares($itemSource, $itemType, $getSpecificShare = false, $path = null, $reshares = false, $id = null) {
if ($itemSource !== null) {
$shares = \OCP\Share::getItemShared($itemType, $itemSource);
$receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $itemSource);
// if a specific share was specified only return this one
if ($getSpecificShare === true) {
foreach ($shares as $share) {
- if ($share['id'] === (int) $params['id']) {
+ if ($share['id'] === $id) {
$shares = array('element' => $share);
break;
}
}
} else {
- $path = $params['path'];
foreach ($shares as $key => $share) {
$shares[$key]['path'] = $path;
}
@@ -129,7 +127,7 @@ class Local {
// include also reshares in the lists. This means that the result
// will contain every user with access to the file.
- if (isset($params['reshares']) && $params['reshares'] === true) {
+ if ($reshares === true) {
$shares = self::addReshares($shares, $itemSource);
}
@@ -189,11 +187,10 @@ class Local {
/**
* get share from all files in a given folder (non-recursive)
- * @param array $params contains 'path' to the folder
+ * @param string $path
* @return \OC_OCS_Result
*/
- private static function getSharesFromFolder($params) {
- $path = $params['path'];
+ private static function getSharesFromFolder($path) {
$view = new \OC\Files\View('/'.\OCP\User::getUser().'/files');
if(!$view->is_dir($path)) {
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index af441b38ff2..3bd568e47af 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -307,6 +307,31 @@ class Test_Files_Sharing_Api extends TestCase {
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
}
+ function testGetAllSharesWithMe() {
+ $fileinfo1 = $this->view->getFileInfo($this->filename);
+ $fileinfo2 = $this->view->getFileInfo($this->folder.$this->filename);
+
+ \OCP\Share::shareItem('file', $fileinfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
+ \OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+
+ $_GET['shared_with_me'] = 1;
+ $result = \OCA\Files_Sharing\API\Local::getAllShares(array());
+
+ $this->assertTrue($result->succeeded());
+ $this->assertTrue(count($result->getData()) === 2);
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+ \OCP\Share::unshare('file', $fileinfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+ \OCP\Share::unshare('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+ }
+
/**
* @medium
* @depends testCreateShare
@@ -506,7 +531,30 @@ class Test_Files_Sharing_Api extends TestCase {
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
\OCP\Share::unshare('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
+ }
+
+ function testGetShareFromFolderWithFile() {
+ $fileInfo1 = $this->view->getFileInfo($this->filename);
+
+ $result = \OCP\Share::shareItem('file', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
+
+ // share was successful?
+ $this->assertTrue($result);
+
+ $_GET = [
+ 'path' => $this->filename,
+ 'subfiles' => 1
+ ];
+ $result = \OCA\Files_Sharing\API\Local::getAllShares([]);
+
+ $this->assertFalse($result->succeeded());
+ $this->assertEquals(400, $result->getStatusCode());
+ $this->assertEquals('not a directory', $result->getMeta()['message']);
+
+ \OCP\Share::unshare('file', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
}
/**