proper fix for getting the shared item if no user is logged in

This commit is contained in:
Thomas Müller 2013-07-05 13:45:21 +02:00
parent d1d6885585
commit 352c1415be
2 changed files with 17 additions and 5 deletions

View File

@ -26,15 +26,18 @@ if (empty($_POST['dirToken'])) {
if (!($linkItem['permissions'] & OCP\PERMISSION_CREATE)) { if (!($linkItem['permissions'] & OCP\PERMISSION_CREATE)) {
OCP\JSON::checkLoggedIn(); OCP\JSON::checkLoggedIn();
} else { } else {
// Setup FS with owner
OC_Util::tearDownFS();
OC_Util::setupFS($linkItem['uid_owner']);
// translate linkItem to the real folder name on the file system // translate linkItem to the real folder name on the file system
$sharedItem = OCP\Share::getItemShared($linkItem['item_type'], $linkItem['item_source']); $sharedItem = OCP\Share::getSharedItem($linkItem['item_type'], $linkItem['item_source'], $linkItem['uid_owner']);
if (!$sharedItem || empty($sharedItem) || $sharedItem === false) { if (!$sharedItem || empty($sharedItem) || $sharedItem === false) {
OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.')))));
die(); die();
} }
// The token defines the target directory (security reasons) // The token defines the target directory (security reasons)
$sharedItem = array_pop($sharedItem);
$dir = sprintf( $dir = sprintf(
"/%s/%s", "/%s/%s",
$sharedItem['path'], $sharedItem['path'],
@ -45,8 +48,6 @@ if (empty($_POST['dirToken'])) {
OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.')))));
die(); die();
} }
// Setup FS with owner
OC_Util::setupFS($linkItem['uid_owner']);
} }
} }

View File

@ -312,11 +312,22 @@ class Share {
* @return Return depends on format * @return Return depends on format
*/ */
public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE, public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE,
$parameters = null, $includeCollections = false) { $parameters = null, $includeCollections = false) {
return self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), $format, return self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), $format,
$parameters, -1, $includeCollections); $parameters, -1, $includeCollections);
} }
/**
* @param $itemType
* @param $itemSource
* @param $uid_owner
* @return mixed
*/
public static function getSharedItem($itemType, $itemSource, $uid_owner) {
return self::getItems($itemType, $itemSource, null, null, $uid_owner, self::FORMAT_NONE,
null, 1, false);
}
/** /**
* Get all users an item is shared with * Get all users an item is shared with
* @param string Item type * @param string Item type