|
|
|
@ -36,10 +36,17 @@ class Api { |
|
|
|
|
$params['itemSource'] = self::getFileId($_GET['path']); |
|
|
|
|
$params['path'] = $_GET['path']; |
|
|
|
|
$params['itemType'] = self::getItemType($_GET['path']); |
|
|
|
|
if (isset($_GET['subfiles']) && $_GET['subfiles'] === 'true') { |
|
|
|
|
|
|
|
|
|
if ( isset($_GET['reshares']) && $_GET['reshares'] !== 'false' ) { |
|
|
|
|
$params['reshares'] = true; |
|
|
|
|
} else { |
|
|
|
|
$params['reshares'] = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($_GET['subfiles']) && $_GET['subfiles'] !== 'false') { |
|
|
|
|
return self::getSharesFromFolder($params); |
|
|
|
|
} |
|
|
|
|
return self::getShare($params); |
|
|
|
|
return self::collectShares($params); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$share = \OCP\Share::getItemShared('file', null); |
|
|
|
@ -59,34 +66,49 @@ class Api { |
|
|
|
|
* @return \OC_OCS_Result share information |
|
|
|
|
*/ |
|
|
|
|
public static function getShare($params) { |
|
|
|
|
// either the $params already contains a itemSource if we come from |
|
|
|
|
// getAllShare() or we need to translate the shareID to a itemSource |
|
|
|
|
if(isset($params['itemSource'])) { |
|
|
|
|
$itemSource = $params['itemSource']; |
|
|
|
|
$itemType = $params['itemType']; |
|
|
|
|
$getSpecificShare = true; |
|
|
|
|
} else { |
|
|
|
|
$s = self::getShareFromId($params['id']); |
|
|
|
|
$itemSource = $s['item_source']; |
|
|
|
|
$itemType = $s['item_type']; |
|
|
|
|
$getSpecificShare = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$s = self::getShareFromId($params['id']); |
|
|
|
|
$params['itemSource'] = $s['item_source']; |
|
|
|
|
$params['itemType'] = $s['item_type']; |
|
|
|
|
$params['specificShare'] = true; |
|
|
|
|
|
|
|
|
|
return self::collectShares($params); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @brief collect all share information, either of a specific share or all |
|
|
|
|
* shares for a given path |
|
|
|
|
* @param array $params |
|
|
|
|
* @return \OC_OCS_Result |
|
|
|
|
*/ |
|
|
|
|
private static function collectShares($params) { |
|
|
|
|
|
|
|
|
|
$itemSource = $params['itemSource']; |
|
|
|
|
$itemType = $params['itemType']; |
|
|
|
|
$getSpecificShare = isset($params['specificShare']) ? $params['specificShare'] : false; |
|
|
|
|
|
|
|
|
|
if ($itemSource !== null) { |
|
|
|
|
$shares = \OCP\Share::getItemShared($itemType, $itemSource); |
|
|
|
|
$reshare = \OCP\Share::getItemSharedWithBySource($itemType, $itemSource); |
|
|
|
|
$receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $itemSource); |
|
|
|
|
// if a specific share was specified only return this one |
|
|
|
|
if ($getSpecificShare === false) { |
|
|
|
|
if ($getSpecificShare === true) { |
|
|
|
|
foreach ($shares as $share) { |
|
|
|
|
if ($share['id'] === (int)$params['id']) { |
|
|
|
|
if ($share['id'] === (int) $params['id']) { |
|
|
|
|
$shares = array('element' => $share); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if ($reshare) { |
|
|
|
|
$shares['received_from'] = $reshare['uid_owner']; |
|
|
|
|
$shares['received_from_displayname'] = \OCP\User::getDisplayName($reshare['uid_owner']); |
|
|
|
|
|
|
|
|
|
// 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) { |
|
|
|
|
$shares = self::addReshares($shares, $itemSource); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($receivedFrom) { |
|
|
|
|
$shares['received_from'] = $receivedFrom['uid_owner']; |
|
|
|
|
$shares['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$shares = null; |
|
|
|
@ -99,6 +121,46 @@ class Api { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @brief add reshares to a array of shares |
|
|
|
|
* @param array $shares array of shares |
|
|
|
|
* @param int $itemSource item source ID |
|
|
|
|
* @return array new shares array which includes reshares |
|
|
|
|
*/ |
|
|
|
|
private static function addReshares($shares, $itemSource) { |
|
|
|
|
|
|
|
|
|
// if there are no shares than there are also no reshares |
|
|
|
|
if (count($shares) > 0) { |
|
|
|
|
$ids = array(); |
|
|
|
|
$firstShare = reset($shares); |
|
|
|
|
$path = $firstShare['path']; |
|
|
|
|
foreach ($shares as $share) { |
|
|
|
|
$ids[] = $share['id']; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return $shares; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path` , `permissions`, `stime`, `expiration`, `token`, `storage`, `mail_send`, `mail_send`'; |
|
|
|
|
$getReshares = \OC_DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `*PREFIX*share`.`file_source` = ? AND `*PREFIX*share`.`item_type` IN (\'file\', \'folder\')'); |
|
|
|
|
$reshares = $getReshares->execute(array($itemSource))->fetchAll(); |
|
|
|
|
|
|
|
|
|
foreach ($reshares as $key => $reshare) { |
|
|
|
|
// remove reshares we already have in the shares array. |
|
|
|
|
if (in_array($reshare['id'], $ids)) { |
|
|
|
|
unset($reshares[$key]); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (isset($reshare['share_with']) && $reshare['share_with'] !== '') { |
|
|
|
|
$reshares[$key]['share_with_displayname'] = \OCP\User::getDisplayName($reshare['share_with']); |
|
|
|
|
} |
|
|
|
|
// add correct path to the result |
|
|
|
|
$reshares[$key]['path'] = $path; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return array_merge($shares, $reshares); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @brief get share from all files in a given folder (non-recursive) |
|
|
|
|
* @param array $params contains 'path' to the folder |
|
|
|
@ -119,10 +181,10 @@ class Api { |
|
|
|
|
// 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']); |
|
|
|
|
$receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $file['fileid']); |
|
|
|
|
if ($receivedFrom) { |
|
|
|
|
$share['received_from'] = $receivedFrom['uid_owner']; |
|
|
|
|
$share['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']); |
|
|
|
|
} |
|
|
|
|
if ($share) { |
|
|
|
|
$share['filename'] = $file['name']; |
|
|
|
|