From 9bf76d2bad08b2e8c8e6bab9f3e514515fb89058 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 23 Nov 2020 23:59:50 +0100 Subject: [PATCH] Streamline user creation and deletion events CreateUserEvent was the only one that didn't matched the naming scheme of BeforePASTTENSEEvent and PASTTENSEEvent. The event wasn't used at all so this just removes it again as there is BeforeUserCreatedEvent that is also available since 18. Signed-off-by: Morris Jobke --- lib/composer/composer/autoload_classmap.php | 1 - lib/composer/composer/autoload_static.php | 1 - lib/private/Server.php | 16 ++--- lib/private/User/Manager.php | 8 +-- lib/private/User/User.php | 8 +++ lib/public/User/Events/CreateUserEvent.php | 65 --------------------- 6 files changed, 16 insertions(+), 83 deletions(-) delete mode 100644 lib/public/User/Events/CreateUserEvent.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index b874bd58db..4f04d90b22 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -521,7 +521,6 @@ return array( 'OCP\\User\\Events\\BeforeUserLoggedInEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedInEvent.php', 'OCP\\User\\Events\\BeforeUserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php', 'OCP\\User\\Events\\BeforeUserLoggedOutEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedOutEvent.php', - 'OCP\\User\\Events\\CreateUserEvent' => $baseDir . '/lib/public/User/Events/CreateUserEvent.php', 'OCP\\User\\Events\\PasswordUpdatedEvent' => $baseDir . '/lib/public/User/Events/PasswordUpdatedEvent.php', 'OCP\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/public/User/Events/PostLoginEvent.php', 'OCP\\User\\Events\\UserChangedEvent' => $baseDir . '/lib/public/User/Events/UserChangedEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 26a7afff15..2797276757 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -550,7 +550,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\User\\Events\\BeforeUserLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedInEvent.php', 'OCP\\User\\Events\\BeforeUserLoggedInWithCookieEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php', 'OCP\\User\\Events\\BeforeUserLoggedOutEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedOutEvent.php', - 'OCP\\User\\Events\\CreateUserEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/CreateUserEvent.php', 'OCP\\User\\Events\\PasswordUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PasswordUpdatedEvent.php', 'OCP\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PostLoginEvent.php', 'OCP\\User\\Events\\UserChangedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserChangedEvent.php', diff --git a/lib/private/Server.php b/lib/private/Server.php index 3952495716..275caf306e 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -524,33 +524,25 @@ class Server extends ServerContainer implements IServerContainer { $c->get(ILogger::class), $c->get(IEventDispatcher::class) ); + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); - - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $this->get(IEventDispatcher::class); - $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); }); + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { /** @var \OC\User\User $user */ \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); }); + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { /** @var \OC\User\User $user */ \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); - - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $this->get(IEventDispatcher::class); - $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); }); + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ $userSession->listen('\OC\User', 'postDelete', function ($user) { /** @var \OC\User\User $user */ \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); - - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $this->get(IEventDispatcher::class); - $dispatcher->dispatchTyped(new UserDeletedEvent($user)); }); $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { /** @var \OC\User\User $user */ diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index debe2f14f2..1201a456ce 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -43,7 +43,7 @@ use OCP\IUser; use OCP\IUserBackend; use OCP\IUserManager; use OCP\User\Backend\IGetRealUIDBackend; -use OCP\User\Events\CreateUserEvent; +use OCP\User\Events\BeforeUserCreatedEvent; use OCP\User\Events\UserCreatedEvent; use OCP\UserInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -365,16 +365,16 @@ class Manager extends PublicEmitter implements IUserManager { throw new \InvalidArgumentException($l->t('The username is already being used')); } - /** @depreacted 21.0.0 use CreateUserEvent event with the IEventDispatcher instead */ + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ $this->emit('\OC\User', 'preCreateUser', [$uid, $password]); - $this->eventDispatcher->dispatchTyped(new CreateUserEvent($uid, $password)); + $this->eventDispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); $state = $backend->createUser($uid, $password); if ($state === false) { throw new \InvalidArgumentException($l->t('Could not create user')); } $user = $this->getUserObject($uid, $backend); if ($user instanceof IUser) { - /** @depreacted 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ $this->emit('\OC\User', 'postCreateUser', [$user, $password]); $this->eventDispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); } diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 3ca05afb31..c1dc8b91af 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -50,6 +50,8 @@ use OCP\IImage; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserBackend; +use OCP\User\Events\BeforeUserDeletedEvent; +use OCP\User\Events\UserDeletedEvent; use OCP\User\GetQuotaEvent; use OCP\UserInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -212,10 +214,13 @@ class User implements IUser { * @return bool */ public function delete() { + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ $this->legacyDispatcher->dispatch(IUser::class . '::preDelete', new GenericEvent($this)); if ($this->emitter) { + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ $this->emitter->emit('\OC\User', 'preDelete', [$this]); } + $this->dispatcher->dispatchTyped(new BeforeUserDeletedEvent($this)); // get the home now because it won't return it after user deletion $homePath = $this->getHome(); $result = $this->backend->deleteUser($this->uid); @@ -261,10 +266,13 @@ class User implements IUser { $accountManager = \OC::$server->query(AccountManager::class); $accountManager->deleteUser($this); + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ $this->legacyDispatcher->dispatch(IUser::class . '::postDelete', new GenericEvent($this)); if ($this->emitter) { + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ $this->emitter->emit('\OC\User', 'postDelete', [$this]); } + $this->dispatcher->dispatchTyped(new UserDeletedEvent($this)); } return !($result === false); } diff --git a/lib/public/User/Events/CreateUserEvent.php b/lib/public/User/Events/CreateUserEvent.php deleted file mode 100644 index e5c5f8af02..0000000000 --- a/lib/public/User/Events/CreateUserEvent.php +++ /dev/null @@ -1,65 +0,0 @@ - - * - * @author Christoph Wurst - * - * @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 OCP\User\Events; - -use OCP\EventDispatcher\Event; - -/** - * @since 18.0.0 - */ -class CreateUserEvent extends Event { - - /** @var string */ - private $uid; - - /** @var string */ - private $password; - - /** - * @since 18.0.0 - */ - public function __construct(string $uid, - string $password) { - parent::__construct(); - $this->uid = $uid; - $this->password = $password; - } - - /** - * @since 18.0.0 - */ - public function getUid(): string { - return $this->uid; - } - - /** - * @since 18.0.0 - */ - public function getPassword(): string { - return $this->password; - } -}