Merge pull request #16543 from rullzer/files_sharing_proper_function_args
files_sharing private function to proper signature
This commit is contained in:
commit
55dc74bba4
2 changed files with 70 additions and 25 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue