summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-08-05 15:57:51 +0200
committerRobin Appelman <robin@icewind.nl>2020-08-05 16:13:03 +0200
commit227e362842a2340591608d6cb209e46a817f3403 (patch)
treed9a3a22b6f5298b1e433b7f79f603daff7ab5aa2
parenta4d511d82767f54af086b366a6c08bc927cb870c (diff)
downloadnextcloud-server-227e362842a2340591608d6cb209e46a817f3403.tar.gz
nextcloud-server-227e362842a2340591608d6cb209e46a817f3403.zip
allow grouping of activity settings
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--apps/files/composer/composer/autoload_classmap.php1
-rw-r--r--apps/files/composer/composer/autoload_static.php1
-rw-r--r--apps/files/lib/Activity/Settings/FavoriteAction.php16
-rw-r--r--apps/files/lib/Activity/Settings/FileActivitySettings.php48
-rw-r--r--apps/files/lib/Activity/Settings/FileChanged.php16
-rw-r--r--apps/files/lib/Activity/Settings/FileCreated.php16
-rw-r--r--apps/files/lib/Activity/Settings/FileDeleted.php16
-rw-r--r--apps/files/lib/Activity/Settings/FileFavorite.php16
-rw-r--r--apps/files/lib/Activity/Settings/FileRestored.php16
-rw-r--r--lib/private/Activity/ActivitySettingsAdapter.php13
-rw-r--r--lib/private/Activity/Manager.php17
-rw-r--r--lib/private/Server.php4
-rw-r--r--lib/public/Activity/ActivitySettings.php12
-rw-r--r--tests/lib/Activity/ManagerTest.php3
14 files changed, 97 insertions, 98 deletions
diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php
index ecb91fee9c9..2f5bb719166 100644
--- a/apps/files/composer/composer/autoload_classmap.php
+++ b/apps/files/composer/composer/autoload_classmap.php
@@ -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',
diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php
index a8c80a4201a..fe9809f9e29 100644
--- a/apps/files/composer/composer/autoload_static.php
+++ b/apps/files/composer/composer/autoload_static.php
@@ -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',
diff --git a/apps/files/lib/Activity/Settings/FavoriteAction.php b/apps/files/lib/Activity/Settings/FavoriteAction.php
index 9db53eada8e..017669a137c 100644
--- a/apps/files/lib/Activity/Settings/FavoriteAction.php
+++ b/apps/files/lib/Activity/Settings/FavoriteAction.php
@@ -23,21 +23,7 @@
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
index 00000000000..0ec7cb27be5
--- /dev/null
+++ b/apps/files/lib/Activity/Settings/FileActivitySettings.php
@@ -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');
+ }
+}
diff --git a/apps/files/lib/Activity/Settings/FileChanged.php b/apps/files/lib/Activity/Settings/FileChanged.php
index 503201bd129..bf3780a575f 100644
--- a/apps/files/lib/Activity/Settings/FileChanged.php
+++ b/apps/files/lib/Activity/Settings/FileChanged.php
@@ -23,21 +23,7 @@
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
diff --git a/apps/files/lib/Activity/Settings/FileCreated.php b/apps/files/lib/Activity/Settings/FileCreated.php
index 481c719d024..589f905286a 100644
--- a/apps/files/lib/Activity/Settings/FileCreated.php
+++ b/apps/files/lib/Activity/Settings/FileCreated.php
@@ -23,21 +23,7 @@
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
diff --git a/apps/files/lib/Activity/Settings/FileDeleted.php b/apps/files/lib/Activity/Settings/FileDeleted.php
index d4e56b6c717..05754463bc2 100644
--- a/apps/files/lib/Activity/Settings/FileDeleted.php
+++ b/apps/files/lib/Activity/Settings/FileDeleted.php
@@ -23,21 +23,7 @@
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
diff --git a/apps/files/lib/Activity/Settings/FileFavorite.php b/apps/files/lib/Activity/Settings/FileFavorite.php
index ac62242f703..72ba01e537a 100644
--- a/apps/files/lib/Activity/Settings/FileFavorite.php
+++ b/apps/files/lib/Activity/Settings/FileFavorite.php
@@ -23,21 +23,7 @@
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
diff --git a/apps/files/lib/Activity/Settings/FileRestored.php b/apps/files/lib/Activity/Settings/FileRestored.php
index 59b722ddf85..f149554bc88 100644
--- a/apps/files/lib/Activity/Settings/FileRestored.php
+++ b/apps/files/lib/Activity/Settings/FileRestored.php
@@ -23,21 +23,7 @@
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
diff --git a/lib/private/Activity/ActivitySettingsAdapter.php b/lib/private/Activity/ActivitySettingsAdapter.php
index c49231bee2c..ef629be72f7 100644
--- a/lib/private/Activity/ActivitySettingsAdapter.php
+++ b/lib/private/Activity/ActivitySettingsAdapter.php
@@ -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();
}
diff --git a/lib/private/Activity/Manager.php b/lib/private/Activity/Manager.php
index 81fd91c778a..f5ea59491e5 100644
--- a/lib/private/Activity/Manager.php
+++ b/lib/private/Activity/Manager.php
@@ -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');
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 09bb7336785..e59befda727 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -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);
diff --git a/lib/public/Activity/ActivitySettings.php b/lib/public/Activity/ActivitySettings.php
index 98b95061cd7..c7d1ca81fef 100644
--- a/lib/public/Activity/ActivitySettings.php
+++ b/lib/public/Activity/ActivitySettings.php
@@ -40,6 +40,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
* priority values. It is required to return a value between 0 and 100.
diff --git a/tests/lib/Activity/ManagerTest.php b/tests/lib/Activity/ManagerTest.php
index 77c0607916a..f8552e5d45f 100644
--- a/tests/lib/Activity/ManagerTest.php
+++ b/tests/lib/Activity/ManagerTest.php
@@ -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'));