diff --git a/apps/settings/composer/composer/installed.php b/apps/settings/composer/composer/installed.php index 1a66c7f2416b6..230e2aa13ab57 100644 --- a/apps/settings/composer/composer/installed.php +++ b/apps/settings/composer/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'b1797842784b250fb01ed5e3bf130705eb94751b', + 'reference' => '1b774d74ea236e5c276211ee4916484f931eedba', 'type' => 'library', 'install_path' => __DIR__ . '/../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'b1797842784b250fb01ed5e3bf130705eb94751b', + 'reference' => '1b774d74ea236e5c276211ee4916484f931eedba', 'type' => 'library', 'install_path' => __DIR__ . '/../', 'aliases' => array(), diff --git a/apps/settings/lib/Controller/AdminSettingsController.php b/apps/settings/lib/Controller/AdminSettingsController.php index 2e5d2fce953b1..acb6d79fda459 100644 --- a/apps/settings/lib/Controller/AdminSettingsController.php +++ b/apps/settings/lib/Controller/AdminSettingsController.php @@ -7,6 +7,7 @@ * @author Lukas Reschke * @author Robin Appelman * @author Kate Döen + * @author Private Maker * * @license GNU AGPL version 3 or any later version * @@ -68,7 +69,7 @@ public function __construct( * settings for the given section. The user will be gretted by an error message. */ public function index(string $section): TemplateResponse { - return $this->getIndexResponse('admin', $section); + return $this->getAdminResponse($section); } /** diff --git a/apps/settings/lib/Controller/CommonSettingsTrait.php b/apps/settings/lib/Controller/CommonSettingsTrait.php index 8ca62b9d1b3a6..5fcec824ac853 100644 --- a/apps/settings/lib/Controller/CommonSettingsTrait.php +++ b/apps/settings/lib/Controller/CommonSettingsTrait.php @@ -9,6 +9,7 @@ * @author Morris Jobke * @author Robin Appelman * @author Roeland Jago Douma + * @author Private Maker * * @license GNU AGPL version 3 or any later version * @@ -133,28 +134,41 @@ private function formatSettings(array $settings): array { return ['content' => $html]; } - private function getIndexResponse(string $type, string $section): TemplateResponse { - if ($type === 'personal') { - if ($section === 'theming') { - $this->navigationManager->setActiveEntry('accessibility_settings'); - } else { - $this->navigationManager->setActiveEntry('settings'); - } - } elseif ($type === 'admin') { - $this->navigationManager->setActiveEntry('admin_settings'); + private function getPersonalResponse(string $section): TemplateResponse { + $templateParams = []; + $templateParams = array_merge($templateParams, $this->getNavigationParameters('personal', $section)); + $templateParams = array_merge($templateParams, $this->getSettings($section)); + $activeSection = $this->settingsManager->getSection('personal', $section); + + if ($activeSection) { + $templateParams['pageTitle'] = $activeSection->getName(); + $templateParams['activeSectionId'] = $activeSection->getID(); } - $templateParams = []; - $templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section)); + if ($section === 'theming') { + $this->navigationManager->setActiveEntry('accessibility_settings'); + } else { + $this->navigationManager->setActiveEntry('settings'); + } + + return new TemplateResponse('settings', 'settings/personal', $templateParams); + } + + private function getAdminResponse(string $section): TemplateResponse { + $templateParams = []; + $templateParams = array_merge($templateParams, $this->getNavigationParameters('admin', $section)); $templateParams = array_merge($templateParams, $this->getSettings($section)); - $activeSection = $this->settingsManager->getSection($type, $section); - if ($activeSection) { + $activeSection = $this->settingsManager->getSection('admin', $section); + + if ($activeSection) { $templateParams['pageTitle'] = $activeSection->getName(); $templateParams['activeSectionId'] = $activeSection->getID(); - } + } - return new TemplateResponse('settings', 'settings/frame', $templateParams); - } + $this->navigationManager->setActiveEntry('admin_settings'); + + return new TemplateResponse('settings', 'settings/admin', $templateParams); + } abstract protected function getSettings($section); } diff --git a/apps/settings/lib/Controller/PersonalSettingsController.php b/apps/settings/lib/Controller/PersonalSettingsController.php index 09340117610c6..5bdb05ba653db 100644 --- a/apps/settings/lib/Controller/PersonalSettingsController.php +++ b/apps/settings/lib/Controller/PersonalSettingsController.php @@ -7,6 +7,7 @@ * @author Joas Schilling * @author Robin Appelman * @author Kate Döen + * @author Private Maker * * @license GNU AGPL version 3 or any later version * @@ -47,15 +48,11 @@ public function __construct( INavigationManager $navigationManager, ISettingsManager $settingsManager, IUserSession $userSession, - IGroupManager $groupManager, - ISubAdmin $subAdmin ) { parent::__construct($appName, $request); $this->navigationManager = $navigationManager; $this->settingsManager = $settingsManager; $this->userSession = $userSession; - $this->subAdmin = $subAdmin; - $this->groupManager = $groupManager; } /** @@ -64,7 +61,7 @@ public function __construct( * @NoSubAdminRequired */ public function index(string $section): TemplateResponse { - return $this->getIndexResponse('personal', $section); + return $this->getPersonalResponse($section); } /** diff --git a/apps/settings/templates/settings/admin.php b/apps/settings/templates/settings/admin.php new file mode 100644 index 0000000000000..22e60b2343c2b --- /dev/null +++ b/apps/settings/templates/settings/admin.php @@ -0,0 +1,59 @@ + + * + * @author Arthur Schiwon + * @author Private Maker + * + * @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 . + * + */ + +use OCP\IURLGenerator; + +style('settings', 'settings'); +script('settings', 'settings'); +\OCP\Util::addScript('settings', 'legacy-admin'); +script('core', 'setupchecks'); +script('files', 'jquery.fileupload'); +?> + + +
+ +
diff --git a/apps/settings/templates/settings/frame.php b/apps/settings/templates/settings/personal.php similarity index 62% rename from apps/settings/templates/settings/frame.php rename to apps/settings/templates/settings/personal.php index b2b2f04ebe0f2..5d9ed017f2118 100644 --- a/apps/settings/templates/settings/frame.php +++ b/apps/settings/templates/settings/personal.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016 Arthur Schiwon * * @author Arthur Schiwon + * @author Private Maker * * @license GNU AGPL version 3 or any later version * @@ -26,17 +27,13 @@ \OCP\Util::addScript('settings', 'legacy-admin'); script('core', 'setupchecks'); script('files', 'jquery.fileupload'); - ?>
diff --git a/apps/settings/tests/Controller/AdminSettingsControllerTest.php b/apps/settings/tests/Controller/AdminSettingsControllerTest.php index acdcaa136aadc..b6d201f828359 100644 --- a/apps/settings/tests/Controller/AdminSettingsControllerTest.php +++ b/apps/settings/tests/Controller/AdminSettingsControllerTest.php @@ -27,7 +27,6 @@ namespace OCA\Settings\Tests\Controller; use OCA\Settings\Controller\AdminSettingsController; -use OCA\Settings\Settings\Personal\ServerDevNotice; use OCP\AppFramework\Http\TemplateResponse; use OCP\Group\ISubAdmin; use OCP\IGroupManager; @@ -126,8 +125,8 @@ public function testIndex() { $idx = $this->adminSettingsController->index('test'); - $expected = new TemplateResponse('settings', 'settings/frame', [ - 'forms' => ['personal' => [], 'admin' => []], + $expected = new TemplateResponse('settings', 'settings/admin', [ + 'forms' => ['admin' => []], 'content' => '' ]); $this->assertEquals($expected, $idx); diff --git a/apps/settings/tests/Controller/PersonalSettingsControllerTest.php b/apps/settings/tests/Controller/PersonalSettingsControllerTest.php new file mode 100644 index 0000000000000..874c916c99b6f --- /dev/null +++ b/apps/settings/tests/Controller/PersonalSettingsControllerTest.php @@ -0,0 +1,110 @@ + + * + * @author Arthur Schiwon + * @author Christoph Wurst + * @author Jan C. Borchardt + * @author Lukas Reschke + * @author Roeland Jago Douma + * @author Private Maker + * + * @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\Tests\Controller; + +use OCA\Settings\Controller\PersonalSettingsController; +use OCA\Settings\Settings\Personal\ServerDevNotice; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Group\ISubAdmin; +use OCP\IGroupManager; +use OCP\INavigationManager; +use OCP\IRequest; +use OCP\IUser; +use OCP\IUserSession; +use OCP\Settings\IManager; +use PHPUnit\Framework\MockObject\MockObject; +use Test\TestCase; + +/** + * Class PersonalSettingsControllerTest + * + * @group DB + * + * @package Tests\Settings\Controller + */ +class PersonalSettingsControllerTest extends TestCase { + + /** @var PersonalSettingsController */ + private $personalSettingsController; + /** @var IRequest|MockObject */ + private $request; + /** @var INavigationManager|MockObject */ + private $navigationManager; + /** @var IManager|MockObject */ + private $settingsManager; + /** @var IUserSession|MockObject */ + private $userSession; + /** @var IGroupManager|MockObject */ + + protected function setUp(): void { + parent::setUp(); + + $this->request = $this->createMock(IRequest::class); + $this->navigationManager = $this->createMock(INavigationManager::class); + $this->settingsManager = $this->createMock(IManager::class); + $this->userSession = $this->createMock(IUserSession::class); + + $this->personalSettingsController = new PersonalSettingsController( + 'settings', + $this->request, + $this->navigationManager, + $this->settingsManager, + $this->userSession, + ); + + $user = \OC::$server->getUserManager()->createUser($this->adminUid, 'mylongrandompassword'); + \OC_User::setUserId($user->getUID()); + // \OC::$server->getGroupManager()->createGroup('admin')->addUser($user); + } + + protected function tearDown(): void { + // \OC::$server->getUserManager()->get($this->adminUid)->delete(); + + parent::tearDown(); + } + + public function testIndex() { + $user = $this->createMock(IUser::class); + $this->userSession + ->method('getUser') + ->willReturn($user); + $user->method('getUID')->willReturn('user123'); + $this->settingsManager + ->expects($this->once()) + ->method('getPersonalSections') + ->willReturn([]); + + $idx = $this->personalSettingsController->index('test'); + + $expected = new TemplateResponse('settings', 'settings/personal', [ + 'forms' => ['personal' => []], + 'content' => '' + ]); + $this->assertEquals($expected, $idx); + } +}