From 332ea778651386671e7b096769c42a00b69cc32d Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 5 Feb 2015 14:00:05 +0100 Subject: [PATCH] only create a db entry for the user in case of a name conflict on group share --- lib/private/share/share.php | 9 +++++++-- tests/lib/share/share.php | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/private/share/share.php b/lib/private/share/share.php index e624e8da451..729dbe79d38 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -1905,7 +1905,11 @@ class Share extends \OC\Share\Constants { $isGroupShare = false; if ($shareType == self::SHARE_TYPE_GROUP) { $isGroupShare = true; - $users = \OC_Group::usersInGroup($shareWith['group']); + if (isset($shareWith['users'])) { + $users = $shareWith['users']; + } else { + $users = \OC_Group::usersInGroup($shareWith['group']); + } // remove current user from list if (in_array(\OCP\User::getUser(), $users)) { unset($users[array_search(\OCP\User::getUser(), $users)]); @@ -2016,7 +2020,8 @@ class Share extends \OC\Share\Constants { $fileTarget = null; } - if ($itemTarget === $groupItemTarget && (isset($fileSource) && $fileTarget === $groupItemTarget)) { + if (($itemTarget === $groupItemTarget) && + (!isset($fileSource) || $fileTarget === $groupFileTarget)) { continue; } } diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index 523f7b379a0..124ad450e2e 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -545,6 +545,13 @@ class Test_Share extends \Test\TestCase { // Valid share $this->shareUserOneTestFileWithGroupOne(); + // check if only the group share was created and not a single db-entry for each user + $statement = \OCP\DB::prepare('select `id` from `*PREFIX*share`'); + $query = $statement->execute(); + $result = $query->fetchAll(); + $this->assertSame(1, count($result)); + + // Attempt to share again OC_User::setUserId($this->user1); $message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1;