diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-09-07 18:51:07 +0300 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-09-08 23:50:05 +0300 |
commit | f95982861634d26da1900f9704c04dbf34dc6e72 (patch) | |
tree | 37c29fc071fdb6f5bf898dc4ada7b9e123e28f90 /apps/settings | |
parent | 919a8d473b0f63de585fe37c44368a4ddcf4253a (diff) |
emit typed event for user management
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/settings')
5 files changed, 69 insertions, 21 deletions
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index 25a089dfad3..3ccd7d9d030 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -29,6 +29,7 @@ return array( 'OCA\\Settings\\Controller\\TwoFactorSettingsController' => $baseDir . '/../lib/Controller/TwoFactorSettingsController.php', 'OCA\\Settings\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php', 'OCA\\Settings\\Controller\\WebAuthnController' => $baseDir . '/../lib/Controller/WebAuthnController.php', + 'OCA\\Settings\\Events\\BeforeTemplateRenderedEvent' => $baseDir . '/../lib/Events/BeforeTemplateRenderedEvent.php', 'OCA\\Settings\\Hooks' => $baseDir . '/../lib/Hooks.php', 'OCA\\Settings\\Mailer\\NewUserMailHelper' => $baseDir . '/../lib/Mailer/NewUserMailHelper.php', 'OCA\\Settings\\Middleware\\SubadminMiddleware' => $baseDir . '/../lib/Middleware/SubadminMiddleware.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index 4cea507c081..bf831a81cd4 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -44,6 +44,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\Controller\\TwoFactorSettingsController' => __DIR__ . '/..' . '/../lib/Controller/TwoFactorSettingsController.php', 'OCA\\Settings\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php', 'OCA\\Settings\\Controller\\WebAuthnController' => __DIR__ . '/..' . '/../lib/Controller/WebAuthnController.php', + 'OCA\\Settings\\Events\\BeforeTemplateRenderedEvent' => __DIR__ . '/..' . '/../lib/Events/BeforeTemplateRenderedEvent.php', 'OCA\\Settings\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', 'OCA\\Settings\\Mailer\\NewUserMailHelper' => __DIR__ . '/..' . '/../lib/Mailer/NewUserMailHelper.php', 'OCA\\Settings\\Middleware\\SubadminMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/SubadminMiddleware.php', diff --git a/apps/settings/lib/Controller/UsersController.php b/apps/settings/lib/Controller/UsersController.php index 4c5a9b9e456..e228ebd8811 100644 --- a/apps/settings/lib/Controller/UsersController.php +++ b/apps/settings/lib/Controller/UsersController.php @@ -41,6 +41,7 @@ use OC\ForbiddenException; use OC\Security\IdentityProof\Manager; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Settings\BackgroundJobs\VerifyUserData; +use OCA\Settings\Events\BeforeTemplateRenderedEvent; use OCA\User_LDAP\User_Proxy; use OCP\App\IAppManager; use OCP\AppFramework\Controller; @@ -49,6 +50,7 @@ use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\BackgroundJob\IJobList; use OCP\Encryption\IManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; @@ -87,23 +89,28 @@ class UsersController extends Controller { private $jobList; /** @var IManager */ private $encryptionManager; - - - public function __construct(string $appName, - IRequest $request, - IUserManager $userManager, - IGroupManager $groupManager, - IUserSession $userSession, - IConfig $config, - bool $isAdmin, - IL10N $l10n, - IMailer $mailer, - IFactory $l10nFactory, - IAppManager $appManager, - AccountManager $accountManager, - Manager $keyManager, - IJobList $jobList, - IManager $encryptionManager) { + /** @var IEventDispatcher */ + private $dispatcher; + + + public function __construct( + string $appName, + IRequest $request, + IUserManager $userManager, + IGroupManager $groupManager, + IUserSession $userSession, + IConfig $config, + bool $isAdmin, + IL10N $l10n, + IMailer $mailer, + IFactory $l10nFactory, + IAppManager $appManager, + AccountManager $accountManager, + Manager $keyManager, + IJobList $jobList, + IManager $encryptionManager, + IEventDispatcher $dispatcher + ) { parent::__construct($appName, $request); $this->userManager = $userManager; $this->groupManager = $groupManager; @@ -118,6 +125,7 @@ class UsersController extends Controller { $this->keyManager = $keyManager; $this->jobList = $jobList; $this->encryptionManager = $encryptionManager; + $this->dispatcher = $dispatcher; } @@ -224,7 +232,9 @@ class UsersController extends Controller { $quotaPreset = $this->parseQuotaPreset($this->config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB')); $defaultQuota = $this->config->getAppValue('files', 'default_quota', 'none'); - \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts'); + $event = new BeforeTemplateRenderedEvent(); + $this->dispatcher->dispatch('OC\Settings\Users::loadAdditionalScripts', $event); + $this->dispatcher->dispatchTyped($event); /* LANGUAGES */ $languages = $this->l10nFactory->getLanguages(); diff --git a/apps/settings/lib/Events/BeforeTemplateRenderedEvent.php b/apps/settings/lib/Events/BeforeTemplateRenderedEvent.php new file mode 100644 index 00000000000..3d553ac3833 --- /dev/null +++ b/apps/settings/lib/Events/BeforeTemplateRenderedEvent.php @@ -0,0 +1,31 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @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 OCA\Settings\Events; + +use OCP\EventDispatcher\Event; + +class BeforeTemplateRenderedEvent extends Event { +} diff --git a/apps/settings/tests/Controller/UsersControllerTest.php b/apps/settings/tests/Controller/UsersControllerTest.php index f15734d1f86..4679fd8f7ba 100644 --- a/apps/settings/tests/Controller/UsersControllerTest.php +++ b/apps/settings/tests/Controller/UsersControllerTest.php @@ -36,6 +36,7 @@ use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; use OCP\Encryption\IEncryptionModule; use OCP\Encryption\IManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IAvatarManager; use OCP\IConfig; use OCP\IGroupManager; @@ -55,7 +56,6 @@ use OCP\Security\ISecureRandom; * @package Tests\Settings\Controller */ class UsersControllerTest extends \Test\TestCase { - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ private $groupManager; /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ @@ -90,6 +90,8 @@ class UsersControllerTest extends \Test\TestCase { private $encryptionManager; /** @var IEncryptionModule | \PHPUnit\Framework\MockObject\MockObject */ private $encryptionModule; + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ + private $dispatcher; protected function setUp(): void { parent::setUp(); @@ -106,6 +108,7 @@ class UsersControllerTest extends \Test\TestCase { $this->securityManager = $this->getMockBuilder(\OC\Security\IdentityProof\Manager::class)->disableOriginalConstructor()->getMock(); $this->jobList = $this->createMock(IJobList::class); $this->encryptionManager = $this->createMock(IManager::class); + $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->l->method('t') ->willReturnCallback(function ($text, $parameters = []) { @@ -140,7 +143,8 @@ class UsersControllerTest extends \Test\TestCase { $this->accountManager, $this->securityManager, $this->jobList, - $this->encryptionManager + $this->encryptionManager, + $this->dispatcher ); } else { return $this->getMockBuilder(UsersController::class) @@ -160,7 +164,8 @@ class UsersControllerTest extends \Test\TestCase { $this->accountManager, $this->securityManager, $this->jobList, - $this->encryptionManager + $this->encryptionManager, + $this->dispatcher ] )->setMethods($mockedMethods)->getMock(); } |