]> source.dussan.org Git - nextcloud-server.git/commitdiff
comments: Stop using a service alias for controller
authorjld3103 <jld3103yt@gmail.com>
Mon, 19 Jun 2023 05:48:03 +0000 (07:48 +0200)
committerjld3103 <jld3103yt@gmail.com>
Mon, 19 Jun 2023 06:12:25 +0000 (08:12 +0200)
Signed-off-by: jld3103 <jld3103yt@gmail.com>
apps/comments/composer/composer/autoload_classmap.php
apps/comments/composer/composer/autoload_static.php
apps/comments/lib/AppInfo/Application.php
apps/comments/lib/Controller/Notifications.php [deleted file]
apps/comments/lib/Controller/NotificationsController.php [new file with mode: 0644]
apps/comments/tests/Unit/AppInfo/ApplicationTest.php
apps/comments/tests/Unit/Controller/NotificationsTest.php

index 6afc14d07a1199b1957c2701d71ff21133c71969..61def2ecc46fd6fc51742f802863ad74de9c2d97 100644 (file)
@@ -14,7 +14,7 @@ return array(
     'OCA\\Comments\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
     'OCA\\Comments\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
     'OCA\\Comments\\Collaboration\\CommentersSorter' => $baseDir . '/../lib/Collaboration/CommentersSorter.php',
-    'OCA\\Comments\\Controller\\Notifications' => $baseDir . '/../lib/Controller/Notifications.php',
+    'OCA\\Comments\\Controller\\NotificationsController' => $baseDir . '/../lib/Controller/NotificationsController.php',
     'OCA\\Comments\\EventHandler' => $baseDir . '/../lib/EventHandler.php',
     'OCA\\Comments\\Listener\\CommentsEntityEventListener' => $baseDir . '/../lib/Listener/CommentsEntityEventListener.php',
     'OCA\\Comments\\Listener\\LoadAdditionalScripts' => $baseDir . '/../lib/Listener/LoadAdditionalScripts.php',
index 0f832e1849bcd4da11acf5bcd7f0807d14f0b9b4..9732ee9f4cab27b3d9b9afd5175e57b11dd66eaa 100644 (file)
@@ -7,14 +7,14 @@ namespace Composer\Autoload;
 class ComposerStaticInitComments
 {
     public static $prefixLengthsPsr4 = array (
-        'O' => 
+        'O' =>
         array (
             'OCA\\Comments\\' => 13,
         ),
     );
 
     public static $prefixDirsPsr4 = array (
-        'OCA\\Comments\\' => 
+        'OCA\\Comments\\' =>
         array (
             0 => __DIR__ . '/..' . '/../lib',
         ),
@@ -29,7 +29,7 @@ class ComposerStaticInitComments
         'OCA\\Comments\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
         'OCA\\Comments\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
         'OCA\\Comments\\Collaboration\\CommentersSorter' => __DIR__ . '/..' . '/../lib/Collaboration/CommentersSorter.php',
-        'OCA\\Comments\\Controller\\Notifications' => __DIR__ . '/..' . '/../lib/Controller/Notifications.php',
+        'OCA\\Comments\\Controller\\NotificationsController' => __DIR__ . '/..' . '/../lib/Controller/NotificationsController.php',
         'OCA\\Comments\\EventHandler' => __DIR__ . '/..' . '/../lib/EventHandler.php',
         'OCA\\Comments\\Listener\\CommentsEntityEventListener' => __DIR__ . '/..' . '/../lib/Listener/CommentsEntityEventListener.php',
         'OCA\\Comments\\Listener\\LoadAdditionalScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScripts.php',
index 527c5d99fc347ce7113dfc3bb2dca45a9e905e09..bfd66c43ecd78ed46e6b5a70c561d35bbd9a10a9 100644 (file)
@@ -28,7 +28,6 @@ namespace OCA\Comments\AppInfo;
 
 use Closure;
 use OCA\Comments\Capabilities;
-use OCA\Comments\Controller\Notifications;
 use OCA\Comments\EventHandler;
 use OCA\Comments\Listener\CommentsEntityEventListener;
 use OCA\Comments\Listener\LoadAdditionalScripts;
@@ -58,8 +57,6 @@ class Application extends App implements IBootstrap {
        public function register(IRegistrationContext $context): void {
                $context->registerCapability(Capabilities::class);
 
-               $context->registerServiceAlias('NotificationsController', Notifications::class);
-
                $context->registerEventListener(
                        LoadAdditionalScriptsEvent::class,
                        LoadAdditionalScripts::class
diff --git a/apps/comments/lib/Controller/Notifications.php b/apps/comments/lib/Controller/Notifications.php
deleted file mode 100644 (file)
index ba61a0d..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @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\Comments\Controller;
-
-use OCP\AppFramework\Controller;
-use OCP\AppFramework\Http\NotFoundResponse;
-use OCP\AppFramework\Http\RedirectResponse;
-use OCP\AppFramework\Http\Response;
-use OCP\Comments\IComment;
-use OCP\Comments\ICommentsManager;
-use OCP\Files\IRootFolder;
-use OCP\IRequest;
-use OCP\IURLGenerator;
-use OCP\IUser;
-use OCP\IUserSession;
-use OCP\Notification\IManager;
-
-/**
- * Class Notifications
- *
- * @package OCA\Comments\Controller
- */
-class Notifications extends Controller {
-
-       protected IRootFolder $rootFolder;
-       protected ICommentsManager $commentsManager;
-       protected IURLGenerator $urlGenerator;
-       protected IManager $notificationManager;
-       protected IUserSession $userSession;
-
-       /**
-        * Notifications constructor.
-        */
-       public function __construct(
-               string $appName,
-               IRequest $request,
-               ICommentsManager $commentsManager,
-               IRootFolder $rootFolder,
-               IURLGenerator $urlGenerator,
-               IManager $notificationManager,
-               IUserSession $userSession
-       ) {
-               parent::__construct($appName, $request);
-               $this->commentsManager = $commentsManager;
-               $this->rootFolder = $rootFolder;
-               $this->urlGenerator = $urlGenerator;
-               $this->notificationManager = $notificationManager;
-               $this->userSession = $userSession;
-       }
-
-       /**
-        * @PublicPage
-        * @NoCSRFRequired
-        */
-       public function view(string $id): Response {
-               $currentUser = $this->userSession->getUser();
-               if (!$currentUser instanceof IUser) {
-                       return new RedirectResponse(
-                               $this->urlGenerator->linkToRoute('core.login.showLoginForm', [
-                                       'redirect_url' => $this->urlGenerator->linkToRoute(
-                                               'comments.Notifications.view',
-                                               ['id' => $id]
-                                       ),
-                               ])
-                       );
-               }
-
-               try {
-                       $comment = $this->commentsManager->get($id);
-                       if ($comment->getObjectType() !== 'files') {
-                               return new NotFoundResponse();
-                       }
-                       $userFolder = $this->rootFolder->getUserFolder($currentUser->getUID());
-                       $files = $userFolder->getById((int)$comment->getObjectId());
-
-                       $this->markProcessed($comment, $currentUser);
-
-                       if (empty($files)) {
-                               return new NotFoundResponse();
-                       }
-
-                       $url = $this->urlGenerator->linkToRouteAbsolute(
-                               'files.viewcontroller.showFile',
-                               [ 'fileid' => $comment->getObjectId() ]
-                       );
-
-                       return new RedirectResponse($url);
-               } catch (\Exception $e) {
-                       return new NotFoundResponse();
-               }
-       }
-
-       /**
-        * Marks the notification about a comment as processed
-        */
-       protected function markProcessed(IComment $comment, IUser $currentUser): void {
-               $notification = $this->notificationManager->createNotification();
-               $notification->setApp('comments')
-                       ->setObject('comment', $comment->getId())
-                       ->setSubject('mention')
-                       ->setUser($currentUser->getUID());
-               $this->notificationManager->markProcessed($notification);
-       }
-}
diff --git a/apps/comments/lib/Controller/NotificationsController.php b/apps/comments/lib/Controller/NotificationsController.php
new file mode 100644 (file)
index 0000000..41a9541
--- /dev/null
@@ -0,0 +1,126 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @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\Comments\Controller;
+
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\NotFoundResponse;
+use OCP\AppFramework\Http\RedirectResponse;
+use OCP\AppFramework\Http\Response;
+use OCP\Comments\IComment;
+use OCP\Comments\ICommentsManager;
+use OCP\Files\IRootFolder;
+use OCP\IRequest;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserSession;
+use OCP\Notification\IManager;
+
+/**
+ * Class NotificationsController
+ *
+ * @package OCA\Comments\Controller
+ */
+class NotificationsController extends Controller {
+
+       protected IRootFolder $rootFolder;
+       protected ICommentsManager $commentsManager;
+       protected IURLGenerator $urlGenerator;
+       protected IManager $notificationManager;
+       protected IUserSession $userSession;
+
+       /**
+        * NotificationsController constructor.
+        */
+       public function __construct(
+               string $appName,
+               IRequest $request,
+               ICommentsManager $commentsManager,
+               IRootFolder $rootFolder,
+               IURLGenerator $urlGenerator,
+               IManager $notificationManager,
+               IUserSession $userSession
+       ) {
+               parent::__construct($appName, $request);
+               $this->commentsManager = $commentsManager;
+               $this->rootFolder = $rootFolder;
+               $this->urlGenerator = $urlGenerator;
+               $this->notificationManager = $notificationManager;
+               $this->userSession = $userSession;
+       }
+
+       /**
+        * @PublicPage
+        * @NoCSRFRequired
+        */
+       public function view(string $id): Response {
+               $currentUser = $this->userSession->getUser();
+               if (!$currentUser instanceof IUser) {
+                       return new RedirectResponse(
+                               $this->urlGenerator->linkToRoute('core.login.showLoginForm', [
+                                       'redirect_url' => $this->urlGenerator->linkToRoute(
+                                               'comments.Notifications.view',
+                                               ['id' => $id]
+                                       ),
+                               ])
+                       );
+               }
+
+               try {
+                       $comment = $this->commentsManager->get($id);
+                       if ($comment->getObjectType() !== 'files') {
+                               return new NotFoundResponse();
+                       }
+                       $userFolder = $this->rootFolder->getUserFolder($currentUser->getUID());
+                       $files = $userFolder->getById((int)$comment->getObjectId());
+
+                       $this->markProcessed($comment, $currentUser);
+
+                       if (empty($files)) {
+                               return new NotFoundResponse();
+                       }
+
+                       $url = $this->urlGenerator->linkToRouteAbsolute(
+                               'files.viewcontroller.showFile',
+                               [ 'fileid' => $comment->getObjectId() ]
+                       );
+
+                       return new RedirectResponse($url);
+               } catch (\Exception $e) {
+                       return new NotFoundResponse();
+               }
+       }
+
+       /**
+        * Marks the notification about a comment as processed
+        */
+       protected function markProcessed(IComment $comment, IUser $currentUser): void {
+               $notification = $this->notificationManager->createNotification();
+               $notification->setApp('comments')
+                       ->setObject('comment', $comment->getId())
+                       ->setSubject('mention')
+                       ->setUser($currentUser->getUID());
+               $this->notificationManager->markProcessed($notification);
+       }
+}
index 6e3658c0e5b16e76e8a0dc73b01073e0a1e7664a..a0ec722b36821c422db4eb5892356f0b7f8694c3 100644 (file)
@@ -51,11 +51,8 @@ class ApplicationTest extends TestCase {
                $app = new Application();
                $c = $app->getContainer();
 
-               // assert service instances in the container are properly setup
-               $s = $c->get('NotificationsController');
-               $this->assertInstanceOf('OCA\Comments\Controller\Notifications', $s);
-
                $services = [
+                       'OCA\Comments\Controller\NotificationsController',
                        'OCA\Comments\Activity\Filter',
                        'OCA\Comments\Activity\Listener',
                        'OCA\Comments\Activity\Provider',
index c21101030e80c0cdd0601b5f77089dc21be4a035..4ccb553739bfadc7773c0f77a68a5de8aef69555 100644 (file)
@@ -25,7 +25,7 @@
  */
 namespace OCA\Comments\Tests\Unit\Controller;
 
-use OCA\Comments\Controller\Notifications;
+use OCA\Comments\Controller\NotificationsController;
 use OCP\AppFramework\Http\NotFoundResponse;
 use OCP\AppFramework\Http\RedirectResponse;
 use OCP\Comments\IComment;
@@ -43,7 +43,7 @@ use OCP\Notification\INotification;
 use Test\TestCase;
 
 class NotificationsTest extends TestCase {
-       /** @var Notifications */
+       /** @var NotificationsController */
        protected $notificationsController;
 
        /** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
@@ -70,7 +70,7 @@ class NotificationsTest extends TestCase {
                $this->notificationManager = $this->createMock(IManager::class);
                $this->urlGenerator = $this->createMock(IURLGenerator::class);
 
-               $this->notificationsController = new Notifications(
+               $this->notificationsController = new NotificationsController(
                        'comments',
                        $this->createMock(IRequest::class),
                        $this->commentsManager,