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-06-04 20:41:47 +0400
committerRobin Appelman <icewind@owncloud.com>2014-06-06 11:56:02 +0400
commit86d7371d0c797d5c97198eebf9152ad748961927 (patch)
tree5145d744eec40d85dbff8b101ec204a772c92855 /lib/private/share
parent09970e1816644661d4ad1984793232c880aac1ac (diff)
fix unshareFromSelf()
Diffstat (limited to 'lib/private/share')
-rw-r--r--lib/private/share/share.php61
1 files changed, 38 insertions, 23 deletions
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 10b3cc34467..646405a37b5 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -717,33 +717,48 @@ class Share extends \OC\Share\Constants {
* Unsharing from self is not allowed for items inside collections
*/
public static function unshareFromSelf($itemType, $itemTarget) {
- $item = self::getItemSharedWith($itemType, $itemTarget);
- if (!empty($item)) {
- if ((int)$item['share_type'] === self::SHARE_TYPE_GROUP) {
- // Insert an extra row for the group share and set permission
- // to 0 to prevent it from showing up for the user
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share`'
+
+ if ($itemType === 'file' || $itemType === 'folder') {
+ $statement = 'SELECT * FROM `*PREFIX*share` WHERE `item_type` = ? and `file_target` = ?';
+ } else {
+ $statement = 'SELECT * FROM `*PREFIX*share` WHERE `item_type` = ? and `item_target` = ?';
+ }
+
+ $query = \OCP\DB::prepare($statement);
+ $result = $query->execute(array($itemType, $itemTarget));
+
+ $shares = $result->fetchAll();
+
+ $itemUnshared = false;
+ foreach ($shares as $share) {
+ if ((int)$share['share_type'] === \OCP\Share::SHARE_TYPE_USER) {
+ Helper::delete($share['id']);
+ $itemUnshared = true;
+ break;
+ } elseif ((int)$share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) {
+ $groupShare = $share;
+ } elseif ((int)$share['share_type'] === self::$shareTypeGroupUserUnique) {
+ $uniqueGroupShare = $share;
+ }
+ }
+
+ if (!$itemUnshared && isset($groupShare)) {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share`'
.' (`item_type`, `item_source`, `item_target`, `parent`, `share_type`,'
.' `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`)'
.' VALUES (?,?,?,?,?,?,?,?,?,?,?)');
- $query->execute(array($item['item_type'], $item['item_source'], $item['item_target'],
- $item['id'], self::$shareTypeGroupUserUnique,
- \OC_User::getUser(), $item['uid_owner'], 0, $item['stime'], $item['file_source'],
- $item['file_target']));
- \OC_DB::insertid('*PREFIX*share');
- // Delete all reshares by this user of the group share
- Helper::delete($item['id'], true, \OC_User::getUser());
- } else if ((int)$item['share_type'] === self::$shareTypeGroupUserUnique) {
- // Set permission to 0 to prevent it from showing up for the user
- $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `permissions` = ? WHERE `id` = ?');
- $query->execute(array(0, $item['id']));
- Helper::delete($item['id'], true);
- } else {
- Helper::delete($item['id']);
- }
- return true;
+ $query->execute(array($groupShare['item_type'], $groupShare['item_source'], $groupShare['item_target'],
+ $groupShare['id'], self::$shareTypeGroupUserUnique,
+ \OC_User::getUser(), $groupShare['uid_owner'], 0, $groupShare['stime'], $groupShare['file_source'],
+ $groupShare['file_target']));
+ $itemUnshared = true;
+ } elseif (!$itemUnshared && isset($uniqueGroupShare)) {
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `permissions` = ? WHERE `id` = ?');
+ $query->execute(array(0, $uniqueGroupShare['id']));
+ $itemUnshared = true;
}
- return false;
+
+ return $itemUnshared;
}
/**