From c69a709f219a960c1004bd500145feed03b7d467 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 27 Jul 2020 12:12:11 +0200 Subject: [PATCH 1/2] Correctly remove usergroup shares on removing group members Signed-off-by: Joas Schilling --- lib/base.php | 7 ++- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Share20/Hooks.php | 2 +- lib/private/Share20/UserRemovedListener.php | 47 +++++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 lib/private/Share20/UserRemovedListener.php diff --git a/lib/base.php b/lib/base.php index b1f9569926..36f85836b2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -61,6 +61,7 @@ * */ +use OCP\Group\Events\UserRemovedEvent; use OCP\ILogger; use OCP\Share; use OC\Encryption\HookManager; @@ -900,8 +901,12 @@ class OC { public static function registerShareHooks() { if (\OC::$server->getSystemConfig()->getValue('installed')) { OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); - OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroup'); + OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroupLDAP'); OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); + + /** @var \OCP\EventDispatcher\IEventDispatcher $dispatcher */ + $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); + $dispatcher->addServiceListener(UserRemovedEvent::class, \OC\Share20\UserRemovedListener::class); } } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 9562d88bcc..62b137523c 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1255,6 +1255,7 @@ return array( 'OC\\Share20\\ProviderFactory' => $baseDir . '/lib/private/Share20/ProviderFactory.php', 'OC\\Share20\\Share' => $baseDir . '/lib/private/Share20/Share.php', 'OC\\Share20\\ShareHelper' => $baseDir . '/lib/private/Share20/ShareHelper.php', + 'OC\\Share20\\UserRemovedListener' => $baseDir . '/lib/private/Share20/UserRemovedListener.php', 'OC\\Share\\Constants' => $baseDir . '/lib/private/Share/Constants.php', 'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => $baseDir . '/lib/private/Share/SearchResultSorter.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 2a2f9fd77f..285a834e5c 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1284,6 +1284,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Share20\\ProviderFactory' => __DIR__ . '/../../..' . '/lib/private/Share20/ProviderFactory.php', 'OC\\Share20\\Share' => __DIR__ . '/../../..' . '/lib/private/Share20/Share.php', 'OC\\Share20\\ShareHelper' => __DIR__ . '/../../..' . '/lib/private/Share20/ShareHelper.php', + 'OC\\Share20\\UserRemovedListener' => __DIR__ . '/../../..' . '/lib/private/Share20/UserRemovedListener.php', 'OC\\Share\\Constants' => __DIR__ . '/../../..' . '/lib/private/Share/Constants.php', 'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => __DIR__ . '/../../..' . '/lib/private/Share/SearchResultSorter.php', diff --git a/lib/private/Share20/Hooks.php b/lib/private/Share20/Hooks.php index 711306db6f..0e41e20a2c 100644 --- a/lib/private/Share20/Hooks.php +++ b/lib/private/Share20/Hooks.php @@ -31,7 +31,7 @@ class Hooks { \OC::$server->getShareManager()->groupDeleted($arguments['gid']); } - public static function post_removeFromGroup($arguments) { + public static function post_removeFromGroupLDAP($arguments) { \OC::$server->getShareManager()->userDeletedFromGroup($arguments['uid'], $arguments['gid']); } } diff --git a/lib/private/Share20/UserRemovedListener.php b/lib/private/Share20/UserRemovedListener.php new file mode 100644 index 0000000000..06ac52c05d --- /dev/null +++ b/lib/private/Share20/UserRemovedListener.php @@ -0,0 +1,47 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +namespace OC\Share20; + +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Group\Events\UserRemovedEvent; +use OCP\Share\IManager; + +class UserRemovedListener implements IEventListener { + + /** @var IManager */ + protected $shareManager; + + public function __construct(IManager $shareManager) { + $this->shareManager = $shareManager; + } + + public function handle(Event $event): void { + if (!$event instanceof UserRemovedEvent) { + return; + } + + $this->shareManager->userDeletedFromGroup($event->getUser()->getUID(), $event->getGroup()->getGID()); + } +} From 29d41ba06127d378dc98c682d7471c7d09b70c3a Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 30 Jul 2020 10:03:59 +0200 Subject: [PATCH 2/2] Use old IServerContainer methods Signed-off-by: Morris Jobke --- lib/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index 36f85836b2..e549881d89 100644 --- a/lib/base.php +++ b/lib/base.php @@ -905,7 +905,7 @@ class OC { OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); /** @var \OCP\EventDispatcher\IEventDispatcher $dispatcher */ - $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); + $dispatcher = \OC::$server->query(\OCP\EventDispatcher\IEventDispatcher::class); $dispatcher->addServiceListener(UserRemovedEvent::class, \OC\Share20\UserRemovedListener::class); } }