Skip to content
Snippets Groups Projects
Commit a6d93193 authored by Björn Schießle's avatar Björn Schießle
Browse files

Merge pull request #5269 from owncloud/ocs_share_api_add_received_from

ocs share api: add "received_from" and "received_from_displayname" field
parents fa341e49 7a1705d2
Branches
No related tags found
No related merge requests found
...@@ -31,11 +31,11 @@ class Api { ...@@ -31,11 +31,11 @@ class Api {
* @return \OC_OCS_Result share information * @return \OC_OCS_Result share information
*/ */
public static function getAllShares($params) { public static function getAllShares($params) {
// if a file is specified, get the share for this file // if a file is specified, get the share for this file
if (isset($_GET['path'])) { if (isset($_GET['path'])) {
$params['itemSource'] = self::getFileId($_GET['path']); $params['itemSource'] = self::getFileId($_GET['path']);
$params['path'] = $_GET['path']; $params['path'] = $_GET['path'];
$params['itemType'] = self::getItemType($_GET['path']);
if (isset($_GET['subfiles']) && $_GET['subfiles'] === 'true') { if (isset($_GET['subfiles']) && $_GET['subfiles'] === 'true') {
return self::getSharesFromFolder($params); return self::getSharesFromFolder($params);
} }
...@@ -59,20 +59,22 @@ class Api { ...@@ -59,20 +59,22 @@ class Api {
* @return \OC_OCS_Result share information * @return \OC_OCS_Result share information
*/ */
public static function getShare($params) { public static function getShare($params) {
// either the $params already contains a itemSource if we come from // either the $params already contains a itemSource if we come from
// getAllShare() or we need to translate the shareID to a itemSource // getAllShare() or we need to translate the shareID to a itemSource
if(isset($params['itemSource'])) { if(isset($params['itemSource'])) {
$itemSource = $params['itemSource']; $itemSource = $params['itemSource'];
$itemType = $params['itemType'];
$getSpecificShare = true; $getSpecificShare = true;
} else { } else {
$s = self::getShareFromId($params['id']); $s = self::getShareFromId($params['id']);
$itemSource = $s['item_source']; $itemSource = $s['item_source'];
$itemType = $s['item_type'];
$getSpecificShare = false; $getSpecificShare = false;
} }
if ($itemSource !== null) { if ($itemSource !== null) {
$shares = \OCP\Share::getItemShared('file', $itemSource); $shares = \OCP\Share::getItemShared($itemType, $itemSource);
$reshare = \OCP\Share::getItemSharedWithBySource($itemType, $itemSource);
// if a specific share was specified only return this one // if a specific share was specified only return this one
if ($getSpecificShare === false) { if ($getSpecificShare === false) {
foreach ($shares as $share) { foreach ($shares as $share) {
...@@ -82,6 +84,10 @@ class Api { ...@@ -82,6 +84,10 @@ class Api {
} }
} }
} }
if ($reshare) {
$shares['received_from'] = $reshare['uid_owner'];
$shares['received_from_displayname'] = \OCP\User::getDisplayName($reshare['uid_owner']);
}
} else { } else {
$shares = null; $shares = null;
} }
...@@ -110,7 +116,14 @@ class Api { ...@@ -110,7 +116,14 @@ class Api {
$result = array(); $result = array();
foreach ($content as $file) { foreach ($content as $file) {
$share = \OCP\Share::getItemShared('file', $file['fileid']); // workaround because folders are named 'dir' in this context
$itemType = $file['type'] === 'file' ? 'file' : 'folder';
$share = \OCP\Share::getItemShared($itemType, $file['fileid']);
$reshare = \OCP\Share::getItemSharedWithBySource($itemType, $file['fileid']);
if ($reshare) {
$share['received_from'] = $reshare['uid_owner'];
$share['received_from_displayname'] = \OCP\User::getDisplayName($reshare['uid_owner']);
}
if ($share) { if ($share) {
$share['filename'] = $file['name']; $share['filename'] = $file['name'];
$result[] = $share; $result[] = $share;
...@@ -132,7 +145,6 @@ class Api { ...@@ -132,7 +145,6 @@ class Api {
if($path === null) { if($path === null) {
return new \OC_OCS_Result(null, 400, "please specify a file or folder path"); return new \OC_OCS_Result(null, 400, "please specify a file or folder path");
} }
$itemSource = self::getFileId($path); $itemSource = self::getFileId($path);
$itemType = self::getItemType($path); $itemType = self::getItemType($path);
...@@ -184,7 +196,7 @@ class Api { ...@@ -184,7 +196,7 @@ class Api {
if ($token) { if ($token) {
$data = array(); $data = array();
$data['id'] = 'unknown'; $data['id'] = 'unknown';
$shares = \OCP\Share::getItemShared('file', $itemSource); $shares = \OCP\Share::getItemShared($itemType, $itemSource);
if(is_string($token)) { //public link share if(is_string($token)) { //public link share
foreach ($shares as $share) { foreach ($shares as $share) {
if ($share['token'] === $token) { if ($share['token'] === $token) {
...@@ -414,7 +426,6 @@ class Api { ...@@ -414,7 +426,6 @@ class Api {
$view = new \OC\Files\View('/'.\OCP\User::getUser().'/files'); $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files');
$fileId = null; $fileId = null;
$fileInfo = $view->getFileInfo($path); $fileInfo = $view->getFileInfo($path);
if ($fileInfo) { if ($fileInfo) {
$fileId = $fileInfo['fileid']; $fileId = $fileInfo['fileid'];
......
...@@ -197,7 +197,8 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase { ...@@ -197,7 +197,8 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK,
null, 1); null, 1);
$params = array('itemSource' => $fileInfo['fileid']); $params = array('itemSource' => $fileInfo['fileid'],
'itemType' => 'file');
$result = Share\Api::getShare($params); $result = Share\Api::getShare($params);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment