From 51fa743c7a4a28fe4323a4a4f608e4ea2534cc09 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 10 Sep 2020 15:07:34 +0200 Subject: [PATCH] makes LDAP's group updater dispatch type events * fixes group share updates on added users Signed-off-by: Arthur Schiwon --- apps/user_ldap/lib/Jobs/UpdateGroups.php | 16 ++++++++++++++-- lib/base.php | 1 - lib/private/Share20/Hooks.php | 4 ---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/user_ldap/lib/Jobs/UpdateGroups.php b/apps/user_ldap/lib/Jobs/UpdateGroups.php index 6241483cb9..334b63f836 100644 --- a/apps/user_ldap/lib/Jobs/UpdateGroups.php +++ b/apps/user_ldap/lib/Jobs/UpdateGroups.php @@ -43,6 +43,9 @@ use OCA\User_LDAP\LogWrapper; use OCA\User_LDAP\Mapping\GroupMapping; use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\Manager; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Group\Events\UserAddedEvent; +use OCP\Group\Events\UserRemovedEvent; use OCP\ILogger; class UpdateGroups extends \OC\BackgroundJob\TimedJob { @@ -93,6 +96,11 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob { * @param string[] $groups */ private static function handleKnownGroups($groups) { + /** @var IEventDispatcher $dispatcher */ + $dispatcher = \OC::$server->query(IEventDispatcher::class); + $groupManager = \OC::$server->getGroupManager(); + $userManager = \OC::$server->getUserManager(); + \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', ILogger::DEBUG); $query = \OC_DB::prepare(' UPDATE `*PREFIX*ldap_group_members` @@ -104,15 +112,19 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob { $knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']); $actualUsers = self::getGroupBE()->usersInGroup($group); $hasChanged = false; + + $groupObject = $groupManager->get($group); foreach (array_diff($knownUsers, $actualUsers) as $removedUser) { - \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', ['uid' => $removedUser, 'gid' => $group]); + $userObject = $userManager->get($removedUser); + $dispatcher->dispatchTyped(new UserRemovedEvent($groupObject, $userObject)); \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".', ILogger::INFO); $hasChanged = true; } foreach (array_diff($actualUsers, $knownUsers) as $addedUser) { - \OCP\Util::emitHook('OC_User', 'post_addToGroup', ['uid' => $addedUser, 'gid' => $group]); + $userObject = $userManager->get($addedUser); + $dispatcher->dispatchTyped(new UserAddedEvent($groupObject, $userObject)); \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".', ILogger::INFO); diff --git a/lib/base.php b/lib/base.php index e549881d89..de9588da5c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -901,7 +901,6 @@ 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_removeFromGroupLDAP'); OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); /** @var \OCP\EventDispatcher\IEventDispatcher $dispatcher */ diff --git a/lib/private/Share20/Hooks.php b/lib/private/Share20/Hooks.php index 0e41e20a2c..b596123bbe 100644 --- a/lib/private/Share20/Hooks.php +++ b/lib/private/Share20/Hooks.php @@ -30,8 +30,4 @@ class Hooks { public static function post_deleteGroup($arguments) { \OC::$server->getShareManager()->groupDeleted($arguments['gid']); } - - public static function post_removeFromGroupLDAP($arguments) { - \OC::$server->getShareManager()->userDeletedFromGroup($arguments['uid'], $arguments['gid']); - } }