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

Conversation

privatemaker
Copy link
Contributor

This is my first PHP contribution to Nextcloud, as far as I can tell no tests were required, but if so please advise further. If accepted, this resolves #40490

Summary

I created the following new methods in CommonSettingsTrait.php

  • getPersonalResponse()
  • getAdminResponse()

I think this is better than conditionals in getIndexResponse as it is more locked down (no trailing elseif) and makes room for future adjustments respective to only Personal or Admin areas. This comes at the expense of being slightly less DRY of repeated lines.

Checklist

resolves nextcloud#40490

Signed-off-by: Private Maker <privatemaker@posteo.net>
@privatemaker privatemaker self-assigned this Sep 20, 2023
@provokateurin provokateurin removed their request for review September 20, 2023 19:19
Copy link
Contributor

@szaimen szaimen left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the contribution! Tested and works great! :)

Copy link
Member

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

Please fix the indents issues. I see spaces and wrong indents ;)

Copy link
Contributor

@kesselb kesselb left a comment

Choose a reason for hiding this comment

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

@@ -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

@@ -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.

foreach ($_['forms']['personal'] as $form) {
if (isset($form['anchor'])) {
<li class="app-navigation-caption"><?php p($l->t('Personal')); ?></li>
<?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.

?>

<?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.

$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);

@JuliaKirschenheuter
Copy link
Contributor

JuliaKirschenheuter commented Sep 29, 2023

Please adapt your changes to two independent nav's https://github.com/nextcloud/server/pull/40576/files
Thank you!

@skjnldsv skjnldsv mentioned this pull request Nov 1, 2023
This was referenced Nov 6, 2023
This was referenced Nov 14, 2023
@blizzz blizzz modified the milestones: Nextcloud 28, Nextcloud 29 Nov 23, 2023
This was referenced Mar 12, 2024
This was referenced Mar 20, 2024
@skjnldsv skjnldsv mentioned this pull request Mar 28, 2024
81 tasks
@skjnldsv skjnldsv modified the milestones: Nextcloud 29, Nextcloud 30 Mar 28, 2024
@skjnldsv skjnldsv added 2. developing Work in progress stale Ticket or PR with no recent activity and removed 3. to review Waiting for reviews labels Jul 27, 2024
This was referenced Jul 30, 2024
@skjnldsv skjnldsv closed this Aug 3, 2024
@skjnldsv skjnldsv removed this from the Nextcloud 30 milestone Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress design Design, UI, UX, etc. enhancement stale Ticket or PR with no recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only show context relevant links (Personal or Administration settings) in sidebar
8 participants