]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow grouping of activity settings 22117/head
authorRobin Appelman <robin@icewind.nl>
Wed, 5 Aug 2020 13:57:51 +0000 (15:57 +0200)
committerRobin Appelman <robin@icewind.nl>
Wed, 5 Aug 2020 14:13:03 +0000 (16:13 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
14 files changed:
apps/files/composer/composer/autoload_classmap.php
apps/files/composer/composer/autoload_static.php
apps/files/lib/Activity/Settings/FavoriteAction.php
apps/files/lib/Activity/Settings/FileActivitySettings.php [new file with mode: 0644]
apps/files/lib/Activity/Settings/FileChanged.php
apps/files/lib/Activity/Settings/FileCreated.php
apps/files/lib/Activity/Settings/FileDeleted.php
apps/files/lib/Activity/Settings/FileFavorite.php
apps/files/lib/Activity/Settings/FileRestored.php
lib/private/Activity/ActivitySettingsAdapter.php
lib/private/Activity/Manager.php
lib/private/Server.php
lib/public/Activity/ActivitySettings.php
tests/lib/Activity/ManagerTest.php

index ecb91fee9c9b077d0ff6c1b189768dd96569a727..2f5bb719166e0a6f003b89a0312b42896859a631 100644 (file)
@@ -12,6 +12,7 @@ return array(
     'OCA\\Files\\Activity\\Helper' => $baseDir . '/../lib/Activity/Helper.php',
     'OCA\\Files\\Activity\\Provider' => $baseDir . '/../lib/Activity/Provider.php',
     'OCA\\Files\\Activity\\Settings\\FavoriteAction' => $baseDir . '/../lib/Activity/Settings/FavoriteAction.php',
+    'OCA\\Files\\Activity\\Settings\\FileActivitySettings' => $baseDir . '/../lib/Activity/Settings/FileActivitySettings.php',
     'OCA\\Files\\Activity\\Settings\\FileChanged' => $baseDir . '/../lib/Activity/Settings/FileChanged.php',
     'OCA\\Files\\Activity\\Settings\\FileCreated' => $baseDir . '/../lib/Activity/Settings/FileCreated.php',
     'OCA\\Files\\Activity\\Settings\\FileDeleted' => $baseDir . '/../lib/Activity/Settings/FileDeleted.php',
index a8c80a4201acce4659bd902d92d692b199dc8f5d..fe9809f9e29cb2e516dc2e5150997b0ce33fd249 100644 (file)
@@ -27,6 +27,7 @@ class ComposerStaticInitFiles
         'OCA\\Files\\Activity\\Helper' => __DIR__ . '/..' . '/../lib/Activity/Helper.php',
         'OCA\\Files\\Activity\\Provider' => __DIR__ . '/..' . '/../lib/Activity/Provider.php',
         'OCA\\Files\\Activity\\Settings\\FavoriteAction' => __DIR__ . '/..' . '/../lib/Activity/Settings/FavoriteAction.php',
+        'OCA\\Files\\Activity\\Settings\\FileActivitySettings' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileActivitySettings.php',
         'OCA\\Files\\Activity\\Settings\\FileChanged' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileChanged.php',
         'OCA\\Files\\Activity\\Settings\\FileCreated' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileCreated.php',
         'OCA\\Files\\Activity\\Settings\\FileDeleted' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileDeleted.php',
index 9db53eada8e1ba6abef99995b732cedcb3663791..017669a137ca96cd38496ccecabae77d0e898099 100644 (file)
 
 namespace OCA\Files\Activity\Settings;
 
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FavoriteAction implements ISetting {
-
-       /** @var IL10N */
-       protected $l;
-
-       /**
-        * @param IL10N $l
-        */
-       public function __construct(IL10N $l) {
-               $this->l = $l;
-       }
-
+class FavoriteAction extends FileActivitySettings {
        /**
         * @return string Lowercase a-z and underscore only identifier
         * @since 11.0.0
diff --git a/apps/files/lib/Activity/Settings/FileActivitySettings.php b/apps/files/lib/Activity/Settings/FileActivitySettings.php
new file mode 100644 (file)
index 0000000..0ec7cb2
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
+ *
+ * @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\Files\Activity\Settings;
+
+use OCP\Activity\ActivitySettings;
+use OCP\IL10N;
+
+abstract class FileActivitySettings extends ActivitySettings {
+       /** @var IL10N */
+       protected $l;
+
+       /**
+        * @param IL10N $l
+        */
+       public function __construct(IL10N $l) {
+               $this->l = $l;
+       }
+
+       public function getGroupIdentifier() {
+               return 'files';
+       }
+
+       public function getGroupName() {
+               return $this->l->t('Files');
+       }
+}
index 503201bd129e1e6e6a94857813b2de646ea003f6..bf3780a575f694ac1caf158f649f002d4fd4c553 100644 (file)
 
 namespace OCA\Files\Activity\Settings;
 
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileChanged implements ISetting {
-
-       /** @var IL10N */
-       protected $l;
-
-       /**
-        * @param IL10N $l
-        */
-       public function __construct(IL10N $l) {
-               $this->l = $l;
-       }
-
+class FileChanged extends FileActivitySettings {
        /**
         * @return string Lowercase a-z and underscore only identifier
         * @since 11.0.0
index 481c719d0241f67d5f3ec748292edc4418999446..589f905286a8effbd757b5fc866caeb73787e8f6 100644 (file)
 
 namespace OCA\Files\Activity\Settings;
 
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileCreated implements ISetting {
-
-       /** @var IL10N */
-       protected $l;
-
-       /**
-        * @param IL10N $l
-        */
-       public function __construct(IL10N $l) {
-               $this->l = $l;
-       }
-
+class FileCreated extends FileActivitySettings {
        /**
         * @return string Lowercase a-z and underscore only identifier
         * @since 11.0.0
index d4e56b6c717cf2511f5ae6f9d561b52760e61a03..05754463bc2b47c95a8633637a217be696f40ee9 100644 (file)
 
 namespace OCA\Files\Activity\Settings;
 
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileDeleted implements ISetting {
-
-       /** @var IL10N */
-       protected $l;
-
-       /**
-        * @param IL10N $l
-        */
-       public function __construct(IL10N $l) {
-               $this->l = $l;
-       }
-
+class FileDeleted extends FileActivitySettings {
        /**
         * @return string Lowercase a-z and underscore only identifier
         * @since 11.0.0
index ac62242f703bce087beca20d92f07a18cdb217ed..72ba01e537a743c87760794afaebf0ad04a8ed47 100644 (file)
 
 namespace OCA\Files\Activity\Settings;
 
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileFavorite implements ISetting {
-
-       /** @var IL10N */
-       protected $l;
-
-       /**
-        * @param IL10N $l
-        */
-       public function __construct(IL10N $l) {
-               $this->l = $l;
-       }
-
+class FileFavorite extends FileActivitySettings {
        /**
         * @return string Lowercase a-z and underscore only identifier
         * @since 11.0.0
index 59b722ddf85ace706155cb799cd08de4aeaaa3c8..f149554bc887afdf62c22a8878e39ca3d1393ec5 100644 (file)
 
 namespace OCA\Files\Activity\Settings;
 
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileRestored implements ISetting {
-
-       /** @var IL10N */
-       protected $l;
-
-       /**
-        * @param IL10N $l
-        */
-       public function __construct(IL10N $l) {
-               $this->l = $l;
-       }
-
+class FileRestored extends FileActivitySettings {
        /**
         * @return string Lowercase a-z and underscore only identifier
         * @since 11.0.0
index c49231bee2cab4ad48644891f391f42d8932f32d..ef629be72f7573e716f27313a1ed7b78718ec39c 100644 (file)
@@ -25,6 +25,7 @@ namespace OC\Activity;
 
 use OCP\Activity\ActivitySettings;
 use OCP\Activity\ISetting;
+use OCP\IL10N;
 
 /**
  * Adapt the old interface based settings into the new abstract
@@ -32,9 +33,11 @@ use OCP\Activity\ISetting;
  */
 class ActivitySettingsAdapter extends ActivitySettings {
        private $oldSettings;
+       private $l10n;
 
-       public function __construct(ISetting $oldSettings) {
+       public function __construct(ISetting $oldSettings, IL10N $l10n) {
                $this->oldSettings = $oldSettings;
+               $this->l10n = $l10n;
        }
 
        public function getIdentifier() {
@@ -45,6 +48,14 @@ class ActivitySettingsAdapter extends ActivitySettings {
                return $this->oldSettings->getName();
        }
 
+       public function getGroupIdentifier() {
+               return 'other';
+       }
+
+       public function getGroupName() {
+               return $this->l10n->t('Other activities');
+       }
+
        public function getPriority() {
                return $this->oldSettings->getPriority();
        }
index 81fd91c778af0af59f97b1c4cff293d7d4b01c52..f5ea59491e58abbee942087b94c69e8bfa3f75ae 100644 (file)
@@ -36,6 +36,7 @@ use OCP\Activity\IManager;
 use OCP\Activity\IProvider;
 use OCP\Activity\ISetting;
 use OCP\IConfig;
+use OCP\IL10N;
 use OCP\IRequest;
 use OCP\IUser;
 use OCP\IUserSession;
@@ -66,14 +67,20 @@ class Manager implements IManager {
        /** @var string */
        protected $currentUserId;
 
-       public function __construct(IRequest $request,
-                                                               IUserSession $session,
-                                                               IConfig $config,
-                                                               IValidator $validator) {
+       protected $l10n;
+
+       public function __construct(
+                       IRequest $request,
+                       IUserSession $session,
+                       IConfig $config,
+                       IValidator $validator,
+                       IL10N $l10n
+       ) {
                $this->request = $request;
                $this->session = $session;
                $this->config = $config;
                $this->validator = $validator;
+               $this->l10n = $l10n;
        }
 
        /** @var \Closure[] */
@@ -273,7 +280,7 @@ class Manager implements IManager {
 
                        if ($setting instanceof ISetting) {
                                if (!$setting instanceof ActivitySettings) {
-                                       $setting = new ActivitySettingsAdapter($setting);
+                                       $setting = new ActivitySettingsAdapter($setting, $this->l10n);
                                }
                        } else {
                                throw new \InvalidArgumentException('Invalid activity filter registered');
index 09bb7336785a77dd1cd9d1be70f504ee5effe5bd..e59befda727482d781cc5a9245b2ae5bb6f7b6bf 100644 (file)
@@ -694,11 +694,13 @@ class Server extends ServerContainer implements IServerContainer {
                });
 
                $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
+                       $l10n = $this->get(IFactory::class)->get('activity');
                        return new \OC\Activity\Manager(
                                $c->getRequest(),
                                $c->getUserSession(),
                                $c->getConfig(),
-                               $c->query(IValidator::class)
+                               $c->query(IValidator::class),
+                               $l10n
                        );
                });
                $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
index 98b95061cd71188abfb3fb01ac69e6c3461a4403..c7d1ca81fef4c29b72ace2b21cf6e9ac35d769a6 100644 (file)
@@ -39,6 +39,18 @@ abstract class ActivitySettings implements ISetting {
         */
        abstract public function getName();
 
+       /**
+        * @return string Lowercase a-z and underscore only group identifier
+        * @since 20.0.0
+        */
+       abstract public function getGroupIdentifier();
+
+       /**
+        * @return string A translated string for the settings group
+        * @since 20.0.0
+        */
+       abstract public function getGroupName();
+
        /**
         * @return int whether the filter should be rather on the top or bottom of
         * the admin section. The filters are arranged in ascending order of the
index 77c0607916a5fd8921c48067111c3ceba9f704de..f8552e5d45fee6710c4a92747fbd5f143488bffa 100644 (file)
@@ -56,7 +56,8 @@ class ManagerTest extends TestCase {
                        $this->request,
                        $this->session,
                        $this->config,
-                       $this->validator
+                       $this->validator,
+                       $this->createMock(IL10N::class)
                );
 
                $this->assertSame([], self::invokePrivate($this->activityManager, 'getConsumers'));