diff --git a/apps/encryption/appinfo/info.xml b/apps/encryption/appinfo/info.xml index 3a4d9018e758d..e35c6f2cbf83c 100644 --- a/apps/encryption/appinfo/info.xml +++ b/apps/encryption/appinfo/info.xml @@ -19,7 +19,7 @@ admin-encryption false - 1.3.0 + 1.3.1 @@ -27,5 +27,7 @@ openssl - + + OCA\Encryption\Settings\Admin + diff --git a/apps/encryption/lib/AppInfo/Application.php b/apps/encryption/lib/AppInfo/Application.php index bba522fbc8c7c..a43646d86d9bc 100644 --- a/apps/encryption/lib/AppInfo/Application.php +++ b/apps/encryption/lib/AppInfo/Application.php @@ -269,7 +269,6 @@ function (IAppContainer $c) { 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 0000000000000..2faa118e2a248 --- /dev/null +++ b/apps/encryption/lib/Settings/Admin.php @@ -0,0 +1,127 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 a424ea038741c..0000000000000 --- a/apps/encryption/settings/settings-admin.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @author Clark Tomlinson - * @author Lukas Reschke - * @author Thomas Müller - * - * @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 - * - */ - -$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 5c551267ff5f0..405dbaf703f38 100644 --- a/apps/encryption/templates/settings-admin.php +++ b/apps/encryption/templates/settings-admin.php @@ -6,6 +6,7 @@ style('encryption', 'settings-admin'); ?>
+

t("Default encryption module")); ?>

t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?> diff --git a/apps/encryption/tests/Settings/AdminTest.php b/apps/encryption/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..93896585dad5c --- /dev/null +++ b/apps/encryption/tests/Settings/AdminTest.php @@ -0,0 +1,100 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 ff734c1356c6f..411716c5c3273 100644 --- a/apps/federatedfilesharing/appinfo/info.xml +++ b/apps/federatedfilesharing/appinfo/info.xml @@ -5,10 +5,13 @@ Provide federated file sharing across servers AGPL Bjoern Schiessle, Roeland Jago Douma - 1.0.0 + 1.0.1 FederatedFileSharing other + + OCA\FederatedFileSharing\Settings\Admin + diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index b4ddc6cfe0455..b767a322505b2 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -40,7 +40,6 @@ public function __construct() { * 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 0000000000000..64619e329f371 --- /dev/null +++ b/apps/federatedfilesharing/lib/Settings/Admin.php @@ -0,0 +1,69 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 5ccd223b0a337..0000000000000 --- a/apps/federatedfilesharing/settings-admin.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @author Björn Schießle - * @author Morris Jobke - * - * @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 - * - */ - -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 5d2eb04c1706e..c454eeba17bf2 100644 --- a/apps/federatedfilesharing/templates/settings-admin.php +++ b/apps/federatedfilesharing/templates/settings-admin.php @@ -4,7 +4,7 @@ script('federatedfilesharing', 'settings-admin'); ?> -
+

t('Federated Cloud Sharing'));?>

+ * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 92b64b9c05855..6c53810dd2c22 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 c6d1debd108b0..e702c9363cd71 100644 --- a/apps/federation/appinfo/info.xml +++ b/apps/federation/appinfo/info.xml @@ -5,7 +5,7 @@ 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. AGPL Bjoern Schiessle - 1.0.0 + 1.0.1 Federation other @@ -19,4 +19,8 @@ OCA\Federation\SyncJob + + + OCA\Federation\Settings\Admin + diff --git a/apps/federation/lib/AppInfo/Application.php b/apps/federation/lib/AppInfo/Application.php index 5d8da05c8e111..cdc6145dfb45f 100644 --- a/apps/federation/lib/AppInfo/Application.php +++ b/apps/federation/lib/AppInfo/Application.php @@ -51,13 +51,6 @@ public function __construct($urlParams = array()) { $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 0000000000000..eccb3237f7d81 --- /dev/null +++ b/apps/federation/lib/Settings/Admin.php @@ -0,0 +1,69 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 aa21a1e9920e3..0000000000000 --- a/apps/federation/settings/settings-admin.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * @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 - * - */ - -$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 0000000000000..758bda6bc5e13 --- /dev/null +++ b/apps/federation/tests/Settings/AdminTest.php @@ -0,0 +1,70 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 ad7b16a3a23f1..0000000000000 --- a/apps/files/admin.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @author Clark Tomlinson - * @author Frank Karlitschek - * @author Michael Göhler - * @author Morris Jobke - * @author Robin Appelman - * @author Robin McCorkell - * @author Thomas Müller - * - * @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 - * - */ - -$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 cc86e9bf27096..0cd7870a42612 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -26,8 +26,8 @@ * along with this program. If not, see * */ -\OCP\App::registerAdmin('files', 'admin'); +$l = \OC::$server->getL10N('files'); \OC::$server->getNavigationManager()->add(function () { $urlGenerator = \OC::$server->getURLGenerator(); diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml index 573285f8b3b1f..fdce3d81541bd 100644 --- a/apps/files/appinfo/info.xml +++ b/apps/files/appinfo/info.xml @@ -6,7 +6,7 @@ AGPL Robin Appelman, Vincent Petry - 1.5.1 + 1.5.2 @@ -22,4 +22,8 @@ OCA\Files\BackgroundJob\DeleteOrphanedItems OCA\Files\BackgroundJob\CleanupFileLocks + + + OCA\Files\Settings\Admin + diff --git a/apps/files/lib/Settings/Admin.php b/apps/files/lib/Settings/Admin.php new file mode 100644 index 0000000000000..9ec23d47517b9 --- /dev/null +++ b/apps/files/lib/Settings/Admin.php @@ -0,0 +1,93 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 0000000000000..1ab8a992879c1 --- /dev/null +++ b/apps/files/tests/Settings/AdminTest.php @@ -0,0 +1,83 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 9bdd528990e09..ba12d1ff676dd 100644 --- a/apps/files_external/appinfo/info.xml +++ b/apps/files_external/appinfo/info.xml @@ -13,7 +13,7 @@ admin-external-storage false - 1.0.0 + 1.0.2 @@ -24,4 +24,9 @@ + + + OCA\Files_External\Settings\Admin + OCA\Files_External\Settings\Section + diff --git a/apps/files_external/lib/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php index a32a3a26c7f3f..06c163419f060 100644 --- a/apps/files_external/lib/AppInfo/Application.php +++ b/apps/files_external/lib/AppInfo/Application.php @@ -68,10 +68,6 @@ public function __construct(array $urlParams = array()) { * 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 0000000000000..54711443f895a --- /dev/null +++ b/apps/files_external/lib/Settings/Admin.php @@ -0,0 +1,96 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 0000000000000..4b4bac93d2934 --- /dev/null +++ b/apps/files_external/lib/Settings/Section.php @@ -0,0 +1,67 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 cb9ee5ccde036..0000000000000 --- a/apps/files_external/settings.php +++ /dev/null @@ -1,48 +0,0 @@ - - * @author Michael Gapczynski - * @author Morris Jobke - * @author Robin Appelman - * @author Robin McCorkell - * - * @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 - * - */ - -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 0000000000000..fdf9680e7c378 --- /dev/null +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -0,0 +1,109 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 0000000000000..b5dfb28b382d5 --- /dev/null +++ b/apps/files_external/tests/Settings/SectionTest.php @@ -0,0 +1,62 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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/appinfo/app.php b/apps/systemtags/appinfo/app.php index 5a365c4ef1595..af91e5fdbcd54 100644 --- a/apps/systemtags/appinfo/app.php +++ b/apps/systemtags/appinfo/app.php @@ -78,9 +78,6 @@ function() { $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 e9fd3541c4813..aa17600a3e94b 100644 --- a/apps/systemtags/appinfo/info.xml +++ b/apps/systemtags/appinfo/info.xml @@ -7,7 +7,7 @@ AGPL Vincent Petry, Joas Schilling - 1.0.0 + 1.0.1 @@ -15,4 +15,7 @@ + + OCA\SystemTags\Settings\Admin + diff --git a/apps/systemtags/lib/Settings/Admin.php b/apps/systemtags/lib/Settings/Admin.php new file mode 100644 index 0000000000000..fbdec8741f784 --- /dev/null +++ b/apps/systemtags/lib/Settings/Admin.php @@ -0,0 +1,56 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 0000000000000..b1faf82cf25b0 --- /dev/null +++ b/apps/systemtags/tests/Settings/AdminTest.php @@ -0,0 +1,52 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 051a2e279e596..f558c35e61f23 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 c7d4e40519996..0495ac218f21b 100644 --- a/apps/theming/appinfo/info.xml +++ b/apps/theming/appinfo/info.xml @@ -5,7 +5,7 @@ Adjust the Nextcloud theme AGPL Nextcloud - 1.0.0 + 1.0.1 Theming other @@ -18,4 +18,9 @@ + + + OCA\Theming\Settings\Admin + OCA\Theming\Settings\Section + diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 0db4dfe062700..8d3e2a5f2e284 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 @@ * @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 @@ public function __construct( $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 0000000000000..1f79449e65816 --- /dev/null +++ b/apps/theming/lib/Settings/Admin.php @@ -0,0 +1,98 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 0000000000000..cffbb8901c82b --- /dev/null +++ b/apps/theming/lib/Settings/Section.php @@ -0,0 +1,67 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 similarity index 90% rename from apps/theming/lib/Template.php rename to apps/theming/lib/ThemingDefaults.php index 25730aad95b14..7b846919db358 100644 --- a/apps/theming/lib/Template.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -1,11 +1,6 @@ - * @copyright Copyright (c) 2016 Lukas Reschke - * - * @author Bjoern Schiessle - * @author Joas Schilling - * @author Lukas Reschke * * @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 @@ public function getTitle() { 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 @@ public function undo($setting) { return $returnValue; } + } diff --git a/apps/theming/settings/settings-admin.php b/apps/theming/settings/settings-admin.php deleted file mode 100644 index 8ef499789e899..0000000000000 --- a/apps/theming/settings/settings-admin.php +++ /dev/null @@ -1,52 +0,0 @@ - - * @copyright Copyright (c) 2016 Lukas Reschke - * - * @author Bjoern Schiessle - * @author Lukas Reschke - * - * @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 . - * - */ - -$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 81b6b886c9fc5..688e3d62bfff8 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\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 0000000000000..18c2064e8cec4 --- /dev/null +++ b/apps/theming/tests/Settings/AdminTest.php @@ -0,0 +1,155 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 0000000000000..3a3a4375236b2 --- /dev/null +++ b/apps/theming/tests/Settings/SectionTest.php @@ -0,0 +1,62 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 similarity index 98% rename from apps/theming/tests/TemplateTest.php rename to apps/theming/tests/ThemingDefaultsTest.php index c3c792657ec6e..6ef7deea152b9 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 @@ public function setUp() { ->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 81c7a8fb5576c..0000000000000 --- a/apps/updatenotification/admin.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * @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 - * - */ - -$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 0f49d2525e57d..f5bcf3456696b 100644 --- a/apps/updatenotification/appinfo/app.php +++ b/apps/updatenotification/appinfo/app.php @@ -38,7 +38,6 @@ \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 55c6fba068367..00e667c880ffe 100644 --- a/apps/updatenotification/appinfo/info.xml +++ b/apps/updatenotification/appinfo/info.xml @@ -5,7 +5,7 @@ Displays update notifications for ownCloud and provides the SSO for the updater. AGPL Lukas Reschke - 1.0.0 + 1.0.1 UpdateNotification @@ -15,4 +15,8 @@ OCA\UpdateNotification\Notification\BackgroundJob + + + OCA\UpdateNotification\Controller\AdminController + diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index ada04bdd68cc6..ebb3fa642f1e3 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -34,8 +34,9 @@ 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 @@ public function createCredentials() { 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 b1cc76534e357..3c3d6cbd4cd8b 100644 --- a/apps/updatenotification/templates/admin.php +++ b/apps/updatenotification/templates/admin.php @@ -13,9 +13,7 @@ /** @var string $currentChannel */ $currentChannel = $_['currentChannel']; ?> - -

t('Updater')); ?>

- + t('A new version is available: %s', [$newVersionString])); ?> diff --git a/apps/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php index 0343542ef4187..cf99679e680af 100644 --- a/apps/updatenotification/tests/Controller/AdminControllerTest.php +++ b/apps/updatenotification/tests/Controller/AdminControllerTest.php @@ -59,15 +59,14 @@ class AdminControllerTest extends TestCase { public function setUp() { parent::setUp(); - $this->request = $this->getMock('\\OCP\\IRequest'); - $this->jobList = $this->getMock('\\OCP\\BackgroundJob\\IJobList'); - $this->secureRandom = $this->getMock('\\OCP\\Security\\ISecureRandom'); - $this->config = $this->getMock('\\OCP\\IConfig'); - $this->timeFactory = $this->getMock('\\OCP\\AppFramework\\Utility\\ITimeFactory'); - $this->l10n = $this->getMock('\\OCP\\IL10N'); - $this->updateChecker = $this->getMockBuilder('\\OCA\\UpdateNotification\\UpdateChecker') - ->disableOriginalConstructor()->getMock(); - $this->dateTimeFormatter = $this->getMock('\\OCP\\IDateTimeFormatter'); + $this->request = $this->getMockBuilder('\\OCP\\IRequest')->getMock(); + $this->jobList = $this->getMockBuilder('\\OCP\\BackgroundJob\\IJobList')->getMock(); + $this->secureRandom = $this->getMockBuilder('\\OCP\\Security\\ISecureRandom')->getMock(); + $this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock(); + $this->timeFactory = $this->getMockBuilder('\\OCP\\AppFramework\\Utility\\ITimeFactory')->getMock(); + $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->getMock(); + $this->updateChecker = $this->getMockBuilder('\\OCA\\UpdateNotification\\UpdateChecker')->disableOriginalConstructor()->getMock(); + $this->dateTimeFormatter = $this->getMockBuilder('\\OCP\\IDateTimeFormatter')->getMock(); $this->adminController = new AdminController( 'updatenotification', @@ -197,4 +196,12 @@ public function testCreateCredentials() { $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 10cc003a3f5a8..caacbea5619c5 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 fc44a01687e3e..63e76901406cf 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 AGPL Dominik Schmidt and Arthur Schiwon - 1.0.0 + 1.0.1 @@ -27,4 +27,9 @@ A user logs into ownCloud with their LDAP or AD credentials, and is granted acce OCA\User_LDAP\Jobs\UpdateGroups OCA\User_LDAP\Jobs\CleanUp + + + OCA\User_LDAP\Settings\Admin + OCA\User_LDAP\Settings\Section + diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php new file mode 100644 index 0000000000000..ca7db66c788dc --- /dev/null +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -0,0 +1,89 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 0000000000000..82d8d0c84fa80 --- /dev/null +++ b/apps/user_ldap/lib/Settings/Section.php @@ -0,0 +1,67 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +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 f20f873e1343b..0000000000000 --- a/apps/user_ldap/settings.php +++ /dev/null @@ -1,75 +0,0 @@ - - * @author Dominik Schmidt - * @author Joas Schilling - * @author Lukas Reschke - * @author Morris Jobke - * @author Robin Appelman - * @author Robin McCorkell - * @author Volkan Gezer - * - * @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 - * - */ - -// 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 a1511071af484..eb4c7b9912759 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -49,6 +49,9 @@ style('user_ldap', 'settings'); +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + ?> @@ -56,20 +59,24 @@
- '.$l->t('Warning: Apps user_ldap and user_webdavauth are incompatible. You may experience unexpected behavior. Please ask your system administrator to disable one of them.').'

'); - } - if(!function_exists('ldap_connect')) { - print_unescaped('

'.$l->t('Warning: The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'

'); - } - ?> - + '.$l->t('Warning: Apps user_ldap and user_webdavauth are incompatible. You may experience unexpected behavior. Please ask your system administrator to disable one of them.').'

'); + } + if(!function_exists('ldap_connect')) { + print_unescaped('

'.$l->t('Warning: The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'

'); + } + ?> + + + +

t('Connection Settings'));?>

diff --git a/apps/user_ldap/tests/Settings/AdminTest.php b/apps/user_ldap/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..4ac5a14f58b42 --- /dev/null +++ b/apps/user_ldap/tests/Settings/AdminTest.php @@ -0,0 +1,90 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 0000000000000..2d2165b8e56d2 --- /dev/null +++ b/apps/user_ldap/tests/Settings/SectionTest.php @@ -0,0 +1,62 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/core/templates/untrustedDomain.php b/core/templates/untrustedDomain.php index 46bad2168225f..735f83fedec3f 100644 --- a/core/templates/untrustedDomain.php +++ b/core/templates/untrustedDomain.php @@ -10,7 +10,7 @@ t('Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.')); ?>

- + t('Add "%s" as trusted domain', array($_['domain']))); ?>

diff --git a/db_structure.xml b/db_structure.xml index 04c91ea494f70..77f6d7689863f 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -1976,4 +1976,125 @@ + + + *dbprefix*admin_sections + + + + + id + text + + false + 64 + + + + class + text + + true + 255 + + + + priority + integer + + true + 1 + + + + admin_sections_id_index + true + + id + ascending + + + + + admin_sections_class + true + + class + ascending + + + + +
+ + + + *dbprefix*admin_settings + + + + + id + integer + 0 + true + 1 + 4 + + + + class + text + + true + 255 + + + + + section + text + + false + 64 + + + + priority + integer + + true + 1 + + + + admin_settings_id_index + true + + id + ascending + + + + + admin_settings_class + true + + class + ascending + + + + + admin_settings_section + false + + section + ascending + + + + +
+ diff --git a/lib/base.php b/lib/base.php index d22490ca5dc7e..99ba21f86aa6b 100644 --- a/lib/base.php +++ b/lib/base.php @@ -723,6 +723,7 @@ public static function init() { self::registerLogRotate(); self::registerEncryptionWrapper(); self::registerEncryptionHooks(); + self::registerSettingsHooks(); //make sure temporary files are cleaned up $tmpManager = \OC::$server->getTempManager(); @@ -801,6 +802,22 @@ public static function registerCacheHooks() { } } + public static function registerSettingsHooks() { + $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { + /** @var \OCP\App\ManagerEvent $event */ + \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); + }); + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { + /** @var \OCP\App\ManagerEvent $event */ + $jobList = \OC::$server->getJobList(); + $job = 'OC\\Settings\\RemoveOrphaned'; + if(!($jobList->has($job, null))) { + $jobList->add($job); + } + }); + } + private static function registerEncryptionWrapper() { $manager = self::$server->getEncryptionManager(); \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 27f99118bd0b5..6f6815268fc6f 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -124,6 +124,10 @@ public function __construct($appName, $urlParams = array()){ return $this->getServer()->getDateTimeZone(); }); + $this->registerService('OCP\\IDateTimeFormatter', function($c) { + return $this->getServer()->getDateTimeFormatter(); + }); + $this->registerService('OCP\\IDb', function($c) { return $this->getServer()->getDb(); }); @@ -148,6 +152,10 @@ public function __construct($appName, $urlParams = array()){ return $this->getServer()->getMountProviderCollection(); }); + $this->registerService('OCP\\Files\\Config\\IUserMountCache', function($c) { + return $this->getServer()->getUserMountCache(); + }); + $this->registerService('OCP\\Files\\IRootFolder', function($c) { return $this->getServer()->getRootFolder(); }); @@ -306,6 +314,10 @@ public function __construct($appName, $urlParams = array()){ return $c->query('ServerContainer')->getWebRoot(); }); + $this->registerService('OCP\Encryption\IManager', function ($c) { + return $this->getServer()->getEncryptionManager(); + }); + /** * App Framework APIs diff --git a/lib/private/Installer.php b/lib/private/Installer.php index eed97e18d94ce..3d8a923417a5d 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -593,6 +593,12 @@ public static function installShippedApp($app) { OC_App::setAppTypes($info['id']); + if(isset($info['settings']) && is_array($info['settings'])) { + // requires that autoloading was registered for the app, + // as happens before running the install.php some lines above + \OC::$server->getSettingsManager()->setupSettings($info['settings']); + } + return $info['id']; } diff --git a/lib/private/Server.php b/lib/private/Server.php index 16a6ee3ba6423..9f305ddfd2060 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -82,7 +82,7 @@ use OC\Security\TrustedDomainHelper; use OC\Session\CryptoWrapper; use OC\Tagging\TagMapper; -use OCA\Theming\Template; +use OCA\Theming\ThemingDefaults; use OCP\IL10N; use OCP\IServerContainer; use OCP\Security\IContentSecurityPolicyManager; @@ -650,7 +650,7 @@ public function __construct($webRoot, \OC\Config $config) { } if ($classExists && $this->getConfig()->getSystemValue('installed', false) && $this->getAppManager()->isInstalled('theming')) { - return new Template( + return new ThemingDefaults( $this->getConfig(), $this->getL10N('theming'), $this->getURLGenerator(), @@ -721,6 +721,18 @@ public function __construct($webRoot, \OC\Config $config) { return $manager; }); + $this->registerService('SettingsManager', function(Server $c) { + $manager = new \OC\Settings\Manager( + $c->getLogger(), + $c->getDatabaseConnection(), + $c->getL10N('core'), + $c->getConfig(), + $c->getEncryptionManager(), + $c->getUserManager(), + $c->getLockingProvider() + ); + return $manager; + }); } /** @@ -1276,6 +1288,11 @@ function getMountManager() { return $this->query('MountManager'); } + /** @return \OCP\Files\Config\IUserMountCache */ + function getUserMountCache() { + return $this->query('UserMountCache'); + } + /** * Get the MimeTypeDetector * @@ -1424,4 +1441,11 @@ public function getShareManager() { public function getLDAPProvider() { return $this->query('LDAPProvider'); } + + /** + * @return \OCP\Settings\IManager + */ + public function getSettingsManager() { + return $this->query('SettingsManager'); + } } diff --git a/lib/private/Settings/Admin/Additional.php b/lib/private/Settings/Admin/Additional.php new file mode 100644 index 0000000000000..d133e4737a76b --- /dev/null +++ b/lib/private/Settings/Admin/Additional.php @@ -0,0 +1,88 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings\Admin; + +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\SqlitePlatform; +use OC\Lock\DBLockingProvider; +use OC\Lock\NoopLockingProvider; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IL10N; +use OCP\Lock\ILockingProvider; +use OCP\Settings\ISettings; + +class Additional implements ISettings { + /** @var IConfig */ + private $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $parameters = [ + // Mail + 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'), + 'mail_domain' => $this->config->getSystemValue('mail_domain', ''), + 'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''), + 'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''), + 'mail_smtpsecure' => $this->config->getSystemValue('mail_smtpsecure', ''), + 'mail_smtphost' => $this->config->getSystemValue('mail_smtphost', ''), + 'mail_smtpport' => $this->config->getSystemValue('mail_smtpport', ''), + 'mail_smtpauthtype' => $this->config->getSystemValue('mail_smtpauthtype', ''), + 'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false), + 'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''), + 'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''), + ]; + + return new TemplateResponse('settings', 'admin/additional-mail', $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 0; + } +} diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php new file mode 100644 index 0000000000000..6e93407f1a391 --- /dev/null +++ b/lib/private/Settings/Admin/Encryption.php @@ -0,0 +1,91 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings\Admin; + +use OC\Encryption\Manager; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IUserManager; +use OCP\Settings\ISettings; + +class Encryption implements ISettings { + /** @var Manager */ + private $manager; + + /** @var IUserManager */ + private $userManager; + + /** + * @param Manager $manager + * @param IUserManager $userManager + */ + public function __construct(Manager $manager, IUserManager $userManager) { + $this->manager = $manager; + $this->userManager = $userManager; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $encryptionModules = $this->manager->getEncryptionModules(); + $defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId(); + $encryptionModuleList = []; + foreach ($encryptionModules as $module) { + $encryptionModuleList[$module['id']]['displayName'] = $module['displayName']; + $encryptionModuleList[$module['id']]['default'] = false; + if ($module['id'] === $defaultEncryptionModuleId) { + $encryptionModuleList[$module['id']]['default'] = true; + } + } + + $parameters = [ + // Encryption API + 'encryptionEnabled' => $this->manager->isEnabled(), + 'encryptionReady' => $this->manager->isReady(), + 'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1, + // Modules + 'encryptionModules' => $encryptionModuleList, + ]; + + return new TemplateResponse('settings', 'admin/encryption', $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 0; + } +} diff --git a/lib/private/Settings/Admin/Logging.php b/lib/private/Settings/Admin/Logging.php new file mode 100644 index 0000000000000..3212e035df78e --- /dev/null +++ b/lib/private/Settings/Admin/Logging.php @@ -0,0 +1,86 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings\Admin; + +use OC\Log\Owncloud as LogFile; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\Settings\ISettings; + +class Logging implements ISettings { + /** @var IConfig */ + private $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $logType = $this->config->getSystemValue('log_type', 'file'); + $showLog = ($logType === 'file' || $logType === 'owncloud'); + + $numEntriesToLoad = 5; + $entries = LogFile::getEntries($numEntriesToLoad + 1); + $entriesRemaining = count($entries) > $numEntriesToLoad; + $entries = array_slice($entries, 0, $numEntriesToLoad); + + $logFileExists = file_exists(LogFile::getLogFilePath()) ; + $logFileSize = $logFileExists ? filesize(LogFile::getLogFilePath()) : 0; + + $parameters = [ + 'loglevel' => $this->config->getSystemValue('loglevel', 2), + 'entries' => $entries, + 'entriesremain' => $entriesRemaining, + 'doesLogFileExist' => $logFileExists, + 'logFileSize' => $logFileSize, + 'showLog' => $showLog, + ]; + + return new TemplateResponse('settings', 'admin/logging', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'logging'; + } + + /** + * @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 0; + } +} diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php new file mode 100644 index 0000000000000..6b381ab48ed7f --- /dev/null +++ b/lib/private/Settings/Admin/Server.php @@ -0,0 +1,149 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings\Admin; + +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\SqlitePlatform; +use OC\Lock\DBLockingProvider; +use OC\Lock\NoopLockingProvider; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IL10N; +use OCP\Lock\ILockingProvider; +use OCP\Settings\ISettings; + +class Server implements ISettings { + /** @var IDBConnection|Connection */ + private $db; + /** @var IConfig */ + private $config; + /** @var ILockingProvider */ + private $lockingProvider; + /** @var IL10N */ + private $l; + + /** + * @param IDBConnection $db + * @param IConfig $config + * @param ILockingProvider $lockingProvider + * @param IL10N $l + */ + public function __construct(IDBConnection $db, + IConfig $config, + ILockingProvider $lockingProvider, + IL10N $l) { + $this->db = $db; + $this->config = $config; + $this->lockingProvider = $lockingProvider; + $this->l = $l; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + try { + if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) { + $invalidTransactionIsolationLevel = false; + } else { + $invalidTransactionIsolationLevel = $this->db->getTransactionIsolation() !== Connection::TRANSACTION_READ_COMMITTED; + } + } catch (DBALException $e) { + // ignore + $invalidTransactionIsolationLevel = false; + } + + $envPath = getenv('PATH'); + + // warn if outdated version of a memcache module is used + $caches = [ + 'apcu' => ['name' => $this->l->t('APCu'), 'version' => '4.0.6'], + 'redis' => ['name' => $this->l->t('Redis'), 'version' => '2.2.5'], + ]; + $outdatedCaches = []; + foreach ($caches as $php_module => $data) { + $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<'); + if ($isOutdated) { + $outdatedCaches[$php_module] = $data; + } + } + + if ($this->lockingProvider instanceof NoopLockingProvider) { + $fileLockingType = 'none'; + } else if ($this->lockingProvider instanceof DBLockingProvider) { + $fileLockingType = 'db'; + } else { + $fileLockingType = 'cache'; + } + + // If the current web root is non-empty but the web root from the config is, + // and system cron is used, the URL generator fails to build valid URLs. + $shouldSuggestOverwriteCliUrl = $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron' + && \OC::$WEBROOT && \OC::$WEBROOT !== '/' + && !$this->config->getSystemValue('overwrite.cli.url', ''); + $suggestedOverwriteCliUrl = ($shouldSuggestOverwriteCliUrl) ? \OC::$WEBROOT : ''; + + $parameters = [ + // Diagnosis + 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(), + 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(), + 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(), + 'checkForWorkingWellKnownSetup' => $this->config->getSystemValue('check_for_working_wellknown_setup', true), + 'has_fileinfo' => \OC_Util::fileInfoLoaded(), + 'invalidTransactionIsolationLevel' => $invalidTransactionIsolationLevel, + 'getenvServerNotWorking' => empty($envPath), + 'OutdatedCacheWarning' => $outdatedCaches, + 'fileLockingType' => $fileLockingType, + 'suggestedOverwriteCliUrl' => $suggestedOverwriteCliUrl, + + // Background jobs + 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'), + 'cron_log' => $this->config->getSystemValue('cron_log', true), + 'lastcron' => $this->config->getAppValue('core', 'lastcron', false), + 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'), + ]; + + return new TemplateResponse('settings', 'admin/server', $parameters, ''); + } + + /** + * @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 0; + } +} diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php new file mode 100644 index 0000000000000..8d3ddc9b3b55a --- /dev/null +++ b/lib/private/Settings/Admin/Sharing.php @@ -0,0 +1,90 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings\Admin; + +use OC\Share\Share; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\Settings\ISettings; +use OCP\Util; + +class Sharing implements ISettings { + /** @var IConfig */ + private $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); + $excludeGroupsList = !is_null(json_decode($excludedGroups)) + ? implode('|', json_decode($excludedGroups, true)) : ''; + + $parameters = [ + // Built-In Sharing + 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), + 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), + 'allowMailNotification' => $this->config->getAppValue('core', 'shareapi_allow_mail_notification', 'no'), + 'allowPublicMailNotification' => $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no'), + 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), + 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), + 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), + 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), + 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(), + 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), + 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), + 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), + 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), + 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false, + 'shareExcludedGroupsList' => $excludeGroupsList, + ]; + + return new TemplateResponse('settings', 'admin/sharing', $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 0; + } +} diff --git a/lib/private/Settings/Admin/TipsTricks.php b/lib/private/Settings/Admin/TipsTricks.php new file mode 100644 index 0000000000000..fd0fd5958445a --- /dev/null +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -0,0 +1,71 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings\Admin; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\Settings\ISettings; + +class TipsTricks implements ISettings { + /** @var IConfig */ + private $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $databaseOverload = (strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false); + + $parameters = [ + 'databaseOverload' => $databaseOverload, + ]; + + return new TemplateResponse('settings', 'admin/tipstricks', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'tips-tricks'; + } + + /** + * @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 0; + } +} diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php new file mode 100644 index 0000000000000..7574695d709fd --- /dev/null +++ b/lib/private/Settings/Manager.php @@ -0,0 +1,431 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings; + +use OCP\AppFramework\QueryException; +use OCP\Encryption\IManager as EncryptionManager; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IL10N; +use OCP\ILogger; +use OCP\IUserManager; +use OCP\Lock\ILockingProvider; +use OCP\Settings\ISettings; +use OCP\Settings\IManager; +use OCP\Settings\ISection; + +class Manager implements IManager { + const TABLE_ADMIN_SETTINGS = 'admin_settings'; + const TABLE_ADMIN_SECTIONS = 'admin_sections'; + + /** @var ILogger */ + private $log; + /** @var IDBConnection */ + private $dbc; + /** @var IL10N */ + private $l; + /** @var IConfig */ + private $config; + /** @var EncryptionManager */ + private $encryptionManager; + /** @var IUserManager */ + private $userManager; + /** @var ILockingProvider */ + private $lockingProvider; + + /** + * @param ILogger $log + * @param IDBConnection $dbc + * @param IL10N $l + * @param IConfig $config + * @param EncryptionManager $encryptionManager + * @param IUserManager $userManager + * @param ILockingProvider $lockingProvider + */ + public function __construct( + ILogger $log, + IDBConnection $dbc, + IL10N $l, + IConfig $config, + EncryptionManager $encryptionManager, + IUserManager $userManager, + ILockingProvider $lockingProvider + ) { + $this->log = $log; + $this->dbc = $dbc; + $this->l = $l; + $this->config = $config; + $this->encryptionManager = $encryptionManager; + $this->userManager = $userManager; + $this->lockingProvider = $lockingProvider; + } + + /** + * @inheritdoc + */ + public function setupSettings(array $settings) { + if(isset($settings[IManager::KEY_ADMIN_SECTION])) { + $this->setupAdminSection($settings[IManager::KEY_ADMIN_SECTION]); + } + if(isset($settings[IManager::KEY_ADMIN_SETTINGS])) { + $this->setupAdminSettings($settings[IManager::KEY_ADMIN_SETTINGS]); + } + } + + /** + * attempts to remove an apps section and/or settings entry. A listener is + * added centrally making sure that this method is called ones an app was + * disabled. + * + * @param string $appId + * @since 9.1.0 + */ + public function onAppDisabled($appId) { + $appInfo = \OC_App::getAppInfo($appId); // hello static legacy + + if(isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { + $this->remove(self::TABLE_ADMIN_SECTIONS, $appInfo['settings'][IManager::KEY_ADMIN_SECTION]); + } + if(isset($settings['settings'][IManager::KEY_ADMIN_SETTINGS])) { + $this->remove(self::TABLE_ADMIN_SETTINGS, $appInfo['settings'][IManager::KEY_ADMIN_SETTINGS]); + } + } + + public function checkForOrphanedClassNames() { + $tables = [ self::TABLE_ADMIN_SECTIONS, self::TABLE_ADMIN_SETTINGS ]; + foreach ($tables as $table) { + $classes = $this->getClasses($table); + foreach($classes as $className) { + try { + \OC::$server->query($className); + } catch (QueryException $e) { + $this->remove($table, $className); + } + } + } + } + + /** + * returns the registerd classes in the given table + * + * @param $table + * @return string[] + */ + private function getClasses($table) { + $q = $this->dbc->getQueryBuilder(); + $resultStatement = $q->select('class') + ->from($table) + ->execute(); + $data = $resultStatement->fetchAll(); + $resultStatement->closeCursor(); + + return array_map(function($row) { return $row['class']; }, $data); + } + + /** + * @param string $sectionClassName + */ + private function setupAdminSection($sectionClassName) { + if(!class_exists($sectionClassName)) { + $this->log->debug('Could not find admin section class ' . $sectionClassName); + return; + } + try { + $section = $this->query($sectionClassName); + } catch (QueryException $e) { + // cancel + return; + } + + if(!$section instanceof ISection) { + $this->log->error( + 'Admin section instance must implement \OCP\ISection. Invalid class: {class}', + ['class' => $sectionClassName] + ); + return; + } + if(!$this->hasAdminSection(get_class($section))) { + $this->addAdminSection($section); + } else { + $this->updateAdminSection($section); + } + } + + private function addAdminSection(ISection $section) { + $this->add(self::TABLE_ADMIN_SECTIONS, [ + 'id' => $section->getID(), + 'class' => get_class($section), + 'priority' => $section->getPriority(), + ]); + } + + private function addAdminSettings(ISettings $settings) { + $this->add(self::TABLE_ADMIN_SETTINGS, [ + 'class' => get_class($settings), + 'section' => $settings->getSection(), + 'priority' => $settings->getPriority(), + ]); + } + + /** + * @param string $table + * @param array $values + */ + private function add($table, array $values) { + $query = $this->dbc->getQueryBuilder(); + $values = array_map(function($value) use ($query) { + return $query->createNamedParameter($value); + }, $values); + $query->insert($table)->values($values); + $query->execute(); + } + + private function updateAdminSettings(ISettings $settings) { + $this->update( + self::TABLE_ADMIN_SETTINGS, + 'class', + get_class($settings), + [ + 'section' => $settings->getSection(), + 'priority' => $settings->getPriority(), + ] + ); + } + + private function updateAdminSection(ISection $section) { + $this->update( + self::TABLE_ADMIN_SECTIONS, + 'class', + get_class($section), + [ + 'id' => $section->getID(), + 'priority' => $section->getPriority(), + ] + ); + } + + private function update($table, $idCol, $id, $values) { + $query = $this->dbc->getQueryBuilder(); + $query->update($table); + foreach($values as $key => $value) { + $query->set($key, $query->createNamedParameter($value)); + } + $query + ->where($query->expr()->eq($idCol, $query->createParameter($idCol))) + ->setParameter($idCol, $id) + ->execute(); + } + + /** + * @param string $className + * @return bool + */ + private function hasAdminSection($className) { + return $this->has(self::TABLE_ADMIN_SECTIONS, $className); + } + + /** + * @param string $className + * @return bool + */ + private function hasAdminSettings($className) { + return $this->has(self::TABLE_ADMIN_SETTINGS, $className); + } + + /** + * @param string $table + * @param string $className + * @return bool + */ + private function has($table, $className) { + $query = $this->dbc->getQueryBuilder(); + $query->select('class') + ->from($table) + ->where($query->expr()->eq('class', $query->createNamedParameter($className))) + ->setMaxResults(1); + + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + return (bool) $row; + } + + /** + * deletes an settings or admin entry from the given table + * + * @param $table + * @param $className + */ + private function remove($table, $className) { + $query = $this->dbc->getQueryBuilder(); + $query->delete($table) + ->where($query->expr()->eq('class', $query->createNamedParameter($className))); + + $query->execute(); + } + + private function setupAdminSettings($settingsClassName) { + if(!class_exists($settingsClassName)) { + $this->log->debug('Could not find admin section class ' . $settingsClassName); + return; + } + + try { + /** @var ISettings $settings */ + $settings = $this->query($settingsClassName); + } catch (QueryException $e) { + // cancel + return; + } + + if(!$settings instanceof ISettings) { + $this->log->error( + 'Admin section instance must implement \OCP\ISection. Invalid class: {class}', + ['class' => $settingsClassName] + ); + return; + } + if(!$this->hasAdminSettings(get_class($settings))) { + $this->addAdminSettings($settings); + } else { + $this->updateAdminSettings($settings); + } + } + + private function query($className) { + try { + return \OC::$server->query($className); + } catch (QueryException $e) { + $this->log->logException($e); + throw $e; + } + } + + /** + * @inheritdoc + */ + public function getAdminSections() { + $query = $this->dbc->getQueryBuilder(); + $query->select(['class', 'priority']) + ->from(self::TABLE_ADMIN_SECTIONS); + + // built-in sections + $sections = [ + 0 => [new Section('server', $this->l->t('Server settings'), 0)], + 5 => [new Section('sharing', $this->l->t('Sharing'), 0)], + 45 => [new Section('encryption', $this->l->t('Encryption'), 0)], + 90 => [new Section('logging', $this->l->t('Logging'), 0)], + 98 => [new Section('additional', $this->l->t('Additional settings'), 0)], + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0)], + ]; + + $result = $query->execute(); + while($row = $result->fetch()) { + if(!isset($sections[$row['priority']])) { + $sections[$row['priority']] = []; + } + try { + $sections[$row['priority']][] = $this->query($row['class']); + } catch (QueryException $e) { + // skip + } + } + $result->closeCursor(); + + ksort($sections); + return $sections; + } + + private function getBuiltInAdminSettings($section) { + $forms = []; + try { + if($section === 'server') { + /** @var ISettings $form */ + $form = new Admin\Server($this->dbc, $this->config, $this->lockingProvider, $this->l); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'encryption') { + /** @var ISettings $form */ + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'sharing') { + /** @var ISettings $form */ + $form = new Admin\Sharing($this->config); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'logging') { + /** @var ISettings $form */ + $form = new Admin\Logging($this->config); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'additional') { + /** @var ISettings $form */ + $form = new Admin\Additional($this->config); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'tips-tricks') { + /** @var ISettings $form */ + $form = new Admin\TipsTricks($this->config); + $forms[$form->getPriority()] = [$form]; + } + } catch (QueryException $e) { + // skip + } + return $forms; + } + + private function getAdminSettingsFromDB($section, &$settings) { + $query = $this->dbc->getQueryBuilder(); + $query->select(['class', 'priority']) + ->from(self::TABLE_ADMIN_SETTINGS) + ->where($query->expr()->eq('section', $this->dbc->getQueryBuilder()->createParameter('section'))) + ->setParameter('section', $section); + + $result = $query->execute(); + while($row = $result->fetch()) { + if(!isset($settings[$row['priority']])) { + $settings[$row['priority']] = []; + } + try { + $settings[$row['priority']][] = $this->query($row['class']); + } catch (QueryException $e) { + // skip + } + } + $result->closeCursor(); + + ksort($settings); + } + + /** + * @inheritdoc + */ + public function getAdminSettings($section) { + $settings = $this->getBuiltInAdminSettings($section); + $this->getAdminSettingsFromDB($section, $settings); + return $settings; + } +} diff --git a/lib/private/Settings/RemoveOrphaned.php b/lib/private/Settings/RemoveOrphaned.php new file mode 100644 index 0000000000000..fbee95c887973 --- /dev/null +++ b/lib/private/Settings/RemoveOrphaned.php @@ -0,0 +1,91 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings; + +use OC\BackgroundJob\JobList; +use OC\BackgroundJob\TimedJob; +use OC\NeedsUpdateException; +use OCP\BackgroundJob\IJobList; +use OCP\ILogger; + +/** + * Class RemoveOrphaned + * + * @package OC\Settings + */ +class RemoveOrphaned extends TimedJob { + + /** @var IJobList */ + private $jobList; + + /** @var ILogger */ + private $logger; + + /** @var Manager */ + private $manager; + + public function __construct(Manager $manager = null) { + if($manager !== null) { + $this->manager = $manager; + } else { + // fix DI for Jobs + $this->manager = \OC::$server->getSettingsManager(); + } + } + + /** + * run the job, then remove it from the job list + * + * @param JobList $jobList + * @param ILogger $logger + */ + public function execute($jobList, ILogger $logger = null) { + // add an interval of 15 mins + $this->setInterval(15*60); + + $this->jobList = $jobList; + $this->logger = $logger; + parent::execute($jobList, $logger); + } + + /** + * @param array $argument + * @throws \Exception + * @throws \OC\NeedsUpdateException + */ + protected function run($argument) { + try { + \OC_App::loadApps(); + } catch (NeedsUpdateException $ex) { + // only run when apps are up to date + return; + } + + $this->manager->checkForOrphanedClassNames(); + + // remove the job once executed successfully + $this->jobList->remove($this); + } + +} diff --git a/lib/private/Settings/Section.php b/lib/private/Settings/Section.php new file mode 100644 index 0000000000000..b3cf242279fc2 --- /dev/null +++ b/lib/private/Settings/Section.php @@ -0,0 +1,77 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OC\Settings; + +use OCP\Settings\ISection; + +class Section implements ISection { + /** @var string */ + private $id; + /** @var string */ + private $name; + /** @var int */ + private $priority; + + /** + * @param string $id + * @param string $name + * @param int $priority + */ + public function __construct($id, $name, $priority) { + $this->id = $id; + $this->name = $name; + $this->priority = $priority; + } + + /** + * returns the ID of the section. It is supposed to be a lower case string, + * e.g. 'ldap' + * + * @returns string + */ + public function getID() { + return $this->id; + } + + /** + * 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->name; + } + + /** + * @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 $this->priority; + } +} diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 5395d1daeee2a..ac0bcf11f364f 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -51,6 +51,7 @@ use OC\Installer; use OC\OCSClient; use OC\Repair; +use OCP\App\ManagerEvent; /** * This class manages the apps. It allows them to register and integrate in the @@ -345,6 +346,13 @@ public static function enable($app, $groups = null) { } else { $appManager->enableApp($app); } + + $info = self::getAppInfo($app); + if(isset($info['settings']) && is_array($info['settings'])) { + $appPath = self::getAppPath($app); + self::registerAutoloading($app, $appPath); + \OC::$server->getSettingsManager()->setupSettings($info['settings']); + } } /** @@ -471,7 +479,7 @@ public static function getSettingsNavigation() { $settings[] = array( "id" => "admin", "order" => 1000, - "href" => $urlGenerator->linkToRoute('settings_admin'), + "href" => $urlGenerator->linkToRoute('settings.AdminSettings.index'), "name" => $l->t("Admin"), "icon" => $urlGenerator->imagePath("settings", "admin.svg") ); @@ -1162,6 +1170,13 @@ public static function installApp($app) { if (isset($appData['id'])) { $config->setAppValue($app, 'ocsid', $appData['id']); } + + if(isset($info['settings']) && is_array($info['settings'])) { + $appPath = self::getAppPath($app); + self::registerAutoloading($app, $appPath); + \OC::$server->getSettingsManager()->setupSettings($info['settings']); + } + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); } else { if(empty($appName) ) { @@ -1199,6 +1214,11 @@ public static function updateApp($appId) { include $appPath . '/appinfo/update.php'; } self::setupBackgroundJobs($appData['background-jobs']); + if(isset($appData['settings']) && is_array($appData['settings'])) { + $appPath = self::getAppPath($appId); + self::registerAutoloading($appId, $appPath); + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); + } //set remote/public handlers if (array_key_exists('ocsid', $appData)) { @@ -1218,6 +1238,10 @@ public static function updateApp($appId) { $version = \OC_App::getAppVersion($appId); \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( + ManagerEvent::EVENT_APP_UPDATE, $appId + )); + return true; } diff --git a/lib/public/App/ManagerEvent.php b/lib/public/App/ManagerEvent.php index a70345b62fd15..b25ea55aee6f4 100644 --- a/lib/public/App/ManagerEvent.php +++ b/lib/public/App/ManagerEvent.php @@ -36,6 +36,11 @@ class ManagerEvent extends Event { const EVENT_APP_ENABLE_FOR_GROUPS = 'OCP\App\IAppManager::enableAppForGroups'; const EVENT_APP_DISABLE = 'OCP\App\IAppManager::disableApp'; + /** + * @since 9.1.0 + */ + const EVENT_APP_UPDATE = 'OCP\App\IAppManager::updateApp'; + /** @var string */ protected $event; /** @var string */ diff --git a/lib/public/Settings/IManager.php b/lib/public/Settings/IManager.php new file mode 100644 index 0000000000000..a406915ad0900 --- /dev/null +++ b/lib/public/Settings/IManager.php @@ -0,0 +1,98 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OCP\Settings; + +/** + * @since 9.1 + */ +interface IManager { + /** + * @since 9.1.0 + */ + const KEY_ADMIN_SETTINGS = 'admin'; + + /** + * @since 9.1.0 + */ + const KEY_ADMIN_SECTION = 'admin-section'; + + /** + * sets up settings according to data specified by an apps info.xml, within + * the element. + * + * @param array $settings an associative array, allowed keys are as specified + * by the KEY_ constant of this interface. The value + * must always be a class name, implement either + * IAdmin or ISection. I.e. only one section and admin + * setting can be configured per app. + * @since 9.1.0 + */ + public function setupSettings(array $settings); + + /** + * attempts to remove an apps section and/or settings entry. A listener is + * added centrally making sure that this method is called ones an app was + * disabled. + * + * What this does not help with is when applications change their settings + * or section classes during their life time. New entries will be added, + * but inactive ones will still reside in the database. + * + * @param string $appId + * @since 9.1.0 + */ + public function onAppDisabled($appId); + + /** + * The method should check all registered classes whether they are still + * instantiable and remove them, if not. This method is called by a + * background job once, after one or more apps were updated. + * + * An app`s info.xml can change during an update and make it unknown whether + * a registered class name was changed or not. An old one would just stay + * registered. Another case is if an admin takes a radical approach and + * simply removes an app from the app folder. These unregular checks will + * take care of such situations. + * + * @since 9.1.0 + */ + public function checkForOrphanedClassNames(); + + /** + * returns a list of the admin sections + * + * @return array array of ISection[] where key is the priority + * @since 9.1.0 + */ + public function getAdminSections(); + + /** + * returns a list of the admin settings + * + * @param string $section the section id for which to load the settings + * @return array array of IAdmin[] where key is the priority + * @since 9.1.0 + */ + public function getAdminSettings($section); +} diff --git a/lib/public/Settings/ISection.php b/lib/public/Settings/ISection.php new file mode 100644 index 0000000000000..5edf5de0ca4f5 --- /dev/null +++ b/lib/public/Settings/ISection.php @@ -0,0 +1,57 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OCP\Settings; + +/** + * @since 9.1 + */ +interface ISection { + /** + * returns the ID of the section. It is supposed to be a lower case string, + * e.g. 'ldap' + * + * @returns string + * @since 9.1 + */ + public function getID(); + + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + * @since 9.1 + */ + public function getName(); + + /** + * @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 + * @since 9.1 + */ + public function getPriority(); +} diff --git a/lib/public/Settings/ISettings.php b/lib/public/Settings/ISettings.php new file mode 100644 index 0000000000000..611bb713b33bd --- /dev/null +++ b/lib/public/Settings/ISettings.php @@ -0,0 +1,54 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OCP\Settings; + +use OCP\AppFramework\Http\TemplateResponse; + +/** + * @since 9.1 + */ +interface ISettings { + + /** + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered + * @since 9.1 + */ + public function getForm(); + + /** + * @return string the section ID, e.g. 'sharing' + * @since 9.1 + */ + public function getSection(); + + /** + * @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 + * @since 9.1 + */ + public function getPriority(); +} diff --git a/settings/Application.php b/settings/Application.php index 657b3fe490a5b..57e27c8998b74 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -32,6 +32,7 @@ use OC\Files\View; use OC\Server; +use OC\Settings\Controller\AdminSettingsController; use OC\Settings\Controller\AppSettingsController; use OC\Settings\Controller\AuthSettingsController; use OC\Settings\Controller\CertificateController; @@ -177,6 +178,14 @@ public function __construct(array $urlParams=[]){ $c->query('Checker') ); }); + $container->registerService('AdminSettingsController', function(IContainer $c) { + return new AdminSettingsController( + $c->query('AppName'), + $c->query('Request'), + $c->query('INavigationManager'), + $c->query('SettingsManager') + ); + }); /** * Middleware @@ -268,5 +277,14 @@ public function __construct(array $urlParams=[]){ $server = $c->query('ServerContainer'); return $server->getIntegrityCodeChecker(); }); + $container->registerService('EventDispatcher', function (IContainer $c) { + return $c->query('ServerContainer')->getEventDispatcher(); + }); + $container->registerService('EncryptionManager', function (IContainer $c) { + return $c->query('ServerContainer')->getEncryptionManager(); + }); + $container->registerService('SettingsManager', function (IContainer $c) { + return $c->query('ServerContainer')->getSettingsManager(); + }); } } diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php new file mode 100644 index 0000000000000..ef70caf56902f --- /dev/null +++ b/settings/Controller/AdminSettingsController.php @@ -0,0 +1,148 @@ + + * + * @author Arthur Schiwon + * @author Lukas Reschke + * + * @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 . + * + */ + +namespace OC\Settings\Controller; + +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\INavigationManager; +use OCP\IRequest; +use OCP\Settings\IManager as ISettingsManager; +use OCP\Template; + +/** + * @package OC\Settings\Controller + */ +class AdminSettingsController extends Controller { + /** @var INavigationManager */ + private $navigationManager; + /** @var ISettingsManager */ + private $settingsManager; + + /** + * @param string $appName + * @param IRequest $request + * @param INavigationManager $navigationManager + * @param ISettingsManager $settingsManager + */ + public function __construct( + $appName, + IRequest $request, + INavigationManager $navigationManager, + ISettingsManager $settingsManager + ) { + parent::__construct($appName, $request); + $this->navigationManager = $navigationManager; + $this->settingsManager = $settingsManager; + } + + /** + * @param string $section + * @return TemplateResponse + * + * @NoCSRFRequired + */ + public function index($section) { + $this->navigationManager->setActiveEntry('admin'); + + $templateParams = []; + $templateParams = array_merge($templateParams, $this->getNavigationParameters($section)); + $templateParams = array_merge($templateParams, $this->getSettings($section)); + + return new TemplateResponse('settings', 'admin/frame', $templateParams); + } + + /** + * @param string $section + * @return array + */ + private function getSettings($section) { + $html = ''; + $settings = $this->settingsManager->getAdminSettings($section); + foreach ($settings as $prioritizedSettings) { + foreach ($prioritizedSettings as $setting) { + /** @var \OCP\Settings\ISettings $setting */ + $form = $setting->getForm(); + $html .= $form->renderAs('')->render(); + } + } + if($section === 'additional') { + $html .= $this->getLegacyForms(); + } + return ['content' => $html]; + } + + /** + * @return bool|string + */ + private function getLegacyForms() { + $forms = \OC_App::getForms('admin'); + + $forms = array_map(function ($form) { + if (preg_match('%([^>]*)>.*?)%i', $form, $regs)) { + $sectionName = str_replace('', '', $regs[0]); + $sectionName = str_replace('', '', $sectionName); + $anchor = strtolower($sectionName); + $anchor = str_replace(' ', '-', $anchor); + + return array( + 'anchor' => $anchor, + 'section-name' => $sectionName, + 'form' => $form + ); + } + return array( + 'form' => $form + ); + }, $forms); + + $out = new Template('settings', 'admin/additional'); + $out->assign('forms', $forms); + + return $out->fetchPage(); + } + + /** + * @param string $currentSection + * @return array + */ + private function getNavigationParameters($currentSection) { + $sections = $this->settingsManager->getAdminSections(); + $templateParameters = []; + /** @var \OC\Settings\Section[] $prioritizedSections */ + foreach($sections as $prioritizedSections) { + foreach ($prioritizedSections as $section) { + $templateParameters[] = [ + 'anchor' => $section->getID(), + 'section-name' => $section->getName(), + 'active' => $section->getID() === $currentSection, + ]; + } + } + + return [ + 'forms' => $templateParameters + ]; + } +} diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php index 48c0783f17db3..86b9b768747f4 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -268,7 +268,7 @@ private function isCorrectMemcachedPHPModuleInstalled() { public function rescanFailedIntegrityCheck() { $this->checker->runInstanceVerification(); return new RedirectResponse( - $this->urlGenerator->linkToRoute('settings_admin') + $this->urlGenerator->linkToRoute('settings.AdminSettings.index') ); } diff --git a/settings/admin.php b/settings/admin.php deleted file mode 100644 index 11d3a3f40db10..0000000000000 --- a/settings/admin.php +++ /dev/null @@ -1,271 +0,0 @@ - - * @author Björn Schießle - * @author Georg Ehrke - * @author Jan-Christoph Borchardt - * @author Joas Schilling - * @author Lukas Reschke - * @author Martin Mattel - * @author Morris Jobke - * @author Robin Appelman - * @author Roeland Jago Douma - * @author Thomas Müller - * @author Vincent Petry - * - * @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 - * - */ - -use OC\Lock\NoopLockingProvider; - -OC_Util::checkAdminUser(); -\OC::$server->getNavigationManager()->setActiveEntry("admin"); - -$template = new OC_Template('settings', 'admin', 'user'); -$l = \OC::$server->getL10N('settings'); - -OC_Util::addScript('settings', 'certificates'); -OC_Util::addScript('files', 'jquery.fileupload'); - -\OC::$server->getEventDispatcher()->dispatch('OC\Settings\Admin::loadAdditionalScripts'); - -$showLog = (\OC::$server->getConfig()->getSystemValue('log_type', 'owncloud') === 'owncloud'); -$numEntriesToLoad = 3; -$entries = \OC\Log\Owncloud::getEntries($numEntriesToLoad + 1); -$entriesRemaining = count($entries) > $numEntriesToLoad; -$entries = array_slice($entries, 0, $numEntriesToLoad); -$logFilePath = \OC\Log\Owncloud::getLogFilePath(); -$doesLogFileExist = file_exists($logFilePath); -$logFileSize = 0; -if($doesLogFileExist) { - $logFileSize = filesize($logFilePath); -} - -$config = \OC::$server->getConfig(); -$appConfig = \OC::$server->getAppConfig(); -$request = \OC::$server->getRequest(); -$certificateManager = \OC::$server->getCertificateManager(null); -$urlGenerator = \OC::$server->getURLGenerator(); - -// Should we display sendmail as an option? -$template->assign('sendmail_is_available', (bool) \OC_Helper::findBinaryPath('sendmail')); - -$template->assign('loglevel', $config->getSystemValue("loglevel", 2)); -$template->assign('mail_domain', $config->getSystemValue("mail_domain", '')); -$template->assign('mail_from_address', $config->getSystemValue("mail_from_address", '')); -$template->assign('mail_smtpmode', $config->getSystemValue("mail_smtpmode", '')); -$template->assign('mail_smtpsecure', $config->getSystemValue("mail_smtpsecure", '')); -$template->assign('mail_smtphost', $config->getSystemValue("mail_smtphost", '')); -$template->assign('mail_smtpport', $config->getSystemValue("mail_smtpport", '')); -$template->assign('mail_smtpauthtype', $config->getSystemValue("mail_smtpauthtype", '')); -$template->assign('mail_smtpauth', $config->getSystemValue("mail_smtpauth", false)); -$template->assign('mail_smtpname', $config->getSystemValue("mail_smtpname", '')); -$template->assign('mail_smtppassword', $config->getSystemValue("mail_smtppassword", '')); -$template->assign('entries', $entries); -$template->assign('entriesremain', $entriesRemaining); -$template->assign('logFileSize', $logFileSize); -$template->assign('doesLogFileExist', $doesLogFileExist); -$template->assign('showLog', $showLog); -$template->assign('readOnlyConfigEnabled', OC_Helper::isReadOnlyConfigEnabled()); -$template->assign('isLocaleWorking', OC_Util::isSetLocaleWorking()); -$template->assign('isAnnotationsWorking', OC_Util::isAnnotationsWorking()); -$template->assign('checkForWorkingWellKnownSetup', $config->getSystemValue('check_for_working_wellknown_setup', true)); -$template->assign('has_fileinfo', OC_Util::fileInfoLoaded()); -$template->assign('backgroundjobs_mode', $appConfig->getValue('core', 'backgroundjobs_mode', 'ajax')); -$template->assign('cron_log', $config->getSystemValue('cron_log', true)); -$template->assign('lastcron', $appConfig->getValue('core', 'lastcron', false)); -$template->assign('shareAPIEnabled', $appConfig->getValue('core', 'shareapi_enabled', 'yes')); -$template->assign('shareDefaultExpireDateSet', $appConfig->getValue('core', 'shareapi_default_expire_date', 'no')); -$template->assign('shareExpireAfterNDays', $appConfig->getValue('core', 'shareapi_expire_after_n_days', '7')); -$template->assign('shareEnforceExpireDate', $appConfig->getValue('core', 'shareapi_enforce_expire_date', 'no')); -$excludeGroups = $appConfig->getValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false; -$template->assign('shareExcludeGroups', $excludeGroups); -$excludedGroupsList = $appConfig->getValue('core', 'shareapi_exclude_groups_list', ''); -$excludedGroupsList = json_decode($excludedGroupsList); -$template->assign('shareExcludedGroupsList', !is_null($excludedGroupsList) ? implode('|', $excludedGroupsList) : ''); -$template->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled()); -$backends = \OC::$server->getUserManager()->getBackends(); -$externalBackends = (count($backends) > 1) ? true : false; -$template->assign('encryptionReady', \OC::$server->getEncryptionManager()->isReady()); -$template->assign('externalBackendsEnabled', $externalBackends); - -/** @var \Doctrine\DBAL\Connection $connection */ -$connection = \OC::$server->getDatabaseConnection(); -try { - if ($connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { - $template->assign('invalidTransactionIsolationLevel', false); - } else { - $template->assign('invalidTransactionIsolationLevel', $connection->getTransactionIsolation() !== \Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED); - } -} catch (\Doctrine\DBAL\DBALException $e) { - // ignore - $template->assign('invalidTransactionIsolationLevel', false); -} - -$encryptionModules = \OC::$server->getEncryptionManager()->getEncryptionModules(); -$defaultEncryptionModuleId = \OC::$server->getEncryptionManager()->getDefaultEncryptionModuleId(); - -$encModulues = array(); -foreach ($encryptionModules as $module) { - $encModulues[$module['id']]['displayName'] = $module['displayName']; - $encModulues[$module['id']]['default'] = false; - if ($module['id'] === $defaultEncryptionModuleId) { - $encModulues[$module['id']]['default'] = true; - } -} -$template->assign('encryptionModules', $encModulues); - -// If the current web root is non-empty but the web root from the config is, -// and system cron is used, the URL generator fails to build valid URLs. -$shouldSuggestOverwriteCliUrl = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron' && - \OC::$WEBROOT && \OC::$WEBROOT !== '/' && - !$config->getSystemValue('overwrite.cli.url', ''); -$suggestedOverwriteCliUrl = ($shouldSuggestOverwriteCliUrl) ? \OC::$WEBROOT : ''; -$template->assign('suggestedOverwriteCliUrl', $suggestedOverwriteCliUrl); - -$template->assign('allowLinks', $appConfig->getValue('core', 'shareapi_allow_links', 'yes')); -$template->assign('enforceLinkPassword', \OCP\Util::isPublicLinkPasswordRequired()); -$template->assign('allowPublicUpload', $appConfig->getValue('core', 'shareapi_allow_public_upload', 'yes')); -$template->assign('allowResharing', $appConfig->getValue('core', 'shareapi_allow_resharing', 'yes')); -$template->assign('allowPublicMailNotification', $appConfig->getValue('core', 'shareapi_allow_public_notification', 'no')); -$template->assign('allowMailNotification', $appConfig->getValue('core', 'shareapi_allow_mail_notification', 'no')); -$template->assign('allowShareDialogUserEnumeration', $appConfig->getValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')); -$template->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly()); -$template->assign('allowGroupSharing', $appConfig->getValue('core', 'shareapi_allow_group_sharing', 'yes')); -$databaseOverload = (strpos(\OCP\Config::getSystemValue('dbtype'), 'sqlite') !== false); -$template->assign('databaseOverload', $databaseOverload); -$template->assign('cronErrors', $appConfig->getValue('core', 'cronErrors')); - -// warn if php is not setup properly to get system variables with getenv -$path = getenv('PATH'); -$template->assign('getenvServerNotWorking', empty($path)); - -// warn if outdated version of a memcache module is used -$caches = [ - 'apcu' => ['name' => $l->t('APCu'), 'version' => '4.0.6'], - 'redis' => ['name' => $l->t('Redis'), 'version' => '2.2.5'], -]; - -$outdatedCaches = []; -foreach ($caches as $php_module => $data) { - $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<'); - if ($isOutdated) { - $outdatedCaches[$php_module] = $data; - } -} -$template->assign('OutdatedCacheWarning', $outdatedCaches); - -// add hardcoded forms from the template -$forms = OC_App::getForms('admin'); - -if ($config->getSystemValue('enable_certificate_management', false)) { - $certificatesTemplate = new OC_Template('settings', 'certificates'); - $certificatesTemplate->assign('type', 'admin'); - $certificatesTemplate->assign('uploadRoute', 'settings.Certificate.addSystemRootCertificate'); - $certificatesTemplate->assign('certs', $certificateManager->listCertificates()); - $certificatesTemplate->assign('urlGenerator', $urlGenerator); - $forms[] = $certificatesTemplate->fetchPage(); -} - -$formsAndMore = array(); -if ($request->getServerProtocol() !== 'https' || !OC_Util::isAnnotationsWorking() || - $suggestedOverwriteCliUrl || !OC_Util::isSetLocaleWorking() || - !OC_Util::fileInfoLoaded() || $databaseOverload -) { - $formsAndMore[] = array('anchor' => 'security-warning', 'section-name' => $l->t('Security & setup warnings')); -} -$formsAndMore[] = array('anchor' => 'shareAPI', 'section-name' => $l->t('Sharing')); -$formsAndMore[] = ['anchor' => 'encryptionAPI', 'section-name' => $l->t('Server-side encryption')]; - -// Prioritize fileSharingSettings and files_external and move updater to the version -$fileSharingSettings = $filesExternal = $updaterAppPanel = $ocDefaultEncryptionModulePanel = ''; -foreach ($forms as $index => $form) { - if (strpos($form, 'id="fileSharingSettings"')) { - $fileSharingSettings = $form; - unset($forms[$index]); - continue; - } - if (strpos($form, 'id="files_external"')) { - $filesExternal = $form; - unset($forms[$index]); - continue; - } - if (strpos($form, 'class="updater-admin"')) { - $updaterAppPanel = $form; - unset($forms[$index]); - continue; - } - if (strpos($form, 'id="ocDefaultEncryptionModule"')) { - $ocDefaultEncryptionModulePanel = $form; - unset($forms[$index]); - continue; - } -} -if ($filesExternal) { - $formsAndMore[] = array('anchor' => 'files_external', 'section-name' => $l->t('External Storage')); -} - -$template->assign('fileSharingSettings', $fileSharingSettings); -$template->assign('filesExternal', $filesExternal); -$template->assign('updaterAppPanel', $updaterAppPanel); -$template->assign('ocDefaultEncryptionModulePanel', $ocDefaultEncryptionModulePanel); -$lockingProvider = \OC::$server->getLockingProvider(); -if ($lockingProvider instanceof NoopLockingProvider) { - $template->assign('fileLockingType', 'none'); -} else if ($lockingProvider instanceof \OC\Lock\DBLockingProvider) { - $template->assign('fileLockingType', 'db'); -} else { - $template->assign('fileLockingType', 'cache'); -} - -$formsMap = array_map(function ($form) { - if (preg_match('%([^>]*)>.*?)%i', $form, $regs)) { - $sectionName = str_replace('', '', $regs[0]); - $sectionName = str_replace('', '', $sectionName); - $anchor = strtolower($sectionName); - $anchor = str_replace(' ', '-', $anchor); - - return array( - 'anchor' => $anchor, - 'section-name' => $sectionName, - 'form' => $form - ); - } - return array( - 'form' => $form - ); -}, $forms); - -$formsAndMore = array_merge($formsAndMore, $formsMap); - -// add bottom hardcoded forms from the template -$formsAndMore[] = ['anchor' => 'backgroundjobs', 'section-name' => $l->t('Cron')]; -$formsAndMore[] = ['anchor' => 'mail_general_settings', 'section-name' => $l->t('Email server')]; -$formsAndMore[] = ['anchor' => 'log-section', 'section-name' => $l->t('Log')]; -$formsAndMore[] = ['anchor' => 'admin-tips', 'section-name' => $l->t('Tips & tricks')]; -if ($updaterAppPanel) { - $formsAndMore[] = ['anchor' => 'updater', 'section-name' => $l->t('Updates')]; -} - -$template->assign('forms', $formsAndMore); - -$template->printPage(); - -$util = new \OC_Util(); -$util->createHtaccessTestFile(\OC::$server->getConfig()); - diff --git a/settings/css/settings.css b/settings/css/settings.css index b6d0e57995bd4..589373e14f947 100644 --- a/settings/css/settings.css +++ b/settings/css/settings.css @@ -372,6 +372,14 @@ span.version { .section h2.app-name { margin-bottom: 8px; } +.followupsection { + display: block; + padding: 0 30px 30px 30px; + color: #555; + margin-bottom: 24px; + margin-top: -30px; + position: relative; +} .app-image { float: left; padding-right: 10px; diff --git a/settings/routes.php b/settings/routes.php index 94732b3192a6a..f77da543e1006 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -64,6 +64,8 @@ ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'], ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], + ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']], + ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'], ] ]); @@ -76,8 +78,6 @@ ->actionInclude('settings/personal.php'); $this->create('settings_users', '/settings/users') ->actionInclude('settings/users.php'); -$this->create('settings_admin', '/settings/admin') - ->actionInclude('settings/admin.php'); // Settings ajax actions // users $this->create('settings_ajax_setquota', '/settings/ajax/setquota.php') diff --git a/settings/templates/admin.php b/settings/templates/admin.php deleted file mode 100644 index 1bd055a180010..0000000000000 --- a/settings/templates/admin.php +++ /dev/null @@ -1,578 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or later. - * See the COPYING-README file. - */ -/** - * @var array $_ - * @var \OCP\IL10N $l - * @var OC_Defaults $theme - */ - -style('settings', 'settings'); -script('settings', [ 'settings', 'admin', 'log'] ); -script('core', ['multiselect', 'setupchecks']); -vendor_script('select2/select2'); -vendor_style('select2/select2'); - -$levels = ['Debug', 'Info', 'Warning', 'Error', 'Fatal']; -$levelLabels = [ - $l->t( 'Everything (fatal issues, errors, warnings, info, debug)' ), - $l->t( 'Info, warnings, errors and fatal issues' ), - $l->t( 'Warnings, errors and fatal issues' ), - $l->t( 'Errors and fatal issues' ), - $l->t( 'Fatal issues only' ), -]; - -$mail_smtpauthtype = [ - '' => $l->t('None'), - 'LOGIN' => $l->t('Login'), - 'PLAIN' => $l->t('Plain'), - 'NTLM' => $l->t('NT LAN Manager'), -]; - -$mail_smtpsecure = [ - '' => $l->t('None'), - 'ssl' => $l->t('SSL'), - 'tls' => $l->t('TLS'), -]; - -$mail_smtpmode = [ - ['php', 'PHP'], - ['smtp', 'SMTP'], -]; -if ($_['sendmail_is_available']) { - $mail_smtpmode[] = ['sendmail', 'Sendmail']; -} -if ($_['mail_smtpmode'] == 'qmail') { - $mail_smtpmode[] = ['qmail', 'qmail']; -} -?> - -
-
    - %s", \OCP\Util::sanitizeHTML($anchor), \OCP\Util::sanitizeHTML($sectionName))); - } - }?> -
-
- -
- -
-

t('Security & setup warnings'));?>

-
    - -
  • - t('php does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.')); ?>
    - t('Please check the installation documentation ↗ for php configuration notes and the php configuration of your server, especially when using php-fpm.', link_to_docs('admin-php-fpm'))); ?> -
  • - -
  • - t('The Read-Only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.')); ?> -
  • - -
  • - t('PHP is apparently setup to strip inline doc blocks. This will make several core apps inaccessible.')); ?>
    - t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')); ?> -
  • - -
  • - t('Your database does not run with "READ COMMITED" transaction isolation level. This can cause problems when multiple actions are executed in parallel.')); ?> -
  • - $data) { - ?> -
  • - t('%1$s below version %2$s is installed, for stability and performance reasons we recommend updating to a newer %1$s version.', $data)); ?> -
  • - -
  • - t('The PHP module \'fileinfo\' is missing. We strongly recommend to enable this module to get best results with mime-type detection.')); ?> -
  • - -
  • - t('Transactional file locking is disabled, this might lead to issues with race conditions. Enable \'filelocking.enabled\' in config.php to avoid these problems. See the documentation ↗ for more information.', link_to_docs('admin-transactional-locking'))); ?> -
  • - -
  • - t('System locale can not be set to a one which supports UTF-8.')); - ?> -
    - t('This means that there might be problems with certain characters in file names.')); - ?> -
    - t('We strongly suggest installing the required packages on your system to support one of the following locales: %s.', [$locales])); - ?> -
  • - -
  • - t('If your installation is not installed in the root of the domain and uses system cron, there can be issues with the URL generation. To avoid these problems, please set the "overwrite.cli.url" option in your config.php file to the webroot path of your installation (Suggested: "%s")', $_['suggestedOverwriteCliUrl'])); ?> -
  • - -
  • - t('It was not possible to execute the cronjob via CLI. The following technical errors have appeared:')); ?> -
    -
      - error)) {?> -
    1. error) ?> hint) ?>
    2. - -
    -
  • - -
- -
-
- - - - -
-
- -
-
- -
-

t('Sharing'));?>

- -

- /> -
-

-

- /> -
-

- -

- /> -
- - /> -
- - /> -
- - /> -
- -

-

- t( 'Expire after ' )); ?> - ' /> - t( 'days' )); ?> - /> -
-

-

- /> -
-

-

- /> -
-

-

- /> -
-

-

- /> -
-

-

- /> -
-

-

- -
- t('These groups will still be able to receive shares, but not to initiate them.')); ?> -

-

- /> -
-

- - -
- - - - -
- - -
-

t('Cron'));?>

- -

- - - - t("Last cron job execution: %s.", [$relative_time]));?> - - - - - t("Last cron job execution: %s. Something seems wrong.", [$relative_time]));?> - - - - t("Cron was not executed yet!")); - endif; ?> -

- - - -

- > -
- t("Execute one task with each page loaded")); ?> -

-

- > -
- t("cron.php is registered at a webcron service to call cron.php every 15 minutes over http.")); ?> -

-

- > -
- t("Use system's cron service to call the cron.php file every 15 minutes.")); ?> -

-
- -
-

t('Server-side encryption')); ?>

- - -

- /> -
-

- - - -
-
- t('No encryption module loaded, please enable an encryption module in the app menu.')); - } else { ?> -

t('Select default encryption module:')) ?>

-
- $module): ?> - > - -
- - - -
- -
-
- t('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one. Please enable the "Default encryption module" and run \'occ encryption:migrate\'')); - } elseif ($_['encryptionReady'] === false && $_['externalBackendsEnabled'] === false) { - p($l->t('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one.')); ?> - - -
-
-
- -
- -

t('Email server'));?>

- - -

t('This is used for sending out notifications.')); ?>

- -

- - - - - -

- -

- - ' />@ - ' /> -

- - - - - -
- -
- -
- t( 'Test email settings' )); ?> - - -
- -
-

t('Log'));?>

- - - - - - - - - - - -
- level]);?> - - app);?> - - message);?> - - time)){ - p(OC_Util::formatDate($entry->time)); - } else { - p($entry->time); - }?> - user) ? p($entry->user) : p('--') ?>
- 0): ?> - t('Download logfile'));?> - - - - - - (100 * 1024 * 1024)): ?> -
- - t('The logfile is bigger than 100 MB. Downloading it may take some time!')); ?> - - - - -

t('What to log'));?>

-
- -
-

t('Tips & tricks'));?>

- -
- - -
- - -
-

t('Version'));?>

-

getTitle()); ?>

-

-
- - - - -
diff --git a/settings/templates/admin/additional-mail.php b/settings/templates/admin/additional-mail.php new file mode 100644 index 0000000000000..88eec421ec5e4 --- /dev/null +++ b/settings/templates/admin/additional-mail.php @@ -0,0 +1,140 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + +$mail_smtpauthtype = [ + '' => $l->t('None'), + 'LOGIN' => $l->t('Login'), + 'PLAIN' => $l->t('Plain'), + 'NTLM' => $l->t('NT LAN Manager'), +]; + +$mail_smtpsecure = [ + '' => $l->t('None'), + 'ssl' => $l->t('SSL'), + 'tls' => $l->t('TLS'), +]; + +$mail_smtpmode = [ + ['php', 'PHP'], + ['smtp', 'SMTP'], +]; +if ($_['sendmail_is_available']) { + $mail_smtpmode[] = ['sendmail', 'Sendmail']; +} +if ($_['mail_smtpmode'] == 'qmail') { + $mail_smtpmode[] = ['qmail', 'qmail']; +} + +?> + +
+
+

t('Email server'));?>

+ + +

t('This is used for sending out notifications.')); ?>

+ +

+ + + + + +

+ +

+ + ' />@ + ' /> +

+ + + + +
+
+ +
+ +
+ t( 'Test email settings' )); ?> + + +
+ diff --git a/apps/systemtags/admin.php b/settings/templates/admin/additional.php similarity index 65% rename from apps/systemtags/admin.php rename to settings/templates/admin/additional.php index 45ea577e8ab67..2ad2c5af4e5d5 100644 --- a/apps/systemtags/admin.php +++ b/settings/templates/admin/additional.php @@ -1,6 +1,8 @@ + * @copyright Copyright (c) 2016 Arthur Schiwon + * + * @author Arthur Schiwon * * @license GNU AGPL version 3 or any later version * @@ -19,5 +21,13 @@ * */ -$template = new \OCP\Template('systemtags', 'admin'); -return $template->fetchPage(); +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + +?> + + +
+ diff --git a/settings/templates/admin/encryption.php b/settings/templates/admin/encryption.php new file mode 100644 index 0000000000000..4b6d9045689bc --- /dev/null +++ b/settings/templates/admin/encryption.php @@ -0,0 +1,90 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + +?> + +
+

t('Server-side encryption')); ?>

+ + +

+ /> +
+

+ + + +
+
+ t('No encryption module loaded, please enable an encryption module in the app menu.')); + } else { ?> +

t('Select default encryption module:')) ?>

+
+ $module): ?> + > + +
+ +
+ +
+
+ t('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one. Please enable the "Default encryption module" and run \'occ encryption:migrate\'')); + } elseif ($_['encryptionReady'] === false && $_['externalBackendsEnabled'] === false) { + p($l->t('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one.')); ?> + + +
+
+
diff --git a/settings/templates/admin/frame.php b/settings/templates/admin/frame.php new file mode 100644 index 0000000000000..1d9f6dc7a7845 --- /dev/null +++ b/settings/templates/admin/frame.php @@ -0,0 +1,48 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +style('settings', 'settings'); +script('settings', [ 'settings', 'admin', 'log', 'certificates'] ); +script('core', ['multiselect', 'setupchecks']); +script('files', 'jquery.fileupload'); +vendor_script('select2/select2'); +vendor_style('select2/select2'); + +?> + +
+
    + getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); + $sectionName = $form['section-name']; + $active = $form['active'] ? ' class="active"' : ''; + print_unescaped(sprintf("%s", $active, \OCP\Util::sanitizeHTML($anchor), \OCP\Util::sanitizeHTML($sectionName))); + } + }?> +
+
+ +
+ +
diff --git a/settings/templates/admin/logging.php b/settings/templates/admin/logging.php new file mode 100644 index 0000000000000..2f60629c42a41 --- /dev/null +++ b/settings/templates/admin/logging.php @@ -0,0 +1,88 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + +$levels = ['Debug', 'Info', 'Warning', 'Error', 'Fatal']; +$levelLabels = [ + $l->t( 'Everything (fatal issues, errors, warnings, info, debug)' ), + $l->t( 'Info, warnings, errors and fatal issues' ), + $l->t( 'Warnings, errors and fatal issues' ), + $l->t( 'Errors and fatal issues' ), + $l->t( 'Fatal issues only' ), +]; + +?> + +
+

t('Log'));?>

+ + + + + + + + + + + +
+ level]);?> + + app);?> + + message);?> + + time)){ + p(OC_Util::formatDate($entry->time)); + } else { + p($entry->time); + }?> + user) ? p($entry->user) : p('--') ?>
+

t('What to log'));?>

+ + 0): ?> + t('Download logfile'));?> + + + + + + (100 * 1024 * 1024)): ?> +
+ + t('The logfile is bigger than 100 MB. Downloading it may take some time!')); ?> + + + +
diff --git a/settings/templates/admin/server.php b/settings/templates/admin/server.php new file mode 100644 index 0000000000000..a15705a90e2d5 --- /dev/null +++ b/settings/templates/admin/server.php @@ -0,0 +1,215 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + +?> + +
+

t('Security & setup warnings'));?>

+
    + +
  • + t('php does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.')); ?>
    + t('Please check the installation documentation ↗ for php configuration notes and the php configuration of your server, especially when using php-fpm.', link_to_docs('admin-php-fpm'))); ?> +
  • + +
  • + t('The Read-Only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.')); ?> +
  • + +
  • + t('PHP is apparently setup to strip inline doc blocks. This will make several core apps inaccessible.')); ?>
    + t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')); ?> +
  • + +
  • + t('Your database does not run with "READ COMMITTED" transaction isolation level. This can cause problems when multiple actions are executed in parallel.')); ?> +
  • + $data) { + ?> +
  • + t('%1$s below version %2$s is installed, for stability and performance reasons we recommend updating to a newer %1$s version.', $data)); ?> +
  • + +
  • + t('The PHP module \'fileinfo\' is missing. We strongly recommend to enable this module to get best results with mime-type detection.')); ?> +
  • + +
  • + t('Transactional file locking is disabled, this might lead to issues with race conditions. Enable \'filelocking.enabled\' in config.php to avoid these problems. See the documentation ↗ for more information.', link_to_docs('admin-transactional-locking'))); ?> +
  • + +
  • + t('System locale can not be set to a one which supports UTF-8.')); + ?> +
    + t('This means that there might be problems with certain characters in file names.')); + ?> +
    + t('We strongly suggest installing the required packages on your system to support one of the following locales: %s.', [$locales])); + ?> +
  • + +
  • + t('If your installation is not installed in the root of the domain and uses system cron, there can be issues with the URL generation. To avoid these problems, please set the "overwrite.cli.url" option in your config.php file to the webroot path of your installation (Suggested: "%s")', $_['suggestedOverwriteCliUrl'])); ?> +
  • + +
  • + t('It was not possible to execute the cronjob via CLI. The following technical errors have appeared:')); ?> +
    +
      + error)) {?> +
    1. error) ?> hint) ?>
    2. + +
    +
  • + +
+ +
+
+ + + + +
+
+ +
+
+ +
+

t('Cron'));?>

+ +

+ + + + t("Last cron job execution: %s.", [$relative_time]));?> + + + + + t("Last cron job execution: %s. Something seems wrong.", [$relative_time]));?> + + + + t("Cron was not executed yet!")); + endif; ?> +

+ + + +

+ > +
+ t("Execute one task with each page loaded")); ?> +

+

+ > +
+ t("cron.php is registered at a webcron service to call cron.php every 15 minutes over http.")); ?> +

+

+ > +
+ t("Use system's cron service to call the cron.php file every 15 minutes.")); ?> +

+
+ +
+ +

t('Version'));?>

+

getTitle()); ?>

+

+
diff --git a/settings/templates/admin/sharing.php b/settings/templates/admin/sharing.php new file mode 100644 index 0000000000000..b8f8e92024627 --- /dev/null +++ b/settings/templates/admin/sharing.php @@ -0,0 +1,107 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + +?> + +
+

t('Sharing'));?>

+ +

+ /> +
+

+

+ /> +
+

+ +

+ /> +
+ + /> +
+ + /> +
+ + /> +
+ +

+

+ t( 'Expire after ' )); ?> + ' /> + t( 'days' )); ?> + /> +
+

+

+ /> +
+

+

+ /> +
+

+

+ /> +
+

+

+ /> +
+

+

+ /> +
+

+

+ +
+ t('These groups will still be able to receive shares, but not to initiate them.')); ?> +

+

+ /> +
+

+
diff --git a/settings/templates/admin/tipstricks.php b/settings/templates/admin/tipstricks.php new file mode 100644 index 0000000000000..e924a96deadad --- /dev/null +++ b/settings/templates/admin/tipstricks.php @@ -0,0 +1,49 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + +?> + +
+

t('Tips & tricks'));?>

+ +
diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index 0f3945efd48f1..8eaa7c9843b65 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -57,14 +57,14 @@ class LoginControllerTest extends TestCase { public function setUp() { parent::setUp(); - $this->request = $this->createMock('\\OCP\\IRequest'); - $this->userManager = $this->createMock('\\OCP\\IUserManager'); - $this->config = $this->createMock('\\OCP\\IConfig'); - $this->session = $this->createMock('\\OCP\\ISession'); + $this->request = $this->getMockBuilder('\\OCP\\IRequest')->getMock(); + $this->userManager = $this->getMockBuilder('\\OCP\\IUserManager')->getMock(); + $this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock(); + $this->session = $this->getMockBuilder('\\OCP\\ISession')->getMock(); $this->userSession = $this->getMockBuilder('\\OC\\User\\Session') ->disableOriginalConstructor() ->getMock(); - $this->urlGenerator = $this->createMock('\\OCP\\IURLGenerator'); + $this->urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->getMock(); $this->twoFactorManager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager') ->disableOriginalConstructor() ->getMock(); @@ -110,7 +110,7 @@ public function testLogoutWithToken() { ->method('getCookie') ->with('oc_token') ->willReturn('MyLoginToken'); - $user = $this->createMock('\\OCP\\IUser'); + $user = $this->getMockBuilder('\\OCP\\IUser')->getMock(); $user ->expects($this->once()) ->method('getUID') @@ -218,7 +218,7 @@ public function testShowLoginFormWithPasswordResetOption($canChangePassword, ->method('getSystemValue') ->with('lost_password_link') ->willReturn(false); - $user = $this->createMock('\\OCP\\IUser'); + $user = $this->getMockBuilder('\\OCP\\IUser')->getMock(); $user ->expects($this->once()) ->method('canChangePassword') @@ -257,7 +257,7 @@ public function testShowLoginFormForUserNamedNull() { ->method('getSystemValue') ->with('lost_password_link') ->willReturn(false); - $user = $this->createMock('\\OCP\\IUser'); + $user = $this->getMockBuilder('\\OCP\\IUser')->getMock(); $user ->expects($this->once()) ->method('canChangePassword') @@ -329,7 +329,7 @@ public function testLoginWithInvalidCredentials() { public function testLoginWithValidCredentials() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $password = 'secret'; $indexPageUrl = \OC_Util::getDefaultPageUrl(); @@ -370,7 +370,7 @@ public function testLoginWithValidCredentials() { public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('jane')); @@ -405,7 +405,7 @@ public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn() { public function testLoginWithoutPassedCsrfCheckAndLoggedIn() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('jane')); @@ -445,7 +445,7 @@ public function testLoginWithoutPassedCsrfCheckAndLoggedIn() { public function testLoginWithValidCredentialsAndRedirectUrl() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('jane')); @@ -492,7 +492,7 @@ public function testLoginWithValidCredentialsAndRedirectUrl() { public function testLoginWithTwoFactorEnforced() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('john')); @@ -543,7 +543,7 @@ public function testLoginWithTwoFactorEnforced() { public function testToNotLeakLoginName() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('john')); diff --git a/tests/Settings/Controller/AdminSettingsControllerTest.php b/tests/Settings/Controller/AdminSettingsControllerTest.php new file mode 100644 index 0000000000000..6c93bca0d680c --- /dev/null +++ b/tests/Settings/Controller/AdminSettingsControllerTest.php @@ -0,0 +1,72 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ +namespace Tests\Settings\Controller; + + +use OC\Settings\Admin\TipsTricks; +use OC\Settings\Controller\AdminSettingsController; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\INavigationManager; +use OCP\IRequest; +use OCP\Settings\IManager; +use Test\TestCase; + +class AdminSettingsControllerTest extends TestCase { + /** @var AdminSettingsController */ + private $adminSettingsController; + /** @var IRequest */ + private $request; + /** @var INavigationManager */ + private $navigationManager; + /** @var IManager */ + private $settingsManager; + + public function setUp() { + parent::setUp(); + + $this->request = $this->getMockBuilder('\OCP\IRequest')->getMock(); + $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->getMock(); + $this->settingsManager = $this->getMockBuilder('\OCP\Settings\IManager')->getMock(); + + $this->adminSettingsController = new AdminSettingsController( + 'settings', + $this->request, + $this->navigationManager, + $this->settingsManager + ); + } + + public function testIndex() { + $this->settingsManager + ->expects($this->once()) + ->method('getAdminSections') + ->willReturn([]); + $this->settingsManager + ->expects($this->once()) + ->method('getAdminSettings') + ->with('test') + ->willReturn([5 => new TipsTricks($this->getMockBuilder('\OCP\IConfig')->getMock())]); + $expected = new TemplateResponse('settings', 'admin/frame', ['forms' => [], 'content' => '']); + $this->assertEquals($expected, $this->adminSettingsController->index('test')); + } +} diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index b2c8498409a1f..74e942386b09e 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -29,6 +29,7 @@ use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IL10N; +use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use OC_Util; @@ -55,6 +56,8 @@ class CheckSetupControllerTest extends TestCase { private $util; /** @var IL10N */ private $l10n; + /** @var ILogger */ + private $logger; /** @var Checker */ private $checker; @@ -82,6 +85,7 @@ public function setUp() { })); $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') ->disableOriginalConstructor()->getMock(); + $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') ->setConstructorArgs([ 'settings', @@ -92,6 +96,7 @@ public function setUp() { $this->util, $this->l10n, $this->checker, + $this->logger ]) ->setMethods(['getCurlVersion', 'isPhpOutdated'])->getMock(); } @@ -366,7 +371,8 @@ public function testGetCurlVersion() { $this->urlGenerator, $this->util, $this->l10n, - $this->checker + $this->checker, + $this->logger ]) ->setMethods(null)->getMock(); @@ -605,7 +611,7 @@ public function testRescanFailedIntegrityCheck() { $this->urlGenerator ->expects($this->once()) ->method('linkToRoute') - ->with('settings_admin') + ->with('settings.AdminSettings.index') ->will($this->returnValue('/admin')); $expected = new RedirectResponse('/admin'); diff --git a/tests/lib/Settings/Admin/AdditionalTest.php b/tests/lib/Settings/Admin/AdditionalTest.php new file mode 100644 index 0000000000000..3a99893cf7c56 --- /dev/null +++ b/tests/lib/Settings/Admin/AdditionalTest.php @@ -0,0 +1,127 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +namespace Test\Settings\Admin; + +use OC\Settings\Admin\Additional; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use Test\TestCase; + +class AdditionalTest extends TestCase { + /** @var Additional */ + private $admin; + /** @var IConfig */ + private $config; + + public function setUp() { + parent::setUp(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + + $this->admin = new Additional( + $this->config + ); + } + + public function testGetForm() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('mail_domain', '') + ->willReturn('mx.nextcloud.com'); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('mail_from_address', '') + ->willReturn('no-reply@nextcloud.com'); + $this->config + ->expects($this->at(2)) + ->method('getSystemValue') + ->with('mail_smtpmode', '') + ->willReturn('php'); + $this->config + ->expects($this->at(3)) + ->method('getSystemValue') + ->with('mail_smtpsecure', '') + ->willReturn(true); + $this->config + ->expects($this->at(4)) + ->method('getSystemValue') + ->with('mail_smtphost', '') + ->willReturn('smtp.nextcloud.com'); + $this->config + ->expects($this->at(5)) + ->method('getSystemValue') + ->with('mail_smtpport', '') + ->willReturn(25); + $this->config + ->expects($this->at(6)) + ->method('getSystemValue') + ->with('mail_smtpauthtype', '') + ->willReturn('login'); + $this->config + ->expects($this->at(7)) + ->method('getSystemValue') + ->with('mail_smtpauth', false) + ->willReturn(true); + $this->config + ->expects($this->at(8)) + ->method('getSystemValue') + ->with('mail_smtpname', '') + ->willReturn('smtp.sender.com'); + $this->config + ->expects($this->at(9)) + ->method('getSystemValue') + ->with('mail_smtppassword', '') + ->willReturn('mypassword'); + + $expected = new TemplateResponse( + 'settings', + 'admin/additional-mail', + [ + 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'), + 'mail_domain' => 'mx.nextcloud.com', + 'mail_from_address' => 'no-reply@nextcloud.com', + 'mail_smtpmode' => 'php', + 'mail_smtpsecure' => true, + 'mail_smtphost' => 'smtp.nextcloud.com', + 'mail_smtpport' => 25, + 'mail_smtpauthtype' => 'login', + 'mail_smtpauth' => true, + 'mail_smtpname' => 'smtp.sender.com', + 'mail_smtppassword' => 'mypassword', + ], + '' + ); + + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('additional', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(0, $this->admin->getPriority()); + } +} diff --git a/tests/lib/Settings/Admin/EncryptionTest.php b/tests/lib/Settings/Admin/EncryptionTest.php new file mode 100644 index 0000000000000..a282b059c921e --- /dev/null +++ b/tests/lib/Settings/Admin/EncryptionTest.php @@ -0,0 +1,138 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +namespace Test\Settings\Admin; + +use OC\Encryption\Manager; +use OC\Settings\Admin\Encryption; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IUserManager; +use Test\TestCase; + +class EncryptionTest extends TestCase { + /** @var Encryption */ + private $admin; + /** @var Manager */ + private $manager; + /** @var IUserManager */ + private $userManager; + + public function setUp() { + parent::setUp(); + $this->manager = $this->getMockBuilder('\OC\Encryption\Manager')->disableOriginalConstructor()->getMock(); + $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); + + $this->admin = new Encryption( + $this->manager, + $this->userManager + ); + } + + /** + * @return array + */ + public function encryptionSettingsProvider() { + return [ + [true], + [false], + ]; + } + + /** + * @dataProvider encryptionSettingsProvider + * @param bool $enabled + */ + public function testGetFormWithOnlyOneBackend($enabled) { + $this->manager + ->expects($this->once()) + ->method('isEnabled') + ->willReturn($enabled); + $this->manager + ->expects($this->once()) + ->method('isReady') + ->willReturn($enabled); + $this->manager + ->expects($this->once()) + ->method('getEncryptionModules') + ->willReturn([]); + $this->userManager + ->expects($this->once()) + ->method('getBackends') + ->willReturn(['entry']); + $expected = new TemplateResponse( + 'settings', + 'admin/encryption', + [ + 'encryptionEnabled' => $enabled, + 'encryptionReady' => $enabled, + 'externalBackendsEnabled' => false, + 'encryptionModules' => [] + ], + '' + ); + $this->assertEquals($expected, $this->admin->getForm()); + } + + /** + * @dataProvider encryptionSettingsProvider + * @param bool $enabled + */ + public function testGetFormWithMultipleBackends($enabled) { + $this->manager + ->expects($this->once()) + ->method('isEnabled') + ->willReturn($enabled); + $this->manager + ->expects($this->once()) + ->method('isReady') + ->willReturn($enabled); + $this->manager + ->expects($this->once()) + ->method('getEncryptionModules') + ->willReturn([]); + $this->userManager + ->expects($this->once()) + ->method('getBackends') + ->willReturn(['entry', 'entry']); + $expected = new TemplateResponse( + 'settings', + 'admin/encryption', + [ + 'encryptionEnabled' => $enabled, + 'encryptionReady' => $enabled, + 'externalBackendsEnabled' => true, + 'encryptionModules' => [] + ], + '' + ); + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('encryption', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(0, $this->admin->getPriority()); + } +} diff --git a/tests/lib/Settings/Admin/LoggingTest.php b/tests/lib/Settings/Admin/LoggingTest.php new file mode 100644 index 0000000000000..1899143b266dc --- /dev/null +++ b/tests/lib/Settings/Admin/LoggingTest.php @@ -0,0 +1,91 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +namespace Test\Settings\Admin; + +use OC\Settings\Admin\Logging; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use Test\TestCase; +use OC\Log\Owncloud as LogFile; + +class LoggingTest extends TestCase { + /** @var Logging */ + private $admin; + /** @var IConfig */ + private $config; + + public function setUp() { + parent::setUp(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + + $this->admin = new Logging( + $this->config + ); + } + + public function testGetForm() { + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('log_type', 'file') + ->willReturn('owncloud'); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('loglevel', 2) + ->willReturn(3); + + $numEntriesToLoad = 5; + $entries = LogFile::getEntries($numEntriesToLoad + 1); + $entriesRemaining = count($entries) > $numEntriesToLoad; + $entries = array_slice($entries, 0, $numEntriesToLoad); + + $logFileExists = file_exists(LogFile::getLogFilePath()) ; + $logFileSize = $logFileExists ? filesize(LogFile::getLogFilePath()) : 0; + + $expected = new TemplateResponse( + 'settings', + 'admin/logging', + [ + 'loglevel' => 3, + 'entries' => $entries, + 'entriesremain' => $entriesRemaining, + 'doesLogFileExist' => $logFileExists, + 'logFileSize' => $logFileSize, + 'showLog' => true, + ], + '' + ); + + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('logging', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(0, $this->admin->getPriority()); + } +} diff --git a/tests/lib/Settings/Admin/ServerTest.php b/tests/lib/Settings/Admin/ServerTest.php new file mode 100644 index 0000000000000..874422307e073 --- /dev/null +++ b/tests/lib/Settings/Admin/ServerTest.php @@ -0,0 +1,154 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +namespace Test\Settings\Admin; + +use Doctrine\DBAL\Platforms\SqlitePlatform; +use OC\Settings\Admin\Server; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IL10N; +use OCP\Lock\ILockingProvider; +use Test\TestCase; + +class ServerTest extends TestCase { + /** @var Server */ + private $admin; + /** @var IDBConnection */ + private $dbConnection; + /** @var IConfig */ + private $config; + /** @var ILockingProvider */ + private $lockingProvider; + /** @var IL10N */ + private $l10n; + + public function setUp() { + parent::setUp(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->dbConnection = $this->getMockBuilder('\OCP\IDBConnection')->getMock(); + $this->lockingProvider = $this->getMockBuilder('\OCP\Lock\ILockingProvider')->getMock(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); + + $this->admin = new Server( + $this->dbConnection, + $this->config, + $this->lockingProvider, + $this->l10n + ); + } + + public function testGetForm() { + $this->dbConnection + ->expects($this->once()) + ->method('getDatabasePlatform') + ->willReturn(new SqlitePlatform()); + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'backgroundjobs_mode', 'ajax') + ->willReturn('ajax'); + $this->config + ->expects($this->at(2)) + ->method('getAppValue') + ->with('core', 'backgroundjobs_mode', 'ajax') + ->willReturn('ajax'); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'lastcron', false) + ->willReturn(false); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'cronErrors') + ->willReturn(''); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('check_for_working_wellknown_setup', true) + ->willReturn(true); + $this->config + ->expects($this->at(3)) + ->method('getSystemValue') + ->with('cron_log', true) + ->willReturn(true); + $this->l10n + ->expects($this->at(0)) + ->method('t') + ->with('APCu') + ->willReturn('APCu'); + $this->l10n + ->expects($this->at(1)) + ->method('t') + ->with('Redis') + ->willReturn('Redis'); + $outdatedCaches = []; + $caches = [ + 'apcu' => ['name' => 'APCu', 'version' => '4.0.6'], + 'redis' => ['name' => 'Redis', 'version' => '2.2.5'], + ]; + foreach ($caches as $php_module => $data) { + $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<'); + if ($isOutdated) { + $outdatedCaches[$php_module] = $data; + } + } + $envPath = getenv('PATH'); + $expected = new TemplateResponse( + 'settings', + 'admin/server', + [ + // Diagnosis + 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(), + 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(), + 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(), + 'checkForWorkingWellKnownSetup' => true, + 'has_fileinfo' => \OC_Util::fileInfoLoaded(), + 'invalidTransactionIsolationLevel' => false, + 'getenvServerNotWorking' => empty($envPath), + 'OutdatedCacheWarning' => $outdatedCaches, + 'fileLockingType' => 'cache', + 'suggestedOverwriteCliUrl' => '', + + // Background jobs + 'backgroundjobs_mode' => 'ajax', + 'cron_log' => true, + 'lastcron' => false, + 'cronErrors' => '' + ], + '' + ); + + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('server', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(0, $this->admin->getPriority()); + } +} diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php new file mode 100644 index 0000000000000..38ab7614d1cc5 --- /dev/null +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -0,0 +1,239 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +namespace Test\Settings\Admin; + +use OC\Settings\Admin\Sharing; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use Test\TestCase; + +class SharingTest extends TestCase { + /** @var Sharing */ + private $admin; + /** @var IConfig */ + private $config; + + public function setUp() { + parent::setUp(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + + $this->admin = new Sharing( + $this->config + ); + } + + public function testGetFormWithoutExcludedGroups() { + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'shareapi_exclude_groups_list', '') + ->willReturn(''); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_group_sharing', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(2)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_links', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_mail_notification', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_public_notification', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_public_upload', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(6)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_resharing', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(7)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(8)) + ->method('getAppValue') + ->with('core', 'shareapi_enabled', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(9)) + ->method('getAppValue') + ->with('core', 'shareapi_default_expire_date', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(10)) + ->method('getAppValue') + ->with('core', 'shareapi_expire_after_n_days', '7') + ->willReturn('7'); + $this->config + ->expects($this->at(11)) + ->method('getAppValue') + ->with('core', 'shareapi_enforce_expire_date', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(12)) + ->method('getAppValue') + ->with('core', 'shareapi_exclude_groups', 'no') + ->willReturn('no'); + + $expected = new TemplateResponse( + 'settings', + 'admin/sharing', + [ + 'allowGroupSharing' => 'yes', + 'allowLinks' => 'yes', + 'allowMailNotification' => 'no', + 'allowPublicMailNotification' => 'no', + 'allowPublicUpload' => 'yes', + 'allowResharing' => 'yes', + 'allowShareDialogUserEnumeration' => 'yes', + 'enforceLinkPassword' => false, + 'onlyShareWithGroupMembers' => false, + 'shareAPIEnabled' => 'yes', + 'shareDefaultExpireDateSet' => 'no', + 'shareExpireAfterNDays' => '7', + 'shareEnforceExpireDate' => 'no', + 'shareExcludeGroups' => false, + 'shareExcludedGroupsList' => '', + ], + '' + ); + + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetFormWithExcludedGroups() { + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'shareapi_exclude_groups_list', '') + ->willReturn('["NoSharers","OtherNoSharers"]'); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_group_sharing', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(2)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_links', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_mail_notification', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_public_notification', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_public_upload', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(6)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_resharing', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(7)) + ->method('getAppValue') + ->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(8)) + ->method('getAppValue') + ->with('core', 'shareapi_enabled', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(9)) + ->method('getAppValue') + ->with('core', 'shareapi_default_expire_date', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(10)) + ->method('getAppValue') + ->with('core', 'shareapi_expire_after_n_days', '7') + ->willReturn('7'); + $this->config + ->expects($this->at(11)) + ->method('getAppValue') + ->with('core', 'shareapi_enforce_expire_date', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(12)) + ->method('getAppValue') + ->with('core', 'shareapi_exclude_groups', 'no') + ->willReturn('yes'); + + $expected = new TemplateResponse( + 'settings', + 'admin/sharing', + [ + 'allowGroupSharing' => 'yes', + 'allowLinks' => 'yes', + 'allowMailNotification' => 'no', + 'allowPublicMailNotification' => 'no', + 'allowPublicUpload' => 'yes', + 'allowResharing' => 'yes', + 'allowShareDialogUserEnumeration' => 'yes', + 'enforceLinkPassword' => false, + 'onlyShareWithGroupMembers' => false, + 'shareAPIEnabled' => 'yes', + 'shareDefaultExpireDateSet' => 'no', + 'shareExpireAfterNDays' => '7', + 'shareEnforceExpireDate' => 'no', + 'shareExcludeGroups' => true, + 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers', + ], + '' + ); + + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('sharing', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(0, $this->admin->getPriority()); + } +} diff --git a/tests/lib/Settings/Admin/TipsTricksTest.php b/tests/lib/Settings/Admin/TipsTricksTest.php new file mode 100644 index 0000000000000..0e8857b56d0bc --- /dev/null +++ b/tests/lib/Settings/Admin/TipsTricksTest.php @@ -0,0 +1,91 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +namespace Test\Settings\Admin; + +use OC\Settings\Admin\TipsTricks; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use Test\TestCase; + +class TipsTrickTest extends TestCase { + /** @var TipsTricks */ + private $admin; + /** @var IConfig */ + private $config; + + public function setUp() { + parent::setUp(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + + $this->admin = new TipsTricks( + $this->config + ); + } + + public function testGetFormWithExcludedGroupsWithSQLite() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('dbtype') + ->willReturn('sqlite'); + + $expected = new TemplateResponse( + 'settings', + 'admin/tipstricks', + [ + 'databaseOverload' => true, + ], + '' + ); + + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetFormWithExcludedGroupsWithoutSQLite() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('dbtype') + ->willReturn('mysql'); + + $expected = new TemplateResponse( + 'settings', + 'admin/tipstricks', + [ + 'databaseOverload' => false, + ], + '' + ); + + $this->assertEquals($expected, $this->admin->getForm()); + } + + public function testGetSection() { + $this->assertSame('tips-tricks', $this->admin->getSection()); + } + + public function testGetPriority() { + $this->assertSame(0, $this->admin->getPriority()); + } +} diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php new file mode 100644 index 0000000000000..cd5100eff6d6b --- /dev/null +++ b/tests/lib/Settings/ManagerTest.php @@ -0,0 +1,220 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +namespace Tests\Settings; + +use OC\Settings\Admin\Sharing; +use OC\Settings\Manager; +use OC\Settings\Section; +use OCP\Encryption\IManager; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IL10N; +use OCP\ILogger; +use OCP\IUserManager; +use OCP\Lock\ILockingProvider; +use Test\TestCase; + +class ManagerTest extends TestCase { + /** @var Manager */ + private $manager; + /** @var ILogger */ + private $logger; + /** @var IDBConnection */ + private $dbConnection; + /** @var IL10N */ + private $l10n; + /** @var IConfig */ + private $config; + /** @var IManager */ + private $encryptionManager; + /** @var IUserManager */ + private $userManager; + /** @var ILockingProvider */ + private $lockingProvider; + + public function setUp() { + parent::setUp(); + + $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); + $this->dbConnection = $this->getMockBuilder('\OCP\IDBConnection')->getMock(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->encryptionManager = $this->getMockBuilder('\OCP\Encryption\IManager')->getMock(); + $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); + $this->lockingProvider = $this->getMockBuilder('\OCP\Lock\ILockingProvider')->getMock(); + + $this->manager = new Manager( + $this->logger, + $this->dbConnection, + $this->l10n, + $this->config, + $this->encryptionManager, + $this->userManager, + $this->lockingProvider + ); + } + + public function testSetupSettings() { + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); + $qb + ->expects($this->once()) + ->method('select') + ->with('class') + ->willReturn($qb); + $this->dbConnection + ->expects($this->at(0)) + ->method('getQueryBuilder') + ->willReturn($qb); + $qb + ->expects($this->once()) + ->method('from') + ->with('admin_settings') + ->willReturn($qb); + $expressionBuilder = $this->getMockBuilder('\OCP\DB\QueryBuilder\IExpressionBuilder')->getMock(); + $qb + ->expects($this->once()) + ->method('expr') + ->willReturn($expressionBuilder); + $param = $this->getMockBuilder('\OCP\DB\QueryBuilder\IParameter')->getMock(); + $qb + ->expects($this->once()) + ->method('createNamedParameter') + ->with('OCA\Files\Settings\Admin') + ->willReturn($param); + $expressionBuilder + ->expects($this->once()) + ->method('eq') + ->with('class', $param) + ->willReturn('myString'); + $qb + ->expects($this->once()) + ->method('where') + ->with('myString') + ->willReturn($qb); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); + $qb + ->expects($this->once()) + ->method('execute') + ->willReturn($stmt); + + $qb1 = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); + $qb1 + ->expects($this->once()) + ->method('insert') + ->with('admin_settings') + ->willReturn($qb1); + $this->dbConnection + ->expects($this->at(1)) + ->method('getQueryBuilder') + ->willReturn($qb1); + + $this->manager->setupSettings([ + 'admin' => 'OCA\Files\Settings\Admin', + ]); + } + + public function testGetAdminSections() { + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); + $qb + ->expects($this->once()) + ->method('select') + ->with(['class', 'priority']) + ->willReturn($qb); + $qb + ->expects($this->once()) + ->method('from') + ->with('admin_sections') + ->willReturn($qb); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); + $qb + ->expects($this->once()) + ->method('execute') + ->willReturn($stmt); + $this->dbConnection + ->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($qb); + $this->l10n + ->expects($this->any()) + ->method('t') + ->will($this->returnArgument(0)); + + $this->assertEquals([ + 0 => [new Section('server', 'Server settings', 0)], + 5 => [new Section('sharing', 'Sharing', 0)], + 45 => [new Section('encryption', 'Encryption', 0)], + 90 => [new Section('logging', 'Logging', 0)], + 98 => [new Section('additional', 'Additional settings', 0)], + 99 => [new Section('tips-tricks', 'Tips & tricks', 0)], + ], $this->manager->getAdminSections()); + } + + public function testGetAdminSettings() { + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); + $qb + ->expects($this->once()) + ->method('select') + ->with(['class', 'priority']) + ->willReturn($qb); + $qb + ->expects($this->once()) + ->method('from') + ->with('admin_settings') + ->willReturn($qb); + $expressionBuilder = $this->getMockBuilder('\OCP\DB\QueryBuilder\IExpressionBuilder')->getMock(); + $qb + ->expects($this->once()) + ->method('expr') + ->willReturn($expressionBuilder); + $param = $this->getMockBuilder('\OCP\DB\QueryBuilder\IParameter')->getMock(); + $qb + ->expects($this->once()) + ->method('createParameter') + ->with('section') + ->willReturn($param); + $expressionBuilder + ->expects($this->once()) + ->method('eq') + ->with('section', $param) + ->willReturn('myString'); + $qb + ->expects($this->once()) + ->method('where') + ->with('myString') + ->willReturn($qb); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); + $qb + ->expects($this->once()) + ->method('execute') + ->willReturn($stmt); + $this->dbConnection + ->expects($this->exactly(2)) + ->method('getQueryBuilder') + ->willReturn($qb); + + $this->assertEquals([ + 0 => [new Sharing($this->config)], + ], $this->manager->getAdminSettings('sharing')); + } +} diff --git a/apps/systemtags/lib/AppInfo/Application.php b/tests/lib/Settings/SectionTest.php similarity index 57% rename from apps/systemtags/lib/AppInfo/Application.php rename to tests/lib/Settings/SectionTest.php index 7cd49d6424b34..422b931bb4be5 100644 --- a/apps/systemtags/lib/AppInfo/Application.php +++ b/tests/lib/Settings/SectionTest.php @@ -1,6 +1,8 @@ + * @copyright Copyright (c) 2016 Lukas Reschke + * + * @author Lukas Reschke * * @license GNU AGPL version 3 or any later version * @@ -19,19 +21,19 @@ * */ -namespace OCA\SystemTags\AppInfo; +namespace Tests\Settings; -use OCP\AppFramework\App; +use OC\Settings\Section; +use Test\TestCase; -class Application extends App { - public function __construct() { - parent::__construct('systemtags'); +class SectionTest extends TestCase { + public function testGetID() { + $this->assertSame('ldap', (new Section('ldap', 'name', 1))->getID()); } - - /** - * Register admin settings - */ - public function registerAdminPage() { - \OCP\App::registerAdmin($this->getContainer()->getAppName(), 'admin'); + public function testGetName() { + $this->assertSame('name', (new Section('ldap', 'name', 1))->getName()); + } + public function testGetPriority() { + $this->assertSame(1, (new Section('ldap', 'name', 1))->getPriority()); } } diff --git a/version.php b/version.php index 59bac04a9d69f..d03fbdaae8832 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ // We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // when updating major/minor version number. -$OC_Version = array(9, 1, 0, 14); +$OC_Version = array(9, 1, 0, 15); // The human readable string $OC_VersionString = '10.0 beta';