]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix unsharing from self for group shares and add test for it
authorMichael Gapczynski <mtgap@owncloud.com>
Sun, 9 Sep 2012 00:15:35 +0000 (20:15 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Sun, 9 Sep 2012 00:15:47 +0000 (20:15 -0400)
lib/public/share.php
tests/lib/share/share.php

index cf61681424fdf00c105ef781b6ebff918a3ca7e5..a3cfe4f6ddb56153b2ba3bdc35c0352472dd5307 100644 (file)
@@ -337,10 +337,21 @@ class Share {
        public static function unshareFromSelf($itemType, $itemTarget) {
                if ($item = self::getItemSharedWith($itemType, $itemTarget)) {
                        if ((int)$item['share_type'] === self::SHARE_TYPE_GROUP) {
-                               // TODO
+                               // 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` (`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
+                               self::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']));
+                               self::delete($item['id'], true);
+                       } else {
+                               self::delete($item['id']);
                        }
-                       // Delete
-                       return self::delete($item['id']);
+                       return true;
                }
                return false;
        }
@@ -629,6 +640,9 @@ class Share {
                                $row['share_with'] = $items[$row['parent']]['share_with'];
                                // Remove the parent group share
                                unset($items[$row['parent']]);
+                               if ($row['permissions'] == 0) {
+                                       continue;
+                               }
                        } else if (!isset($uidOwner)) {
                                // Check if the same target already exists
                                if (isset($targets[$row[$column]])) {
index b45779038baee5ea939bab42e3e596ed78687fda..b2fecdc8bf7a57b8da964dd355fe4d8c6f2c663b 100644 (file)
@@ -249,6 +249,7 @@ class Test_Share extends UnitTestCase {
                $this->assertTrue(in_array('test1.txt', $to_test));
 
                // Remove user
+               OC_User::setUserId($this->user1);
                OC_User::deleteUser($this->user1);
                OC_User::setUserId($this->user2);
                $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt'));
@@ -383,8 +384,15 @@ class Test_Share extends UnitTestCase {
                OC_Group::addToGroup($this->user4, $this->group1);
                $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
                
+               // Unshare from self
+               $this->assertTrue(OCP\Share::unshareFromSelf('test', 'test.txt'));
+               $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array());
+               OC_User::setUserId($this->user2);
+               $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
+               
                // Remove group
                OC_Group::deleteGroup($this->group1);
+               OC_User::setUserId($this->user4);
                $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array());
                OC_User::setUserId($this->user3);
                $this->assertEqual(OCP\Share::getItemsShared('test'), array());