diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2020-11-26 14:09:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-26 14:09:54 +0100 |
commit | 54e3beba165739c480730f797e2b386b12a92713 (patch) | |
tree | d256127f52920a8e5f72d15c19fd85602e6b3d3b /lib | |
parent | f8a4e07a8ce57d6bffed6cf510478fcc8f0821e6 (diff) | |
parent | 9bf76d2bad08b2e8c8e6bab9f3e514515fb89058 (diff) | |
download | nextcloud-server-54e3beba165739c480730f797e2b386b12a92713.tar.gz nextcloud-server-54e3beba165739c480730f797e2b386b12a92713.zip |
Merge pull request #24319 from nextcloud/techdebt/noid/streamline-user-creation-and-deletion-events
Streamline user creation and deletion events
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/Server.php | 16 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 8 | ||||
-rw-r--r-- | lib/private/User/User.php | 8 | ||||
-rw-r--r-- | lib/public/User/Events/CreateUserEvent.php | 65 |
6 files changed, 16 insertions, 83 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index b874bd58dbe..4f04d90b22b 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 26a7afff156..27972767576 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 d2567995270..b426c9c454d 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -525,33 +525,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 debe2f14f2e..1201a456ce2 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 3ca05afb313..c1dc8b91af8 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 e5c5f8af026..00000000000 --- a/lib/public/User/Events/CreateUserEvent.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -declare(strict_types=1); - -/** - * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @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 <http://www.gnu.org/licenses/>. - * - */ - -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; - } -} |