Merge pull request #22117 from nextcloud/activity-settings-grouping

allow grouping of activity settings
This commit is contained in:
Morris Jobke 2020-08-11 11:24:23 +02:00 committed by GitHub
commit 8fc877ff7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 97 additions and 98 deletions

View File

@ -12,6 +12,7 @@ return array(
'OCA\\Files\\Activity\\Helper' => $baseDir . '/../lib/Activity/Helper.php', 'OCA\\Files\\Activity\\Helper' => $baseDir . '/../lib/Activity/Helper.php',
'OCA\\Files\\Activity\\Provider' => $baseDir . '/../lib/Activity/Provider.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\\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\\FileChanged' => $baseDir . '/../lib/Activity/Settings/FileChanged.php',
'OCA\\Files\\Activity\\Settings\\FileCreated' => $baseDir . '/../lib/Activity/Settings/FileCreated.php', 'OCA\\Files\\Activity\\Settings\\FileCreated' => $baseDir . '/../lib/Activity/Settings/FileCreated.php',
'OCA\\Files\\Activity\\Settings\\FileDeleted' => $baseDir . '/../lib/Activity/Settings/FileDeleted.php', 'OCA\\Files\\Activity\\Settings\\FileDeleted' => $baseDir . '/../lib/Activity/Settings/FileDeleted.php',

View File

@ -27,6 +27,7 @@ class ComposerStaticInitFiles
'OCA\\Files\\Activity\\Helper' => __DIR__ . '/..' . '/../lib/Activity/Helper.php', 'OCA\\Files\\Activity\\Helper' => __DIR__ . '/..' . '/../lib/Activity/Helper.php',
'OCA\\Files\\Activity\\Provider' => __DIR__ . '/..' . '/../lib/Activity/Provider.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\\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\\FileChanged' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileChanged.php',
'OCA\\Files\\Activity\\Settings\\FileCreated' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileCreated.php', 'OCA\\Files\\Activity\\Settings\\FileCreated' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileCreated.php',
'OCA\\Files\\Activity\\Settings\\FileDeleted' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileDeleted.php', 'OCA\\Files\\Activity\\Settings\\FileDeleted' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileDeleted.php',

View File

@ -23,21 +23,7 @@
namespace OCA\Files\Activity\Settings; namespace OCA\Files\Activity\Settings;
use OCP\Activity\ISetting; class FavoriteAction extends FileActivitySettings {
use OCP\IL10N;
class FavoriteAction implements ISetting {
/** @var IL10N */
protected $l;
/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}
/** /**
* @return string Lowercase a-z and underscore only identifier * @return string Lowercase a-z and underscore only identifier
* @since 11.0.0 * @since 11.0.0

View File

@ -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');
}
}

View File

@ -23,21 +23,7 @@
namespace OCA\Files\Activity\Settings; namespace OCA\Files\Activity\Settings;
use OCP\Activity\ISetting; class FileChanged extends FileActivitySettings {
use OCP\IL10N;
class FileChanged implements ISetting {
/** @var IL10N */
protected $l;
/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}
/** /**
* @return string Lowercase a-z and underscore only identifier * @return string Lowercase a-z and underscore only identifier
* @since 11.0.0 * @since 11.0.0

View File

@ -23,21 +23,7 @@
namespace OCA\Files\Activity\Settings; namespace OCA\Files\Activity\Settings;
use OCP\Activity\ISetting; class FileCreated extends FileActivitySettings {
use OCP\IL10N;
class FileCreated implements ISetting {
/** @var IL10N */
protected $l;
/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}
/** /**
* @return string Lowercase a-z and underscore only identifier * @return string Lowercase a-z and underscore only identifier
* @since 11.0.0 * @since 11.0.0

View File

@ -23,21 +23,7 @@
namespace OCA\Files\Activity\Settings; namespace OCA\Files\Activity\Settings;
use OCP\Activity\ISetting; class FileDeleted extends FileActivitySettings {
use OCP\IL10N;
class FileDeleted implements ISetting {
/** @var IL10N */
protected $l;
/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}
/** /**
* @return string Lowercase a-z and underscore only identifier * @return string Lowercase a-z and underscore only identifier
* @since 11.0.0 * @since 11.0.0

View File

@ -23,21 +23,7 @@
namespace OCA\Files\Activity\Settings; namespace OCA\Files\Activity\Settings;
use OCP\Activity\ISetting; class FileFavorite extends FileActivitySettings {
use OCP\IL10N;
class FileFavorite implements ISetting {
/** @var IL10N */
protected $l;
/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}
/** /**
* @return string Lowercase a-z and underscore only identifier * @return string Lowercase a-z and underscore only identifier
* @since 11.0.0 * @since 11.0.0

View File

@ -23,21 +23,7 @@
namespace OCA\Files\Activity\Settings; namespace OCA\Files\Activity\Settings;
use OCP\Activity\ISetting; class FileRestored extends FileActivitySettings {
use OCP\IL10N;
class FileRestored implements ISetting {
/** @var IL10N */
protected $l;
/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}
/** /**
* @return string Lowercase a-z and underscore only identifier * @return string Lowercase a-z and underscore only identifier
* @since 11.0.0 * @since 11.0.0

View File

@ -25,6 +25,7 @@ namespace OC\Activity;
use OCP\Activity\ActivitySettings; use OCP\Activity\ActivitySettings;
use OCP\Activity\ISetting; use OCP\Activity\ISetting;
use OCP\IL10N;
/** /**
* Adapt the old interface based settings into the new abstract * Adapt the old interface based settings into the new abstract
@ -32,9 +33,11 @@ use OCP\Activity\ISetting;
*/ */
class ActivitySettingsAdapter extends ActivitySettings { class ActivitySettingsAdapter extends ActivitySettings {
private $oldSettings; private $oldSettings;
private $l10n;
public function __construct(ISetting $oldSettings) { public function __construct(ISetting $oldSettings, IL10N $l10n) {
$this->oldSettings = $oldSettings; $this->oldSettings = $oldSettings;
$this->l10n = $l10n;
} }
public function getIdentifier() { public function getIdentifier() {
@ -45,6 +48,14 @@ class ActivitySettingsAdapter extends ActivitySettings {
return $this->oldSettings->getName(); return $this->oldSettings->getName();
} }
public function getGroupIdentifier() {
return 'other';
}
public function getGroupName() {
return $this->l10n->t('Other activities');
}
public function getPriority() { public function getPriority() {
return $this->oldSettings->getPriority(); return $this->oldSettings->getPriority();
} }

View File

@ -36,6 +36,7 @@ use OCP\Activity\IManager;
use OCP\Activity\IProvider; use OCP\Activity\IProvider;
use OCP\Activity\ISetting; use OCP\Activity\ISetting;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
@ -66,14 +67,20 @@ class Manager implements IManager {
/** @var string */ /** @var string */
protected $currentUserId; protected $currentUserId;
public function __construct(IRequest $request, protected $l10n;
public function __construct(
IRequest $request,
IUserSession $session, IUserSession $session,
IConfig $config, IConfig $config,
IValidator $validator) { IValidator $validator,
IL10N $l10n
) {
$this->request = $request; $this->request = $request;
$this->session = $session; $this->session = $session;
$this->config = $config; $this->config = $config;
$this->validator = $validator; $this->validator = $validator;
$this->l10n = $l10n;
} }
/** @var \Closure[] */ /** @var \Closure[] */
@ -273,7 +280,7 @@ class Manager implements IManager {
if ($setting instanceof ISetting) { if ($setting instanceof ISetting) {
if (!$setting instanceof ActivitySettings) { if (!$setting instanceof ActivitySettings) {
$setting = new ActivitySettingsAdapter($setting); $setting = new ActivitySettingsAdapter($setting, $this->l10n);
} }
} else { } else {
throw new \InvalidArgumentException('Invalid activity filter registered'); throw new \InvalidArgumentException('Invalid activity filter registered');

View File

@ -695,11 +695,13 @@ class Server extends ServerContainer implements IServerContainer {
}); });
$this->registerService(\OCP\Activity\IManager::class, function (Server $c) { $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
$l10n = $this->get(IFactory::class)->get('activity');
return new \OC\Activity\Manager( return new \OC\Activity\Manager(
$c->getRequest(), $c->getRequest(),
$c->getUserSession(), $c->getUserSession(),
$c->getConfig(), $c->getConfig(),
$c->query(IValidator::class) $c->query(IValidator::class),
$l10n
); );
}); });
$this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);

View File

@ -39,6 +39,18 @@ abstract class ActivitySettings implements ISetting {
*/ */
abstract public function getName(); 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 * @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 * the admin section. The filters are arranged in ascending order of the

View File

@ -56,7 +56,8 @@ class ManagerTest extends TestCase {
$this->request, $this->request,
$this->session, $this->session,
$this->config, $this->config,
$this->validator $this->validator,
$this->createMock(IL10N::class)
); );
$this->assertSame([], self::invokePrivate($this->activityManager, 'getConsumers')); $this->assertSame([], self::invokePrivate($this->activityManager, 'getConsumers'));