summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/user_ldap/lib/Jobs/UpdateGroups.php11
-rw-r--r--lib/base.php6
-rw-r--r--lib/private/Share20/Hooks.php4
-rw-r--r--lib/private/User/User.php12
4 files changed, 23 insertions, 10 deletions
diff --git a/apps/user_ldap/lib/Jobs/UpdateGroups.php b/apps/user_ldap/lib/Jobs/UpdateGroups.php
index 58254bf41e9..035caf0c33c 100644
--- a/apps/user_ldap/lib/Jobs/UpdateGroups.php
+++ b/apps/user_ldap/lib/Jobs/UpdateGroups.php
@@ -44,6 +44,8 @@ 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\UserRemovedEvent;
use OCP\ILogger;
class UpdateGroups extends \OC\BackgroundJob\TimedJob {
@@ -94,6 +96,10 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
* @param string[] $groups
*/
private static function handleKnownGroups($groups) {
+ $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`
@@ -105,8 +111,11 @@ 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);
diff --git a/lib/base.php b/lib/base.php
index a491cb11c80..8b8e8e5fe32 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -61,6 +61,7 @@
*
*/
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\UserRemovedEvent;
use OCP\ILogger;
use OCP\Share;
@@ -898,11 +899,10 @@ 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 */
- $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = \OC::$server->get(IEventDispatcher::class);
$dispatcher->addServiceListener(UserRemovedEvent::class, \OC\Share20\UserRemovedListener::class);
}
}
diff --git a/lib/private/Share20/Hooks.php b/lib/private/Share20/Hooks.php
index 0e41e20a2cd..b596123bbe0 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']);
- }
}
diff --git a/lib/private/User/User.php b/lib/private/User/User.php
index 08bbce4701b..199ddb569dd 100644
--- a/lib/private/User/User.php
+++ b/lib/private/User/User.php
@@ -41,6 +41,9 @@ use OC\Avatar\AvatarManager;
use OC\Files\Cache\Storage;
use OC\Hooks\Emitter;
use OC_Helper;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Events\BeforeUserRemovedEvent;
+use OCP\Group\Events\UserRemovedEvent;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IImage;
@@ -63,6 +66,9 @@ class User implements IUser {
/** @var EventDispatcherInterface */
private $dispatcher;
+ /** @var IEventDispatcher */
+ private $newDispatcher;
+
/** @var bool */
private $enabled;
@@ -100,6 +106,8 @@ class User implements IUser {
if (is_null($this->urlGenerator)) {
$this->urlGenerator = \OC::$server->getURLGenerator();
}
+ // TODO: inject
+ $this->newDispatcher = \OC::$server->query(IEventDispatcher::class);
}
/**
@@ -219,9 +227,9 @@ class User implements IUser {
foreach ($groupManager->getUserGroupIds($this) as $groupId) {
$group = $groupManager->get($groupId);
if ($group) {
- \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]);
+ $this->newDispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $this));
$group->removeUser($this);
- \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]);
+ $this->newDispatcher->dispatchTyped(new UserRemovedEvent($group, $this));
}
}
// Delete the user's keys in preferences