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 | |
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')
61 files changed, 1949 insertions, 518 deletions
diff --git a/apps/encryption/appinfo/info.xml b/apps/encryption/appinfo/info.xml index 83f4107384d..539f9f116d2 100644 --- a/apps/encryption/appinfo/info.xml +++ b/apps/encryption/appinfo/info.xml @@ -19,7 +19,7 @@ <admin>admin-encryption</admin> </documentation> <rememberlogin>false</rememberlogin> - <version>1.4.0</version> + <version>1.4.1</version> <types> <filesystem/> </types> @@ -27,5 +27,7 @@ <lib>openssl</lib> <owncloud min-version="9.2" max-version="9.2" /> </dependencies> - + <settings> + <admin>OCA\Encryption\Settings\Admin</admin> + </settings> </info> diff --git a/apps/encryption/lib/AppInfo/Application.php b/apps/encryption/lib/AppInfo/Application.php index bba522fbc8c..a43646d86d9 100644 --- a/apps/encryption/lib/AppInfo/Application.php +++ b/apps/encryption/lib/AppInfo/Application.php @@ -269,7 +269,6 @@ class Application extends \OCP\AppFramework\App { public function registerSettings() { // Register settings scripts - App::registerAdmin('encryption', 'settings/settings-admin'); App::registerPersonal('encryption', 'settings/settings-personal'); } } diff --git a/apps/encryption/lib/Settings/Admin.php b/apps/encryption/lib/Settings/Admin.php new file mode 100644 index 00000000000..2faa118e2a2 --- /dev/null +++ b/apps/encryption/lib/Settings/Admin.php @@ -0,0 +1,127 @@ +<?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\Encryption\Settings; + +use OC\Files\View; +use OCA\Encryption\Crypto\Crypt; +use OCA\Encryption\Session; +use OCA\Encryption\Util; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IL10N; +use OCP\ILogger; +use OCP\ISession; +use OCP\IUserManager; +use OCP\IUserSession; +use OCP\Settings\ISettings; +use OCP\IConfig; + +class Admin implements ISettings { + + /** @var IL10N */ + private $l; + + /** @var ILogger */ + private $logger; + + /** @var IUserSession */ + private $userSession; + + /** @var IConfig */ + private $config; + + /** @var IUserManager */ + private $userManager; + + /** @var ISession */ + private $session; + + public function __construct( + IL10N $l, + ILogger $logger, + IUserSession $userSession, + IConfig $config, + IUserManager $userManager, + ISession $session + ) { + $this->l = $l; + $this->logger = $logger; + $this->userSession = $userSession; + $this->config = $config; + $this->userManager = $userManager; + $this->session = $session; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $crypt = new Crypt( + $this->logger, + $this->userSession, + $this->config, + $this->l); + + $util = new Util( + new View(), + $crypt, + $this->logger, + $this->userSession, + $this->config, + $this->userManager); + + // Check if an adminRecovery account is enabled for recovering files after lost pwd + $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0'); + $session = new Session($this->session); + + $encryptHomeStorage = $util->shouldEncryptHomeStorage(); + + $parameters = [ + 'recoveryEnabled' => $recoveryAdminEnabled, + 'initStatus' => $session->getStatus(), + 'encryptHomeStorage' => $encryptHomeStorage, + 'masterKeyEnabled' => $util->isMasterKeyEnabled(), + ]; + + return new TemplateResponse('encryption', 'settings-admin', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'encryption'; + } + + /** + * @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/encryption/settings/settings-admin.php b/apps/encryption/settings/settings-admin.php deleted file mode 100644 index a424ea03874..00000000000 --- a/apps/encryption/settings/settings-admin.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * @author Clark Tomlinson <fallen013@gmail.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @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/> - * - */ - -$tmpl = new OCP\Template('encryption', 'settings-admin'); - -$crypt = new \OCA\Encryption\Crypto\Crypt( - \OC::$server->getLogger(), - \OC::$server->getUserSession(), - \OC::$server->getConfig(), - \OC::$server->getL10N('encryption')); - -$util = new \OCA\Encryption\Util( - new \OC\Files\View(), - $crypt, - \OC::$server->getLogger(), - \OC::$server->getUserSession(), - \OC::$server->getConfig(), - \OC::$server->getUserManager()); - -// Check if an adminRecovery account is enabled for recovering files after lost pwd -$recoveryAdminEnabled = \OC::$server->getConfig()->getAppValue('encryption', 'recoveryAdminEnabled', '0'); -$session = new \OCA\Encryption\Session(\OC::$server->getSession()); - -$encryptHomeStorage = $util->shouldEncryptHomeStorage(); - -$tmpl->assign('recoveryEnabled', $recoveryAdminEnabled); -$tmpl->assign('initStatus', $session->getStatus()); -$tmpl->assign('encryptHomeStorage', $encryptHomeStorage); -$tmpl->assign('masterKeyEnabled', $util->isMasterKeyEnabled()); - -return $tmpl->fetchPage(); diff --git a/apps/encryption/templates/settings-admin.php b/apps/encryption/templates/settings-admin.php index 5c551267ff5..405dbaf703f 100644 --- a/apps/encryption/templates/settings-admin.php +++ b/apps/encryption/templates/settings-admin.php @@ -6,6 +6,7 @@ script('core', 'multiselect'); style('encryption', 'settings-admin'); ?> <form id="ocDefaultEncryptionModule" class="sub-section"> + <h3><?php p($l->t("Default encryption module")); ?></h3> <?php if(!$_["initStatus"]): ?> <?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?> <?php else: ?> diff --git a/apps/encryption/tests/Settings/AdminTest.php b/apps/encryption/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..93896585dad --- /dev/null +++ b/apps/encryption/tests/Settings/AdminTest.php @@ -0,0 +1,100 @@ +<?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\Encryption\Tests\Settings; + +use OCA\Encryption\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\ISession; +use OCP\IUserManager; +use OCP\IUserSession; +use OCP\IL10N; +use OCP\ILogger; +use Test\TestCase; + +class AdminTest extends TestCase { + /** @var Admin */ + private $admin; + /** @var IL10N */ + private $l; + /** @var ILogger */ + private $logger; + /** @var IUserSession */ + private $userSession; + /** @var IConfig */ + private $config; + /** @var IUserManager */ + private $userManager; + /** @var ISession */ + private $session; + + public function setUp() { + parent::setUp(); + + $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock(); + $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); + $this->userSession = $this->getMockBuilder('\OCP\IUserSession')->getMock(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); + $this->session = $this->getMockBuilder('\OCP\ISession')->getMock(); + + $this->admin = new Admin( + $this->l, + $this->logger, + $this->userSession, + $this->config, + $this->userManager, + $this->session + ); + } + + public function testGetForm() { + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('encryption', 'recoveryAdminEnabled', '0') + ->willReturn(1); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('encryption', 'encryptHomeStorage', '1') + ->willReturn(1); + $params = [ + 'recoveryEnabled' => 1, + 'initStatus' => '0', + 'encryptHomeStorage' => false, + 'masterKeyEnabled' => false + ]; + $expected = new TemplateResponse('encryption', 'settings-admin', $params, ''); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('encryption', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(5, $this->admin->getPriority()); + } +} diff --git a/apps/federatedfilesharing/appinfo/info.xml b/apps/federatedfilesharing/appinfo/info.xml index 2a80bd54da3..984235f0851 100644 --- a/apps/federatedfilesharing/appinfo/info.xml +++ b/apps/federatedfilesharing/appinfo/info.xml @@ -5,10 +5,13 @@ <description>Provide federated file sharing across servers</description> <licence>AGPL</licence> <author>Bjoern Schiessle, Roeland Jago Douma</author> - <version>1.1.0</version> + <version>1.1.1</version> <namespace>FederatedFileSharing</namespace> <category>other</category> <dependencies> <owncloud min-version="9.2" max-version="9.2" /> </dependencies> + <settings> + <admin>OCA\FederatedFileSharing\Settings\Admin</admin> + </settings> </info> diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index b4ddc6cfe04..b767a322505 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -40,7 +40,6 @@ class Application extends App { * register personal and admin settings page */ public function registerSettings() { - \OCP\App::registerAdmin('federatedfilesharing', 'settings-admin'); \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); } diff --git a/apps/federatedfilesharing/lib/Settings/Admin.php b/apps/federatedfilesharing/lib/Settings/Admin.php new file mode 100644 index 00000000000..64619e329f3 --- /dev/null +++ b/apps/federatedfilesharing/lib/Settings/Admin.php @@ -0,0 +1,69 @@ +<?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\FederatedFileSharing\Settings; + +use OCA\FederatedFileSharing\FederatedShareProvider; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; + +class Admin implements ISettings { + + /** @var FederatedShareProvider */ + private $fedShareProvider; + + public function __construct(FederatedShareProvider $fedShareProvider) { + $this->fedShareProvider = $fedShareProvider; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $parameters = [ + 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), + 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), + ]; + + return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'sharing'; + } + + /** + * @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 20; + } + +} diff --git a/apps/federatedfilesharing/settings-admin.php b/apps/federatedfilesharing/settings-admin.php deleted file mode 100644 index 5ccd223b0a3..00000000000 --- a/apps/federatedfilesharing/settings-admin.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bjoern Schiessle <bjoern@schiessle.org> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Morris Jobke <hey@morrisjobke.de> - * - * @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/> - * - */ - -use OCA\FederatedFileSharing\AppInfo\Application; - -$app = new Application(); -$federatedShareProvider = $app->getFederatedShareProvider(); - -$tmpl = new OCP\Template('federatedfilesharing', 'settings-admin'); -$tmpl->assign('outgoingServer2serverShareEnabled', $federatedShareProvider->isOutgoingServer2serverShareEnabled()); -$tmpl->assign('incomingServer2serverShareEnabled', $federatedShareProvider->isIncomingServer2serverShareEnabled()); - -return $tmpl->fetchPage(); diff --git a/apps/federatedfilesharing/templates/settings-admin.php b/apps/federatedfilesharing/templates/settings-admin.php index 5d2eb04c170..c454eeba17b 100644 --- a/apps/federatedfilesharing/templates/settings-admin.php +++ b/apps/federatedfilesharing/templates/settings-admin.php @@ -4,7 +4,7 @@ script('federatedfilesharing', 'settings-admin'); ?> -<div id="fileSharingSettings"> +<div id="fileSharingSettings" class="followupsection"> <h3><?php p($l->t('Federated Cloud Sharing'));?></h3> <a target="_blank" rel="noreferrer" class="icon-info svg" title="<?php p($l->t('Open documentation'));?>" diff --git a/apps/federatedfilesharing/tests/Settings/AdminTest.php b/apps/federatedfilesharing/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..60fadca7b56 --- /dev/null +++ b/apps/federatedfilesharing/tests/Settings/AdminTest.php @@ -0,0 +1,84 @@ +<?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\FederatedFileSharing\Tests\Settings; + +use OCA\FederatedFileSharing\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; +use Test\TestCase; + +class AdminTest extends TestCase { + /** @var Admin */ + private $admin; + /** @var \OCA\FederatedFileSharing\FederatedShareProvider */ + private $federatedShareProvider; + + public function setUp() { + parent::setUp(); + $this->federatedShareProvider = $this->getMockBuilder('\OCA\FederatedFileSharing\FederatedShareProvider')->disableOriginalConstructor()->getMock(); + $this->admin = new Admin( + $this->federatedShareProvider + ); + } + + public function sharingStateProvider() { + return [ + [ + true, + ], + [ + false, + ] + ]; + } + + /** + * @dataProvider sharingStateProvider + * @param bool $state + */ + public function testGetForm($state) { + $this->federatedShareProvider + ->expects($this->once()) + ->method('isOutgoingServer2serverShareEnabled') + ->willReturn($state); + $this->federatedShareProvider + ->expects($this->once()) + ->method('isIncomingServer2serverShareEnabled') + ->willReturn($state); + + $params = [ + 'outgoingServer2serverShareEnabled' => $state, + 'incomingServer2serverShareEnabled' => $state, + ]; + $expected = new TemplateResponse('federatedfilesharing', 'settings-admin', $params, ''); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('sharing', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(20, $this->admin->getPriority()); + } +} diff --git a/apps/federation/appinfo/app.php b/apps/federation/appinfo/app.php index 92b64b9c058..6c53810dd2c 100644 --- a/apps/federation/appinfo/app.php +++ b/apps/federation/appinfo/app.php @@ -23,5 +23,4 @@ namespace OCA\Federation\AppInfo; $app = new Application(); -$app->registerSettings(); $app->registerHooks(); diff --git a/apps/federation/appinfo/info.xml b/apps/federation/appinfo/info.xml index b8d697a4db2..da65fef2446 100644 --- a/apps/federation/appinfo/info.xml +++ b/apps/federation/appinfo/info.xml @@ -5,7 +5,7 @@ <description>Federation allows you to connect with other trusted servers to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.</description> <licence>AGPL</licence> <author>Bjoern Schiessle</author> - <version>1.1.0</version> + <version>1.1.1</version> <namespace>Federation</namespace> <category>other</category> <dependencies> @@ -19,4 +19,8 @@ <background-jobs> <job>OCA\Federation\SyncJob</job> </background-jobs> + + <settings> + <admin>OCA\Federation\Settings\Admin</admin> + </settings> </info> diff --git a/apps/federation/lib/AppInfo/Application.php b/apps/federation/lib/AppInfo/Application.php index 5d8da05c8e1..cdc6145dfb4 100644 --- a/apps/federation/lib/AppInfo/Application.php +++ b/apps/federation/lib/AppInfo/Application.php @@ -51,13 +51,6 @@ class Application extends \OCP\AppFramework\App { $this->registerMiddleware(); } - /** - * register setting scripts - */ - public function registerSettings() { - App::registerAdmin('federation', 'settings/settings-admin'); - } - private function registerService() { $container = $this->getContainer(); diff --git a/apps/federation/lib/Settings/Admin.php b/apps/federation/lib/Settings/Admin.php new file mode 100644 index 00000000000..eccb3237f7d --- /dev/null +++ b/apps/federation/lib/Settings/Admin.php @@ -0,0 +1,69 @@ +<?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\Federation\Settings; + +use OCA\Federation\TrustedServers; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; + +class Admin implements ISettings { + + /** @var TrustedServers */ + private $trustedServers; + + public function __construct(TrustedServers $trustedServers) { + $this->trustedServers = $trustedServers; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $parameters = [ + 'trustedServers' => $this->trustedServers->getServers(), + 'autoAddServers' => $this->trustedServers->getAutoAddServers(), + ]; + + return new TemplateResponse('federation', 'settings-admin', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'sharing'; + } + + /** + * @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 30; + } + +} diff --git a/apps/federation/settings/settings-admin.php b/apps/federation/settings/settings-admin.php deleted file mode 100644 index aa21a1e9920..00000000000 --- a/apps/federation/settings/settings-admin.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * - * @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/> - * - */ - -$template = new OCP\Template('federation', 'settings-admin'); - -$dbHandler = new \OCA\Federation\DbHandler( - \OC::$server->getDatabaseConnection(), - \OC::$server->getL10N('federation') -); - -$trustedServers = new \OCA\Federation\TrustedServers( - $dbHandler, - \OC::$server->getHTTPClientService(), - \OC::$server->getLogger(), - \OC::$server->getJobList(), - \OC::$server->getSecureRandom(), - \OC::$server->getConfig(), - \OC::$server->getEventDispatcher() -); - -$template->assign('trustedServers', $trustedServers->getServers()); -$template->assign('autoAddServers', $trustedServers->getAutoAddServers()); - -return $template->fetchPage(); diff --git a/apps/federation/tests/Settings/AdminTest.php b/apps/federation/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..758bda6bc5e --- /dev/null +++ b/apps/federation/tests/Settings/AdminTest.php @@ -0,0 +1,70 @@ +<?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\Federation\Tests\Settings; + +use OCA\Federation\Settings\Admin; +use OCA\Federation\TrustedServers; +use OCP\AppFramework\Http\TemplateResponse; +use Test\TestCase; + +class AdminTest extends TestCase { + /** @var Admin */ + private $admin; + /** @var TrustedServers */ + private $trustedServers; + + public function setUp() { + parent::setUp(); + $this->trustedServers = $this->getMockBuilder('\OCA\Federation\TrustedServers')->disableOriginalConstructor()->getMock(); + $this->admin = new Admin( + $this->trustedServers + ); + } + + public function testGetForm() { + $this->trustedServers + ->expects($this->once()) + ->method('getServers') + ->willReturn(['myserver', 'secondserver']); + $this->trustedServers + ->expects($this->once()) + ->method('getAutoAddServers') + ->willReturn(['autoserver1', 'autoserver2']); + + $params = [ + 'trustedServers' => ['myserver', 'secondserver'], + 'autoAddServers' => ['autoserver1', 'autoserver2'], + ]; + $expected = new TemplateResponse('federation', 'settings-admin', $params, ''); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('sharing', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(30, $this->admin->getPriority()); + } +} diff --git a/apps/files/admin.php b/apps/files/admin.php deleted file mode 100644 index ad7b16a3a23..00000000000 --- a/apps/files/admin.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Clark Tomlinson <fallen013@gmail.com> - * @author Frank Karlitschek <frank@karlitschek.de> - * @author Michael Göhler <somebody.here@gmx.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @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/> - * - */ - -$htaccessWorking=(getenv('htaccessWorking')=='true'); -$upload_max_filesize = OC::$server->getIniWrapper()->getBytes('upload_max_filesize'); -$post_max_size = OC::$server->getIniWrapper()->getBytes('post_max_size'); -$maxUploadFilesize = OCP\Util::humanFileSize(min($upload_max_filesize, $post_max_size)); -if($_POST && \OC::$server->getRequest()->passesCSRFCheck()) { - if(isset($_POST['maxUploadSize'])) { - if(($setMaxSize = OC_Files::setUploadLimit(OCP\Util::computerFileSize($_POST['maxUploadSize']))) !== false) { - $maxUploadFilesize = OCP\Util::humanFileSize($setMaxSize); - } - } -} - -$htaccessWritable=is_writable(OC::$SERVERROOT.'/.htaccess'); -$userIniWritable=is_writable(OC::$SERVERROOT.'/.user.ini'); - -$tmpl = new OCP\Template( 'files', 'admin' ); -$tmpl->assign( 'uploadChangable', ($htaccessWorking and $htaccessWritable) or $userIniWritable ); -$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize); -// max possible makes only sense on a 32 bit system -$tmpl->assign( 'displayMaxPossibleUploadSize', PHP_INT_SIZE===4); -$tmpl->assign( 'maxPossibleUploadSize', OCP\Util::humanFileSize(PHP_INT_MAX)); -return $tmpl->fetchPage(); diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index 850c335c27d..afb327e24ba 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -26,8 +26,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -\OCP\App::registerAdmin('files', 'admin'); - $l = \OC::$server->getL10N('files'); \OC::$server->getNavigationManager()->add(function () { diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml index 8b26a6af711..513940f73a9 100644 --- a/apps/files/appinfo/info.xml +++ b/apps/files/appinfo/info.xml @@ -6,7 +6,7 @@ <licence>AGPL</licence> <author>Robin Appelman, Vincent Petry</author> <default_enable/> - <version>1.6.0</version> + <version>1.6.1</version> <types> <filesystem/> </types> @@ -22,4 +22,8 @@ <job>OCA\Files\BackgroundJob\DeleteOrphanedItems</job> <job>OCA\Files\BackgroundJob\CleanupFileLocks</job> </background-jobs> + + <settings> + <admin>OCA\Files\Settings\Admin</admin> + </settings> </info> diff --git a/apps/files/lib/Settings/Admin.php b/apps/files/lib/Settings/Admin.php new file mode 100644 index 00000000000..9ec23d47517 --- /dev/null +++ b/apps/files/lib/Settings/Admin.php @@ -0,0 +1,93 @@ +<?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\Files\Settings; + +use bantu\IniGetWrapper\IniGetWrapper; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IRequest; +use OCP\Settings\ISettings; +use OCP\Util; + +class Admin implements ISettings { + + /** @var IniGetWrapper */ + private $iniWrapper; + + /** @var IRequest */ + private $request; + + public function __construct(IniGetWrapper $iniWrapper, IRequest $request) { + $this->iniWrapper = $iniWrapper; + $this->request = $request; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $htaccessWorking = (getenv('htaccessWorking') == 'true'); + $htaccessWritable = is_writable(\OC::$SERVERROOT.'/.htaccess'); + $userIniWritable = is_writable(\OC::$SERVERROOT.'/.user.ini'); + + $upload_max_filesize = $this->iniWrapper->getBytes('upload_max_filesize'); + $post_max_size = $this->iniWrapper->getBytes('post_max_size'); + $maxUploadFilesize = Util::humanFileSize(min($upload_max_filesize, $post_max_size)); + if($_POST && $this->request->passesCSRFCheck()) { + if(isset($_POST['maxUploadSize'])) { + if(($setMaxSize = \OC_Files::setUploadLimit(Util::computerFileSize($_POST['maxUploadSize']))) !== false) { + $maxUploadFilesize = Util::humanFileSize($setMaxSize); + } + } + } + + $parameters = [ + 'uploadChangable' => (($htaccessWorking and $htaccessWritable) or $userIniWritable ), + 'uploadMaxFilesize' => $maxUploadFilesize, + // max possible makes only sense on a 32 bit system + 'displayMaxPossibleUploadSize' => PHP_INT_SIZE === 4, + 'maxPossibleUploadSize' => Util::humanFileSize(PHP_INT_MAX), + ]; + + return new TemplateResponse('files', 'admin', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'additional'; + } + + /** + * @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/files/tests/Settings/AdminTest.php b/apps/files/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..1ab8a992879 --- /dev/null +++ b/apps/files/tests/Settings/AdminTest.php @@ -0,0 +1,83 @@ +<?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\Files\Tests\Settings; + +use bantu\IniGetWrapper\IniGetWrapper; +use OCA\Files\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IRequest; +use OCP\Util; +use Test\TestCase; + +class AdminTest extends TestCase { + /** @var Admin */ + private $admin; + /** @var IniGetWrapper */ + private $iniGetWrapper; + /** @var IRequest */ + private $request; + + public function setUp() { + parent::setUp(); + $this->iniGetWrapper = $this->getMockBuilder('\bantu\IniGetWrapper\IniGetWrapper')->disableOriginalConstructor()->getMock(); + $this->request = $this->getMockBuilder('\OCP\IRequest')->getMock(); + $this->admin = new Admin( + $this->iniGetWrapper, + $this->request + ); + } + + public function testGetForm() { + $htaccessWorking = (getenv('htaccessWorking') == 'true'); + $htaccessWritable = is_writable(\OC::$SERVERROOT.'/.htaccess'); + $userIniWritable = is_writable(\OC::$SERVERROOT.'/.user.ini'); + + $this->iniGetWrapper + ->expects($this->at(0)) + ->method('getBytes') + ->with('upload_max_filesize') + ->willReturn(1234); + $this->iniGetWrapper + ->expects($this->at(1)) + ->method('getBytes') + ->with('post_max_size') + ->willReturn(1234); + $params = [ + 'uploadChangable' => (($htaccessWorking and $htaccessWritable) or $userIniWritable ), + 'uploadMaxFilesize' => '1 KB', + 'displayMaxPossibleUploadSize' => PHP_INT_SIZE === 4, + 'maxPossibleUploadSize' => Util::humanFileSize(PHP_INT_MAX), + ]; + $expected = new TemplateResponse('files', 'admin', $params, ''); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('additional', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(5, $this->admin->getPriority()); + } +} diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index 43f06d60843..60131759880 100644 --- a/apps/files_external/appinfo/info.xml +++ b/apps/files_external/appinfo/info.xml @@ -13,7 +13,7 @@ <admin>admin-external-storage</admin> </documentation> <rememberlogin>false</rememberlogin> - <version>1.1.0</version> + <version>1.1.2</version> <types> <filesystem/> </types> @@ -24,4 +24,9 @@ <dependencies> <owncloud min-version="9.2" max-version="9.2" /> </dependencies> + + <settings> + <admin>OCA\Files_External\Settings\Admin</admin> + <admin-section>OCA\Files_External\Settings\Section</admin-section> + </settings> </info> diff --git a/apps/files_external/lib/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php index a32a3a26c7f..06c163419f0 100644 --- a/apps/files_external/lib/AppInfo/Application.php +++ b/apps/files_external/lib/AppInfo/Application.php @@ -68,10 +68,6 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide * Register settings templates */ public function registerSettings() { - $container = $this->getContainer(); - $backendService = $container->query('OCA\\Files_External\\Service\\BackendService'); - - \OCP\App::registerAdmin('files_external', 'settings'); \OCP\App::registerPersonal('files_external', 'personal'); } diff --git a/apps/files_external/lib/Settings/Admin.php b/apps/files_external/lib/Settings/Admin.php new file mode 100644 index 00000000000..54711443f89 --- /dev/null +++ b/apps/files_external/lib/Settings/Admin.php @@ -0,0 +1,96 @@ +<?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\Files_External\Settings; + +use OCA\Files_External\Lib\Auth\Password\GlobalAuth; +use OCA\Files_External\Service\BackendService; +use OCA\Files_External\Service\GlobalStoragesService; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Encryption\IManager; +use OCP\Settings\ISettings; + +class Admin implements ISettings { + + /** @var IManager */ + private $encryptionManager; + + /** @var GlobalStoragesService */ + private $globalStoragesService; + + /** @var BackendService */ + private $backendService; + + /** @var GlobalAuth */ + private $globalAuth; + + public function __construct( + IManager $encryptionManager, + GlobalStoragesService $globalStoragesService, + BackendService $backendService, + GlobalAuth $globalAuth + ) { + $this->encryptionManager = $encryptionManager; + $this->globalStoragesService = $globalStoragesService; + $this->backendService = $backendService; + $this->globalAuth = $globalAuth; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $parameters = [ + 'encryptionEnabled' => $this->encryptionManager->isEnabled(), + 'visibilityType' => BackendService::VISIBILITY_ADMIN, + 'storages' => $this->globalStoragesService->getStorages(), + 'backends' => $this->backendService->getAvailableBackends(), + 'authMechanisms' => $this->backendService->getAuthMechanisms(), + 'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()), + 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), + 'globalCredentials' => $this->globalAuth->getAuth(''), + 'globalCredentialsUid' => '', + ]; + + return new TemplateResponse('files_external', 'settings', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'externalstorages'; + } + + /** + * @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 40; + } + +} diff --git a/apps/files_external/lib/Settings/Section.php b/apps/files_external/lib/Settings/Section.php new file mode 100644 index 00000000000..4b4bac93d29 --- /dev/null +++ b/apps/files_external/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\Files_External\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 'externalstorages'; + } + + /** + * 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('External storages'); + } + + /** + * @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 10; + } +} diff --git a/apps/files_external/settings.php b/apps/files_external/settings.php deleted file mode 100644 index cb9ee5ccde0..00000000000 --- a/apps/files_external/settings.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * - * @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/> - * - */ - -use \OCA\Files_External\Service\BackendService; - -// we must use the same container -$appContainer = \OC_Mount_Config::$app->getContainer(); -$backendService = $appContainer->query('OCA\Files_External\Service\BackendService'); -$globalStoragesService = $appContainer->query('OCA\Files_External\Service\GlobalStoragesService'); -$globalAuth = $appContainer->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth'); - -\OC_Util::addVendorScript('select2/select2'); -\OC_Util::addVendorStyle('select2/select2'); - -$tmpl = new OCP\Template('files_external', 'settings'); -$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled()); -$tmpl->assign('visibilityType', BackendService::VISIBILITY_ADMIN); -$tmpl->assign('storages', $globalStoragesService->getStorages()); -$tmpl->assign('backends', $backendService->getAvailableBackends()); -$tmpl->assign('authMechanisms', $backendService->getAuthMechanisms()); -$tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends())); -$tmpl->assign('allowUserMounting', $backendService->isUserMountingAllowed()); -$tmpl->assign('globalCredentials', $globalAuth->getAuth('')); -$tmpl->assign('globalCredentialsUid', ''); -return $tmpl->fetchPage(); diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..fdf9680e7c3 --- /dev/null +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -0,0 +1,109 @@ +<?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\Files_External\Tests\Settings; + +use OCA\Files_External\Lib\Auth\Password\GlobalAuth; +use OCA\Files_External\Service\BackendService; +use OCA\Files_External\Service\GlobalStoragesService; +use OCA\Files_External\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Encryption\IManager; +use Test\TestCase; + +class AdminTest extends TestCase { + /** @var Admin */ + private $admin; + /** @var IManager */ + private $encryptionManager; + /** @var GlobalStoragesService */ + private $globalStoragesService; + /** @var BackendService */ + private $backendService; + /** @var GlobalAuth */ + private $globalAuth; + + public function setUp() { + parent::setUp(); + $this->encryptionManager = $this->getMockBuilder('\OCP\Encryption\IManager')->getMock(); + $this->globalStoragesService = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService')->disableOriginalConstructor()->getMock(); + $this->backendService = $this->getMockBuilder('\OCA\Files_External\Service\BackendService')->disableOriginalConstructor()->getMock(); + $this->globalAuth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Password\GlobalAuth')->disableOriginalConstructor()->getMock(); + + $this->admin = new Admin( + $this->encryptionManager, + $this->globalStoragesService, + $this->backendService, + $this->globalAuth + ); + } + + public function testGetForm() { + $this->encryptionManager + ->expects($this->once()) + ->method('isEnabled') + ->willReturn(false); + $this->globalStoragesService + ->expects($this->once()) + ->method('getStorages') + ->willReturn(['a', 'b', 'c']); + $this->backendService + ->expects($this->once()) + ->method('getAvailableBackends') + ->willReturn(['d', 'e', 'f']); + $this->backendService + ->expects($this->once()) + ->method('getAuthMechanisms') + ->willReturn(['g', 'h', 'i']); + $this->backendService + ->expects($this->once()) + ->method('isUserMountingAllowed') + ->willReturn(true); + $this->globalAuth + ->expects($this->once()) + ->method('getAuth') + ->with('') + ->willReturn('asdf:asdf'); + $params = [ + 'encryptionEnabled' => false, + 'visibilityType' => BackendService::VISIBILITY_ADMIN, + 'storages' => ['a', 'b', 'c'], + 'backends' => ['d', 'e', 'f'], + 'authMechanisms' => ['g', 'h', 'i'], + 'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()), + 'allowUserMounting' => true, + 'globalCredentials' => 'asdf:asdf', + 'globalCredentialsUid' => '', + ]; + $expected = new TemplateResponse('files_external', 'settings', $params, ''); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('externalstorages', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(40, $this->admin->getPriority()); + } +} diff --git a/apps/files_external/tests/Settings/SectionTest.php b/apps/files_external/tests/Settings/SectionTest.php new file mode 100644 index 00000000000..b5dfb28b382 --- /dev/null +++ b/apps/files_external/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\Files_External\Tests\Settings; + +use OCA\Files_External\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')->disableOriginalConstructor()->getMock(); + + $this->section = new Section( + $this->l + ); + } + + public function testGetID() { + $this->assertSame('externalstorages', $this->section->getID()); + } + + public function testGetName() { + $this->l + ->expects($this->once()) + ->method('t') + ->with('External storages') + ->willReturn('External storages'); + + $this->assertSame('External storages', $this->section->getName()); + } + + public function testGetPriority() { + $this->assertSame(10, $this->section->getPriority()); + } +} diff --git a/apps/systemtags/admin.php b/apps/systemtags/admin.php deleted file mode 100644 index 45ea577e8ab..00000000000 --- a/apps/systemtags/admin.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @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/>. - * - */ - -$template = new \OCP\Template('systemtags', 'admin'); -return $template->fetchPage(); diff --git a/apps/systemtags/appinfo/app.php b/apps/systemtags/appinfo/app.php index 5a365c4ef15..af91e5fdbcd 100644 --- a/apps/systemtags/appinfo/app.php +++ b/apps/systemtags/appinfo/app.php @@ -78,9 +78,6 @@ $mapperListener = function(MapperEvent $event) use ($activityManager) { $eventDispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener); $eventDispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); -$app = new \OCA\SystemTags\AppInfo\Application(); -$app->registerAdminPage(); - $l = \OC::$server->getL10N('systemtags'); \OCA\Files\App::getNavigationManager()->add( diff --git a/apps/systemtags/appinfo/info.xml b/apps/systemtags/appinfo/info.xml index 5eced10b710..46bb9278838 100644 --- a/apps/systemtags/appinfo/info.xml +++ b/apps/systemtags/appinfo/info.xml @@ -7,7 +7,7 @@ <licence>AGPL</licence> <author>Vincent Petry, Joas Schilling</author> <default_enable/> - <version>1.1.0</version> + <version>1.1.1</version> <dependencies> <owncloud min-version="9.2" max-version="9.2" /> </dependencies> @@ -15,4 +15,7 @@ <types> <logging/> </types> + <settings> + <admin>OCA\SystemTags\Settings\Admin</admin> + </settings> </info> diff --git a/apps/systemtags/lib/AppInfo/Application.php b/apps/systemtags/lib/AppInfo/Application.php deleted file mode 100644 index 7cd49d6424b..00000000000 --- a/apps/systemtags/lib/AppInfo/Application.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @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\SystemTags\AppInfo; - -use OCP\AppFramework\App; - -class Application extends App { - public function __construct() { - parent::__construct('systemtags'); - } - - /** - * Register admin settings - */ - public function registerAdminPage() { - \OCP\App::registerAdmin($this->getContainer()->getAppName(), 'admin'); - } -} diff --git a/apps/systemtags/lib/Settings/Admin.php b/apps/systemtags/lib/Settings/Admin.php new file mode 100644 index 00000000000..fbdec8741f7 --- /dev/null +++ b/apps/systemtags/lib/Settings/Admin.php @@ -0,0 +1,56 @@ +<?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\SystemTags\Settings; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; + +class Admin implements ISettings { + + /** + * @return TemplateResponse + */ + public function getForm() { + return new TemplateResponse('systemtags', 'admin', [], ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'sharing'; + } + + /** + * @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 70; + } + +} diff --git a/apps/systemtags/tests/Settings/AdminTest.php b/apps/systemtags/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..b1faf82cf25 --- /dev/null +++ b/apps/systemtags/tests/Settings/AdminTest.php @@ -0,0 +1,52 @@ +<?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\SystemTags\Tests\Settings; + +use OCA\SystemTags\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; +use Test\TestCase; + +class AdminTest extends TestCase { + /** @var Admin */ + private $admin; + + public function setUp() { + parent::setUp(); + + $this->admin = new Admin(); + } + + public function testGetForm() { + $expected = new TemplateResponse('systemtags', 'admin', [], ''); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('sharing', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(70, $this->admin->getPriority()); + } +} diff --git a/apps/theming/appinfo/app.php b/apps/theming/appinfo/app.php index 051a2e279e5..f558c35e61f 100644 --- a/apps/theming/appinfo/app.php +++ b/apps/theming/appinfo/app.php @@ -23,8 +23,6 @@ * */ -\OCP\App::registerAdmin('theming', 'settings/settings-admin'); - $linkToCSS = \OC::$server->getURLGenerator()->linkToRoute( 'theming.Theming.getStylesheet', [ diff --git a/apps/theming/appinfo/info.xml b/apps/theming/appinfo/info.xml index 8ae1d3eb73a..423d11d2aef 100644 --- a/apps/theming/appinfo/info.xml +++ b/apps/theming/appinfo/info.xml @@ -5,7 +5,7 @@ <description>Adjust the Nextcloud theme</description> <licence>AGPL</licence> <author>Nextcloud</author> - <version>1.1.0</version> + <version>1.1.1</version> <namespace>Theming</namespace> <category>other</category> @@ -18,4 +18,9 @@ </types> <default_enable/> + + <settings> + <admin>OCA\Theming\Settings\Admin</admin> + <admin-section>OCA\Theming\Settings\Section</admin-section> + </settings> </info> diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 0db4dfe0627..8d3e2a5f2e2 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -27,7 +27,7 @@ namespace OCA\Theming\Controller; -use OCA\Theming\Template; +use OCA\Theming\ThemingDefaults; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataDownloadResponse; @@ -48,7 +48,7 @@ use OCA\Theming\Util; * @package OCA\Theming\Controller */ class ThemingController extends Controller { - /** @var Template */ + /** @var ThemingDefaults */ private $template; /** @var Util */ private $util; @@ -67,7 +67,7 @@ class ThemingController extends Controller { * @param string $appName * @param IRequest $request * @param IConfig $config - * @param Template $template + * @param ThemingDefaults $template * @param Util $util * @param ITimeFactory $timeFactory * @param IL10N $l @@ -77,7 +77,7 @@ class ThemingController extends Controller { $appName, IRequest $request, IConfig $config, - Template $template, + ThemingDefaults $template, Util $util, ITimeFactory $timeFactory, IL10N $l, diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php new file mode 100644 index 00000000000..1f79449e658 --- /dev/null +++ b/apps/theming/lib/Settings/Admin.php @@ -0,0 +1,98 @@ +<?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\Theming\Settings; + +use OCA\Theming\ThemingDefaults; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\ISettings; + +class Admin implements ISettings { + /** @var IConfig */ + private $config; + /** @var IL10N */ + private $l; + /** @var ThemingDefaults */ + private $themingDefaults; + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IConfig $config, + IL10N $l, + ThemingDefaults $themingDefaults, + IURLGenerator $urlGenerator) { + $this->config = $config; + $this->l = $l; + $this->themingDefaults = $themingDefaults; + $this->urlGenerator = $urlGenerator; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $path = $this->urlGenerator->linkToRoute('theming.Theming.updateLogo'); + + $themable = true; + $errorMessage = ''; + $theme = $this->config->getSystemValue('theme', ''); + if ($theme !== '') { + $themable = false; + $errorMessage = $this->l->t('You already use a custom theme'); + } + + $parameters = [ + 'themable' => $themable, + 'errorMessage' => $errorMessage, + 'name' => $this->themingDefaults->getEntity(), + 'url' => $this->themingDefaults->getBaseUrl(), + 'slogan' => $this->themingDefaults->getSlogan(), + 'color' => $this->themingDefaults->getMailHeaderColor(), + 'uploadLogoRoute' => $path, + ]; + + return new TemplateResponse('theming', 'settings-admin', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'theming'; + } + + /** + * @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/theming/lib/Settings/Section.php b/apps/theming/lib/Settings/Section.php new file mode 100644 index 00000000000..cffbb8901c8 --- /dev/null +++ b/apps/theming/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\Theming\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 'theming'; + } + + /** + * 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('Theming'); + } + + /** + * @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 30; + } +} diff --git a/apps/theming/lib/Template.php b/apps/theming/lib/ThemingDefaults.php index 25730aad95b..7b846919db3 100644 --- a/apps/theming/lib/Template.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -1,11 +1,6 @@ <?php /** * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> - * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> - * - * @author Bjoern Schiessle <bjoern@schiessle.org> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> * * @license GNU AGPL version 3 or any later version * @@ -24,20 +19,19 @@ * */ + namespace OCA\Theming; + + + use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; -/** - * Class Template - * - * Handle all the values which can be modified by this app - * - * @package OCA\Theming - */ -class Template extends \OC_Defaults { + +class ThemingDefaults extends \OC_Defaults { + /** @var IConfig */ private $config; /** @var IL10N */ @@ -54,7 +48,7 @@ class Template extends \OC_Defaults { private $color; /** - * Template constructor. + * ThemingDefaults constructor. * * @param IConfig $config * @param IL10N $l @@ -92,7 +86,7 @@ class Template extends \OC_Defaults { public function getEntity() { return $this->config->getAppValue('theming', 'name', $this->name); } - + public function getBaseUrl() { return $this->config->getAppValue('theming', 'url', $this->url); } @@ -168,4 +162,5 @@ class Template extends \OC_Defaults { return $returnValue; } + } diff --git a/apps/theming/settings/settings-admin.php b/apps/theming/settings/settings-admin.php deleted file mode 100644 index 8ef499789e8..00000000000 --- a/apps/theming/settings/settings-admin.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> - * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> - * - * @author Bjoern Schiessle <bjoern@schiessle.org> - * @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/>. - * - */ - -$config = \OC::$server->getConfig(); -$l = \OC::$server->getL10N('theming'); -$urlGenerator = \OC::$server->getURLGenerator(); - -$theming = \OC::$server->getThemingDefaults(); - -$themable = true; -$errorMessage = ''; -$theme = $config->getSystemValue('theme', ''); - -if ($theme !== '') { - $themable = false; - $errorMessage = $l->t('You already use a custom theme'); -} - -$template = new \OCP\Template('theming', 'settings-admin'); - -$template->assign('themable', $themable); -$template->assign('errorMessage', $errorMessage); -$template->assign('name', $theming->getEntity()); -$template->assign('url', $theming->getBaseUrl()); -$template->assign('slogan', $theming->getSlogan()); -$template->assign('color', $theming->getMailHeaderColor()); -$path = $urlGenerator->linkToRoute('theming.Theming.updateLogo'); -$template->assign('uploadLogoRoute', $path); - -return $template->fetchPage(); diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 81b6b886c9f..688e3d62bff 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -25,7 +25,6 @@ namespace OCA\Theming\Tests\Controller; use OCA\Theming\Controller\ThemingController; -use OCA\Theming\Template; use OCA\Theming\Util; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -34,13 +33,14 @@ use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; use Test\TestCase; +use OCA\Theming\ThemingDefaults; class ThemingControllerTest extends TestCase { /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ private $request; /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; - /** @var Template|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */ private $template; /** @var Util */ private $util; @@ -56,7 +56,7 @@ class ThemingControllerTest extends TestCase { public function setUp() { $this->request = $this->getMockBuilder('OCP\IRequest')->getMock(); $this->config = $this->getMockBuilder('OCP\IConfig')->getMock(); - $this->template = $this->getMockBuilder('OCA\Theming\Template') + $this->template = $this->getMockBuilder('OCA\Theming\ThemingDefaults') ->disableOriginalConstructor()->getMock(); $this->util = new Util(); $this->timeFactory = $this->getMockBuilder('OCP\AppFramework\Utility\ITimeFactory') diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..18c2064e8ce --- /dev/null +++ b/apps/theming/tests/Settings/AdminTest.php @@ -0,0 +1,155 @@ +<?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\Theming\Tests\Settings; + +use OCA\Theming\Settings\Admin; +use OCA\Theming\ThemingDefaults; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IURLGenerator; +use Test\TestCase; + +class AdminTest extends TestCase { + /** @var Admin */ + private $admin; + /** @var IConfig */ + private $config; + /** @var ThemingDefaults */ + private $themingDefaults; + /** @var IURLGenerator */ + private $urlGenerator; + /** @var IL10N */ + private $l10n; + + public function setUp() { + parent::setUp(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); + $this->themingDefaults = $this->getMockBuilder('\OCA\Theming\ThemingDefaults')->disableOriginalConstructor()->getMock(); + $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')->getMock(); + + $this->admin = new Admin( + $this->config, + $this->l10n, + $this->themingDefaults, + $this->urlGenerator + ); + } + + public function testGetFormNoErrors() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('theme', '') + ->willReturn(''); + $this->themingDefaults + ->expects($this->once()) + ->method('getEntity') + ->willReturn('MyEntity'); + $this->themingDefaults + ->expects($this->once()) + ->method('getBaseUrl') + ->willReturn('https://example.com'); + $this->themingDefaults + ->expects($this->once()) + ->method('getSlogan') + ->willReturn('MySlogan'); + $this->themingDefaults + ->expects($this->once()) + ->method('getMailHeaderColor') + ->willReturn('#fff'); + $this->urlGenerator + ->expects($this->once()) + ->method('linkToRoute') + ->with('theming.Theming.updateLogo') + ->willReturn('/my/route'); + $params = [ + 'themable' => true, + 'errorMessage' => '', + 'name' => 'MyEntity', + 'url' => 'https://example.com', + 'slogan' => 'MySlogan', + 'color' => '#fff', + 'uploadLogoRoute' => '/my/route', + ]; + + $expected = new TemplateResponse('theming', 'settings-admin', $params, ''); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetFormWithErrors() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('theme', '') + ->willReturn('MyCustomTheme'); + $this->l10n + ->expects($this->once()) + ->method('t') + ->with('You already use a custom theme') + ->willReturn('You already use a custom theme'); + $this->themingDefaults + ->expects($this->once()) + ->method('getEntity') + ->willReturn('MyEntity'); + $this->themingDefaults + ->expects($this->once()) + ->method('getBaseUrl') + ->willReturn('https://example.com'); + $this->themingDefaults + ->expects($this->once()) + ->method('getSlogan') + ->willReturn('MySlogan'); + $this->themingDefaults + ->expects($this->once()) + ->method('getMailHeaderColor') + ->willReturn('#fff'); + $this->urlGenerator + ->expects($this->once()) + ->method('linkToRoute') + ->with('theming.Theming.updateLogo') + ->willReturn('/my/route'); + $params = [ + 'themable' => false, + 'errorMessage' => 'You already use a custom theme', + 'name' => 'MyEntity', + 'url' => 'https://example.com', + 'slogan' => 'MySlogan', + 'color' => '#fff', + 'uploadLogoRoute' => '/my/route', + ]; + + $expected = new TemplateResponse('theming', 'settings-admin', $params, ''); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('theming', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(5, $this->admin->getPriority()); + } +} diff --git a/apps/theming/tests/Settings/SectionTest.php b/apps/theming/tests/Settings/SectionTest.php new file mode 100644 index 00000000000..3a3a4375236 --- /dev/null +++ b/apps/theming/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\Theming\Tests\Settings; + +use OCA\Theming\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('theming', $this->section->getID()); + } + + public function testGetName() { + $this->l + ->expects($this->once()) + ->method('t') + ->with('Theming') + ->willReturn('Theming'); + + $this->assertSame('Theming', $this->section->getName()); + } + + public function testGetPriority() { + $this->assertSame(30, $this->section->getPriority()); + } +} diff --git a/apps/theming/tests/TemplateTest.php b/apps/theming/tests/ThemingDefaultsTest.php index c3c792657ec..6ef7deea152 100644 --- a/apps/theming/tests/TemplateTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -23,13 +23,13 @@ */ namespace OCA\Theming\Tests; -use OCA\Theming\Template; +use OCA\Theming\ThemingDefaults; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; use Test\TestCase; -class TemplateTest extends TestCase { +class ThemingDefaultsTest extends TestCase { /** @var IConfig */ private $config; /** @var IL10N */ @@ -38,7 +38,7 @@ class TemplateTest extends TestCase { private $urlGenerator; /** @var \OC_Defaults */ private $defaults; - /** @var Template */ + /** @var ThemingDefaults */ private $template; public function setUp() { @@ -64,7 +64,7 @@ class TemplateTest extends TestCase { ->expects($this->at(3)) ->method('getMailHeaderColor') ->willReturn('#000'); - $this->template = new Template( + $this->template = new ThemingDefaults( $this->config, $this->l10n, $this->urlGenerator, diff --git a/apps/updatenotification/admin.php b/apps/updatenotification/admin.php deleted file mode 100644 index 81c7a8fb557..00000000000 --- a/apps/updatenotification/admin.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Lukas Reschke <lukas@statuscode.ch> - * - * @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/> - * - */ - -$app = new \OCA\UpdateNotification\AppInfo\Application(); -/** @var OCA\UpdateNotification\Controller\AdminController $controller */ -$controller = $app->getContainer()->query('AdminController'); -return $controller->displayPanel()->render(); diff --git a/apps/updatenotification/appinfo/app.php b/apps/updatenotification/appinfo/app.php index 0f49d2525e5..f5bcf345669 100644 --- a/apps/updatenotification/appinfo/app.php +++ b/apps/updatenotification/appinfo/app.php @@ -38,7 +38,6 @@ if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) { \OCP\Util::addScript('updatenotification', 'notification'); OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'getJavaScript'); } - \OC_App::registerAdmin('updatenotification', 'admin'); } } diff --git a/apps/updatenotification/appinfo/info.xml b/apps/updatenotification/appinfo/info.xml index 4070e90f221..2fe400a3587 100644 --- a/apps/updatenotification/appinfo/info.xml +++ b/apps/updatenotification/appinfo/info.xml @@ -5,7 +5,7 @@ <description>Displays update notifications for ownCloud and provides the SSO for the updater.</description> <licence>AGPL</licence> <author>Lukas Reschke</author> - <version>1.1.0</version> + <version>1.1.1</version> <namespace>UpdateNotification</namespace> <default_enable/> <dependencies> @@ -15,4 +15,8 @@ <background-jobs> <job>OCA\UpdateNotification\Notification\BackgroundJob</job> </background-jobs> + + <settings> + <admin>OCA\UpdateNotification\Controller\AdminController</admin> + </settings> </info> diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index ada04bdd68c..ebb3fa642f1 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -34,8 +34,9 @@ use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IRequest; use OCP\Security\ISecureRandom; +use OCP\Settings\ISettings; -class AdminController extends Controller { +class AdminController extends Controller implements ISettings { /** @var IJobList */ private $jobList; /** @var ISecureRandom */ @@ -144,4 +145,29 @@ class AdminController extends Controller { return new DataResponse($newToken); } + + /** + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered + */ + public function getForm() { + return $this->displayPanel(); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'server'; + } + + /** + * @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 1; + } } diff --git a/apps/updatenotification/templates/admin.php b/apps/updatenotification/templates/admin.php index b1cc76534e3..3c3d6cbd4cd 100644 --- a/apps/updatenotification/templates/admin.php +++ b/apps/updatenotification/templates/admin.php @@ -13,9 +13,7 @@ /** @var string $currentChannel */ $currentChannel = $_['currentChannel']; ?> -<form id="oca_updatenotification_section" class="section"> - <h2><?php p($l->t('Updater')); ?></h2> - +<form id="oca_updatenotification_section" class="followupsection"> <?php if($isNewVersionAvailable === true): ?> <strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong> <input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>"> diff --git a/apps/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php index 20b0c534c46..336edffc957 100644 --- a/apps/updatenotification/tests/Controller/AdminControllerTest.php +++ b/apps/updatenotification/tests/Controller/AdminControllerTest.php @@ -197,4 +197,12 @@ class AdminControllerTest extends TestCase { $expected = new DataResponse('MyGeneratedToken'); $this->assertEquals($expected, $this->adminController->createCredentials()); } + + public function testGetSection() { + $this->assertSame('server', $this->adminController->getSection()); + } + + public function testGetPriority() { + $this->assertSame(1, $this->adminController->getPriority()); + } } 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()); + } +} |