From 03df1b4c51d8a02613a81e9ac9da1fc91ce66623 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 28 Jan 2020 12:38:11 +0100 Subject: [PATCH] Move admin sections to settings app Signed-off-by: Roeland Jago Douma --- apps/settings/appinfo/info.xml | 6 ++ .../composer/composer/autoload_classmap.php | 6 ++ .../composer/composer/autoload_static.php | 6 ++ .../lib/Sections/Admin/Additional.php | 59 +++++++++++++ .../settings/lib/Sections/Admin/Groupware.php | 59 +++++++++++++ apps/settings/lib/Sections/Admin/Overview.php | 59 +++++++++++++ apps/settings/lib/Sections/Admin/Security.php | 59 +++++++++++++ apps/settings/lib/Sections/Admin/Server.php | 59 +++++++++++++ apps/settings/lib/Sections/Admin/Sharing.php | 59 +++++++++++++ lib/private/Settings/Manager.php | 13 +-- tests/lib/Settings/ManagerTest.php | 87 +------------------ 11 files changed, 374 insertions(+), 98 deletions(-) create mode 100644 apps/settings/lib/Sections/Admin/Additional.php create mode 100644 apps/settings/lib/Sections/Admin/Groupware.php create mode 100644 apps/settings/lib/Sections/Admin/Overview.php create mode 100644 apps/settings/lib/Sections/Admin/Security.php create mode 100644 apps/settings/lib/Sections/Admin/Server.php create mode 100644 apps/settings/lib/Sections/Admin/Sharing.php diff --git a/apps/settings/appinfo/info.xml b/apps/settings/appinfo/info.xml index d774988f4a..61bfe454ca 100644 --- a/apps/settings/appinfo/info.xml +++ b/apps/settings/appinfo/info.xml @@ -18,6 +18,12 @@ + OCA\Settings\Sections\Admin\Additional + OCA\Settings\Sections\Admin\Groupware + OCA\Settings\Sections\Admin\Overview + OCA\Settings\Sections\Admin\Security + OCA\Settings\Sections\Admin\Server + OCA\Settings\Sections\Admin\Sharing OCA\Settings\Sections\Personal\PersonalInfo OCA\Settings\Sections\Personal\Security OCA\Settings\Sections\Personal\SyncClients diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index ac7bd9577e..52c4f4de47 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -41,6 +41,12 @@ return array( 'OCA\\Settings\\Personal\\Security' => $baseDir . '/../lib/Settings/Personal/Security.php', 'OCA\\Settings\\Personal\\Security\\Authtokens' => $baseDir . '/../lib/Settings/Personal/Security/Authtokens.php', 'OCA\\Settings\\Personal\\ServerDevNotice' => $baseDir . '/../lib/Settings/Personal/ServerDevNotice.php', + 'OCA\\Settings\\Sections\\Admin\\Additional' => $baseDir . '/../lib/Sections/Admin/Additional.php', + 'OCA\\Settings\\Sections\\Admin\\Groupware' => $baseDir . '/../lib/Sections/Admin/Groupware.php', + 'OCA\\Settings\\Sections\\Admin\\Overview' => $baseDir . '/../lib/Sections/Admin/Overview.php', + 'OCA\\Settings\\Sections\\Admin\\Security' => $baseDir . '/../lib/Sections/Admin/Security.php', + 'OCA\\Settings\\Sections\\Admin\\Server' => $baseDir . '/../lib/Sections/Admin/Server.php', + 'OCA\\Settings\\Sections\\Admin\\Sharing' => $baseDir . '/../lib/Sections/Admin/Sharing.php', 'OCA\\Settings\\Sections\\Personal\\PersonalInfo' => $baseDir . '/../lib/Sections/Personal/PersonalInfo.php', 'OCA\\Settings\\Sections\\Personal\\Security' => $baseDir . '/../lib/Sections/Personal/Security.php', 'OCA\\Settings\\Sections\\Personal\\SyncClients' => $baseDir . '/../lib/Sections/Personal/SyncClients.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index 36ae0f3a5d..3c81d42c97 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -56,6 +56,12 @@ class ComposerStaticInitSettings 'OCA\\Settings\\Personal\\Security' => __DIR__ . '/..' . '/../lib/Settings/Personal/Security.php', 'OCA\\Settings\\Personal\\Security\\Authtokens' => __DIR__ . '/..' . '/../lib/Settings/Personal/Security/Authtokens.php', 'OCA\\Settings\\Personal\\ServerDevNotice' => __DIR__ . '/..' . '/../lib/Settings/Personal/ServerDevNotice.php', + 'OCA\\Settings\\Sections\\Admin\\Additional' => __DIR__ . '/..' . '/../lib/Sections/Admin/Additional.php', + 'OCA\\Settings\\Sections\\Admin\\Groupware' => __DIR__ . '/..' . '/../lib/Sections/Admin/Groupware.php', + 'OCA\\Settings\\Sections\\Admin\\Overview' => __DIR__ . '/..' . '/../lib/Sections/Admin/Overview.php', + 'OCA\\Settings\\Sections\\Admin\\Security' => __DIR__ . '/..' . '/../lib/Sections/Admin/Security.php', + 'OCA\\Settings\\Sections\\Admin\\Server' => __DIR__ . '/..' . '/../lib/Sections/Admin/Server.php', + 'OCA\\Settings\\Sections\\Admin\\Sharing' => __DIR__ . '/..' . '/../lib/Sections/Admin/Sharing.php', 'OCA\\Settings\\Sections\\Personal\\PersonalInfo' => __DIR__ . '/..' . '/../lib/Sections/Personal/PersonalInfo.php', 'OCA\\Settings\\Sections\\Personal\\Security' => __DIR__ . '/..' . '/../lib/Sections/Personal/Security.php', 'OCA\\Settings\\Sections\\Personal\\SyncClients' => __DIR__ . '/..' . '/../lib/Sections/Personal/SyncClients.php', diff --git a/apps/settings/lib/Sections/Admin/Additional.php b/apps/settings/lib/Sections/Admin/Additional.php new file mode 100644 index 0000000000..ebe9297572 --- /dev/null +++ b/apps/settings/lib/Sections/Admin/Additional.php @@ -0,0 +1,59 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCA\Settings\Sections\Admin; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class Additional implements IIconSection { + + /** @var IL10N */ + private $l; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IL10N $l, IURLGenerator $urlGenerator) { + $this->l = $l; + $this->urlGenerator = $urlGenerator; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('core', 'actions/settings-dark.svg'); + } + + public function getID(): string { + return 'additional'; + } + + public function getName(): string { + return $this->l->t('Additional settings'); + } + + public function getPriority(): int { + return 98; + } +} diff --git a/apps/settings/lib/Sections/Admin/Groupware.php b/apps/settings/lib/Sections/Admin/Groupware.php new file mode 100644 index 0000000000..5f26b00304 --- /dev/null +++ b/apps/settings/lib/Sections/Admin/Groupware.php @@ -0,0 +1,59 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCA\Settings\Sections\Admin; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class Groupware implements IIconSection { + + /** @var IL10N */ + private $l; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IL10N $l, IURLGenerator $urlGenerator) { + $this->l = $l; + $this->urlGenerator = $urlGenerator; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('core', 'places/contacts.svg'); + } + + public function getID(): string { + return 'groupware'; + } + + public function getName(): string { + return $this->l->t('Groupware'); + } + + public function getPriority(): int { + return 50; + } +} diff --git a/apps/settings/lib/Sections/Admin/Overview.php b/apps/settings/lib/Sections/Admin/Overview.php new file mode 100644 index 0000000000..c5dd8174c8 --- /dev/null +++ b/apps/settings/lib/Sections/Admin/Overview.php @@ -0,0 +1,59 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCA\Settings\Sections\Admin; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class Overview implements IIconSection { + + /** @var IL10N */ + private $l; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IL10N $l, IURLGenerator $urlGenerator) { + $this->l = $l; + $this->urlGenerator = $urlGenerator; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('settings', 'admin.svg'); + } + + public function getID(): string { + return 'overview'; + } + + public function getName(): string { + return $this->l->t('Overview'); + } + + public function getPriority(): int { + return 0; + } +} diff --git a/apps/settings/lib/Sections/Admin/Security.php b/apps/settings/lib/Sections/Admin/Security.php new file mode 100644 index 0000000000..e674d6f045 --- /dev/null +++ b/apps/settings/lib/Sections/Admin/Security.php @@ -0,0 +1,59 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCA\Settings\Sections\Admin; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class Security implements IIconSection { + + /** @var IL10N */ + private $l; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IL10N $l, IURLGenerator $urlGenerator) { + $this->l = $l; + $this->urlGenerator = $urlGenerator; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('core', 'actions/password.svg'); + } + + public function getID(): string { + return 'security'; + } + + public function getName(): string { + return $this->l->t('Security'); + } + + public function getPriority(): int { + return 10; + } +} diff --git a/apps/settings/lib/Sections/Admin/Server.php b/apps/settings/lib/Sections/Admin/Server.php new file mode 100644 index 0000000000..d30f0a8132 --- /dev/null +++ b/apps/settings/lib/Sections/Admin/Server.php @@ -0,0 +1,59 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCA\Settings\Sections\Admin; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class Server implements IIconSection { + + /** @var IL10N */ + private $l; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IL10N $l, IURLGenerator $urlGenerator) { + $this->l = $l; + $this->urlGenerator = $urlGenerator; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('core', 'actions/settings-dark.svg'); + } + + public function getID(): string { + return 'server'; + } + + public function getName(): string { + return $this->l->t('Basic settings'); + } + + public function getPriority(): int { + return 1; + } +} diff --git a/apps/settings/lib/Sections/Admin/Sharing.php b/apps/settings/lib/Sections/Admin/Sharing.php new file mode 100644 index 0000000000..0eeb95c87d --- /dev/null +++ b/apps/settings/lib/Sections/Admin/Sharing.php @@ -0,0 +1,59 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCA\Settings\Sections\Admin; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class Sharing implements IIconSection { + + /** @var IL10N */ + private $l; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IL10N $l, IURLGenerator $urlGenerator) { + $this->l = $l; + $this->urlGenerator = $urlGenerator; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('core', 'actions/share.svg'); + } + + public function getID(): string { + return 'sharing'; + } + + public function getName(): string { + return $this->l->t('Sharing'); + } + + public function getPriority(): int { + return 5; + } +} diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 46a047e53c..87ef74aaba 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -208,19 +208,8 @@ class Manager implements IManager { * @inheritdoc */ public function getAdminSections(): array { - if ($this->l === null) { - $this->l = $this->l10nFactory->get('lib'); - } - // built-in sections - $sections = [ - 0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))], - 1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], - 50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))], - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], - ]; + $sections = []; $appSections = $this->getSections('admin'); diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 2ba3b2e7b5..3980990c7b 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -69,51 +69,14 @@ class ManagerTest extends TestCase { } public function testGetAdminSections() { - $this->l10nFactory - ->expects($this->once()) - ->method('get') - ->with('lib') - ->willReturn($this->l10n); - $this->l10n - ->expects($this->any()) - ->method('t') - ->will($this->returnArgument(0)); - $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); - $this->url->expects($this->exactly(6)) - ->method('imagePath') - ->willReturnMap([ - ['settings', 'admin.svg', '0'], - ['core', 'actions/settings-dark.svg', '1'], - ['core', 'actions/share.svg', '2'], - ['core', 'actions/password.svg', '3'], - ['core', 'places/contacts.svg', '5'], - ['settings', 'help.svg', '4'], - ]); - $this->assertEquals([ - 0 => [new Section('overview', 'Overview', 0, '0')], - 1 => [new Section('server', 'Basic settings', 0, '1')], - 5 => [new Section('sharing', 'Sharing', 0, '2')], - 10 => [new Section('security', 'Security', 0, '3')], - 50 => [new Section('groupware', 'Groupware', 0, '5')], 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], - 98 => [new Section('additional', 'Additional settings', 0, '1')], ], $this->manager->getAdminSections()); } public function testGetPersonalSections() { - $this->l10nFactory - ->expects($this->once()) - ->method('get') - ->with('lib') - ->willReturn($this->l10n); - $this->l10n - ->expects($this->any()) - ->method('t') - ->will($this->returnArgument(0)); - $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); $this->assertEquals([ @@ -122,35 +85,7 @@ class ManagerTest extends TestCase { } public function testGetAdminSectionsEmptySection() { - $this->l10nFactory - ->expects($this->once()) - ->method('get') - ->with('lib') - ->willReturn($this->l10n); - $this->l10n - ->expects($this->any()) - ->method('t') - ->will($this->returnArgument(0)); - - $this->url->expects($this->exactly(6)) - ->method('imagePath') - ->willReturnMap([ - ['settings', 'admin.svg', '0'], - ['core', 'actions/settings-dark.svg', '1'], - ['core', 'actions/share.svg', '2'], - ['core', 'actions/password.svg', '3'], - ['core', 'places/contacts.svg', '5'], - ['settings', 'help.svg', '4'], - ]); - - $this->assertEquals([ - 0 => [new Section('overview', 'Overview', 0, '0')], - 1 => [new Section('server', 'Basic settings', 0, '1')], - 5 => [new Section('sharing', 'Sharing', 0, '2')], - 10 => [new Section('security', 'Security', 0, '3')], - 50 => [new Section('groupware', 'Groupware', 0, '5')], - 98 => [new Section('additional', 'Additional settings', 0, '1')], - ], $this->manager->getAdminSections()); + $this->assertEquals([], $this->manager->getAdminSections()); } public function testGetPersonalSectionsEmptySection() { @@ -253,32 +188,12 @@ class ManagerTest extends TestCase { $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); - $this->url->expects($this->exactly(6)) - ->method('imagePath') - ->willReturnMap([ - ['core', 'actions/user.svg', '1'], - ['settings', 'password.svg', '2'], - ['core', 'clients/phone.svg', '3'], - ['settings', 'admin.svg', '0'], - ['core', 'actions/settings-dark.svg', '1'], - ['core', 'actions/share.svg', '2'], - ['core', 'actions/password.svg', '3'], - ['core', 'places/contacts.svg', '5'], - ['settings', 'help.svg', '4'], - ]); - $this->assertEquals([ 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], ], $this->manager->getPersonalSections()); $this->assertEquals([ - 0 => [new Section('overview', 'Overview', 0, '0')], - 1 => [new Section('server', 'Basic settings', 0, '1')], - 5 => [new Section('sharing', 'Sharing', 0, '2')], - 10 => [new Section('security', 'Security', 0, '3')], - 50 => [new Section('groupware', 'Groupware', 0, '5')], 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], - 98 => [new Section('additional', 'Additional settings', 0, '1')], ], $this->manager->getAdminSections()); } }