summaryrefslogtreecommitdiffstats
path: root/settings/Controller
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-05-22 10:48:51 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-05-23 20:31:40 +0200
commit22ae6828237a516b1cd36a3dad623b8046dfd76a (patch)
treec00361d0747e295f98e1e089114b8bf48bcc0e57 /settings/Controller
parent09974ae92d6f3bc20143dab43baef9fc75139585 (diff)
downloadnextcloud-server-22ae6828237a516b1cd36a3dad623b8046dfd76a.tar.gz
nextcloud-server-22ae6828237a516b1cd36a3dad623b8046dfd76a.zip
Make it possible to show admin settings for sub admins
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'settings/Controller')
-rw-r--r--settings/Controller/AdminSettingsController.php30
-rw-r--r--settings/Controller/CommonSettingsTrait.php34
-rw-r--r--settings/Controller/PersonalSettingsController.php11
3 files changed, 59 insertions, 16 deletions
diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php
index e2ad577024c..e322a2a5354 100644
--- a/settings/Controller/AdminSettingsController.php
+++ b/settings/Controller/AdminSettingsController.php
@@ -27,8 +27,12 @@ namespace OC\Settings\Controller;
use OCP\AppFramework\Controller;
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 as ISettingsManager;
use OCP\Template;
@@ -38,21 +42,21 @@ use OCP\Template;
class AdminSettingsController extends Controller {
use CommonSettingsTrait;
- /**
- * @param string $appName
- * @param IRequest $request
- * @param INavigationManager $navigationManager
- * @param ISettingsManager $settingsManager
- */
public function __construct(
$appName,
IRequest $request,
INavigationManager $navigationManager,
- ISettingsManager $settingsManager
+ ISettingsManager $settingsManager,
+ IUserSession $userSession,
+ IGroupManager $groupManager,
+ ISubAdmin $subAdmin
) {
parent::__construct($appName, $request);
$this->navigationManager = $navigationManager;
$this->settingsManager = $settingsManager;
+ $this->userSession = $userSession;
+ $this->groupManager = $groupManager;
+ $this->subAdmin = $subAdmin;
}
/**
@@ -60,6 +64,7 @@ class AdminSettingsController extends Controller {
* @return TemplateResponse
*
* @NoCSRFRequired
+ * @SubAdminRequired
*/
public function index($section) {
return $this->getIndexResponse('admin', $section);
@@ -70,9 +75,16 @@ class AdminSettingsController extends Controller {
* @return array
*/
protected function getSettings($section) {
- $settings = $this->settingsManager->getAdminSettings($section);
+ /** @var IUser $user */
+ $user = $this->userSession->getUser();
+ $isSubAdmin = !$this->groupManager->isAdmin($user->getUID()) && $this->subAdmin->isSubAdmin($user);
+ $settings = $this->settingsManager->getAdminSettings(
+ $section,
+ $isSubAdmin
+ );
$formatted = $this->formatSettings($settings);
- if($section === 'additional') {
+ // Do not show legacy forms for sub admins
+ if($section === 'additional' && !$isSubAdmin) {
$formatted['content'] .= $this->getLegacyForms();
}
return $formatted;
diff --git a/settings/Controller/CommonSettingsTrait.php b/settings/Controller/CommonSettingsTrait.php
index 10fc0d84bbd..1844dda551e 100644
--- a/settings/Controller/CommonSettingsTrait.php
+++ b/settings/Controller/CommonSettingsTrait.php
@@ -25,18 +25,32 @@
namespace OC\Settings\Controller;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Group\ISubAdmin;
+use OCP\IGroupManager;
use OCP\INavigationManager;
+use OCP\IUser;
+use OCP\IUserSession;
use OCP\Settings\IManager as ISettingsManager;
use OCP\Settings\IIconSection;
use OCP\Settings\ISettings;
trait CommonSettingsTrait {
+
/** @var ISettingsManager */
private $settingsManager;
/** @var INavigationManager */
private $navigationManager;
+ /** @var IUserSession */
+ private $userSession;
+
+ /** @var IGroupManager */
+ private $groupManager;
+
+ /** @var ISubAdmin */
+ private $subAdmin;
+
/**
* @param string $currentSection
* @return array
@@ -47,8 +61,16 @@ trait CommonSettingsTrait {
'admin' => []
];
- if(\OC_User::isAdminUser(\OC_User::getUser())) {
- $templateParameters['admin'] = $this->formatAdminSections($currentType, $currentSection);
+ /** @var IUser $user */
+ $user = $this->userSession->getUser();
+ $isAdmin = $this->groupManager->isAdmin($user->getUID());
+ $isSubAdmin = $this->subAdmin->isSubAdmin($user);
+ if ($isAdmin || $isSubAdmin) {
+ $templateParameters['admin'] = $this->formatAdminSections(
+ $currentType,
+ $currentSection,
+ !$isAdmin && $isSubAdmin
+ );
}
return [
@@ -56,13 +78,13 @@ trait CommonSettingsTrait {
];
}
- protected function formatSections($sections, $currentSection, $type, $currentType) {
+ protected function formatSections($sections, $currentSection, $type, $currentType, bool $subAdminOnly = false) {
$templateParameters = [];
/** @var \OCP\Settings\ISection[] $prioritizedSections */
foreach($sections as $prioritizedSections) {
foreach ($prioritizedSections as $section) {
if($type === 'admin') {
- $settings = $this->settingsManager->getAdminSettings($section->getID());
+ $settings = $this->settingsManager->getAdminSettings($section->getID(), $subAdminOnly);
} else if($type === 'personal') {
$settings = $this->settingsManager->getPersonalSettings($section->getID());
}
@@ -96,9 +118,9 @@ trait CommonSettingsTrait {
return $templateParameters;
}
- protected function formatAdminSections($currentType, $currentSections) {
+ protected function formatAdminSections($currentType, $currentSections, bool $subAdminOnly) {
$sections = $this->settingsManager->getAdminSections();
- $templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType);
+ $templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType, $subAdminOnly);
return $templateParameters;
}
diff --git a/settings/Controller/PersonalSettingsController.php b/settings/Controller/PersonalSettingsController.php
index 9ec7ce72645..01ef84a1c49 100644
--- a/settings/Controller/PersonalSettingsController.php
+++ b/settings/Controller/PersonalSettingsController.php
@@ -26,8 +26,11 @@ namespace OC\Settings\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Group\ISubAdmin;
+use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IRequest;
+use OCP\IUserSession;
use OCP\Settings\IManager as ISettingsManager;
use OCP\Template;
@@ -38,11 +41,17 @@ class PersonalSettingsController extends Controller {
$appName,
IRequest $request,
INavigationManager $navigationManager,
- ISettingsManager $settingsManager
+ 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;
}
/**