Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Settings of Personal and Admin into own views #40544

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/settings/composer/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'b1797842784b250fb01ed5e3bf130705eb94751b',
'reference' => '1b774d74ea236e5c276211ee4916484f931eedba',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks wrong, please revert.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happens by bash build/autoloader…
It's okay

'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'b1797842784b250fb01ed5e3bf130705eb94751b',
'reference' => '1b774d74ea236e5c276211ee4916484f931eedba',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks wrong, please revert.

'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand Down
3 changes: 2 additions & 1 deletion apps/settings/lib/Controller/AdminSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Robin Appelman <robin@icewind.nl>
* @author Kate Döen <kate.doeen@nextcloud.com>
* @author Private Maker <privatemaker@posteo.net>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down
46 changes: 30 additions & 16 deletions apps/settings/lib/Controller/CommonSettingsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Private Maker <privatemaker@posteo.net>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -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);
}
7 changes: 2 additions & 5 deletions apps/settings/lib/Controller/PersonalSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Joas Schilling <coding@schilljs.com>
* @author Robin Appelman <robin@icewind.nl>
* @author Kate Döen <kate.doeen@nextcloud.com>
* @author Private Maker <privatemaker@posteo.net>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -64,7 +61,7 @@ public function __construct(
* @NoSubAdminRequired
*/
public function index(string $section): TemplateResponse {
return $this->getIndexResponse('personal', $section);
return $this->getPersonalResponse($section);
}

/**
Expand Down
59 changes: 59 additions & 0 deletions apps/settings/templates/settings/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Private Maker <privatemaker@posteo.net>
*
* @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/>.
*
*/

use OCP\IURLGenerator;

style('settings', 'settings');
script('settings', 'settings');
\OCP\Util::addScript('settings', 'legacy-admin');
script('core', 'setupchecks');
script('files', 'jquery.fileupload');
?>

<div id="app-navigation" role="navigation">
<ul tabindex="0">
<li class="app-navigation-caption"><?php p($l->t('Administration')); ?></li>
<?php foreach ($_['forms']['admin'] as $form):
if (isset($form['anchor'])):
$urlGenerator = \OC::$server->get(IURLGenerator::class);
$anchor = $urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]);
$class = 'nav-icon-' . $form['anchor'];
$sectionName = $form['section-name']; ?>
<li <?php print_unescaped($form['active'] ? ' class="active"' : ''); ?> data-section-id="<?php print_unescaped($form['anchor']); ?>" data-section-type="admin">
<a href="<?php p($anchor); ?>"<?php print_unescaped($form['active'] ? ' aria-current="page"' : ''); ?>>
<?php if (!empty($form['icon'])) { ?>
<img alt="" src="<?php print_unescaped($form['icon']); ?>">
<span><?php p($form['section-name']); ?></span>
<?php } else { ?>
<span class="no-icon"><?php p($form['section-name']); ?></span>
<?php } ?>
</a>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
</div>
<div id="app-content" tabindex="0" data-active-section-id="<?php print_unescaped($_['activeSectionId']) ?>">
<?php print_unescaped($_['content']); ?>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Private Maker <privatemaker@posteo.net>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -26,17 +27,13 @@
\OCP\Util::addScript('settings', 'legacy-admin');
script('core', 'setupchecks');
script('files', 'jquery.fileupload');

?>

<div id="app-navigation" role="navigation">
<ul tabindex="0">
<?php if (!empty($_['forms']['admin'])) { ?>
<li class="app-navigation-caption"><?php p($l->t('Personal')); ?></li>
<?php
}
foreach ($_['forms']['personal'] as $form) {
if (isset($form['anchor'])) {
<li class="app-navigation-caption"><?php p($l->t('Personal')); ?></li>
privatemaker marked this conversation as resolved.
Show resolved Hide resolved
<?php foreach ($_['forms']['personal'] as $form):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it weird that the underlying logic to render the setting sections is still executed for admin and personal, even if you visit the personal section and vice versa.

if (isset($form['anchor'])):
$anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => $form['anchor']]);
$class = 'nav-icon-' . $form['anchor'];
$sectionName = $form['section-name']; ?>
Expand All @@ -50,36 +47,8 @@
<?php } ?>
</a>
</li>
<?php
}
}
?>

<?php
if (!empty($_['forms']['admin'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admin right privilege / Administration privileges is broken.

It's possible to make some admin sections visible to groups without granting the users full admin rights. That's called Administration privileges (in Nextcloud) / Admin right privilege (in our Documentation).

  1. Create a group subadmin
  2. Add bob to the subadmin group
  3. Visit Admin -> Administration privileges
  4. Assign a group to a section
  5. Login as bob

Main:

image

Bob see the administration section but only one item.

This PR:

image

Bob does not see the administration section.

It's still possible the admin the section if you know the right url, but there is no link somewhere. The menu item "Administration settings" is only added for users with admin permission, but not administration privileges.

Adding a link below "Settings" is a bit tricky for Administration privileges because you need to figure out the internal url for the given section.

?>
<li class="app-navigation-caption"><?php p($l->t('Administration')); ?></li>
<?php
}
foreach ($_['forms']['admin'] as $form) {
if (isset($form['anchor'])) {
$anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]);
$class = 'nav-icon-' . $form['anchor'];
$sectionName = $form['section-name']; ?>
<li <?php print_unescaped($form['active'] ? ' class="active"' : ''); ?> data-section-id="<?php print_unescaped($form['anchor']); ?>" data-section-type="admin">
<a href="<?php p($anchor); ?>"<?php print_unescaped($form['active'] ? ' aria-current="page"' : ''); ?>>
<?php if (!empty($form['icon'])) { ?>
<img alt="" src="<?php print_unescaped($form['icon']); ?>">
<span><?php p($form['section-name']); ?></span>
<?php } else { ?>
<span class="no-icon"><?php p($form['section-name']); ?></span>
<?php } ?>
</a>
</li>
<?php
}
}
?>
<?php endif ?>
<?php endforeach ?>
</ul>
</div>
<div id="app-content" tabindex="0" data-active-section-id="<?php print_unescaped($_['activeSectionId']) ?>">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
110 changes: 110 additions & 0 deletions apps/settings/tests/Controller/PersonalSettingsControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Jan C. Borchardt <hey@jancborchardt.net>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Private Maker <privatemaker@posteo.net>
*
* @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\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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks weird ;)

Adding @group DB says a test needs a database connection.
Afaict the test only works with mocked data and therefore does not require a db.

Index: apps/settings/tests/Controller/PersonalSettingsControllerTest.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/apps/settings/tests/Controller/PersonalSettingsControllerTest.php b/apps/settings/tests/Controller/PersonalSettingsControllerTest.php
--- a/apps/settings/tests/Controller/PersonalSettingsControllerTest.php	(revision bb2353ae4a18e95dc4ca6346ad696c0e371453e5)
+++ b/apps/settings/tests/Controller/PersonalSettingsControllerTest.php	(date 1695568072588)
@@ -40,13 +40,6 @@
 use PHPUnit\Framework\MockObject\MockObject;
 use Test\TestCase;
 
-/**
- * Class PersonalSettingsControllerTest
- *
- * @group DB
- *
- * @package Tests\Settings\Controller
- */
 class PersonalSettingsControllerTest extends TestCase {
 
 	/** @var PersonalSettingsController */
@@ -76,16 +69,6 @@
 			$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() {
@@ -102,7 +85,10 @@
 		$idx = $this->personalSettingsController->index('test');
 
 		$expected = new TemplateResponse('settings', 'settings/personal', [
-			'forms' => ['personal' => []],
+			'forms' => [
+				'personal' => [],
+				'admin' => [],
+			],
 			'content' => ''
 		]);
 		$this->assertEquals($expected, $idx);
Index: apps/settings/tests/Controller/AdminSettingsControllerTest.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/apps/settings/tests/Controller/AdminSettingsControllerTest.php b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
--- a/apps/settings/tests/Controller/AdminSettingsControllerTest.php	(revision bb2353ae4a18e95dc4ca6346ad696c0e371453e5)
+++ b/apps/settings/tests/Controller/AdminSettingsControllerTest.php	(date 1695568055144)
@@ -27,6 +27,7 @@
 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;
@@ -38,13 +39,6 @@
 use PHPUnit\Framework\MockObject\MockObject;
 use Test\TestCase;
 
-/**
- * Class AdminSettingsControllerTest
- *
- * @group DB
- *
- * @package Tests\Settings\Controller
- */
 class AdminSettingsControllerTest extends TestCase {
 
 	/** @var AdminSettingsController */
@@ -62,7 +56,6 @@
 	/** @var ISubAdmin|MockObject */
 	private $subAdmin;
 	/** @var string */
-	private $adminUid = 'lololo';
 
 	protected function setUp(): void {
 		parent::setUp();
@@ -83,16 +76,6 @@
 			$this->groupManager,
 			$this->subAdmin
 		);
-
-		$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() {
@@ -115,10 +98,6 @@
 			->willReturn([]);
 		$this->settingsManager
 			->expects($this->once())
-			->method('getPersonalSections')
-			->willReturn([]);
-		$this->settingsManager
-			->expects($this->once())
 			->method('getAllowedAdminSettings')
 			->with('test')
 			->willReturn([5 => $this->createMock(ServerDevNotice::class)]);
@@ -126,7 +105,10 @@
 		$idx = $this->adminSettingsController->index('test');
 
 		$expected = new TemplateResponse('settings', 'settings/admin', [
-			'forms' => ['admin' => []],
+			'forms' => [
+				'personal' => [],
+				'admin' => [],
+			],
 			'content' => ''
 		]);
 		$this->assertEquals($expected, $idx);

\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);
}
}