diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-08-16 20:28:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-16 20:28:16 +0200 |
commit | 2d861c9feaa233b89f4d75e1bf4af6b04b05b081 (patch) | |
tree | cd3590b175e6ee923ef1265e002fd1aaa60504fa /apps/user_ldap | |
parent | 9db189174c26326bbb58d96f614a415cd15542d1 (diff) | |
parent | 4943441bde11e78827fdeb599ca4cd7b783672ce (diff) | |
download | nextcloud-server-2d861c9feaa233b89f4d75e1bf4af6b04b05b081.tar.gz nextcloud-server-2d861c9feaa233b89f4d75e1bf4af6b04b05b081.zip |
Merge pull request #796 from nextcloud/implement_712
Admin page split
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/appinfo/app.php | 2 | ||||
-rw-r--r-- | apps/user_ldap/appinfo/info.xml | 7 | ||||
-rw-r--r-- | apps/user_ldap/lib/Settings/Admin.php | 89 | ||||
-rw-r--r-- | apps/user_ldap/lib/Settings/Section.php | 67 | ||||
-rw-r--r-- | apps/user_ldap/settings.php | 75 | ||||
-rw-r--r-- | apps/user_ldap/templates/settings.php | 29 | ||||
-rw-r--r-- | apps/user_ldap/tests/Settings/AdminTest.php | 90 | ||||
-rw-r--r-- | apps/user_ldap/tests/Settings/SectionTest.php | 62 |
8 files changed, 332 insertions, 89 deletions
diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php index 10cc003a3f5..caacbea5619 100644 --- a/apps/user_ldap/appinfo/app.php +++ b/apps/user_ldap/appinfo/app.php @@ -27,8 +27,6 @@ * */ -OCP\App::registerAdmin('user_ldap', 'settings'); - $helper = new \OCA\User_LDAP\Helper(); $configPrefixes = $helper->getServerConfigurationPrefixes(true); $ldapWrapper = new OCA\User_LDAP\LDAP(); diff --git a/apps/user_ldap/appinfo/info.xml b/apps/user_ldap/appinfo/info.xml index b0984dcf624..b16824925c0 100644 --- a/apps/user_ldap/appinfo/info.xml +++ b/apps/user_ldap/appinfo/info.xml @@ -9,7 +9,7 @@ A user logs into ownCloud with their LDAP or AD credentials, and is granted acce </description> <licence>AGPL</licence> <author>Dominik Schmidt and Arthur Schiwon</author> - <version>1.1.0</version> + <version>1.1.1</version> <types> <authentication/> </types> @@ -27,4 +27,9 @@ A user logs into ownCloud with their LDAP or AD credentials, and is granted acce <job>OCA\User_LDAP\Jobs\UpdateGroups</job> <job>OCA\User_LDAP\Jobs\CleanUp</job> </background-jobs> + + <settings> + <admin>OCA\User_LDAP\Settings\Admin</admin> + <admin-section>OCA\User_LDAP\Settings\Section</admin-section> + </settings> </info> diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php new file mode 100644 index 00000000000..ca7db66c788 --- /dev/null +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -0,0 +1,89 @@ +<?php +/** + * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @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\User_LDAP\Settings; + +use OCA\User_LDAP\Configuration; +use OCA\User_LDAP\Helper; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IL10N; +use OCP\Settings\ISettings; +use OCP\Template; + +class Admin implements ISettings { + /** @var IL10N */ + private $l; + + /** + * @param IL10N $l + */ + public function __construct(IL10N $l) { + $this->l = $l; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $helper = new Helper(); + $prefixes = $helper->getServerConfigurationPrefixes(); + $hosts = $helper->getServerConfigurationHosts(); + + $wControls = new Template('user_ldap', 'part.wizardcontrols'); + $wControls = $wControls->fetchPage(); + $sControls = new Template('user_ldap', 'part.settingcontrols'); + $sControls = $sControls->fetchPage(); + + $parameters['serverConfigurationPrefixes'] = $prefixes; + $parameters['serverConfigurationHosts'] = $hosts; + $parameters['settingControls'] = $sControls; + $parameters['wizardControls'] = $wControls; + + // assign default values + $config = new Configuration('', false); + $defaults = $config->getDefaults(); + foreach($defaults as $key => $default) { + $parameters[$key.'_default'] = $default; + } + + return new TemplateResponse('user_ldap', 'settings', $parameters); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'ldap'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 5; + } +} diff --git a/apps/user_ldap/lib/Settings/Section.php b/apps/user_ldap/lib/Settings/Section.php new file mode 100644 index 00000000000..82d8d0c84fa --- /dev/null +++ b/apps/user_ldap/lib/Settings/Section.php @@ -0,0 +1,67 @@ +<?php +/** + * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @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\User_LDAP\Settings; + +use OCP\IL10N; +use OCP\Settings\ISection; + +class Section implements ISection { + /** @var IL10N */ + private $l; + + public function __construct(IL10N $l) { + $this->l = $l; + } + + /** + * returns the ID of the section. It is supposed to be a lower case string, + * e.g. 'ldap' + * + * @returns string + */ + public function getID() { + return 'ldap'; + } + + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + */ + public function getName() { + return $this->l->t('LDAP / AD integration'); + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the settings navigation. The sections are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + * + * E.g.: 70 + */ + public function getPriority() { + return 25; + } +} diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php deleted file mode 100644 index f20f873e134..00000000000 --- a/apps/user_ldap/settings.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Dominik Schmidt <dev@dominik-schmidt.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Volkan Gezer <volkangezer@gmail.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -// fill template -$tmpl = new OCP\Template('user_ldap', 'settings'); - -$helper = new \OCA\User_LDAP\Helper(); -$prefixes = $helper->getServerConfigurationPrefixes(); -$hosts = $helper->getServerConfigurationHosts(); - -$wizardHtml = ''; -$toc = array(); - -$wControls = new OCP\Template('user_ldap', 'part.wizardcontrols'); -$wControls = $wControls->fetchPage(); -$sControls = new OCP\Template('user_ldap', 'part.settingcontrols'); -$sControls = $sControls->fetchPage(); - -$l = \OC::$server->getL10N('user_ldap'); - -$wizTabs = array(); -$wizTabs[] = array('tpl' => 'part.wizard-server', 'cap' => $l->t('Server')); -$wizTabs[] = array('tpl' => 'part.wizard-userfilter', 'cap' => $l->t('Users')); -$wizTabs[] = array('tpl' => 'part.wizard-loginfilter', 'cap' => $l->t('Login Attributes')); -$wizTabs[] = array('tpl' => 'part.wizard-groupfilter', 'cap' => $l->t('Groups')); -$wizTabsCount = count($wizTabs); -for($i = 0; $i < $wizTabsCount; $i++) { - $tab = new OCP\Template('user_ldap', $wizTabs[$i]['tpl']); - if($i === 0) { - $tab->assign('serverConfigurationPrefixes', $prefixes); - $tab->assign('serverConfigurationHosts', $hosts); - } - $tab->assign('wizardControls', $wControls); - $wizardHtml .= $tab->fetchPage(); - $toc['#ldapWizard'.($i+1)] = $wizTabs[$i]['cap']; -} - -$tmpl->assign('tabs', $wizardHtml); -$tmpl->assign('toc', $toc); -$tmpl->assign('settingControls', $sControls); - -// assign default values -$config = new \OCA\User_LDAP\Configuration('', false); -$defaults = $config->getDefaults(); -foreach($defaults as $key => $default) { - $tmpl->assign($key.'_default', $default); -} - -return $tmpl->fetchPage(); diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index a1511071af4..eb4c7b99127 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -49,6 +49,9 @@ script('user_ldap', [ style('user_ldap', 'settings'); +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + ?> <form id="ldap" class="section" action="#" method="post"> @@ -56,20 +59,24 @@ style('user_ldap', 'settings'); <div id="ldapSettings"> <ul> - <?php foreach($_['toc'] as $id => $title) { ?> - <li id="<?php p($id); ?>"><a href="<?php p($id); ?>"><?php p($title); ?></a></li> - <?php } ?> + <li id="#ldapWizard1"><a href="#ldapWizard1"><?php p($l->t('Server'));?></a></li> + <li id="#ldapWizard2"><a href="#ldapWizard2"><?php p($l->t('Users'));?></a></li> + <li id="#ldapWizard3"><a href="#ldapWizard3"><?php p($l->t('Login Attributes'));?></a></li> + <li id="#ldapWizard4"><a href="#ldapWizard4"><?php p($l->t('Groups'));?></a></li> <li class="ldapSettingsTabs"><a href="#ldapSettings-2"><?php p($l->t('Expert'));?></a></li> <li class="ldapSettingsTabs"><a href="#ldapSettings-1"><?php p($l->t('Advanced'));?></a></li> </ul> - <?php if(OCP\App::isEnabled('user_webdavauth')) { - print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> Apps user_ldap and user_webdavauth are incompatible. You may experience unexpected behavior. Please ask your system administrator to disable one of them.').'</p>'); - } - if(!function_exists('ldap_connect')) { - print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>'); - } - ?> - <?php print_unescaped($_['tabs']); ?> + <?php if(OCP\App::isEnabled('user_webdavauth')) { + print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> Apps user_ldap and user_webdavauth are incompatible. You may experience unexpected behavior. Please ask your system administrator to disable one of them.').'</p>'); + } + if(!function_exists('ldap_connect')) { + print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>'); + } + ?> + <?php require_once(__DIR__ . '/part.wizard-server.php'); ?> + <?php require_once(__DIR__ . '/part.wizard-userfilter.php'); ?> + <?php require_once(__DIR__ . '/part.wizard-loginfilter.php'); ?> + <?php require_once(__DIR__ . '/part.wizard-groupfilter.php'); ?> <fieldset id="ldapSettings-1"> <div id="ldapAdvancedAccordion"> <h3><?php p($l->t('Connection Settings'));?></h3> diff --git a/apps/user_ldap/tests/Settings/AdminTest.php b/apps/user_ldap/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..4ac5a14f58b --- /dev/null +++ b/apps/user_ldap/tests/Settings/AdminTest.php @@ -0,0 +1,90 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @author Lukas Reschke <lukas@statuscode.ch> + * + * @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\User_LDAP\Tests\Settings; + +use OCA\User_LDAP\Configuration; +use OCA\User_LDAP\Helper; +use OCA\User_LDAP\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IL10N; +use OCP\Template; +use Test\TestCase; + +/** + * @group DB + * @package OCA\User_LDAP\Tests\Settings + */ +class AdminTest extends TestCase { + /** @var Admin */ + private $admin; + /** @var IL10N */ + private $l10n; + + public function setUp() { + parent::setUp(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); + + $this->admin = new Admin( + $this->l10n + ); + } + + /** + * @UseDB + */ + public function testGetForm() { + + $helper = new Helper(); + $prefixes = $helper->getServerConfigurationPrefixes(); + $hosts = $helper->getServerConfigurationHosts(); + + $wControls = new Template('user_ldap', 'part.wizardcontrols'); + $wControls = $wControls->fetchPage(); + $sControls = new Template('user_ldap', 'part.settingcontrols'); + $sControls = $sControls->fetchPage(); + + $parameters['serverConfigurationPrefixes'] = $prefixes; + $parameters['serverConfigurationHosts'] = $hosts; + $parameters['settingControls'] = $sControls; + $parameters['wizardControls'] = $wControls; + + // assign default values + $config = new Configuration('', false); + $defaults = $config->getDefaults(); + foreach($defaults as $key => $default) { + $parameters[$key.'_default'] = $default; + } + + $expected = new TemplateResponse('user_ldap', 'settings', $parameters); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('ldap', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(5, $this->admin->getPriority()); + } +} diff --git a/apps/user_ldap/tests/Settings/SectionTest.php b/apps/user_ldap/tests/Settings/SectionTest.php new file mode 100644 index 00000000000..2d2165b8e56 --- /dev/null +++ b/apps/user_ldap/tests/Settings/SectionTest.php @@ -0,0 +1,62 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @author Lukas Reschke <lukas@statuscode.ch> + * + * @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\User_LDAP\Tests\Settings; + +use OCA\User_LDAP\Settings\Section; +use OCP\IL10N; +use Test\TestCase; + +class SectionTest extends TestCase { + /** @var IL10N */ + private $l; + /** @var Section */ + private $section; + + public function setUp() { + parent::setUp(); + $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock(); + + $this->section = new Section( + $this->l + ); + } + + public function testGetID() { + $this->assertSame('ldap', $this->section->getID()); + } + + public function testGetName() { + $this->l + ->expects($this->once()) + ->method('t') + ->with('LDAP / AD integration') + ->willReturn('LDAP / AD integration'); + + $this->assertSame('LDAP / AD integration', $this->section->getName()); + } + + public function testGetPriority() { + $this->assertSame(25, $this->section->getPriority()); + } +} |