]> source.dussan.org Git - nextcloud-server.git/commitdiff
emit typed event for user management 22649/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Mon, 7 Sep 2020 15:51:07 +0000 (17:51 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 8 Sep 2020 20:50:05 +0000 (22:50 +0200)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/settings/composer/composer/autoload_classmap.php
apps/settings/composer/composer/autoload_static.php
apps/settings/lib/Controller/UsersController.php
apps/settings/lib/Events/BeforeTemplateRenderedEvent.php [new file with mode: 0644]
apps/settings/tests/Controller/UsersControllerTest.php

index 25a089dfad3b4c23dceea455aa8f18fae1159b38..3ccd7d9d030eec52fcbf1802f884850c576c7414 100644 (file)
@@ -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',
index 4cea507c0815660e130b95fa850398741cfa8398..bf831a81cd451bdb12ab56cdd6c365121a71c2cf 100644 (file)
@@ -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',
index 4c5a9b9e4568df026aa738a08d7b11b3b1ad3baf..e228ebd8811a304ada4ab890fd48c2c82f1a6da6 100644 (file)
@@ -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 (file)
index 0000000..3d553ac
--- /dev/null
@@ -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 {
+}
index f15734d1f86564cb514064440606250df912b0ca..4679fd8f7ba0f664183c2aad1e65bd09e9df87dc 100644 (file)
@@ -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();
                }