Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-09-26 18:58:47 +0400
committerBjoern Schiessle <schiessle@owncloud.com>2014-10-01 17:13:48 +0400
commit1371fecf266765e958dbf07a4dd476c629b32b36 (patch)
tree6910f0cced05f9a3158ba5e5358c7c0bafa9ead5 /lib/private/share
parent1e5c786392c9f5098a328ee0294ec3dd526308ed (diff)
on unshare only unshare childrens if there is no other parent available
Diffstat (limited to 'lib/private/share')
-rw-r--r--lib/private/share/helper.php24
-rw-r--r--lib/private/share/share.php54
2 files changed, 63 insertions, 15 deletions
diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php
index 7e1cbb273b8..90dd12e9842 100644
--- a/lib/private/share/helper.php
+++ b/lib/private/share/helper.php
@@ -85,10 +85,12 @@ class Helper extends \OC\Share\Constants {
* @param int $parent Id of item to delete
* @param bool $excludeParent If true, exclude the parent from the delete (optional)
* @param string $uidOwner The user that the parent was shared with (optional)
+ * @param int $newParent new parent for the childrens
*/
- public static function delete($parent, $excludeParent = false, $uidOwner = null) {
+ public static function delete($parent, $excludeParent = false, $uidOwner = null, $newParent = null) {
$ids = array($parent);
$deletedItems = array();
+ $changeParent = array();
$parents = array($parent);
while (!empty($parents)) {
$parents = "'".implode("','", $parents)."'";
@@ -106,8 +108,6 @@ class Helper extends \OC\Share\Constants {
// Reset parents array, only go through loop again if items are found
$parents = array();
while ($item = $result->fetchRow()) {
- $ids[] = $item['id'];
- $parents[] = $item['id'];
$tmpItem = array(
'id' => $item['id'],
'shareWith' => $item['share_with'],
@@ -118,12 +118,28 @@ class Helper extends \OC\Share\Constants {
if (isset($item['file_target'])) {
$tmpItem['fileTarget'] = $item['file_target'];
}
- $deletedItems[] = $tmpItem;
+ // if we have a new parent for the child we remember the child
+ // to update the parent, if not we add it to the list of items
+ // which should be deleted
+ if ($newParent !== null) {
+ $changeParent[] = $item['id'];
+ } else {
+ $deletedItems[] = $tmpItem;
+ $ids[] = $item['id'];
+ $parents[] = $item['id'];
+ }
}
}
if ($excludeParent) {
unset($ids[0]);
}
+
+ if (!empty($changeParent)) {
+ $idList = "'".implode("','", $changeParent)."'";
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `parent` = ? WHERE `id` IN ('.$idList.')');
+ $query->execute(array($newParent));
+ }
+
if (!empty($ids)) {
$idList = "'".implode("','", $ids)."'";
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` IN ('.$idList.')');
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index bb0217c0a4c..d6b1a2c6eef 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -294,23 +294,32 @@ class Share extends \OC\Share\Constants {
$shares = array();
+ $column = ($itemType === 'file' || $itemType === 'folder') ? 'file_source' : 'item_source';
+
+ $where = ' `' . $column . '` = ? AND `item_type` = ? ';
+ $arguments = array($itemSource, $itemType);
+ // for link shares $user === null
+ if ($user !== null) {
+ $where .= ' AND `share_with` = ? ';
+ $arguments[] = $user;
+ }
+
// first check if there is a db entry for the specific user
$query = \OC_DB::prepare(
- 'SELECT `file_target`, `item_target`, `permissions`, `expiration`
+ 'SELECT *
FROM
`*PREFIX*share`
- WHERE
- `item_source` = ? AND `item_type` = ? AND `share_with` = ?'
+ WHERE' . $where
);
- $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, $user));
+ $result = \OC_DB::executeAudited($query, $arguments);
while ($row = $result->fetchRow()) {
$shares[] = $row;
}
//if didn't found a result than let's look for a group share.
- if(empty($shares)) {
+ if(empty($shares) && $user !== null) {
$groups = \OC_Group::getUserGroups($user);
$query = \OC_DB::prepare(
@@ -318,7 +327,7 @@ class Share extends \OC\Share\Constants {
FROM
`*PREFIX*share`
WHERE
- `item_source` = ? AND `item_type` = ? AND `share_with` in (?)'
+ `' . $column . '` = ? AND `item_type` = ? AND `share_with` in (?)'
);
$result = \OC_DB::executeAudited($query, array($itemSource, $itemType, implode(',', $groups)));
@@ -678,9 +687,31 @@ class Share extends \OC\Share\Constants {
* @return boolean true on success or false on failure
*/
public static function unshare($itemType, $itemSource, $shareType, $shareWith) {
- $item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(),self::FORMAT_NONE, null, 1);
- if (!empty($item)) {
- self::unshareItem($item);
+
+ // check if it is a valid itemType
+ self::getBackend($itemType);
+
+ $items = self::getItemSharedWithUser($itemType, $itemSource, $shareWith);
+
+ $toDelete = array();
+ $newParent = null;
+ $currentUser = \OC_User::getUser();
+ foreach ($items as $item) {
+ // delete the item with the expected share_type and owner
+ if ((int)$item['share_type'] === (int)$shareType && $item['uid_owner'] === $currentUser) {
+ $toDelete = $item;
+ // if there is more then one result we don't have to delete the children
+ // but update their parent. For group shares the new parent should always be
+ // the original group share and not the db entry with the unique name
+ } else if ((int)$item['share_type'] === \OCP\Share::$shareTypeGroupUserUnique) {
+ $newParent = $item['parent'];
+ } else {
+ $newParent = $item['id'];
+ }
+ }
+
+ if (!empty($toDelete)) {
+ self::unshareItem($toDelete, $newParent);
return true;
}
return false;
@@ -1052,9 +1083,10 @@ class Share extends \OC\Share\Constants {
/**
* Unshares a share given a share data array
* @param array $item Share data (usually database row)
+ * @param int new parent ID
* @return null
*/
- protected static function unshareItem(array $item) {
+ protected static function unshareItem(array $item, $newParent = null) {
// Pass all the vars we have for now, they may be useful
$hookParams = array(
'id' => $item['id'],
@@ -1071,7 +1103,7 @@ class Share extends \OC\Share\Constants {
}
\OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams);
- $deletedShares = Helper::delete($item['id']);
+ $deletedShares = Helper::delete($item['id'], false, null, $newParent);
$deletedShares[] = $hookParams;
$hookParams['deletedShares'] = $deletedShares;
\OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams);