diff --git a/lib/base.php b/lib/base.php index a76edb1192..990d45f721 100644 --- a/lib/base.php +++ b/lib/base.php @@ -778,8 +778,6 @@ class OC { public static function registerShareHooks() { if (\OC::$server->getSystemConfig()->getValue('installed')) { OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); - OC_Hook::connect('OC_User', 'post_addToGroup', 'OC\Share\Hooks', 'post_addToGroup'); - OC_Hook::connect('OC_Group', 'pre_addToGroup', 'OC\Share\Hooks', 'pre_addToGroup'); OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share\Hooks', 'post_removeFromGroup'); OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share\Hooks', 'post_deleteGroup'); } diff --git a/lib/private/share/hooks.php b/lib/private/share/hooks.php index dae273eefb..999efc7ca7 100644 --- a/lib/private/share/hooks.php +++ b/lib/private/share/hooks.php @@ -25,124 +25,6 @@ namespace OC\Share; class Hooks extends \OC\Share\Constants { - - /** - * remember which targets need to be updated in the post addToGroup Hook - * @var array - */ - private static $updateTargets = array(); - - /** - * Function that is called before a user is added to a group. - * check if we need to create a unique target for the user - * @param array $arguments - */ - public static function pre_addToGroup($arguments) { - $currentUser = \OC::$server->getUserSession()->getUser(); - $currentUserID = is_null($currentUser) ? '' : $currentUser->getUID(); - - // setup filesystem for added user if it isn't the current user - if($currentUserID !== $arguments['uid']) { - \OC_Util::tearDownFS(); - \OC_Util::setupFS($arguments['uid']); - } - - /** @var \OC\DB\Connection $db */ - $db = \OC::$server->getDatabaseConnection(); - - $insert = $db->createQueryBuilder(); - - $select = $db->createQueryBuilder(); - // Find the group shares and check if the user needs a unique target - $select->select('*') - ->from('`*PREFIX*share`') - ->where($select->expr()->andX( - $select->expr()->eq('`share_type`', ':shareType'), - $select->expr()->eq('`share_with`', ':shareWith') - )) - ->setParameter('shareType', self::SHARE_TYPE_GROUP) - ->setParameter('shareWith', $arguments['gid']); - - $result = $select->execute(); - - while ($item = $result->fetch()) { - - $itemTarget = Helper::generateTarget( - $item['item_type'], - $item['item_source'], - self::SHARE_TYPE_USER, - $arguments['uid'], - $item['uid_owner'], - null, - $item['parent'] - ); - - if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') { - $fileTarget = Helper::generateTarget( - $item['item_type'], - $item['file_target'], - self::SHARE_TYPE_USER, - $arguments['uid'], - $item['uid_owner'], - null, - $item['parent'] - ); - } else { - $fileTarget = null; - } - - - // Insert an extra row for the group share if the item or file target is unique for this user - if ( - ($fileTarget === null && $itemTarget != $item['item_target']) - || ($fileTarget !== null && $fileTarget !== $item['file_target']) - ) { - self::$updateTargets[$arguments['gid']][] = [ - '`item_type`' => $insert->expr()->literal($item['item_type']), - '`item_source`' => $insert->expr()->literal($item['item_source']), - '`item_target`' => $insert->expr()->literal($itemTarget), - '`file_target`' => $insert->expr()->literal($fileTarget), - '`parent`' => $insert->expr()->literal($item['id']), - '`share_type`' => $insert->expr()->literal(self::$shareTypeGroupUserUnique), - '`share_with`' => $insert->expr()->literal($arguments['uid']), - '`uid_owner`' => $insert->expr()->literal($item['uid_owner']), - '`permissions`' => $insert->expr()->literal($item['permissions']), - '`stime`' => $insert->expr()->literal($item['stime']), - '`file_source`' => $insert->expr()->literal($item['file_source']), - ]; - } - } - - // re-setup old filesystem state - if($currentUserID !== $arguments['uid']) { - \OC_Util::tearDownFS(); - if($currentUserID !== '') { - \OC_Util::setupFS($currentUserID); - } - } - } - - /** - * Function that is called after a user is added to a group. - * add unique target for the user if needed - * @param array $arguments - */ - public static function post_addToGroup($arguments) { - /** @var \OC\DB\Connection $db */ - $db = \OC::$server->getDatabaseConnection(); - - $insert = $db->createQueryBuilder(); - $insert->insert('`*PREFIX*share`'); - - if (isset(self::$updateTargets[$arguments['gid']])) { - foreach (self::$updateTargets[$arguments['gid']] as $newTarget) { - $insert->values($newTarget); - $insert->execute(); - } - unset(self::$updateTargets[$arguments['gid']]); - } - } - /** * Function that is called after a user is removed from a group. Shares are cleaned up. * @param array $arguments diff --git a/tests/lib/share/hooktests.php b/tests/lib/share/hooktests.php deleted file mode 100644 index 7e6aaa259f..0000000000 --- a/tests/lib/share/hooktests.php +++ /dev/null @@ -1,115 +0,0 @@ - - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - - -namespace OC\Tests\Share; - - -use Test\TestCase; - -/** - * Class HookTests - * - * @group DB - * - * @package OC\Tests\Share - */ -class HookTests extends TestCase { - - protected function setUp() { - parent::setUp(); - } - - protected function tearDown() { - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `item_type` = ?'); - $query->execute(array('test')); - - parent::tearDown(); - } - - public function testPostAddToGroup() { - - /** @var \OC\DB\Connection $connection */ - $connection = \OC::$server->getDatabaseConnection(); - $query = $connection->createQueryBuilder(); - $expr = $query->expr(); - - // add some dummy values to the private $updateTargets variable - $this->invokePrivate( - new \OC\Share\Hooks(), - 'updateTargets', - [ - [ - 'group1' => - [ - [ - '`item_type`' => $expr->literal('test'), - '`item_source`' => $expr->literal('42'), - '`item_target`' => $expr->literal('42'), - '`file_target`' => $expr->literal('test'), - '`share_type`' => $expr->literal('2'), - '`share_with`' => $expr->literal('group1'), - '`uid_owner`' => $expr->literal('owner'), - '`permissions`' => $expr->literal('0'), - '`stime`' => $expr->literal('676584'), - '`file_source`' => $expr->literal('42'), - ], - [ - '`item_type`' => $expr->literal('test'), - '`item_source`' => $expr->literal('42'), - '`item_target`' => $expr->literal('42 (2)'), - '`share_type`' => $expr->literal('2'), - '`share_with`' => $expr->literal('group1'), - '`uid_owner`' => $expr->literal('owner'), - '`permissions`' => $expr->literal('0'), - '`stime`' => $expr->literal('676584'), - ] - ], - 'group2' => - [ - [ - '`item_type`' => $expr->literal('test'), - '`item_source`' => $expr->literal('42'), - '`item_target`' => $expr->literal('42'), - '`share_type`' => $expr->literal('2'), - '`share_with`' => $expr->literal('group2'), - '`uid_owner`' => $expr->literal('owner'), - '`permissions`' => $expr->literal('0'), - '`stime`' => $expr->literal('676584'), - ] - ] - ] - ] - ); - - // add unique targets for group1 to database - \OC\Share\Hooks::post_addToGroup(['gid' => 'group1']); - - - $query->select('`share_with`')->from('`*PREFIX*share`'); - $result = $query->execute()->fetchAll(); - $this->assertSame(2, count($result)); - foreach ($result as $r) { - $this->assertSame('group1', $r['share_with']); - } - } - -}