summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-06-24 16:42:51 -0400
committerBart Visscher <bartv@thisnet.nl>2012-06-27 01:05:36 +0200
commit819811461535cceb8208651f6a131cbb97efd169 (patch)
tree4e0399b9d8b4813a34fe264de3c3835bf87ebe0e
parent5f1aa1b92e7b8e18e38718b8da6c79eda0840ac1 (diff)
downloadnextcloud-server-819811461535cceb8208651f6a131cbb97efd169.tar.gz
nextcloud-server-819811461535cceb8208651f6a131cbb97efd169.zip
Some more changes to getItems() and fixes in shared storage
-rw-r--r--apps/files_sharing/sharedstorage.php15
-rw-r--r--lib/public/share.php32
2 files changed, 33 insertions, 14 deletions
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index 21aa2f23b94..11a5d39f011 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -38,16 +38,23 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
return $this->sourcePaths[$target];
} else {
if (dirname($target) != $this->sharedFolder) {
- $pos = strlen($this->sharedFolder);
+ $len = strlen($this->sharedFolder);
+ $pos = strpos($target, '/', $len);
// Get shared folder name
- $itemTarget = substr($target, $pos, strpos($target, '/', $pos));
+ $itemTarget = substr($target, $len, $pos);
+ $insideFolder = true;
} else {
$itemTarget = $target;
+ $insideFolder = false;
}
$sourcePath = OCP\Share::getItemSharedWith('file', $itemTarget, OC_Share_Backend_File::FORMAT_SOURCE_PATH);
if ($sourcePath) {
- $this->sourcePaths[$target] = $sourcePath;
- return $sourcePath;
+ if ($insideFolder) {
+ $this->sourcePaths[$target] = $sourcePath.substr($target, $pos);
+ } else {
+ $this->sourcePaths[$target] = $sourcePath;
+ }
+ return $this->sourcePaths[$target];
}
return false;
}
diff --git a/lib/public/share.php b/lib/public/share.php
index ec371ebf982..f4a11a170ac 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -375,11 +375,11 @@ class Share {
// Check if there are any parent types that include this type of items, e.g. a music album contains songs
if (isset($itemType)) {
if ($parents = self::getParentItemTypes($itemType)) {
- $where = "WHERE item_type IN ('".$itemType."'";
- foreach ($parents as $parent) {
- $where .= ", '.$parent.'";
- }
- $where .= ')';
+ $where = "WHERE item_type IN ('".$itemType."'";
+ foreach ($parents as $parent) {
+ $where .= ", '.$parent.'";
+ }
+ $where .= ')';
} else {
$where = "WHERE item_type = '".$itemType."'";
}
@@ -401,6 +401,10 @@ class Share {
}
if (isset($uidOwner)) {
$where .= " AND uid_owner = '".$uidOwner."'";
+ if (!isset($shareType)) {
+ // Prevent unique user targets for group shares from being selected
+ $where .= " AND share_type != '".self::$shareTypeGroupUserUnique."'";
+ }
}
if (isset($item)) {
// If looking for own shared items, check item_source else check item_target
@@ -423,25 +427,33 @@ class Share {
}
}
if ($limit != -1) {
+ if ($limit == 1 && $shareType == self::$shareTypeUserAndGroups) {
+ // Make sure the unique user target is returned if it exists, unique targets should follow the group share in the database
+ // If the limit is not 1, the filtering can be done later
+ $where .= ' ORDER BY id DESC';
+ }
$where .= ' LIMIT '.$limit;
}
$query = \OC_DB::prepare('SELECT * FROM *PREFIX*sharing '.$where);
$result = $query->execute();
$items = array();
while ($item = $result->fetchRow()) {
- // TODO Filter out duplicate group shares for users with unique targets
+ // Filter out duplicate group shares for users with unique targets
if ($item['share_type'] == self::$shareTypeGroupUserUnique) {
- // Group shares should already be in items array
-
+ // Group shares should already be in the items array
+ unset($items[$item['parent']]);
}
// TODO Add in parent item types children?
if ($parents && in_array($item['item_type'], $parents)) {
$children[] = $item;
}
-// $items[] = array($item['item_source'] => $item['id'];
- $items[$item['item']][$item['id']] = array('item_target' => $item['item_target'], 'permissions' => $item['permissions'], 'stime' => $item['stime']);
+ $items[$item['id']] = $item;
}
if ($format == self::FORMAT_NONE) {
+ if ($limit == 1) {
+ // Return just the item instead of 2-dimensional array
+ return $items[key($items)];
+ }
return $items;
} else {
return $backend->formatItems($items, $format);