From f15d15549dfd15672d02ad79ca9d944b4ed4a954 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 8 Aug 2016 23:31:26 +0200 Subject: [PATCH 01/43] Initial work on Apps page split: * interfaces for the Admin settings (IAdmin) and section (ISection) * SettingsManager service * example setup with LDAP app --- apps/user_ldap/appinfo/info.xml | 7 +- apps/user_ldap/lib/Settings/Admin.php | 115 ++++ apps/user_ldap/lib/Settings/Section.php | 67 ++ core/templates/untrustedDomain.php | 2 +- db_structure.xml | 94 +++ lib/private/Installer.php | 1 + lib/private/Server.php | 18 + lib/private/Settings/Admin/Encryption.php | 78 +++ lib/private/Settings/Admin/Logging.php | 87 +++ lib/private/Settings/Admin/Server.php | 114 ++++ lib/private/Settings/Admin/Sharing.php | 79 +++ lib/private/Settings/Admin/TipsTricks.php | 72 +++ lib/private/Settings/Manager.php | 297 +++++++++ lib/private/Settings/Section.php | 77 +++ lib/private/legacy/app.php | 5 +- lib/public/Settings/IAdmin.php | 48 ++ lib/public/Settings/IManager.php | 65 ++ lib/public/Settings/ISection.php | 51 ++ reset.php | 5 + settings/Application.php | 23 + .../Controller/AdminSettingsController.php | 114 ++++ settings/Controller/CheckSetupController.php | 2 +- settings/admin.php | 272 --------- settings/routes.php | 4 +- settings/templates/admin.php | 578 ------------------ settings/templates/admin/encryption.php | 92 +++ settings/templates/admin/frame.php | 47 ++ settings/templates/admin/logging.php | 88 +++ settings/templates/admin/server.php | 325 ++++++++++ settings/templates/admin/sharing.php | 109 ++++ settings/templates/admin/tipstricks.php | 49 ++ 31 files changed, 2129 insertions(+), 856 deletions(-) create mode 100644 apps/user_ldap/lib/Settings/Admin.php create mode 100644 apps/user_ldap/lib/Settings/Section.php create mode 100644 lib/private/Settings/Admin/Encryption.php create mode 100644 lib/private/Settings/Admin/Logging.php create mode 100644 lib/private/Settings/Admin/Server.php create mode 100644 lib/private/Settings/Admin/Sharing.php create mode 100644 lib/private/Settings/Admin/TipsTricks.php create mode 100644 lib/private/Settings/Manager.php create mode 100644 lib/private/Settings/Section.php create mode 100644 lib/public/Settings/IAdmin.php create mode 100644 lib/public/Settings/IManager.php create mode 100644 lib/public/Settings/ISection.php create mode 100644 reset.php create mode 100644 settings/Controller/AdminSettingsController.php delete mode 100644 settings/admin.php delete mode 100644 settings/templates/admin.php create mode 100644 settings/templates/admin/encryption.php create mode 100644 settings/templates/admin/frame.php create mode 100644 settings/templates/admin/logging.php create mode 100644 settings/templates/admin/server.php create mode 100644 settings/templates/admin/sharing.php create mode 100644 settings/templates/admin/tipstricks.php diff --git a/apps/user_ldap/appinfo/info.xml b/apps/user_ldap/appinfo/info.xml index b0984dcf62408..dac4f62879db5 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.1.0 + 1.1.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..11e2627dedd26 --- /dev/null +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -0,0 +1,115 @@ + + * + * @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\IL10N; +use OCP\Settings\IAdmin; +use OCP\Template; + +class Admin implements IAdmin { + + /** @var IL10N */ + private $l; + + public function __construct(IL10N $l) { + $this->l = $l; + } + + /** + * @return Template all parameters are supposed to be assigned + */ + public function render() { + $settings = new Template('user_ldap', 'settings'); + + $helper = new Helper(); + $prefixes = $helper->getServerConfigurationPrefixes(); + $hosts = $helper->getServerConfigurationHosts(); + + $wizardHtml = ''; + $toc = []; + + $wControls = new Template('user_ldap', 'part.wizardcontrols'); + $wControls = $wControls->fetchPage(); + $sControls = new Template('user_ldap', 'part.settingcontrols'); + $sControls = $sControls->fetchPage(); + + $wizTabs = [ + ['tpl' => 'part.wizard-server', 'cap' => $this->l->t('Server')], + ['tpl' => 'part.wizard-userfilter', 'cap' => $this->l->t('Users')], + ['tpl' => 'part.wizard-loginfilter', 'cap' => $this->l->t('Login Attributes')], + ['tpl' => 'part.wizard-groupfilter', 'cap' => $this->l->t('Groups')], + ]; + $wizTabsCount = count($wizTabs); + for($i = 0; $i < $wizTabsCount; $i++) { + $tab = new 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']; + } + + $settings->assign('tabs', $wizardHtml); + $settings->assign('toc', $toc); + $settings->assign('settingControls', $sControls); + + // assign default values + $config = new Configuration('', false); + $defaults = $config->getDefaults(); + foreach($defaults as $key => $default) { + $settings->assign($key.'_default', $default); + } + + return $settings; + } + + /** + * @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; + } + + private function renderControls() { + $controls = new Template('user_ldap', 'part.settingcontrols'); + return $controls->fetchPage(); + + } +} diff --git a/apps/user_ldap/lib/Settings/Section.php b/apps/user_ldap/lib/Settings/Section.php new file mode 100644 index 0000000000000..a10bd7cbb93f7 --- /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/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..f6955be8e0665 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -1976,4 +1976,98 @@ + + + *dbprefix*admin_sections + + + + + id + text + + false + 64 + + + + class + text + + true + 255 + + + + priority + integer + + true + 1 + + + + admin_sections_id_index + true + + id + ascending + + + + +
+ + + + *dbprefix*admin_settings + + + + + id + integer + 0 + true + 1 + 4 + + + + class + text + + true + 255 + + + + + section + text + + false + 64 + + + + priority + integer + + true + 1 + + + + admin_sections_id_index + true + + id + ascending + + + + +
+ diff --git a/lib/private/Installer.php b/lib/private/Installer.php index eed97e18d94ce..a4300785002ae 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -135,6 +135,7 @@ public static function installApp( $data = array()) { } \OC_App::setupBackgroundJobs($info['background-jobs']); + \OC::$server->getSettingsManager()->setupSettings($info['settings']); //run appinfo/install.php if((!isset($data['noinstall']) or $data['noinstall']==false)) { diff --git a/lib/private/Server.php b/lib/private/Server.php index d5808d7f17caf..53c8ee849249f 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -722,6 +722,17 @@ 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() + ); + return $manager; + }); } /** @@ -1425,4 +1436,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/Encryption.php b/lib/private/Settings/Admin/Encryption.php new file mode 100644 index 0000000000000..38197f71143a3 --- /dev/null +++ b/lib/private/Settings/Admin/Encryption.php @@ -0,0 +1,78 @@ + + * + * @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\IUserManager; +use OCP\Settings\IAdmin; +use OCP\Template; + +class Encryption implements IAdmin { + /** @var Manager */ + private $manager; + + /** @var IUserManager */ + private $userManager; + + public function __construct(Manager $manager, IUserManager $userManager) { + $this->manager = $manager; + $this->userManager = $userManager; + } + + /** + * @return Template all parameters are supposed to be assigned + */ + public function render() { + $parameters = [ + // Encryption API + 'encryptionEnabled' => $this->manager->isEnabled(), + 'encryptionReady' => $this->manager->isReady(), + 'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1, + ]; + + $form = new Template('settings', 'admin/encryption'); + foreach ($parameters as $key => $value) { + $form->assign($key, $value); + } + return $form; + } + + /** + * @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..ead55810ec150 --- /dev/null +++ b/lib/private/Settings/Admin/Logging.php @@ -0,0 +1,87 @@ + + * + * @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\File as LogFile; +use OCP\IConfig; +use OCP\Settings\IAdmin; +use OCP\Template; + +class Logging implements IAdmin { + /** @var IConfig */ + private $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return Template all parameters are supposed to be assigned + */ + public function render() { + $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, + ]; + + $form = new Template('settings', 'admin/logging'); + foreach ($parameters as $key => $value) { + $form->assign($key, $value); + } + return $form; + } + + /** + * @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..c0f3584c0afa3 --- /dev/null +++ b/lib/private/Settings/Admin/Server.php @@ -0,0 +1,114 @@ + + * + * @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 OCP\IConfig; +use OCP\IDBConnection; +use OCP\Settings\IAdmin; +use OCP\Template; + +class Server implements IAdmin { + + /** @var IDBConnection|Connection */ + private $db; + + /** @var IConfig */ + private $config; + + public function __construct(IDBConnection $db, IConfig $config) { + $this->db = $db; + $this->config = $config; + } + + /** + * @return Template all parameters are supposed to be assigned + */ + public function render() { + try { + if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) { + $invalidTransactionIsolationLevel = false; + } else { + $invalidTransactionIsolationLevel = $this->db->getTransactionIsolation() !== Connection::TRANSACTION_READ_COMMITTED; + } + } catch (DBALException $e) { + // ignore + $invalidTransactionIsolationLevel = false; + } + + $parameters = [ + // Diagnosis + 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(), + 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(), + 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(), + 'checkForWorkingWellKnownSetup', $this->config->getSystemValue('check_for_working_wellknown_setup'), + 'has_fileinfo' => \OC_Util::fileInfoLoaded(), + 'invalidTransactionIsolationLevel' => $invalidTransactionIsolationLevel, + + // 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), + + // 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', ''), + ]; + + $form = new Template('settings', 'admin/server'); + foreach ($parameters as $key => $value) { + $form->assign($key, $value); + } + return $form; + } + + /** + * @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..7fefa4008a0d0 --- /dev/null +++ b/lib/private/Settings/Admin/Sharing.php @@ -0,0 +1,79 @@ + + * + * @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\IConfig; +use OCP\Settings\IAdmin; +use OCP\Template; + +class Sharing implements IAdmin { + /** @var IConfig */ + private $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return Template all parameters are supposed to be assigned + */ + public function render() { + $excludeGroupsList = !is_null(json_decode($this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''))) + ? implode('|', $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '')) : ''; + + $parameters = [ + // Built-In Sharing + '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, + ]; + + $form = new Template('settings', 'admin/sharing'); + foreach ($parameters as $key => $value) { + $form->assign($key, $value); + } + return $form; + } + + /** + * @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..a0465f5e3cadd --- /dev/null +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -0,0 +1,72 @@ + + * + * @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\IConfig; +use OCP\Settings\IAdmin; +use OCP\Template; + +class TipsTricks implements IAdmin { + /** @var IConfig */ + private $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return Template all parameters are supposed to be assigned + */ + public function render() { + $databaseOverload = (strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false); + + $parameters = [ + 'databaseOverload' => $databaseOverload, + ]; + + $form = new Template('settings', 'admin/tipstricks'); + foreach ($parameters as $key => $value) { + $form->assign($key, $value); + } + return $form; + } + + /** + * @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..b7d02ddd34053 --- /dev/null +++ b/lib/private/Settings/Manager.php @@ -0,0 +1,297 @@ + + * + * @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\Settings\IAdmin; +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 */ + /** @var ILogger */ + private $log; + + /** @var IDBConnection */ + private $dbc; + + /** @var IL10N */ + private $l; + + /** @var IConfig */ + private $config; + + /** @var EncryptionManager */ + private $encryptionManager; + + /** @var IUserManager */ + private $userManager; + + public function __construct( + ILogger $log, + IDBConnection $dbc, + IL10N $l, + IConfig $config, + EncryptionManager $encryptionManager, + IUserManager $userManager + ) { + $this->log = $log; + $this->dbc = $dbc; + $this->l = $l; + $this->config = $config; + $this->encryptionManager = $encryptionManager; + $this->userManager = $userManager; + } + + /** + * @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]); + } + } + + 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($section)) { + $this->addAdminSection($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(IAdmin $settings) { + $this->add(self::TABLE_ADMIN_SETTINGS, [ + 'class' => get_class($settings), + 'section' => $settings->getSection(), + 'priority' => $settings->getPriority(), + ]); + } + + private function add($table, $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 hasAdminSection(ISection $section) { + return $this->has(self::TABLE_ADMIN_SECTIONS, 'id', $section->getID()); + } + + private function hasAdminSettings($pageClass) { + return $this->has(self::TABLE_ADMIN_SETTINGS, 'class', $pageClass); + } + + + private function has($table, $idCol, $id) { + $query = $this->dbc->getQueryBuilder(); + $query->select($idCol) + ->from($table) + ->where($query->expr()->eq($idCol, $query->createNamedParameter($id))) + ->setMaxResults(1); + + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + return (bool) $row; + } + + private function setupAdminSettings($settingsClassName) { + if(!class_exists($settingsClassName)) { + $this->log->debug('Could not find admin section class ' . $settingsClassName); + return; + } + + try { + $settings = $this->query($settingsClassName); + } catch (QueryException $e) { + // cancel + return; + } + + if(!$settings instanceof IAdmin) { + $this->log->error( + 'Admin section instance must implement \OCP\ISection. Invalid class: {class}', + ['class' => $settingsClassName] + ); + return; + } + if(!$this->hasAdminSettings($settings)) { + $this->addAdminSettings($settings); + } + } + + private function query($className) { + try { + return \OC::$server->query($className); + } catch (QueryException $e) { + $this->log->logException($e); + throw $e; + } + } + + /** + * returns a list of the admin sections + * + * @return ISection[] + */ + 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)], + //15 => [new Section('collaboration', $this->l->t('Collaboration'), 0)], + //30 => [new Section('theming', $this->l->t('Theming'), 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 IAdmin $form */ + $form = new Admin\Server($this->dbc, $this->config); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'encryption') { + /** @var IAdmin $form */ + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'sharing') { + /** @var IAdmin $form */ + $form = new Admin\Sharing($this->config); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'logging') { + /** @var IAdmin $form */ + $form = new Admin\Logging($this->config); + $forms[$form->getPriority()] = [$form]; + } + if($section === 'tips-tricks') { + /** @var IAdmin $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); + } + + public function getAdminSettings($section) { + $settings = $this->getBuiltInAdminSettings($section); + $this->getAdminSettingsFromDB($section, $settings); + return $settings; + } + + +} diff --git a/lib/private/Settings/Section.php b/lib/private/Settings/Section.php new file mode 100644 index 0000000000000..2ea614b365ec0 --- /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; + + 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..39f2f1a0efe07 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -471,7 +471,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") ); @@ -1199,6 +1199,9 @@ public static function updateApp($appId) { include $appPath . '/appinfo/update.php'; } self::setupBackgroundJobs($appData['background-jobs']); + if(isset($appData['settings']) && is_array($appData['settings'])) { + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); + } //set remote/public handlers if (array_key_exists('ocsid', $appData)) { diff --git a/lib/public/Settings/IAdmin.php b/lib/public/Settings/IAdmin.php new file mode 100644 index 0000000000000..ce52e3da72546 --- /dev/null +++ b/lib/public/Settings/IAdmin.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 . + * + */ + +namespace OCP\Settings; + +use OCP\Template; + +interface IAdmin { + + /** + * @return Template all parameters are supposed to be assigned + */ + public function render(); + + /** + * @return string the section ID, e.g. 'sharing' + */ + 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 + */ + public function getPriority(); +} diff --git a/lib/public/Settings/IManager.php b/lib/public/Settings/IManager.php new file mode 100644 index 0000000000000..ba0d9da59a36a --- /dev/null +++ b/lib/public/Settings/IManager.php @@ -0,0 +1,65 @@ + + * + * @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; + + +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); + + /** + * returns a list of the admin sections + * + * @return array array of ISection[] where key is the priority + */ + 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 + */ + public function getAdminSettings($section); +} diff --git a/lib/public/Settings/ISection.php b/lib/public/Settings/ISection.php new file mode 100644 index 0000000000000..7802c9b5d6cca --- /dev/null +++ b/lib/public/Settings/ISection.php @@ -0,0 +1,51 @@ + + * + * @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; + +interface ISection { + /** + * returns the ID of the section. It is supposed to be a lower case string, + * e.g. 'ldap' + * + * @returns string + */ + 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 + */ + 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 + */ + public function getPriority(); +} diff --git a/reset.php b/reset.php new file mode 100644 index 0000000000000..f1b772e1cdec4 --- /dev/null +++ b/reset.php @@ -0,0 +1,5 @@ +setPassword('master', 'master'); diff --git a/settings/Application.php b/settings/Application.php index 6db5e2aabf61c..09ca0807e6396 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; @@ -178,6 +179,19 @@ public function __construct(array $urlParams=[]){ $c->query('Logger') ); }); + $container->registerService('AdminSettingsController', function(IContainer $c) { + return new AdminSettingsController( + $c->query('AppName'), + $c->query('Request'), + $c->query('INavigationManager'), + $c->query('L10N'), + $c->query('Config'), + $c->query('EncryptionManager'), + $c->query('UserManager'), + $c->query('DatabaseConnection'), + $c->query('SettingsManager') + ); + }); /** * Middleware @@ -269,5 +283,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..68707addfe4b6 --- /dev/null +++ b/settings/Controller/AdminSettingsController.php @@ -0,0 +1,114 @@ + + * + * @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\Controller; + +use Doctrine\DBAL\Connection; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\TemplateResponse; +use OC\Encryption\Manager as EncryptionManager; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IL10N; +use OCP\INavigationManager; +use OCP\IRequest; +use OCP\IUserManager; +use OCP\Settings\IManager as ISettingsManager; + +/** + * @package OC\Settings\Controller + */ +class AdminSettingsController extends Controller { + + /** @var INavigationManager */ + private $navigationManager; + + /** @var ISettingsManager */ + private $settingsManager; + + public function __construct( + $appName, + IRequest $request, + INavigationManager $navigationManager, + IL10N $l, + IConfig $config, + EncryptionManager $encryptionManager, + IUserManager $userManager, + IDBConnection $db, + 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()); + $templateParams = array_merge($templateParams, $this->getSettings($section)); + + return new TemplateResponse('settings', 'admin/frame', $templateParams); + } + + public function form() { + + } + + private function getSettings($section) { + $settings = $this->settingsManager->getAdminSettings($section); + $html = ''; + foreach ($settings as $prioritizedSettings) { + foreach ($prioritizedSettings as $setting) { + /** @var \OCP\Settings\IAdmin $setting */ + $form = $setting->render(); + $html .= $form->fetchPage(); + } + } + return ['content' => $html]; + } + + private function getNavigationParameters() { + $a = 'anchor'; + $name = 'section-name'; + + $sections = $this->settingsManager->getAdminSections(); + $templateParameters = []; + foreach($sections as $prioritizedSections) { + foreach ($prioritizedSections as $section) { + $templateParameters[] = [$a => $section->getID(), $name => $section->getName()]; + } + } + + return [ + 'forms' => $templateParameters + ]; + } +} diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php index 13e7e443621c5..0441c507f3440 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -290,7 +290,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 a458c813c118e..0000000000000 --- a/settings/admin.php +++ /dev/null @@ -1,272 +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'); - -$logType = \OC::$server->getConfig()->getSystemValue('log_type', 'file'); -$showLog = ($logType === 'file' || $logType === 'owncloud'); -$numEntriesToLoad = 3; -$entries = \OC\Log\File::getEntries($numEntriesToLoad + 1); -$entriesRemaining = count($entries) > $numEntriesToLoad; -$entries = array_slice($entries, 0, $numEntriesToLoad); -$logFilePath = \OC\Log\File::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/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 74fe585962df6..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', - 'smtp', -]; -if ($_['sendmail_is_available']) { - $mail_smtpmode[] = 'sendmail'; -} -if ($_['mail_smtpmode'] == 'qmail') { - $mail_smtpmode[] = '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 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('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('--') ?>
-

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!')); ?> - - - -
- -
-

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

- -
- - -
- - -
-

t('Version'));?>

-

getTitle()); ?>

-

-
- - - - -
diff --git a/settings/templates/admin/encryption.php b/settings/templates/admin/encryption.php new file mode 100644 index 0000000000000..d4c3be8b2c870 --- /dev/null +++ b/settings/templates/admin/encryption.php @@ -0,0 +1,92 @@ + + * + * @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..e0fee1555a3dd --- /dev/null +++ b/settings/templates/admin/frame.php @@ -0,0 +1,47 @@ + + * + * @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']; + print_unescaped(sprintf("
  • %s
  • ", \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..1bf068de39293 --- /dev/null +++ b/settings/templates/admin/server.php @@ -0,0 +1,325 @@ + + * + * @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', + 'smtp', +]; +if ($_['sendmail_is_available']) { + $mail_smtpmode[] = 'sendmail'; +} +if ($_['mail_smtpmode'] == 'qmail') { + $mail_smtpmode[] = 'qmail'; +} +?> + +
+

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('Email server'));?>

+ + +

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

+ +

+ + + + + +

+ +

+ + ' />@ + ' /> +

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

t('Version'));?>

+

getTitle()); ?>

+

+
diff --git a/settings/templates/admin/sharing.php b/settings/templates/admin/sharing.php new file mode 100644 index 0000000000000..c81f7e2ae1c6b --- /dev/null +++ b/settings/templates/admin/sharing.php @@ -0,0 +1,109 @@ + + * + * @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'));?>

+ +
From 608c2a5288d42dcb854e653f16c9f112fce84981 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 9 Aug 2016 22:43:29 +0200 Subject: [PATCH 02/43] fix duplicated db index name --- db_structure.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db_structure.xml b/db_structure.xml index f6955be8e0665..b4c231a924838 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -2059,7 +2059,7 @@ - admin_sections_id_index + admin_settings_id_index true id From 4d29277d31262410d25820de0d573f699060ef46 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 9 Aug 2016 22:47:05 +0200 Subject: [PATCH 03/43] remove mistakenly added file --- reset.php | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 reset.php diff --git a/reset.php b/reset.php deleted file mode 100644 index f1b772e1cdec4..0000000000000 --- a/reset.php +++ /dev/null @@ -1,5 +0,0 @@ -setPassword('master', 'master'); From 3193530488bc88bc8353cbb88819ade33003ff2a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 9 Aug 2016 23:30:07 +0200 Subject: [PATCH 04/43] Fallback for legacy settings. They are placed into Additional Settings --- apps/user_ldap/settings.php | 75 ------------------- .../Controller/AdminSettingsController.php | 31 ++++++++ settings/templates/admin/additional.php | 36 +++++++++ 3 files changed, 67 insertions(+), 75 deletions(-) delete mode 100644 apps/user_ldap/settings.php create mode 100644 settings/templates/admin/additional.php 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/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index 68707addfe4b6..b6a6e74705fcf 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -83,6 +83,10 @@ public function form() { } private function getSettings($section) { + if($section === 'additional') { + return $this->getLegacyForms(); + } + $settings = $this->settingsManager->getAdminSettings($section); $html = ''; foreach ($settings as $prioritizedSettings) { @@ -95,6 +99,33 @@ private function getSettings($section) { return ['content' => $html]; } + 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 \OCP\Template('settings', 'admin/additional'); + $out->assign('forms', $forms); + + return ['content' => $out->fetchPage()]; + } + private function getNavigationParameters() { $a = 'anchor'; $name = 'section-name'; diff --git a/settings/templates/admin/additional.php b/settings/templates/admin/additional.php new file mode 100644 index 0000000000000..c4e70dbddb2cb --- /dev/null +++ b/settings/templates/admin/additional.php @@ -0,0 +1,36 @@ + + * + * @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('Additional Settings'));?>

+ +
+ +
From 0e7033282c90e47a8423799f7d95746c63d63283 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 10 Aug 2016 15:21:25 +0200 Subject: [PATCH 05/43] more admin page splitup improvements * bump version to ensure tables are created * make updatenotification app use settings api * change IAdmin::render() to getForm() and change return type from Template to TemplateResponse * adjust User_LDAP accordingly, as well as built-in forms * add IDateTimeFormatter to AppFramework/DependencyInjection/DIContainer.php. This is important so that \OC::$server->query() is able to resolve the constructor parameters. We should ensure that all OCP/* stuff that is available from \OC::$server is available here. Kudos to @LukasReschke * make sure apps that have settings info in their info.xml are loaded before triggering adding the settings setup method --- apps/updatenotification/admin.php | 26 ------------ apps/updatenotification/appinfo/info.xml | 6 ++- .../lib/Controller/AdminController.php | 28 ++++++++++++- apps/user_ldap/appinfo/info.xml | 4 +- apps/user_ldap/lib/Settings/Admin.php | 40 +++++-------------- apps/user_ldap/templates/settings.php | 29 +++++++++----- .../DependencyInjection/DIContainer.php | 4 ++ lib/private/Settings/Admin/Encryption.php | 12 ++---- lib/private/Settings/Admin/Logging.php | 12 ++---- lib/private/Settings/Admin/Server.php | 12 ++---- lib/private/Settings/Admin/Sharing.php | 12 ++---- lib/private/Settings/Admin/TipsTricks.php | 12 ++---- lib/private/legacy/app.php | 1 + lib/public/Settings/IAdmin.php | 6 +-- .../Controller/AdminSettingsController.php | 4 +- version.php | 2 +- 16 files changed, 92 insertions(+), 118 deletions(-) delete mode 100644 apps/updatenotification/admin.php 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/info.xml b/apps/updatenotification/appinfo/info.xml index 4070e90f221f1..2fe400a35878a 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.1.0 + 1.1.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..5f137120435e1 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\IAdmin; -class AdminController extends Controller { +class AdminController extends Controller implements IAdmin { /** @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 5; + } } diff --git a/apps/user_ldap/appinfo/info.xml b/apps/user_ldap/appinfo/info.xml index dac4f62879db5..b16824925c0fe 100644 --- a/apps/user_ldap/appinfo/info.xml +++ b/apps/user_ldap/appinfo/info.xml @@ -29,7 +29,7 @@ A user logs into ownCloud with their LDAP or AD credentials, and is granted acce - \OCA\User_LDAP\Settings\Admin - \OCA\User_LDAP\Settings\Section + 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 index 11e2627dedd26..f155f1cec8de4 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -23,9 +23,9 @@ 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\IAdmin; use OCP\Template; @@ -40,53 +40,31 @@ public function __construct(IL10N $l) { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { - $settings = new Template('user_ldap', 'settings'); - + public function getForm() { $helper = new Helper(); $prefixes = $helper->getServerConfigurationPrefixes(); $hosts = $helper->getServerConfigurationHosts(); - $wizardHtml = ''; - $toc = []; - $wControls = new Template('user_ldap', 'part.wizardcontrols'); $wControls = $wControls->fetchPage(); $sControls = new Template('user_ldap', 'part.settingcontrols'); $sControls = $sControls->fetchPage(); - $wizTabs = [ - ['tpl' => 'part.wizard-server', 'cap' => $this->l->t('Server')], - ['tpl' => 'part.wizard-userfilter', 'cap' => $this->l->t('Users')], - ['tpl' => 'part.wizard-loginfilter', 'cap' => $this->l->t('Login Attributes')], - ['tpl' => 'part.wizard-groupfilter', 'cap' => $this->l->t('Groups')], - ]; - $wizTabsCount = count($wizTabs); - for($i = 0; $i < $wizTabsCount; $i++) { - $tab = new 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']; - } - - $settings->assign('tabs', $wizardHtml); - $settings->assign('toc', $toc); - $settings->assign('settingControls', $sControls); + $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) { - $settings->assign($key.'_default', $default); + $parameters[$key.'_default'] = $default; } - return $settings; + return new TemplateResponse('user_ldap', 'settings', $parameters); } /** 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/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 66ca59d26e2da..5ddfebc2c7fed 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(); }); diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php index 38197f71143a3..331ddf5452053 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -24,9 +24,9 @@ namespace OC\Settings\Admin; use OC\Encryption\Manager; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IUserManager; use OCP\Settings\IAdmin; -use OCP\Template; class Encryption implements IAdmin { /** @var Manager */ @@ -41,9 +41,9 @@ public function __construct(Manager $manager, IUserManager $userManager) { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { $parameters = [ // Encryption API 'encryptionEnabled' => $this->manager->isEnabled(), @@ -51,11 +51,7 @@ public function render() { 'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1, ]; - $form = new Template('settings', 'admin/encryption'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/encryption', $parameters, ''); } /** diff --git a/lib/private/Settings/Admin/Logging.php b/lib/private/Settings/Admin/Logging.php index ead55810ec150..b05ea93388df5 100644 --- a/lib/private/Settings/Admin/Logging.php +++ b/lib/private/Settings/Admin/Logging.php @@ -24,9 +24,9 @@ namespace OC\Settings\Admin; use OC\Log\File as LogFile; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\Settings\IAdmin; -use OCP\Template; class Logging implements IAdmin { /** @var IConfig */ @@ -37,9 +37,9 @@ public function __construct(IConfig $config) { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { $logType = $this->config->getSystemValue('log_type', 'file'); $showLog = ($logType === 'file' || $logType === 'owncloud'); @@ -60,11 +60,7 @@ public function render() { 'showLog' => $showLog, ]; - $form = new Template('settings', 'admin/logging'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/logging', $parameters, ''); } /** diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php index c0f3584c0afa3..ee2da154da2c2 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -26,10 +26,10 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\SqlitePlatform; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IDBConnection; use OCP\Settings\IAdmin; -use OCP\Template; class Server implements IAdmin { @@ -45,9 +45,9 @@ public function __construct(IDBConnection $db, IConfig $config) { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { try { if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) { $invalidTransactionIsolationLevel = false; @@ -87,11 +87,7 @@ public function render() { 'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''), ]; - $form = new Template('settings', 'admin/server'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/server', $parameters, ''); } /** diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index 7fefa4008a0d0..088021f9057c0 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -23,9 +23,9 @@ namespace OC\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\Settings\IAdmin; -use OCP\Template; class Sharing implements IAdmin { /** @var IConfig */ @@ -36,9 +36,9 @@ public function __construct(IConfig $config) { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { $excludeGroupsList = !is_null(json_decode($this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''))) ? implode('|', $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '')) : ''; @@ -52,11 +52,7 @@ public function render() { 'shareExcludedGroupsList' => $excludeGroupsList, ]; - $form = new Template('settings', 'admin/sharing'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/sharing', $parameters, ''); } /** diff --git a/lib/private/Settings/Admin/TipsTricks.php b/lib/private/Settings/Admin/TipsTricks.php index a0465f5e3cadd..331c33db1c176 100644 --- a/lib/private/Settings/Admin/TipsTricks.php +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -23,9 +23,9 @@ namespace OC\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\Settings\IAdmin; -use OCP\Template; class TipsTricks implements IAdmin { /** @var IConfig */ @@ -36,20 +36,16 @@ public function __construct(IConfig $config) { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { $databaseOverload = (strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false); $parameters = [ 'databaseOverload' => $databaseOverload, ]; - $form = new Template('settings', 'admin/tipstricks'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/tipstricks', $parameters, ''); } /** diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 39f2f1a0efe07..bba4f59555eb4 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -1200,6 +1200,7 @@ public static function updateApp($appId) { } self::setupBackgroundJobs($appData['background-jobs']); if(isset($appData['settings']) && is_array($appData['settings'])) { + self::loadApp($appId, false); \OC::$server->getSettingsManager()->setupSettings($appData['settings']); } diff --git a/lib/public/Settings/IAdmin.php b/lib/public/Settings/IAdmin.php index ce52e3da72546..74977256a1861 100644 --- a/lib/public/Settings/IAdmin.php +++ b/lib/public/Settings/IAdmin.php @@ -23,14 +23,14 @@ namespace OCP\Settings; -use OCP\Template; +use OCP\AppFramework\Http\TemplateResponse; interface IAdmin { /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered */ - public function render(); + public function getForm(); /** * @return string the section ID, e.g. 'sharing' diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index b6a6e74705fcf..f27bdd3ec3304 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -92,8 +92,8 @@ private function getSettings($section) { foreach ($settings as $prioritizedSettings) { foreach ($prioritizedSettings as $setting) { /** @var \OCP\Settings\IAdmin $setting */ - $form = $setting->render(); - $html .= $form->fetchPage(); + $form = $setting->getForm(); + $html .= $form->renderAs('')->render(); } } return ['content' => $html]; diff --git a/version.php b/version.php index e6298ae238f42..7787884db7a4e 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, 2, 0, 1); +$OC_Version = array(9, 2, 0, 2); // The human readable string $OC_VersionString = '11.0 alpha'; From 3691994913dc64a6e556e81a1e4abf311eace16a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 00:45:15 +0200 Subject: [PATCH 06/43] fix registration of admin settings and section on app install --- lib/private/Installer.php | 1 - lib/private/legacy/app.php | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/private/Installer.php b/lib/private/Installer.php index a4300785002ae..eed97e18d94ce 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -135,7 +135,6 @@ public static function installApp( $data = array()) { } \OC_App::setupBackgroundJobs($info['background-jobs']); - \OC::$server->getSettingsManager()->setupSettings($info['settings']); //run appinfo/install.php if((!isset($data['noinstall']) or $data['noinstall']==false)) { diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index bba4f59555eb4..802c4b908b474 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -1162,6 +1162,12 @@ public static function installApp($app) { if (isset($appData['id'])) { $config->setAppValue($app, 'ocsid', $appData['id']); } + + if(isset($info['settings']) && is_array($info['settings'])) { + self::loadApp($app, false); + \OC::$server->getSettingsManager()->setupSettings($info['settings']); + } + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); } else { if(empty($appName) ) { From bd610b702f2fa1f2fa11c4f4bed4c483a07a5f60 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 01:41:18 +0200 Subject: [PATCH 07/43] fixes, improvements, and another app: * setupSettings now also triggered on enable * fixes detection of present admin section or settings in the DB * add update routine in such cases * encryption app migrated --- apps/encryption/appinfo/info.xml | 6 +- apps/encryption/lib/AppInfo/Application.php | 1 - apps/encryption/lib/Settings/Admin.php | 127 ++++++++++++++++++++ apps/encryption/settings/settings-admin.php | 53 -------- lib/private/Settings/Manager.php | 67 +++++++++-- lib/private/legacy/app.php | 6 + 6 files changed, 195 insertions(+), 65 deletions(-) create mode 100644 apps/encryption/lib/Settings/Admin.php delete mode 100644 apps/encryption/settings/settings-admin.php diff --git a/apps/encryption/appinfo/info.xml b/apps/encryption/appinfo/info.xml index 83f4107384d43..539f9f116d2c3 100644 --- a/apps/encryption/appinfo/info.xml +++ b/apps/encryption/appinfo/info.xml @@ -19,7 +19,7 @@ admin-encryption false - 1.4.0 + 1.4.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..71a365caee194 --- /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\IAdmin; +use OCP\IConfig; + +class Admin implements IAdmin { + + /** @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/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index b7d02ddd34053..fa762003c1d0e 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -104,8 +104,10 @@ private function setupAdminSection($sectionClassName) { ); return; } - if(!$this->hasAdminSection($section)) { + if(!$this->hasAdminSection(get_class($section))) { $this->addAdminSection($section); + } else { + $this->updateAdminSection($section); } } @@ -134,20 +136,64 @@ private function add($table, $values) { $query->execute(); } - private function hasAdminSection(ISection $section) { - return $this->has(self::TABLE_ADMIN_SECTIONS, 'id', $section->getID()); + private function updateAdminSettings(IAdmin $settings) { + $this->update( + self::TABLE_ADMIN_SETTINGS, + 'class', + get_class($settings), + [ + 'section' => $settings->getSection(), + 'priority' => $settings->getPriority(), + ] + ); } - private function hasAdminSettings($pageClass) { - return $this->has(self::TABLE_ADMIN_SETTINGS, 'class', $pageClass); + 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); } - private function has($table, $idCol, $id) { + private function has($table, $className) { $query = $this->dbc->getQueryBuilder(); - $query->select($idCol) + $query->select('class') ->from($table) - ->where($query->expr()->eq($idCol, $query->createNamedParameter($id))) + ->where($query->expr()->eq('class', $query->createNamedParameter($className))) ->setMaxResults(1); $result = $query->execute(); @@ -164,6 +210,7 @@ private function setupAdminSettings($settingsClassName) { } try { + /** @var IAdmin $settings */ $settings = $this->query($settingsClassName); } catch (QueryException $e) { // cancel @@ -177,8 +224,10 @@ private function setupAdminSettings($settingsClassName) { ); return; } - if(!$this->hasAdminSettings($settings)) { + if(!$this->hasAdminSettings(get_class($settings))) { $this->addAdminSettings($settings); + } else { + $this->updateAdminSettings($settings); } } diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 802c4b908b474..4144f3f6cf502 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -345,6 +345,12 @@ public static function enable($app, $groups = null) { } else { $appManager->enableApp($app); } + + $info = self::getAppInfo($app); + if(isset($info['settings']) && is_array($info['settings'])) { + self::loadApp($app, false); + \OC::$server->getSettingsManager()->setupSettings($info['settings']); + } } /** From 78b5558db76425539283430e8b77633ef203af0f Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 14:48:21 +0200 Subject: [PATCH 08/43] rename IAdmin to ISettings, the interface is not bound to a specific settings scope --- apps/encryption/lib/Settings/Admin.php | 4 ++-- .../lib/Controller/AdminController.php | 4 ++-- apps/user_ldap/lib/Settings/Admin.php | 4 ++-- lib/private/Settings/Admin/Encryption.php | 4 ++-- lib/private/Settings/Admin/Logging.php | 4 ++-- lib/private/Settings/Admin/Server.php | 4 ++-- lib/private/Settings/Admin/Sharing.php | 4 ++-- lib/private/Settings/Admin/TipsTricks.php | 4 ++-- lib/private/Settings/Manager.php | 20 +++++++++---------- .../Settings/{IAdmin.php => ISettings.php} | 5 ++++- .../Controller/AdminSettingsController.php | 2 +- 11 files changed, 31 insertions(+), 28 deletions(-) rename lib/public/Settings/{IAdmin.php => ISettings.php} (95%) diff --git a/apps/encryption/lib/Settings/Admin.php b/apps/encryption/lib/Settings/Admin.php index 71a365caee194..2faa118e2a248 100644 --- a/apps/encryption/lib/Settings/Admin.php +++ b/apps/encryption/lib/Settings/Admin.php @@ -33,10 +33,10 @@ use OCP\ISession; use OCP\IUserManager; use OCP\IUserSession; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; use OCP\IConfig; -class Admin implements IAdmin { +class Admin implements ISettings { /** @var IL10N */ private $l; diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index 5f137120435e1..3c6ab4630599a 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -34,9 +34,9 @@ use OCP\IL10N; use OCP\IRequest; use OCP\Security\ISecureRandom; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class AdminController extends Controller implements IAdmin { +class AdminController extends Controller implements ISettings { /** @var IJobList */ private $jobList; /** @var ISecureRandom */ diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php index f155f1cec8de4..606cfe6cf0194 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -27,10 +27,10 @@ use OCA\User_LDAP\Helper; use OCP\AppFramework\Http\TemplateResponse; use OCP\IL10N; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; use OCP\Template; -class Admin implements IAdmin { +class Admin implements ISettings { /** @var IL10N */ private $l; diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php index 331ddf5452053..ceae5aa6d3fd5 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -26,9 +26,9 @@ use OC\Encryption\Manager; use OCP\AppFramework\Http\TemplateResponse; use OCP\IUserManager; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class Encryption implements IAdmin { +class Encryption implements ISettings { /** @var Manager */ private $manager; diff --git a/lib/private/Settings/Admin/Logging.php b/lib/private/Settings/Admin/Logging.php index b05ea93388df5..3097070577dd7 100644 --- a/lib/private/Settings/Admin/Logging.php +++ b/lib/private/Settings/Admin/Logging.php @@ -26,9 +26,9 @@ use OC\Log\File as LogFile; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class Logging implements IAdmin { +class Logging implements ISettings { /** @var IConfig */ private $config; diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php index ee2da154da2c2..4f1edcf469105 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -29,9 +29,9 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IDBConnection; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class Server implements IAdmin { +class Server implements ISettings { /** @var IDBConnection|Connection */ private $db; diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index 088021f9057c0..d186dbed9814b 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -25,9 +25,9 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class Sharing implements IAdmin { +class Sharing implements ISettings { /** @var IConfig */ private $config; diff --git a/lib/private/Settings/Admin/TipsTricks.php b/lib/private/Settings/Admin/TipsTricks.php index 331c33db1c176..217ddacd44307 100644 --- a/lib/private/Settings/Admin/TipsTricks.php +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -25,9 +25,9 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class TipsTricks implements IAdmin { +class TipsTricks implements ISettings { /** @var IConfig */ private $config; diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index fa762003c1d0e..4c96dd07fde8f 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -30,7 +30,7 @@ use OCP\IL10N; use OCP\ILogger; use OCP\IUserManager; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; use OCP\Settings\IManager; use OCP\Settings\ISection; @@ -119,7 +119,7 @@ private function addAdminSection(ISection $section) { ]); } - private function addAdminSettings(IAdmin $settings) { + private function addAdminSettings(ISettings $settings) { $this->add(self::TABLE_ADMIN_SETTINGS, [ 'class' => get_class($settings), 'section' => $settings->getSection(), @@ -136,7 +136,7 @@ private function add($table, $values) { $query->execute(); } - private function updateAdminSettings(IAdmin $settings) { + private function updateAdminSettings(ISettings $settings) { $this->update( self::TABLE_ADMIN_SETTINGS, 'class', @@ -210,14 +210,14 @@ private function setupAdminSettings($settingsClassName) { } try { - /** @var IAdmin $settings */ + /** @var ISettings $settings */ $settings = $this->query($settingsClassName); } catch (QueryException $e) { // cancel return; } - if(!$settings instanceof IAdmin) { + if(!$settings instanceof ISettings) { $this->log->error( 'Admin section instance must implement \OCP\ISection. Invalid class: {class}', ['class' => $settingsClassName] @@ -283,27 +283,27 @@ private function getBuiltInAdminSettings($section) { $forms = []; try { if($section === 'server') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\Server($this->dbc, $this->config); $forms[$form->getPriority()] = [$form]; } if($section === 'encryption') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\Encryption($this->encryptionManager, $this->userManager); $forms[$form->getPriority()] = [$form]; } if($section === 'sharing') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\Sharing($this->config); $forms[$form->getPriority()] = [$form]; } if($section === 'logging') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\Logging($this->config); $forms[$form->getPriority()] = [$form]; } if($section === 'tips-tricks') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\TipsTricks($this->config); $forms[$form->getPriority()] = [$form]; } diff --git a/lib/public/Settings/IAdmin.php b/lib/public/Settings/ISettings.php similarity index 95% rename from lib/public/Settings/IAdmin.php rename to lib/public/Settings/ISettings.php index 74977256a1861..07d265a533e06 100644 --- a/lib/public/Settings/IAdmin.php +++ b/lib/public/Settings/ISettings.php @@ -25,15 +25,17 @@ use OCP\AppFramework\Http\TemplateResponse; -interface IAdmin { +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(); @@ -43,6 +45,7 @@ public function getSection(); * 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/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index f27bdd3ec3304..271aa05265bac 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -91,7 +91,7 @@ private function getSettings($section) { $html = ''; foreach ($settings as $prioritizedSettings) { foreach ($prioritizedSettings as $setting) { - /** @var \OCP\Settings\IAdmin $setting */ + /** @var \OCP\Settings\ISettings $setting */ $form = $setting->getForm(); $html .= $form->renderAs('')->render(); } From 1764befaf8e91b31607976d8c7979050768d2121 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 15:13:40 +0200 Subject: [PATCH 09/43] adjust federatedfilesharing --- apps/federatedfilesharing/appinfo/info.xml | 5 +- .../lib/AppInfo/Application.php | 1 - .../lib/Settings/Admin.php | 69 +++++++++++++++++++ apps/federatedfilesharing/settings-admin.php | 34 --------- .../templates/settings-admin.php | 2 +- 5 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 apps/federatedfilesharing/lib/Settings/Admin.php delete mode 100644 apps/federatedfilesharing/settings-admin.php diff --git a/apps/federatedfilesharing/appinfo/info.xml b/apps/federatedfilesharing/appinfo/info.xml index 2a80bd54da381..984235f085167 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.1.0 + 1.1.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..aa2f551e18d3f 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'));?>

Date: Thu, 11 Aug 2016 15:50:31 +0200 Subject: [PATCH 10/43] adjust files_external --- apps/files_external/appinfo/info.xml | 7 +- .../lib/AppInfo/Application.php | 4 - apps/files_external/lib/Settings/Admin.php | 96 +++++++++++++++++++ apps/files_external/lib/Settings/Section.php | 67 +++++++++++++ apps/files_external/settings.php | 48 ---------- .../DependencyInjection/DIContainer.php | 18 ++++ 6 files changed, 187 insertions(+), 53 deletions(-) create mode 100644 apps/files_external/lib/Settings/Admin.php create mode 100644 apps/files_external/lib/Settings/Section.php delete mode 100644 apps/files_external/settings.php diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index 43f06d60843fb..e4433880d3a45 100644 --- a/apps/files_external/appinfo/info.xml +++ b/apps/files_external/appinfo/info.xml @@ -13,7 +13,7 @@ admin-external-storage false - 1.1.0 + 1.1.1 @@ -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..eebfd71287431 --- /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 'externalstorage'; + } + + /** + * @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_external/lib/Settings/Section.php b/apps/files_external/lib/Settings/Section.php new file mode 100644 index 0000000000000..850b04251a6aa --- /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 'externalstorage'; + } + + /** + * 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 Storage'); + } + + /** + * @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 35; + } +} 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/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 5ddfebc2c7fed..4e3cac6d1eac0 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -310,6 +310,24 @@ public function __construct($appName, $urlParams = array()){ return $c->query('ServerContainer')->getWebRoot(); }); + $this->registerService('\OCP\Encryption\IManager', function ($c) { + $view = new \OC\Files\View(); + $util = new \OC\Encryption\Util( + $view, + $c->query('\OCP\IUserManager'), + $c->query('\OCP\IGroupManager'), + $c->query('\OCP\IConfig') + ); + return new \OC\Encryption\Manager( + $c->query('\OCP\IConfig'), + $c->query('\OCP\ILogger'), + $c->query('ServerContainer')->getL10N('core'), + new \OC\Files\View(), + $util, + new \OC\Memcache\ArrayCache() + ); + }); + /** * App Framework APIs From 1f3c0a6b600f78c4575d846f16afea465d1d4be1 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 16:37:11 +0200 Subject: [PATCH 11/43] make sure shipped apps also setup their admin settings on a fresh install --- lib/private/Installer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/private/Installer.php b/lib/private/Installer.php index eed97e18d94ce..1c45679cd3297 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -593,6 +593,11 @@ public static function installShippedApp($app) { OC_App::setAppTypes($info['id']); + if(isset($info['settings']) && is_array($info['settings'])) { + \OC_App::loadApp($app, false); + \OC::$server->getSettingsManager()->setupSettings($info['settings']); + } + return $info['id']; } From 3fb94727cb6be85cdc753cd1e993eb7d9bb08258 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 16:42:37 +0200 Subject: [PATCH 12/43] superfluous --- apps/updatenotification/appinfo/app.php | 1 - 1 file changed, 1 deletion(-) 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'); } } From 04e6b43e444bc2d56133c6354d9f537960996f7e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 17:29:58 +0200 Subject: [PATCH 13/43] adjust Theming app --- apps/theming/appinfo/app.php | 2 - apps/theming/appinfo/info.xml | 7 +- apps/theming/lib/Settings/Admin.php | 99 ++++++++++++++++++++++++ apps/theming/lib/Settings/Section.php | 67 ++++++++++++++++ apps/theming/settings/settings-admin.php | 52 ------------- lib/private/Settings/Manager.php | 1 - 6 files changed, 172 insertions(+), 56 deletions(-) create mode 100644 apps/theming/lib/Settings/Admin.php create mode 100644 apps/theming/lib/Settings/Section.php delete mode 100644 apps/theming/settings/settings-admin.php diff --git a/apps/theming/appinfo/app.php b/apps/theming/appinfo/app.php index 5ef506e5acd26..fc64c2452bad1 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 8ae1d3eb73aa2..423d11d2aef1e 100644 --- a/apps/theming/appinfo/info.xml +++ b/apps/theming/appinfo/info.xml @@ -5,7 +5,7 @@ Adjust the Nextcloud theme AGPL Nextcloud - 1.1.0 + 1.1.1 Theming other @@ -18,4 +18,9 @@ + + + OCA\Theming\Settings\Admin + OCA\Theming\Settings\Section + diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php new file mode 100644 index 0000000000000..07dfe75ec605b --- /dev/null +++ b/apps/theming/lib/Settings/Admin.php @@ -0,0 +1,99 @@ + + * + * @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\Template; +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 Template */ + private $themingDefaults; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IConfig $config, IL10N $l, Template $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/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/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 4c96dd07fde8f..01beb47879bd9 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -255,7 +255,6 @@ public function getAdminSections() { 0 => [new Section('server', $this->l->t('Server Settings'), 0)], 5 => [new Section('sharing', $this->l->t('Sharing'), 0)], //15 => [new Section('collaboration', $this->l->t('Collaboration'), 0)], - //30 => [new Section('theming', $this->l->t('Theming'), 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)], From f1952f9b9126b972b9d21be33d0b28aff398709c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 18:39:16 +0200 Subject: [PATCH 14/43] adjust files app, and integrate files_external into that section --- apps/files/admin.php | 51 ---------- apps/files/appinfo/app.php | 2 - apps/files/appinfo/info.xml | 7 +- apps/files/lib/Settings/Admin.php | 93 +++++++++++++++++++ .../lib/Settings/Section.php | 8 +- apps/files_external/appinfo/info.xml | 3 +- apps/files_external/lib/Settings/Admin.php | 4 +- 7 files changed, 106 insertions(+), 62 deletions(-) delete mode 100644 apps/files/admin.php create mode 100644 apps/files/lib/Settings/Admin.php rename apps/{files_external => files}/lib/Settings/Section.php (93%) 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 850c335c27d06..afb327e24ba31 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -26,8 +26,6 @@ * along with this program. If not, see * */ -\OCP\App::registerAdmin('files', 'admin'); - $l = \OC::$server->getL10N('files'); \OC::$server->getNavigationManager()->add(function () { diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml index 8b26a6af7110f..c1666af634838 100644 --- a/apps/files/appinfo/info.xml +++ b/apps/files/appinfo/info.xml @@ -6,7 +6,7 @@ AGPL Robin Appelman, Vincent Petry - 1.6.0 + 1.6.1 @@ -22,4 +22,9 @@ OCA\Files\BackgroundJob\DeleteOrphanedItems OCA\Files\BackgroundJob\CleanupFileLocks + + + OCA\Files\Settings\Admin + OCA\Files\Settings\Section + diff --git a/apps/files/lib/Settings/Admin.php b/apps/files/lib/Settings/Admin.php new file mode 100644 index 0000000000000..d0a691ffe6648 --- /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 'files'; + } + + /** + * @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_external/lib/Settings/Section.php b/apps/files/lib/Settings/Section.php similarity index 93% rename from apps/files_external/lib/Settings/Section.php rename to apps/files/lib/Settings/Section.php index 850b04251a6aa..2323870cf9749 100644 --- a/apps/files_external/lib/Settings/Section.php +++ b/apps/files/lib/Settings/Section.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Files_External\Settings; +namespace OCA\Files\Settings; use OCP\IL10N; use OCP\Settings\ISection; @@ -41,7 +41,7 @@ public function __construct(IL10N $l) { * @returns string */ public function getID() { - return 'externalstorage'; + return 'files'; } /** @@ -51,7 +51,7 @@ public function getID() { * @return string */ public function getName() { - return $this->l->t('External Storage'); + return $this->l->t('Files & Storages'); } /** @@ -62,6 +62,6 @@ public function getName() { * E.g.: 70 */ public function getPriority() { - return 35; + return 10; } } diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index e4433880d3a45..cd52c39b30e0c 100644 --- a/apps/files_external/appinfo/info.xml +++ b/apps/files_external/appinfo/info.xml @@ -13,7 +13,7 @@ admin-external-storage false - 1.1.1 + 1.1.2 @@ -27,6 +27,5 @@ OCA\Files_External\Settings\Admin - OCA\Files_External\Settings\Section diff --git a/apps/files_external/lib/Settings/Admin.php b/apps/files_external/lib/Settings/Admin.php index eebfd71287431..102680d0341a7 100644 --- a/apps/files_external/lib/Settings/Admin.php +++ b/apps/files_external/lib/Settings/Admin.php @@ -79,7 +79,7 @@ public function getForm() { * @return string the section ID, e.g. 'sharing' */ public function getSection() { - return 'externalstorage'; + return 'files'; } /** @@ -90,7 +90,7 @@ public function getSection() { * E.g.: 70 */ public function getPriority() { - return 5; + return 40; } } From 2f5adf35259ee176fe7429faf40e501660b91f43 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 18:40:19 +0200 Subject: [PATCH 15/43] superfluous --- apps/user_ldap/appinfo/app.php | 2 -- 1 file changed, 2 deletions(-) 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(); From 628ce019849c0b6bf3adf228af990f673c3016c6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 18:53:45 +0200 Subject: [PATCH 16/43] adjust federation app --- apps/federation/appinfo/app.php | 1 - apps/federation/appinfo/info.xml | 6 +- apps/federation/lib/AppInfo/Application.php | 7 --- apps/federation/lib/Settings/Admin.php | 69 +++++++++++++++++++++ apps/federation/settings/settings-admin.php | 43 ------------- 5 files changed, 74 insertions(+), 52 deletions(-) create mode 100644 apps/federation/lib/Settings/Admin.php delete mode 100644 apps/federation/settings/settings-admin.php 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 b8d697a4db2a7..da65fef2446a2 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.1.0 + 1.1.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(); From 6f09657c55b23444f5df238f04689c0d2aa03459 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 19:03:43 +0200 Subject: [PATCH 17/43] adjust systemtags app --- apps/systemtags/admin.php | 23 -------- apps/systemtags/appinfo/app.php | 3 - apps/systemtags/appinfo/info.xml | 5 +- apps/systemtags/lib/AppInfo/Application.php | 37 ------------ apps/systemtags/lib/Settings/Admin.php | 64 +++++++++++++++++++++ lib/private/Settings/Manager.php | 2 +- 6 files changed, 69 insertions(+), 65 deletions(-) delete mode 100644 apps/systemtags/admin.php delete mode 100644 apps/systemtags/lib/AppInfo/Application.php create mode 100644 apps/systemtags/lib/Settings/Admin.php diff --git a/apps/systemtags/admin.php b/apps/systemtags/admin.php deleted file mode 100644 index 45ea577e8ab67..0000000000000 --- a/apps/systemtags/admin.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * @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 . - * - */ - -$template = new \OCP\Template('systemtags', 'admin'); -return $template->fetchPage(); 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 5eced10b710cb..46bb927883850 100644 --- a/apps/systemtags/appinfo/info.xml +++ b/apps/systemtags/appinfo/info.xml @@ -7,7 +7,7 @@ AGPL Vincent Petry, Joas Schilling - 1.1.0 + 1.1.1 @@ -15,4 +15,7 @@ + + OCA\SystemTags\Settings\Admin + diff --git a/apps/systemtags/lib/AppInfo/Application.php b/apps/systemtags/lib/AppInfo/Application.php deleted file mode 100644 index 7cd49d6424b34..0000000000000 --- a/apps/systemtags/lib/AppInfo/Application.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * @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\AppInfo; - -use OCP\AppFramework\App; - -class Application extends App { - public function __construct() { - parent::__construct('systemtags'); - } - - /** - * Register admin settings - */ - public function registerAdminPage() { - \OCP\App::registerAdmin($this->getContainer()->getAppName(), 'admin'); - } -} diff --git a/apps/systemtags/lib/Settings/Admin.php b/apps/systemtags/lib/Settings/Admin.php new file mode 100644 index 0000000000000..351c226439703 --- /dev/null +++ b/apps/systemtags/lib/Settings/Admin.php @@ -0,0 +1,64 @@ + + * + * @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 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() { + return new TemplateResponse('systemtags', 'admin', [], ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'collaboration'; + } + + /** + * @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/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 01beb47879bd9..769ef71e955b8 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -254,7 +254,7 @@ public function getAdminSections() { $sections = [ 0 => [new Section('server', $this->l->t('Server Settings'), 0)], 5 => [new Section('sharing', $this->l->t('Sharing'), 0)], - //15 => [new Section('collaboration', $this->l->t('Collaboration'), 0)], + 15 => [new Section('collaboration', $this->l->t('Collaboration'), 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)], From d46b7fb83c880316c1efcdcad3f9d49aea54b777 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 11 Aug 2016 19:28:24 +0200 Subject: [PATCH 18/43] Add missing since annotations --- lib/public/Settings/IManager.php | 2 ++ lib/public/Settings/ISection.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/public/Settings/IManager.php b/lib/public/Settings/IManager.php index ba0d9da59a36a..c0170c43bb894 100644 --- a/lib/public/Settings/IManager.php +++ b/lib/public/Settings/IManager.php @@ -52,6 +52,7 @@ public function setupSettings(array $settings); * returns a list of the admin sections * * @return array array of ISection[] where key is the priority + * @since 9.1.0 */ public function getAdminSections(); @@ -60,6 +61,7 @@ public function getAdminSections(); * * @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 index 7802c9b5d6cca..2905b087c326e 100644 --- a/lib/public/Settings/ISection.php +++ b/lib/public/Settings/ISection.php @@ -29,6 +29,7 @@ interface ISection { * e.g. 'ldap' * * @returns string + * @since 9.1 */ public function getID(); @@ -37,6 +38,7 @@ public function getID(); * integration'. Use the L10N service to translate it. * * @return string + * @since 9.1 */ public function getName(); @@ -46,6 +48,7 @@ public function getName(); * the priority values. It is required to return a value between 0 and 99. * * E.g.: 70 + * @since 9.1 */ public function getPriority(); } From 4725f270d899b14649c5f698178fbe26392eb505 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 11 Aug 2016 19:33:37 +0200 Subject: [PATCH 19/43] Add since tags to class --- lib/public/Settings/IManager.php | 4 +++- lib/public/Settings/ISection.php | 3 +++ lib/public/Settings/ISettings.php | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/public/Settings/IManager.php b/lib/public/Settings/IManager.php index c0170c43bb894..8aa7a9ac2488c 100644 --- a/lib/public/Settings/IManager.php +++ b/lib/public/Settings/IManager.php @@ -23,7 +23,9 @@ namespace OCP\Settings; - +/** + * @since 9.1 + */ interface IManager { /** * @since 9.1.0 diff --git a/lib/public/Settings/ISection.php b/lib/public/Settings/ISection.php index 2905b087c326e..5edf5de0ca4f5 100644 --- a/lib/public/Settings/ISection.php +++ b/lib/public/Settings/ISection.php @@ -23,6 +23,9 @@ namespace OCP\Settings; +/** + * @since 9.1 + */ interface ISection { /** * returns the ID of the section. It is supposed to be a lower case string, diff --git a/lib/public/Settings/ISettings.php b/lib/public/Settings/ISettings.php index 07d265a533e06..611bb713b33bd 100644 --- a/lib/public/Settings/ISettings.php +++ b/lib/public/Settings/ISettings.php @@ -25,6 +25,9 @@ use OCP\AppFramework\Http\TemplateResponse; +/** + * @since 9.1 + */ interface ISettings { /** From ac1df882a1ec464886b4f60e550a4d07bd981099 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 11 Aug 2016 19:39:32 +0200 Subject: [PATCH 20/43] Resolve conflict --- settings/templates/admin/server.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/settings/templates/admin/server.php b/settings/templates/admin/server.php index 1bf068de39293..43df787d519e1 100644 --- a/settings/templates/admin/server.php +++ b/settings/templates/admin/server.php @@ -38,14 +38,14 @@ ]; $mail_smtpmode = [ - 'php', - 'smtp', + ['php', 'PHP'], + ['smtp', 'SMTP'], ]; if ($_['sendmail_is_available']) { - $mail_smtpmode[] = 'sendmail'; + $mail_smtpmode[] = ['sendmail', 'Sendmail']; } if ($_['mail_smtpmode'] == 'qmail') { - $mail_smtpmode[] = 'qmail'; + $mail_smtpmode[] = ['qmail', 'qmail']; } ?> @@ -244,10 +244,10 @@ From a53938ff8f41da5128a79a839720af17639d59c7 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 13:23:14 +0200 Subject: [PATCH 21/43] register app autoload instead of loading apps --- apps/systemtags/lib/Settings/Admin.php | 8 -------- lib/private/Installer.php | 3 ++- lib/private/legacy/app.php | 9 ++++++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/apps/systemtags/lib/Settings/Admin.php b/apps/systemtags/lib/Settings/Admin.php index 351c226439703..ed72e17cf506a 100644 --- a/apps/systemtags/lib/Settings/Admin.php +++ b/apps/systemtags/lib/Settings/Admin.php @@ -23,19 +23,11 @@ namespace OCA\SystemTags\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 */ diff --git a/lib/private/Installer.php b/lib/private/Installer.php index 1c45679cd3297..3d8a923417a5d 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -594,7 +594,8 @@ public static function installShippedApp($app) { OC_App::setAppTypes($info['id']); if(isset($info['settings']) && is_array($info['settings'])) { - \OC_App::loadApp($app, false); + // requires that autoloading was registered for the app, + // as happens before running the install.php some lines above \OC::$server->getSettingsManager()->setupSettings($info['settings']); } diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index df76c5b89f089..c786a1fc53d40 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -348,7 +348,8 @@ public static function enable($app, $groups = null) { $info = self::getAppInfo($app); if(isset($info['settings']) && is_array($info['settings'])) { - self::loadApp($app, false); + $appPath = self::getAppPath($app); + self::registerAutoloading($app, $appPath); \OC::$server->getSettingsManager()->setupSettings($info['settings']); } } @@ -1170,7 +1171,8 @@ public static function installApp($app) { } if(isset($info['settings']) && is_array($info['settings'])) { - self::loadApp($app, false); + $appPath = self::getAppPath($app); + self::registerAutoloading($app, $appPath); \OC::$server->getSettingsManager()->setupSettings($info['settings']); } @@ -1212,7 +1214,8 @@ public static function updateApp($appId) { } self::setupBackgroundJobs($appData['background-jobs']); if(isset($appData['settings']) && is_array($appData['settings'])) { - self::loadApp($appId, false); + $appPath = self::getAppPath($appId); + self::registerAutoloading($appId, $appPath); \OC::$server->getSettingsManager()->setupSettings($appData['settings']); } From a015140aa2aaa14ad760449e411146071a071df0 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 12 Aug 2016 15:30:35 +0200 Subject: [PATCH 22/43] rename "Tenmplate" to "ThemingDefaults" to make the auto loader happy" --- apps/theming/lib/Settings/Admin.php | 4 ++-- .../lib/{Template.php => ThemingDefaults.php} | 23 ++++++++----------- ...mplateTest.php => ThemingDefaultsTest.php} | 5 ++-- lib/private/Server.php | 4 ++-- 4 files changed, 16 insertions(+), 20 deletions(-) rename apps/theming/lib/{Template.php => ThemingDefaults.php} (91%) rename apps/theming/tests/{TemplateTest.php => ThemingDefaultsTest.php} (98%) diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index 07dfe75ec605b..03356c1138355 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -23,7 +23,7 @@ namespace OCA\Theming\Settings; -use OCA\Theming\Template; +use OCA\Theming\ThemingDefaults; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IL10N; @@ -44,7 +44,7 @@ class Admin implements ISettings { /** @var IURLGenerator */ private $urlGenerator; - public function __construct(IConfig $config, IL10N $l, Template $themingDefaults, IURLGenerator $urlGenerator) { + public function __construct(IConfig $config, IL10N $l, ThemingDefaults $themingDefaults, IURLGenerator $urlGenerator) { $this->config = $config; $this->l = $l; $this->themingDefaults = $themingDefaults; diff --git a/apps/theming/lib/Template.php b/apps/theming/lib/ThemingDefaults.php similarity index 91% rename from apps/theming/lib/Template.php rename to apps/theming/lib/ThemingDefaults.php index 25730aad95b14..a7af208b96d62 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 */ @@ -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/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..344028253167c 100644 --- a/apps/theming/tests/TemplateTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -24,12 +24,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 */ @@ -64,7 +65,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/lib/private/Server.php b/lib/private/Server.php index 53c8ee849249f..2bbc4871d0874 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; @@ -651,7 +651,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(), From 6a6037e7cba8fce89a8a528cdc89849f34c0680e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 16:00:39 +0200 Subject: [PATCH 23/43] rename remaining occurences of OCA/Theming/Template --- apps/theming/lib/Controller/ThemingController.php | 8 ++++---- apps/theming/lib/Settings/Admin.php | 2 +- apps/theming/lib/ThemingDefaults.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) 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 index 03356c1138355..8aba4696e0049 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -38,7 +38,7 @@ class Admin implements ISettings { /** @var IL10N */ private $l; - /** @var Template */ + /** @var ThemingDefaults */ private $themingDefaults; /** @var IURLGenerator */ diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index a7af208b96d62..7b846919db358 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -48,7 +48,7 @@ class ThemingDefaults extends \OC_Defaults { private $color; /** - * Template constructor. + * ThemingDefaults constructor. * * @param IConfig $config * @param IL10N $l From 130eec217503b9d0134ce60a82247c10c8bd5f64 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 16:52:20 +0200 Subject: [PATCH 24/43] added some missed diagnosis output --- lib/private/Server.php | 3 +- lib/private/Settings/Admin/Server.php | 59 ++++++++++++++++++++++++--- lib/private/Settings/Manager.php | 14 +++++-- 3 files changed, 66 insertions(+), 10 deletions(-) diff --git a/lib/private/Server.php b/lib/private/Server.php index 2bbc4871d0874..05f25a7be8007 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -729,7 +729,8 @@ public function __construct($webRoot, \OC\Config $config) { $c->getL10N('core'), $c->getConfig(), $c->getEncryptionManager(), - $c->getUserManager() + $c->getUserManager(), + $c->getLockingProvider() ); return $manager; }); diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php index 4f1edcf469105..0c72983a887a9 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -26,9 +26,13 @@ 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 { @@ -39,9 +43,17 @@ class Server implements ISettings { /** @var IConfig */ private $config; - public function __construct(IDBConnection $db, IConfig $config) { + /** @var ILockingProvider */ + private $lockingProvider; + + /** @var IL10N */ + private $l; + + public function __construct(IDBConnection $db, IConfig $config, ILockingProvider $lockingProvider, IL10N $l) { $this->db = $db; $this->config = $config; + $this->lockingProvider = $lockingProvider; + $this->l = $l; } /** @@ -59,19 +71,54 @@ public function getForm() { $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'), - 'has_fileinfo' => \OC_Util::fileInfoLoaded(), + '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'), // Mail 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'), diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 769ef71e955b8..7e22d0a3b8cc2 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -30,6 +30,7 @@ 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; @@ -38,7 +39,6 @@ class Manager implements IManager { const TABLE_ADMIN_SETTINGS = 'admin_settings'; const TABLE_ADMIN_SECTIONS = 'admin_sections'; - /** @var ILogger */ /** @var ILogger */ private $log; @@ -57,13 +57,17 @@ class Manager implements IManager { /** @var IUserManager */ private $userManager; + /** @var ILockingProvider */ + private $lockingProvider; + public function __construct( ILogger $log, IDBConnection $dbc, IL10N $l, IConfig $config, EncryptionManager $encryptionManager, - IUserManager $userManager + IUserManager $userManager, + ILockingProvider $lockingProvider ) { $this->log = $log; $this->dbc = $dbc; @@ -71,6 +75,7 @@ public function __construct( $this->config = $config; $this->encryptionManager = $encryptionManager; $this->userManager = $userManager; + $this->lockingProvider = $lockingProvider; } /** @@ -85,6 +90,9 @@ public function setupSettings(array $settings) { } } + /** + * @param string $sectionClassName + */ private function setupAdminSection($sectionClassName) { if(!class_exists($sectionClassName)) { $this->log->debug('Could not find admin section class ' . $sectionClassName); @@ -283,7 +291,7 @@ private function getBuiltInAdminSettings($section) { try { if($section === 'server') { /** @var ISettings $form */ - $form = new Admin\Server($this->dbc, $this->config); + $form = new Admin\Server($this->dbc, $this->config, $this->lockingProvider, $this->l); $forms[$form->getPriority()] = [$form]; } if($section === 'encryption') { From 353a2bfa9ac84bae0b5a2b03d1b3e857da07a768 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 16:58:59 +0200 Subject: [PATCH 25/43] fix theming tests --- apps/theming/tests/Controller/ThemingControllerTest.php | 5 ++--- apps/theming/tests/ThemingDefaultsTest.php | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 81b6b886c9fc5..2662cb16e0f34 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; @@ -40,7 +39,7 @@ class ThemingControllerTest extends TestCase { 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 +55,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/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 344028253167c..6ef7deea152b9 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -23,7 +23,6 @@ */ namespace OCA\Theming\Tests; -use OCA\Theming\Template; use OCA\Theming\ThemingDefaults; use OCP\IConfig; use OCP\IL10N; @@ -39,7 +38,7 @@ class ThemingDefaultsTest extends TestCase { private $urlGenerator; /** @var \OC_Defaults */ private $defaults; - /** @var Template */ + /** @var ThemingDefaults */ private $template; public function setUp() { From 3b73c5a40d4a718af905af3211e03fb787d048ec Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 17:08:32 +0200 Subject: [PATCH 26/43] mark current section --- settings/Controller/AdminSettingsController.php | 17 +++++++++++------ settings/templates/admin/frame.php | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index 271aa05265bac..3efe481ca9ef9 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -72,7 +72,7 @@ public function index($section) { $this->navigationManager->setActiveEntry('admin'); $templateParams = []; - $templateParams = array_merge($templateParams, $this->getNavigationParameters()); + $templateParams = array_merge($templateParams, $this->getNavigationParameters($section)); $templateParams = array_merge($templateParams, $this->getSettings($section)); return new TemplateResponse('settings', 'admin/frame', $templateParams); @@ -126,15 +126,20 @@ private function getLegacyForms() { return ['content' => $out->fetchPage()]; } - private function getNavigationParameters() { - $a = 'anchor'; - $name = 'section-name'; - + /** + * @param string $currentSection + * @return array + */ + private function getNavigationParameters($currentSection) { $sections = $this->settingsManager->getAdminSections(); $templateParameters = []; foreach($sections as $prioritizedSections) { foreach ($prioritizedSections as $section) { - $templateParameters[] = [$a => $section->getID(), $name => $section->getName()]; + $templateParameters[] = [ + 'anchor' => $section->getID(), + 'section-name' => $section->getName(), + 'active' => $section->getID() === $currentSection, + ]; } } diff --git a/settings/templates/admin/frame.php b/settings/templates/admin/frame.php index e0fee1555a3dd..1d9f6dc7a7845 100644 --- a/settings/templates/admin/frame.php +++ b/settings/templates/admin/frame.php @@ -36,7 +36,8 @@ if (isset($form['anchor'])) { $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); $sectionName = $form['section-name']; - print_unescaped(sprintf("
  • %s
  • ", \OCP\Util::sanitizeHTML($anchor), \OCP\Util::sanitizeHTML($sectionName))); + $active = $form['active'] ? ' class="active"' : ''; + print_unescaped(sprintf("%s", $active, \OCP\Util::sanitizeHTML($anchor), \OCP\Util::sanitizeHTML($sectionName))); } }?> From a92bbf2f629722645c91cec568dfc7cf86f6bfa2 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:06:10 +0200 Subject: [PATCH 27/43] change casing in section display names --- apps/files/lib/Settings/Section.php | 2 +- apps/user_ldap/lib/Settings/Section.php | 2 +- lib/private/Settings/Manager.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/files/lib/Settings/Section.php b/apps/files/lib/Settings/Section.php index 2323870cf9749..0a1ddcab6fd4c 100644 --- a/apps/files/lib/Settings/Section.php +++ b/apps/files/lib/Settings/Section.php @@ -51,7 +51,7 @@ public function getID() { * @return string */ public function getName() { - return $this->l->t('Files & Storages'); + return $this->l->t('Files & storages'); } /** diff --git a/apps/user_ldap/lib/Settings/Section.php b/apps/user_ldap/lib/Settings/Section.php index a10bd7cbb93f7..82d8d0c84fa80 100644 --- a/apps/user_ldap/lib/Settings/Section.php +++ b/apps/user_ldap/lib/Settings/Section.php @@ -51,7 +51,7 @@ public function getID() { * @return string */ public function getName() { - return $this->l->t('LDAP / AD Integration'); + return $this->l->t('LDAP / AD integration'); } /** diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 7e22d0a3b8cc2..4b1b5befb2167 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -260,13 +260,13 @@ public function getAdminSections() { // built-in sections $sections = [ - 0 => [new Section('server', $this->l->t('Server Settings'), 0)], + 0 => [new Section('server', $this->l->t('Server settings'), 0)], 5 => [new Section('sharing', $this->l->t('Sharing'), 0)], 15 => [new Section('collaboration', $this->l->t('Collaboration'), 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)], + 98 => [new Section('additional', $this->l->t('Additional settings'), 0)], + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0)], ]; $result = $query->execute(); From f2b3799014740a997f082168bc47fc9606c3e278 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:29:39 +0200 Subject: [PATCH 28/43] make updatenotification settings appear as if it is part of the version part in server settings --- .../updatenotification/lib/Controller/AdminController.php | 2 +- apps/updatenotification/templates/admin.php | 4 +--- settings/css/settings.css | 8 ++++++++ settings/templates/admin/server.php | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index 3c6ab4630599a..ebb3fa642f1e3 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -168,6 +168,6 @@ public function getSection() { * E.g.: 70 */ public function getPriority() { - return 5; + 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/settings/css/settings.css b/settings/css/settings.css index b006f1f565682..b40b7a17904d2 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/templates/admin/server.php b/settings/templates/admin/server.php index 43df787d519e1..1e24043b3dc13 100644 --- a/settings/templates/admin/server.php +++ b/settings/templates/admin/server.php @@ -319,6 +319,7 @@
    +

    t('Version'));?>

    getTitle()); ?>

    From 2019e7e44c022a45e7b74fd1c9b54274910da373 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:33:09 +0200 Subject: [PATCH 29/43] move systemstags to sharign section, drop collaboration section --- apps/systemtags/lib/Settings/Admin.php | 4 ++-- lib/private/Settings/Manager.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/systemtags/lib/Settings/Admin.php b/apps/systemtags/lib/Settings/Admin.php index ed72e17cf506a..fbdec8741f784 100644 --- a/apps/systemtags/lib/Settings/Admin.php +++ b/apps/systemtags/lib/Settings/Admin.php @@ -39,7 +39,7 @@ public function getForm() { * @return string the section ID, e.g. 'sharing' */ public function getSection() { - return 'collaboration'; + return 'sharing'; } /** @@ -50,7 +50,7 @@ public function getSection() { * E.g.: 70 */ public function getPriority() { - return 30; + return 70; } } diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 4b1b5befb2167..21400a9805aff 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -262,7 +262,6 @@ public function getAdminSections() { $sections = [ 0 => [new Section('server', $this->l->t('Server settings'), 0)], 5 => [new Section('sharing', $this->l->t('Sharing'), 0)], - 15 => [new Section('collaboration', $this->l->t('Collaboration'), 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)], From 6ed042a1bac543344f69fd35e093c78ab112a923 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:36:32 +0200 Subject: [PATCH 30/43] change federatedfilesharing css class to followupsection to reduce whitespace --- apps/federatedfilesharing/templates/settings-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/federatedfilesharing/templates/settings-admin.php b/apps/federatedfilesharing/templates/settings-admin.php index aa2f551e18d3f..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'));?>

    Date: Sat, 13 Aug 2016 00:59:04 +0200 Subject: [PATCH 31/43] move mail settings and file handling to additional ones, thus files_external gets its own section --- apps/files/appinfo/info.xml | 1 - apps/files/lib/Settings/Admin.php | 2 +- apps/files_external/appinfo/info.xml | 1 + apps/files_external/lib/Settings/Admin.php | 2 +- .../lib/Settings/Section.php | 6 +- lib/private/Settings/Admin/Additional.php | 86 +++++++++++ lib/private/Settings/Admin/Server.php | 13 -- lib/private/Settings/Manager.php | 5 + .../Controller/AdminSettingsController.php | 14 +- settings/templates/admin/additional-mail.php | 140 ++++++++++++++++++ settings/templates/admin/additional.php | 13 +- settings/templates/admin/server.php | 111 -------------- 12 files changed, 249 insertions(+), 145 deletions(-) rename apps/{files => files_external}/lib/Settings/Section.php (93%) create mode 100644 lib/private/Settings/Admin/Additional.php create mode 100644 settings/templates/admin/additional-mail.php diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml index c1666af634838..513940f73a95c 100644 --- a/apps/files/appinfo/info.xml +++ b/apps/files/appinfo/info.xml @@ -25,6 +25,5 @@ OCA\Files\Settings\Admin - OCA\Files\Settings\Section diff --git a/apps/files/lib/Settings/Admin.php b/apps/files/lib/Settings/Admin.php index d0a691ffe6648..9ec23d47517b9 100644 --- a/apps/files/lib/Settings/Admin.php +++ b/apps/files/lib/Settings/Admin.php @@ -76,7 +76,7 @@ public function getForm() { * @return string the section ID, e.g. 'sharing' */ public function getSection() { - return 'files'; + return 'additional'; } /** diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index cd52c39b30e0c..6013175988026 100644 --- a/apps/files_external/appinfo/info.xml +++ b/apps/files_external/appinfo/info.xml @@ -27,5 +27,6 @@ OCA\Files_External\Settings\Admin + OCA\Files_External\Settings\Section diff --git a/apps/files_external/lib/Settings/Admin.php b/apps/files_external/lib/Settings/Admin.php index 102680d0341a7..54711443f895a 100644 --- a/apps/files_external/lib/Settings/Admin.php +++ b/apps/files_external/lib/Settings/Admin.php @@ -79,7 +79,7 @@ public function getForm() { * @return string the section ID, e.g. 'sharing' */ public function getSection() { - return 'files'; + return 'externalstorages'; } /** diff --git a/apps/files/lib/Settings/Section.php b/apps/files_external/lib/Settings/Section.php similarity index 93% rename from apps/files/lib/Settings/Section.php rename to apps/files_external/lib/Settings/Section.php index 0a1ddcab6fd4c..4b4bac93d2934 100644 --- a/apps/files/lib/Settings/Section.php +++ b/apps/files_external/lib/Settings/Section.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Files\Settings; +namespace OCA\Files_External\Settings; use OCP\IL10N; use OCP\Settings\ISection; @@ -41,7 +41,7 @@ public function __construct(IL10N $l) { * @returns string */ public function getID() { - return 'files'; + return 'externalstorages'; } /** @@ -51,7 +51,7 @@ public function getID() { * @return string */ public function getName() { - return $this->l->t('Files & storages'); + return $this->l->t('External storages'); } /** diff --git a/lib/private/Settings/Admin/Additional.php b/lib/private/Settings/Admin/Additional.php new file mode 100644 index 0000000000000..106f0f65b8af7 --- /dev/null +++ b/lib/private/Settings/Admin/Additional.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 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; + + 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/Server.php b/lib/private/Settings/Admin/Server.php index 0c72983a887a9..20c3a6d7557ed 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -119,19 +119,6 @@ public function getForm() { 'cron_log' => $this->config->getSystemValue('cron_log', true), 'lastcron' => $this->config->getAppValue('core', 'lastcron', false), 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'), - - // 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/server', $parameters, ''); diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 21400a9805aff..fd360ede7f038 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -308,6 +308,11 @@ private function getBuiltInAdminSettings($section) { $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); diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index 3efe481ca9ef9..3954497443b82 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -34,6 +34,7 @@ use OCP\IRequest; use OCP\IUserManager; use OCP\Settings\IManager as ISettingsManager; +use OCP\Template; /** * @package OC\Settings\Controller @@ -83,12 +84,8 @@ public function form() { } private function getSettings($section) { - if($section === 'additional') { - return $this->getLegacyForms(); - } - - $settings = $this->settingsManager->getAdminSettings($section); $html = ''; + $settings = $this->settingsManager->getAdminSettings($section); foreach ($settings as $prioritizedSettings) { foreach ($prioritizedSettings as $setting) { /** @var \OCP\Settings\ISettings $setting */ @@ -96,6 +93,9 @@ private function getSettings($section) { $html .= $form->renderAs('')->render(); } } + if($section === 'additional') { + $html .= $this->getLegacyForms(); + } return ['content' => $html]; } @@ -120,10 +120,10 @@ private function getLegacyForms() { ); }, $forms); - $out = new \OCP\Template('settings', 'admin/additional'); + $out = new Template('settings', 'admin/additional'); $out->assign('forms', $forms); - return ['content' => $out->fetchPage()]; + return $out->fetchPage(); } /** 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/settings/templates/admin/additional.php b/settings/templates/admin/additional.php index c4e70dbddb2cb..2ad2c5af4e5d5 100644 --- a/settings/templates/admin/additional.php +++ b/settings/templates/admin/additional.php @@ -26,11 +26,8 @@ ?> -
    -

    t('Additional Settings'));?>

    - -
    - -
    + +
    + diff --git a/settings/templates/admin/server.php b/settings/templates/admin/server.php index 1e24043b3dc13..a15705a90e2d5 100644 --- a/settings/templates/admin/server.php +++ b/settings/templates/admin/server.php @@ -24,29 +24,6 @@ /** @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']; -} ?>
    @@ -230,94 +207,6 @@

    -
    -
    -

    t('Email server'));?>

    - - -

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

    - -

    - - - - - -

    - -

    - - ' />@ - ' /> -

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

    t('Version'));?>

    From 6ad5c1a255c58ef6fead3e473aa640a386562df8 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 01:26:11 +0200 Subject: [PATCH 32/43] simplify encryption manager fetching in DIContainer --- .../DependencyInjection/DIContainer.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 4e3cac6d1eac0..22bcc0046266b 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -310,22 +310,8 @@ public function __construct($appName, $urlParams = array()){ return $c->query('ServerContainer')->getWebRoot(); }); - $this->registerService('\OCP\Encryption\IManager', function ($c) { - $view = new \OC\Files\View(); - $util = new \OC\Encryption\Util( - $view, - $c->query('\OCP\IUserManager'), - $c->query('\OCP\IGroupManager'), - $c->query('\OCP\IConfig') - ); - return new \OC\Encryption\Manager( - $c->query('\OCP\IConfig'), - $c->query('\OCP\ILogger'), - $c->query('ServerContainer')->getL10N('core'), - new \OC\Files\View(), - $util, - new \OC\Memcache\ArrayCache() - ); + $this->registerService('OCP\Encryption\IManager', function ($c) { + return $this->getServer()->getEncryptionManager(); }); From 87630c6a24353acd492f37ede1b78f5b86132ccc Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 15 Aug 2016 13:38:02 +0200 Subject: [PATCH 33/43] satisfy dependencies for files_external --- lib/private/AppFramework/DependencyInjection/DIContainer.php | 4 ++++ lib/private/Server.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 22bcc0046266b..771928478672b 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -152,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(); }); diff --git a/lib/private/Server.php b/lib/private/Server.php index 05f25a7be8007..245bbb338e2bc 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1289,6 +1289,11 @@ function getMountManager() { return $this->query('MountManager'); } + /** @return \OCP\Files\Config\IUserMountCache */ + function getUserMountCache() { + return $this->query('UserMountCache'); + } + /** * Get the MimeTypeDetector * From d1a1324bad604f172203a39d1c1d4c38b28a55a1 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 16:24:56 +0200 Subject: [PATCH 34/43] Add unit tests --- apps/encryption/tests/Settings/AdminTest.php | 100 ++++++++ .../tests/Settings/AdminTest.php | 84 +++++++ apps/federation/tests/Settings/AdminTest.php | 70 ++++++ apps/files/tests/Settings/AdminTest.php | 83 +++++++ .../tests/Settings/AdminTest.php | 109 +++++++++ .../tests/Settings/SectionTest.php | 62 +++++ apps/systemtags/tests/Settings/AdminTest.php | 52 +++++ apps/theming/lib/Settings/Admin.php | 9 +- .../Controller/ThemingControllerTest.php | 1 + apps/theming/tests/Settings/AdminTest.php | 155 ++++++++++++ apps/theming/tests/Settings/SectionTest.php | 62 +++++ .../tests/Controller/AdminControllerTest.php | 25 +- apps/user_ldap/lib/Settings/Admin.php | 10 +- apps/user_ldap/tests/Settings/AdminTest.php | 90 +++++++ apps/user_ldap/tests/Settings/SectionTest.php | 62 +++++ lib/private/Settings/Admin/Additional.php | 4 +- lib/private/Settings/Admin/Encryption.php | 4 + lib/private/Settings/Admin/Logging.php | 3 + lib/private/Settings/Admin/Server.php | 15 +- lib/private/Settings/Admin/Sharing.php | 8 +- lib/private/Settings/Admin/TipsTricks.php | 3 + lib/private/Settings/Manager.php | 36 +-- lib/private/Settings/Section.php | 10 +- .../Controller/AdminSettingsController.php | 32 ++- tests/Core/Templates/TemplatesTest.php | 2 +- .../AdminSettingsControllerTest.php | 72 ++++++ .../Controller/CheckSetupControllerTest.php | 10 +- tests/lib/Settings/Admin/AdditionalTest.php | 127 ++++++++++ tests/lib/Settings/Admin/EncryptionTest.php | 128 ++++++++++ tests/lib/Settings/Admin/LoggingTest.php | 91 ++++++++ tests/lib/Settings/Admin/ServerTest.php | 154 ++++++++++++ tests/lib/Settings/Admin/SharingTest.php | 151 ++++++++++++ tests/lib/Settings/Admin/TipsTricksTest.php | 91 ++++++++ tests/lib/Settings/ManagerTest.php | 220 ++++++++++++++++++ tests/lib/Settings/SectionTest.php | 39 ++++ 35 files changed, 2107 insertions(+), 67 deletions(-) create mode 100644 apps/encryption/tests/Settings/AdminTest.php create mode 100644 apps/federatedfilesharing/tests/Settings/AdminTest.php create mode 100644 apps/federation/tests/Settings/AdminTest.php create mode 100644 apps/files/tests/Settings/AdminTest.php create mode 100644 apps/files_external/tests/Settings/AdminTest.php create mode 100644 apps/files_external/tests/Settings/SectionTest.php create mode 100644 apps/systemtags/tests/Settings/AdminTest.php create mode 100644 apps/theming/tests/Settings/AdminTest.php create mode 100644 apps/theming/tests/Settings/SectionTest.php create mode 100644 apps/user_ldap/tests/Settings/AdminTest.php create mode 100644 apps/user_ldap/tests/Settings/SectionTest.php create mode 100644 tests/Settings/Controller/AdminSettingsControllerTest.php create mode 100644 tests/lib/Settings/Admin/AdditionalTest.php create mode 100644 tests/lib/Settings/Admin/EncryptionTest.php create mode 100644 tests/lib/Settings/Admin/LoggingTest.php create mode 100644 tests/lib/Settings/Admin/ServerTest.php create mode 100644 tests/lib/Settings/Admin/SharingTest.php create mode 100644 tests/lib/Settings/Admin/TipsTricksTest.php create mode 100644 tests/lib/Settings/ManagerTest.php create mode 100644 tests/lib/Settings/SectionTest.php diff --git a/apps/encryption/tests/Settings/AdminTest.php b/apps/encryption/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..5b0b577e05817 --- /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->createMock('\OCP\IL10N'); + $this->logger = $this->createMock('\OCP\ILogger'); + $this->userSession = $this->createMock('\OCP\IUserSession'); + $this->config = $this->createMock('\OCP\IConfig'); + $this->userManager = $this->createMock('\OCP\IUserManager'); + $this->session = $this->createMock('\OCP\ISession'); + + $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/tests/Settings/AdminTest.php b/apps/federatedfilesharing/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..e082e7bff2317 --- /dev/null +++ b/apps/federatedfilesharing/tests/Settings/AdminTest.php @@ -0,0 +1,84 @@ + + * + * @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->createMock('\OCA\FederatedFileSharing\FederatedShareProvider'); + $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/tests/Settings/AdminTest.php b/apps/federation/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..78cb7201dcdef --- /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->createMock('\OCA\Federation\TrustedServers'); + $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/tests/Settings/AdminTest.php b/apps/files/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..c536377af939e --- /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->createMock('\bantu\IniGetWrapper\IniGetWrapper'); + $this->request = $this->createMock('\OCP\IRequest'); + $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/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..1918e800c9bda --- /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->createMock('\OCP\Encryption\IManager'); + $this->globalStoragesService = $this->createMock('\OCA\Files_External\Service\GlobalStoragesService'); + $this->backendService = $this->createMock('\OCA\Files_External\Service\BackendService'); + $this->globalAuth = $this->createMock('\OCA\Files_External\Lib\Auth\Password\GlobalAuth'); + + $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..9ab456fe30799 --- /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->createMock('\OCP\IL10N'); + + $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/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/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index 8aba4696e0049..1f79449e65816 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -31,20 +31,19 @@ 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) { + public function __construct(IConfig $config, + IL10N $l, + ThemingDefaults $themingDefaults, + IURLGenerator $urlGenerator) { $this->config = $config; $this->l = $l; $this->themingDefaults = $themingDefaults; diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 2662cb16e0f34..688e3d62bfff8 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -33,6 +33,7 @@ use OCP\IL10N; use OCP\IRequest; use Test\TestCase; +use OCA\Theming\ThemingDefaults; class ThemingControllerTest extends TestCase { /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..ff42c6997a659 --- /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->createMock('\OCP\IConfig'); + $this->l10n = $this->createMock('\OCP\IL10N'); + $this->themingDefaults = $this->createMock('\OCA\Theming\ThemingDefaults'); + $this->urlGenerator = $this->createMock('\OCP\IURLGenerator'); + + $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..e8a9a217f1ff9 --- /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->createMock('\OCP\IL10N'); + + $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/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php index 0343542ef4187..a4398715885dc 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->createMock('\\OCP\\IRequest'); + $this->jobList = $this->createMock('\\OCP\\BackgroundJob\\IJobList'); + $this->secureRandom = $this->createMock('\\OCP\\Security\\ISecureRandom'); + $this->config = $this->createMock('\\OCP\\IConfig'); + $this->timeFactory = $this->createMock('\\OCP\\AppFramework\\Utility\\ITimeFactory'); + $this->l10n = $this->createMock('\\OCP\\IL10N'); + $this->updateChecker = $this->createMock('\\OCA\\UpdateNotification\\UpdateChecker'); + $this->dateTimeFormatter = $this->createMock('\\OCP\\IDateTimeFormatter'); $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/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php index 606cfe6cf0194..ca7db66c788dc 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -31,10 +31,12 @@ use OCP\Template; class Admin implements ISettings { - /** @var IL10N */ private $l; + /** + * @param IL10N $l + */ public function __construct(IL10N $l) { $this->l = $l; } @@ -84,10 +86,4 @@ public function getSection() { public function getPriority() { return 5; } - - private function renderControls() { - $controls = new Template('user_ldap', 'part.settingcontrols'); - return $controls->fetchPage(); - - } } diff --git a/apps/user_ldap/tests/Settings/AdminTest.php b/apps/user_ldap/tests/Settings/AdminTest.php new file mode 100644 index 0000000000000..e92684f3ce47e --- /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->createMock('\OCP\IL10N'); + + $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..b5b1f97ce3cae --- /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->createMock('\OCP\IL10N'); + + $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/lib/private/Settings/Admin/Additional.php b/lib/private/Settings/Admin/Additional.php index 106f0f65b8af7..d133e4737a76b 100644 --- a/lib/private/Settings/Admin/Additional.php +++ b/lib/private/Settings/Admin/Additional.php @@ -36,10 +36,12 @@ use OCP\Settings\ISettings; class Additional implements ISettings { - /** @var IConfig */ private $config; + /** + * @param IConfig $config + */ public function __construct(IConfig $config) { $this->config = $config; } diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php index ceae5aa6d3fd5..69c6bd17f0313 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -35,6 +35,10 @@ class Encryption implements ISettings { /** @var IUserManager */ private $userManager; + /** + * @param Manager $manager + * @param IUserManager $userManager + */ public function __construct(Manager $manager, IUserManager $userManager) { $this->manager = $manager; $this->userManager = $userManager; diff --git a/lib/private/Settings/Admin/Logging.php b/lib/private/Settings/Admin/Logging.php index 3097070577dd7..407248ac4b16e 100644 --- a/lib/private/Settings/Admin/Logging.php +++ b/lib/private/Settings/Admin/Logging.php @@ -32,6 +32,9 @@ class Logging implements ISettings { /** @var IConfig */ private $config; + /** + * @param IConfig $config + */ public function __construct(IConfig $config) { $this->config = $config; } diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php index 20c3a6d7557ed..6b381ab48ed7f 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -36,20 +36,25 @@ 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; - public function __construct(IDBConnection $db, IConfig $config, ILockingProvider $lockingProvider, IL10N $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; diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index d186dbed9814b..e110a3d81b7bb 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -31,6 +31,9 @@ class Sharing implements ISettings { /** @var IConfig */ private $config; + /** + * @param IConfig $config + */ public function __construct(IConfig $config) { $this->config = $config; } @@ -39,8 +42,9 @@ public function __construct(IConfig $config) { * @return TemplateResponse */ public function getForm() { - $excludeGroupsList = !is_null(json_decode($this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''))) - ? implode('|', $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '')) : ''; + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); + $excludeGroupsList = !is_null(json_decode($excludedGroups)) + ? implode('|', json_decode($excludedGroups, true)) : ''; $parameters = [ // Built-In Sharing diff --git a/lib/private/Settings/Admin/TipsTricks.php b/lib/private/Settings/Admin/TipsTricks.php index 217ddacd44307..fd0fd5958445a 100644 --- a/lib/private/Settings/Admin/TipsTricks.php +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -31,6 +31,9 @@ class TipsTricks implements ISettings { /** @var IConfig */ private $config; + /** + * @param IConfig $config + */ public function __construct(IConfig $config) { $this->config = $config; } diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index fd360ede7f038..1304a60949e7a 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -41,25 +41,28 @@ class Manager implements IManager { /** @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, @@ -135,7 +138,11 @@ private function addAdminSettings(ISettings $settings) { ]); } - private function add($table, $values) { + /** + * @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); @@ -196,7 +203,11 @@ 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') @@ -249,9 +260,7 @@ private function query($className) { } /** - * returns a list of the admin sections - * - * @return ISection[] + * @inheritdoc */ public function getAdminSections() { $query = $this->dbc->getQueryBuilder(); @@ -347,11 +356,12 @@ private function getAdminSettingsFromDB($section, &$settings) { ksort($settings); } + /** + * @inheritdoc + */ public function getAdminSettings($section) { $settings = $this->getBuiltInAdminSettings($section); $this->getAdminSettingsFromDB($section, $settings); return $settings; } - - } diff --git a/lib/private/Settings/Section.php b/lib/private/Settings/Section.php index 2ea614b365ec0..b3cf242279fc2 100644 --- a/lib/private/Settings/Section.php +++ b/lib/private/Settings/Section.php @@ -21,23 +21,23 @@ * */ - 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; diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index 3954497443b82..ef70caf56902f 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016 Arthur Schiwon * * @author Arthur Schiwon + * @author Lukas Reschke * * @license GNU AGPL version 3 or any later version * @@ -23,16 +24,10 @@ namespace OC\Settings\Controller; -use Doctrine\DBAL\Connection; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; -use OC\Encryption\Manager as EncryptionManager; -use OCP\IConfig; -use OCP\IDBConnection; -use OCP\IL10N; use OCP\INavigationManager; use OCP\IRequest; -use OCP\IUserManager; use OCP\Settings\IManager as ISettingsManager; use OCP\Template; @@ -40,22 +35,21 @@ * @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, - IL10N $l, - IConfig $config, - EncryptionManager $encryptionManager, - IUserManager $userManager, - IDBConnection $db, ISettingsManager $settingsManager ) { parent::__construct($appName, $request); @@ -79,10 +73,10 @@ public function index($section) { return new TemplateResponse('settings', 'admin/frame', $templateParams); } - public function form() { - - } - + /** + * @param string $section + * @return array + */ private function getSettings($section) { $html = ''; $settings = $this->settingsManager->getAdminSettings($section); @@ -99,6 +93,9 @@ private function getSettings($section) { return ['content' => $html]; } + /** + * @return bool|string + */ private function getLegacyForms() { $forms = \OC_App::getForms('admin'); @@ -133,6 +130,7 @@ private function getLegacyForms() { private function getNavigationParameters($currentSection) { $sections = $this->settingsManager->getAdminSections(); $templateParameters = []; + /** @var \OC\Settings\Section[] $prioritizedSections */ foreach($sections as $prioritizedSections) { foreach ($prioritizedSections as $section) { $templateParameters[] = [ diff --git a/tests/Core/Templates/TemplatesTest.php b/tests/Core/Templates/TemplatesTest.php index 03565411a13d3..cd1502fd22cbf 100644 --- a/tests/Core/Templates/TemplatesTest.php +++ b/tests/Core/Templates/TemplatesTest.php @@ -13,7 +13,7 @@ public function test403() { public function test404() { $template = \OC::$SERVERROOT . '/core/templates/404.php'; $href = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); - $expectedHtml = ""; + $expectedHtml = ""; $this->assertTemplate($expectedHtml, $template); } diff --git a/tests/Settings/Controller/AdminSettingsControllerTest.php b/tests/Settings/Controller/AdminSettingsControllerTest.php new file mode 100644 index 0000000000000..86950c9aa9db7 --- /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->createMock('\OCP\IRequest'); + $this->navigationManager = $this->createMock('\OCP\INavigationManager'); + $this->settingsManager = $this->createMock('\OCP\Settings\IManager'); + + $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->createMock('\OCP\IConfig'))]); + $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 f48e9c04f3d18..63c8141cedd88 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; @@ -68,6 +69,8 @@ class CheckSetupControllerTest extends TestCase { private $util; /** @var IL10N */ private $l10n; + /** @var ILogger */ + private $logger; /** @var Checker */ private $checker; @@ -95,6 +98,7 @@ public function setUp() { })); $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') ->disableOriginalConstructor()->getMock(); + $this->logger = $this->createMock('\OCP\ILogger'); $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') ->setConstructorArgs([ 'settings', @@ -105,6 +109,7 @@ public function setUp() { $this->util, $this->l10n, $this->checker, + $this->logger ]) ->setMethods(['getCurlVersion'])->getMock(); } @@ -373,7 +378,8 @@ public function testGetCurlVersion() { $this->urlGenerator, $this->util, $this->l10n, - $this->checker + $this->checker, + $this->logger ]) ->setMethods(null)->getMock(); @@ -612,7 +618,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..178d7550614bb --- /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->createMock('\OCP\IConfig'); + + $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..a68b40ae11b5d --- /dev/null +++ b/tests/lib/Settings/Admin/EncryptionTest.php @@ -0,0 +1,128 @@ + + * + * @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->createMock('\OC\Encryption\Manager'); + $this->userManager = $this->createMock('\OCP\IUserManager'); + + $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->userManager + ->expects($this->once()) + ->method('getBackends') + ->willReturn(['entry']); + $expected = new TemplateResponse( + 'settings', + 'admin/encryption', + [ + 'encryptionEnabled' => $enabled, + 'encryptionReady' => $enabled, + 'externalBackendsEnabled' => false, + ], + '' + ); + $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->userManager + ->expects($this->once()) + ->method('getBackends') + ->willReturn(['entry', 'entry']); + $expected = new TemplateResponse( + 'settings', + 'admin/encryption', + [ + 'encryptionEnabled' => $enabled, + 'encryptionReady' => $enabled, + 'externalBackendsEnabled' => true, + ], + '' + ); + $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..10a94f1c59c34 --- /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\File as LogFile; + +class LoggingTest extends TestCase { + /** @var Logging */ + private $admin; + /** @var IConfig */ + private $config; + + public function setUp() { + parent::setUp(); + $this->config = $this->createMock('\OCP\IConfig'); + + $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..5a4fa22920f3b --- /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->createMock('\OCP\IConfig'); + $this->dbConnection = $this->createMock('\OCP\IDBConnection'); + $this->lockingProvider = $this->createMock('\OCP\Lock\ILockingProvider'); + $this->l10n = $this->createMock('\OCP\IL10N'); + + $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..7aec187d3723c --- /dev/null +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -0,0 +1,151 @@ + + * + * @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->createMock('\OCP\IConfig'); + + $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_enabled', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(2)) + ->method('getAppValue') + ->with('core', 'shareapi_default_expire_date', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('core', 'shareapi_expire_after_n_days', '7') + ->willReturn('7'); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'shareapi_enforce_expire_date', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'shareapi_exclude_groups', 'no') + ->willReturn('no'); + + $expected = new TemplateResponse( + 'settings', + 'admin/sharing', + [ + '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_enabled', 'yes') + ->willReturn('yes'); + $this->config + ->expects($this->at(2)) + ->method('getAppValue') + ->with('core', 'shareapi_default_expire_date', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('core', 'shareapi_expire_after_n_days', '7') + ->willReturn('7'); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'shareapi_enforce_expire_date', 'no') + ->willReturn('no'); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'shareapi_exclude_groups', 'no') + ->willReturn('yes'); + + $expected = new TemplateResponse( + 'settings', + 'admin/sharing', + [ + '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..afa053e833748 --- /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->createMock('\OCP\IConfig'); + + $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..01e226225beb8 --- /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->createMock('\OCP\ILogger'); + $this->dbConnection = $this->createMock('\OCP\IDBConnection'); + $this->l10n = $this->createMock('\OCP\IL10N'); + $this->config = $this->createMock('\OCP\IConfig'); + $this->encryptionManager = $this->createMock('\OCP\Encryption\IManager'); + $this->userManager = $this->createMock('\OCP\IUserManager'); + $this->lockingProvider = $this->createMock('\OCP\Lock\ILockingProvider'); + + $this->manager = new Manager( + $this->logger, + $this->dbConnection, + $this->l10n, + $this->config, + $this->encryptionManager, + $this->userManager, + $this->lockingProvider + ); + } + + public function testSetupSettings() { + $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $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->createMock('\OCP\DB\QueryBuilder\IExpressionBuilder'); + $qb + ->expects($this->once()) + ->method('expr') + ->willReturn($expressionBuilder); + $param = $this->createMock('\OCP\DB\QueryBuilder\IParameter'); + $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->createMock('\Doctrine\DBAL\Driver\Statement'); + $qb + ->expects($this->once()) + ->method('execute') + ->willReturn($stmt); + + $qb1 = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $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->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb + ->expects($this->once()) + ->method('select') + ->with(['class', 'priority']) + ->willReturn($qb); + $qb + ->expects($this->once()) + ->method('from') + ->with('admin_sections') + ->willReturn($qb); + $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement'); + $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->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb + ->expects($this->once()) + ->method('select') + ->with(['class', 'priority']) + ->willReturn($qb); + $qb + ->expects($this->once()) + ->method('from') + ->with('admin_settings') + ->willReturn($qb); + $expressionBuilder = $this->createMock('\OCP\DB\QueryBuilder\IExpressionBuilder'); + $qb + ->expects($this->once()) + ->method('expr') + ->willReturn($expressionBuilder); + $param = $this->createMock('\OCP\DB\QueryBuilder\IParameter'); + $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->createMock('\Doctrine\DBAL\Driver\Statement'); + $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/tests/lib/Settings/SectionTest.php b/tests/lib/Settings/SectionTest.php new file mode 100644 index 0000000000000..422b931bb4be5 --- /dev/null +++ b/tests/lib/Settings/SectionTest.php @@ -0,0 +1,39 @@ + + * + * @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\Section; +use Test\TestCase; + +class SectionTest extends TestCase { + public function testGetID() { + $this->assertSame('ldap', (new Section('ldap', 'name', 1))->getID()); + } + public function testGetName() { + $this->assertSame('name', (new Section('ldap', 'name', 1))->getName()); + } + public function testGetPriority() { + $this->assertSame(1, (new Section('ldap', 'name', 1))->getPriority()); + } +} From 7cfab4163367fc9c4946bb0611b43aeeb228a811 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 16:43:22 +0200 Subject: [PATCH 35/43] Use MockBuilder instead of createMock CI uses an older PHPUnit --- apps/encryption/tests/Settings/AdminTest.php | 12 +++---- .../tests/Settings/AdminTest.php | 2 +- apps/federation/tests/Settings/AdminTest.php | 2 +- apps/files/tests/Settings/AdminTest.php | 4 +-- .../tests/Settings/AdminTest.php | 8 ++--- .../tests/Settings/SectionTest.php | 2 +- apps/theming/tests/Settings/AdminTest.php | 8 ++--- apps/theming/tests/Settings/SectionTest.php | 2 +- .../tests/Controller/AdminControllerTest.php | 16 ++++----- apps/user_ldap/tests/Settings/AdminTest.php | 2 +- apps/user_ldap/tests/Settings/SectionTest.php | 2 +- .../AdminSettingsControllerTest.php | 8 ++--- .../Controller/CheckSetupControllerTest.php | 2 +- tests/lib/Settings/Admin/AdditionalTest.php | 2 +- tests/lib/Settings/Admin/EncryptionTest.php | 4 +-- tests/lib/Settings/Admin/LoggingTest.php | 2 +- tests/lib/Settings/Admin/ServerTest.php | 8 ++--- tests/lib/Settings/Admin/SharingTest.php | 2 +- tests/lib/Settings/Admin/TipsTricksTest.php | 2 +- tests/lib/Settings/ManagerTest.php | 36 +++++++++---------- 20 files changed, 63 insertions(+), 63 deletions(-) diff --git a/apps/encryption/tests/Settings/AdminTest.php b/apps/encryption/tests/Settings/AdminTest.php index 5b0b577e05817..93896585dad5c 100644 --- a/apps/encryption/tests/Settings/AdminTest.php +++ b/apps/encryption/tests/Settings/AdminTest.php @@ -52,12 +52,12 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->l = $this->createMock('\OCP\IL10N'); - $this->logger = $this->createMock('\OCP\ILogger'); - $this->userSession = $this->createMock('\OCP\IUserSession'); - $this->config = $this->createMock('\OCP\IConfig'); - $this->userManager = $this->createMock('\OCP\IUserManager'); - $this->session = $this->createMock('\OCP\ISession'); + $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, diff --git a/apps/federatedfilesharing/tests/Settings/AdminTest.php b/apps/federatedfilesharing/tests/Settings/AdminTest.php index e082e7bff2317..60fadca7b568a 100644 --- a/apps/federatedfilesharing/tests/Settings/AdminTest.php +++ b/apps/federatedfilesharing/tests/Settings/AdminTest.php @@ -35,7 +35,7 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->federatedShareProvider = $this->createMock('\OCA\FederatedFileSharing\FederatedShareProvider'); + $this->federatedShareProvider = $this->getMockBuilder('\OCA\FederatedFileSharing\FederatedShareProvider')->disableOriginalConstructor()->getMock(); $this->admin = new Admin( $this->federatedShareProvider ); diff --git a/apps/federation/tests/Settings/AdminTest.php b/apps/federation/tests/Settings/AdminTest.php index 78cb7201dcdef..758bda6bc5e13 100644 --- a/apps/federation/tests/Settings/AdminTest.php +++ b/apps/federation/tests/Settings/AdminTest.php @@ -36,7 +36,7 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->trustedServers = $this->createMock('\OCA\Federation\TrustedServers'); + $this->trustedServers = $this->getMockBuilder('\OCA\Federation\TrustedServers')->disableOriginalConstructor()->getMock(); $this->admin = new Admin( $this->trustedServers ); diff --git a/apps/files/tests/Settings/AdminTest.php b/apps/files/tests/Settings/AdminTest.php index c536377af939e..1ab8a992879c1 100644 --- a/apps/files/tests/Settings/AdminTest.php +++ b/apps/files/tests/Settings/AdminTest.php @@ -40,8 +40,8 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->iniGetWrapper = $this->createMock('\bantu\IniGetWrapper\IniGetWrapper'); - $this->request = $this->createMock('\OCP\IRequest'); + $this->iniGetWrapper = $this->getMockBuilder('\bantu\IniGetWrapper\IniGetWrapper')->disableOriginalConstructor()->getMock(); + $this->request = $this->getMockBuilder('\OCP\IRequest')->getMock(); $this->admin = new Admin( $this->iniGetWrapper, $this->request diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php index 1918e800c9bda..fdf9680e7c378 100644 --- a/apps/files_external/tests/Settings/AdminTest.php +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -45,10 +45,10 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->encryptionManager = $this->createMock('\OCP\Encryption\IManager'); - $this->globalStoragesService = $this->createMock('\OCA\Files_External\Service\GlobalStoragesService'); - $this->backendService = $this->createMock('\OCA\Files_External\Service\BackendService'); - $this->globalAuth = $this->createMock('\OCA\Files_External\Lib\Auth\Password\GlobalAuth'); + $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, diff --git a/apps/files_external/tests/Settings/SectionTest.php b/apps/files_external/tests/Settings/SectionTest.php index 9ab456fe30799..b5dfb28b382d5 100644 --- a/apps/files_external/tests/Settings/SectionTest.php +++ b/apps/files_external/tests/Settings/SectionTest.php @@ -35,7 +35,7 @@ class SectionTest extends TestCase { public function setUp() { parent::setUp(); - $this->l = $this->createMock('\OCP\IL10N'); + $this->l = $this->getMockBuilder('\OCP\IL10N')->disableOriginalConstructor()->getMock(); $this->section = new Section( $this->l diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php index ff42c6997a659..18c2064e8cec4 100644 --- a/apps/theming/tests/Settings/AdminTest.php +++ b/apps/theming/tests/Settings/AdminTest.php @@ -45,10 +45,10 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); - $this->l10n = $this->createMock('\OCP\IL10N'); - $this->themingDefaults = $this->createMock('\OCA\Theming\ThemingDefaults'); - $this->urlGenerator = $this->createMock('\OCP\IURLGenerator'); + $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, diff --git a/apps/theming/tests/Settings/SectionTest.php b/apps/theming/tests/Settings/SectionTest.php index e8a9a217f1ff9..3a3a4375236b2 100644 --- a/apps/theming/tests/Settings/SectionTest.php +++ b/apps/theming/tests/Settings/SectionTest.php @@ -35,7 +35,7 @@ class SectionTest extends TestCase { public function setUp() { parent::setUp(); - $this->l = $this->createMock('\OCP\IL10N'); + $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock(); $this->section = new Section( $this->l diff --git a/apps/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php index a4398715885dc..cf99679e680af 100644 --- a/apps/updatenotification/tests/Controller/AdminControllerTest.php +++ b/apps/updatenotification/tests/Controller/AdminControllerTest.php @@ -59,14 +59,14 @@ class AdminControllerTest extends TestCase { public function setUp() { parent::setUp(); - $this->request = $this->createMock('\\OCP\\IRequest'); - $this->jobList = $this->createMock('\\OCP\\BackgroundJob\\IJobList'); - $this->secureRandom = $this->createMock('\\OCP\\Security\\ISecureRandom'); - $this->config = $this->createMock('\\OCP\\IConfig'); - $this->timeFactory = $this->createMock('\\OCP\\AppFramework\\Utility\\ITimeFactory'); - $this->l10n = $this->createMock('\\OCP\\IL10N'); - $this->updateChecker = $this->createMock('\\OCA\\UpdateNotification\\UpdateChecker'); - $this->dateTimeFormatter = $this->createMock('\\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', diff --git a/apps/user_ldap/tests/Settings/AdminTest.php b/apps/user_ldap/tests/Settings/AdminTest.php index e92684f3ce47e..4ac5a14f58b42 100644 --- a/apps/user_ldap/tests/Settings/AdminTest.php +++ b/apps/user_ldap/tests/Settings/AdminTest.php @@ -43,7 +43,7 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->l10n = $this->createMock('\OCP\IL10N'); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); $this->admin = new Admin( $this->l10n diff --git a/apps/user_ldap/tests/Settings/SectionTest.php b/apps/user_ldap/tests/Settings/SectionTest.php index b5b1f97ce3cae..2d2165b8e56d2 100644 --- a/apps/user_ldap/tests/Settings/SectionTest.php +++ b/apps/user_ldap/tests/Settings/SectionTest.php @@ -35,7 +35,7 @@ class SectionTest extends TestCase { public function setUp() { parent::setUp(); - $this->l = $this->createMock('\OCP\IL10N'); + $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock(); $this->section = new Section( $this->l diff --git a/tests/Settings/Controller/AdminSettingsControllerTest.php b/tests/Settings/Controller/AdminSettingsControllerTest.php index 86950c9aa9db7..6c93bca0d680c 100644 --- a/tests/Settings/Controller/AdminSettingsControllerTest.php +++ b/tests/Settings/Controller/AdminSettingsControllerTest.php @@ -44,9 +44,9 @@ class AdminSettingsControllerTest extends TestCase { public function setUp() { parent::setUp(); - $this->request = $this->createMock('\OCP\IRequest'); - $this->navigationManager = $this->createMock('\OCP\INavigationManager'); - $this->settingsManager = $this->createMock('\OCP\Settings\IManager'); + $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', @@ -65,7 +65,7 @@ public function testIndex() { ->expects($this->once()) ->method('getAdminSettings') ->with('test') - ->willReturn([5 => new TipsTricks($this->createMock('\OCP\IConfig'))]); + ->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 63c8141cedd88..770d5a4934e8f 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -98,7 +98,7 @@ public function setUp() { })); $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') ->disableOriginalConstructor()->getMock(); - $this->logger = $this->createMock('\OCP\ILogger'); + $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') ->setConstructorArgs([ 'settings', diff --git a/tests/lib/Settings/Admin/AdditionalTest.php b/tests/lib/Settings/Admin/AdditionalTest.php index 178d7550614bb..3a99893cf7c56 100644 --- a/tests/lib/Settings/Admin/AdditionalTest.php +++ b/tests/lib/Settings/Admin/AdditionalTest.php @@ -36,7 +36,7 @@ class AdditionalTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); $this->admin = new Additional( $this->config diff --git a/tests/lib/Settings/Admin/EncryptionTest.php b/tests/lib/Settings/Admin/EncryptionTest.php index a68b40ae11b5d..f9763d85c1f63 100644 --- a/tests/lib/Settings/Admin/EncryptionTest.php +++ b/tests/lib/Settings/Admin/EncryptionTest.php @@ -39,8 +39,8 @@ class EncryptionTest extends TestCase { public function setUp() { parent::setUp(); - $this->manager = $this->createMock('\OC\Encryption\Manager'); - $this->userManager = $this->createMock('\OCP\IUserManager'); + $this->manager = $this->getMockBuilder('\OC\Encryption\Manager')->disableOriginalConstructor()->getMock(); + $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); $this->admin = new Encryption( $this->manager, diff --git a/tests/lib/Settings/Admin/LoggingTest.php b/tests/lib/Settings/Admin/LoggingTest.php index 10a94f1c59c34..181553d3894ab 100644 --- a/tests/lib/Settings/Admin/LoggingTest.php +++ b/tests/lib/Settings/Admin/LoggingTest.php @@ -37,7 +37,7 @@ class LoggingTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); $this->admin = new Logging( $this->config diff --git a/tests/lib/Settings/Admin/ServerTest.php b/tests/lib/Settings/Admin/ServerTest.php index 5a4fa22920f3b..874422307e073 100644 --- a/tests/lib/Settings/Admin/ServerTest.php +++ b/tests/lib/Settings/Admin/ServerTest.php @@ -46,10 +46,10 @@ class ServerTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); - $this->dbConnection = $this->createMock('\OCP\IDBConnection'); - $this->lockingProvider = $this->createMock('\OCP\Lock\ILockingProvider'); - $this->l10n = $this->createMock('\OCP\IL10N'); + $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, diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php index 7aec187d3723c..261e631363a4e 100644 --- a/tests/lib/Settings/Admin/SharingTest.php +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -36,7 +36,7 @@ class SharingTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); $this->admin = new Sharing( $this->config diff --git a/tests/lib/Settings/Admin/TipsTricksTest.php b/tests/lib/Settings/Admin/TipsTricksTest.php index afa053e833748..0e8857b56d0bc 100644 --- a/tests/lib/Settings/Admin/TipsTricksTest.php +++ b/tests/lib/Settings/Admin/TipsTricksTest.php @@ -36,7 +36,7 @@ class TipsTrickTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); $this->admin = new TipsTricks( $this->config diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 01e226225beb8..cd5100eff6d6b 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -56,13 +56,13 @@ class ManagerTest extends TestCase { public function setUp() { parent::setUp(); - $this->logger = $this->createMock('\OCP\ILogger'); - $this->dbConnection = $this->createMock('\OCP\IDBConnection'); - $this->l10n = $this->createMock('\OCP\IL10N'); - $this->config = $this->createMock('\OCP\IConfig'); - $this->encryptionManager = $this->createMock('\OCP\Encryption\IManager'); - $this->userManager = $this->createMock('\OCP\IUserManager'); - $this->lockingProvider = $this->createMock('\OCP\Lock\ILockingProvider'); + $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, @@ -76,7 +76,7 @@ public function setUp() { } public function testSetupSettings() { - $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); $qb ->expects($this->once()) ->method('select') @@ -91,12 +91,12 @@ public function testSetupSettings() { ->method('from') ->with('admin_settings') ->willReturn($qb); - $expressionBuilder = $this->createMock('\OCP\DB\QueryBuilder\IExpressionBuilder'); + $expressionBuilder = $this->getMockBuilder('\OCP\DB\QueryBuilder\IExpressionBuilder')->getMock(); $qb ->expects($this->once()) ->method('expr') ->willReturn($expressionBuilder); - $param = $this->createMock('\OCP\DB\QueryBuilder\IParameter'); + $param = $this->getMockBuilder('\OCP\DB\QueryBuilder\IParameter')->getMock(); $qb ->expects($this->once()) ->method('createNamedParameter') @@ -112,13 +112,13 @@ public function testSetupSettings() { ->method('where') ->with('myString') ->willReturn($qb); - $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement'); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); $qb ->expects($this->once()) ->method('execute') ->willReturn($stmt); - $qb1 = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb1 = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); $qb1 ->expects($this->once()) ->method('insert') @@ -135,7 +135,7 @@ public function testSetupSettings() { } public function testGetAdminSections() { - $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); $qb ->expects($this->once()) ->method('select') @@ -146,7 +146,7 @@ public function testGetAdminSections() { ->method('from') ->with('admin_sections') ->willReturn($qb); - $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement'); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); $qb ->expects($this->once()) ->method('execute') @@ -171,7 +171,7 @@ public function testGetAdminSections() { } public function testGetAdminSettings() { - $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); $qb ->expects($this->once()) ->method('select') @@ -182,12 +182,12 @@ public function testGetAdminSettings() { ->method('from') ->with('admin_settings') ->willReturn($qb); - $expressionBuilder = $this->createMock('\OCP\DB\QueryBuilder\IExpressionBuilder'); + $expressionBuilder = $this->getMockBuilder('\OCP\DB\QueryBuilder\IExpressionBuilder')->getMock(); $qb ->expects($this->once()) ->method('expr') ->willReturn($expressionBuilder); - $param = $this->createMock('\OCP\DB\QueryBuilder\IParameter'); + $param = $this->getMockBuilder('\OCP\DB\QueryBuilder\IParameter')->getMock(); $qb ->expects($this->once()) ->method('createParameter') @@ -203,7 +203,7 @@ public function testGetAdminSettings() { ->method('where') ->with('myString') ->willReturn($qb); - $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement'); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); $qb ->expects($this->once()) ->method('execute') From aa40b75f2def65b01b2980546c5a3e2ec4684ce6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 15 Aug 2016 20:03:19 +0200 Subject: [PATCH 36/43] attempt to remove section and settings entries when an app got disabled --- lib/base.php | 9 +++++++++ lib/private/Settings/Manager.php | 33 ++++++++++++++++++++++++++++++++ lib/public/Settings/IManager.php | 14 ++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/lib/base.php b/lib/base.php index 3457a74e98933..9e56bc09f01e5 100644 --- a/lib/base.php +++ b/lib/base.php @@ -725,6 +725,7 @@ public static function init() { self::registerLogRotate(); self::registerEncryptionWrapper(); self::registerEncryptionHooks(); + self::registerSettingsHooks(); //make sure temporary files are cleaned up $tmpManager = \OC::$server->getTempManager(); @@ -803,6 +804,14 @@ 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()); + }); + } + private static function registerEncryptionWrapper() { $manager = self::$server->getEncryptionManager(); \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 1304a60949e7a..8fdc7fefbb3ac 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -93,6 +93,25 @@ 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. + * + * @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]); + } + } + /** * @param string $sectionClassName */ @@ -222,6 +241,20 @@ private function has($table, $className) { 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); diff --git a/lib/public/Settings/IManager.php b/lib/public/Settings/IManager.php index 8aa7a9ac2488c..cba4efbd03709 100644 --- a/lib/public/Settings/IManager.php +++ b/lib/public/Settings/IManager.php @@ -50,6 +50,20 @@ interface IManager { */ 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); + /** * returns a list of the admin sections * From 03ce4bb37c4b7309ce82a7305fb28e400169a936 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 00:52:41 +0200 Subject: [PATCH 37/43] check registered sections and settings after an app got updated to garbage collect orphaned classes --- lib/base.php | 8 +++ lib/private/Settings/Manager.php | 31 +++++++++ lib/private/Settings/RemoveOrphaned.php | 91 +++++++++++++++++++++++++ lib/private/legacy/app.php | 5 ++ lib/public/App/ManagerEvent.php | 5 ++ lib/public/Settings/IManager.php | 15 ++++ 6 files changed, 155 insertions(+) create mode 100644 lib/private/Settings/RemoveOrphaned.php diff --git a/lib/base.php b/lib/base.php index 9e56bc09f01e5..a69a4dffef812 100644 --- a/lib/base.php +++ b/lib/base.php @@ -810,6 +810,14 @@ public static function registerSettingsHooks() { /** @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() { diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 8fdc7fefbb3ac..7574695d709fd 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -112,6 +112,37 @@ public function onAppDisabled($appId) { } } + 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 */ 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/legacy/app.php b/lib/private/legacy/app.php index c786a1fc53d40..ceb36449bf099 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 @@ -1237,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 index cba4efbd03709..a406915ad0900 100644 --- a/lib/public/Settings/IManager.php +++ b/lib/public/Settings/IManager.php @@ -64,6 +64,21 @@ public function setupSettings(array $settings); */ 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 * From 775c994f8ee60946cb8cfcaeb905ca00a486d407 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 00:53:32 +0200 Subject: [PATCH 38/43] adopt to Controller constructor changes --- settings/Application.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/settings/Application.php b/settings/Application.php index 09ca0807e6396..eceb2b6937c59 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -184,11 +184,6 @@ public function __construct(array $urlParams=[]){ $c->query('AppName'), $c->query('Request'), $c->query('INavigationManager'), - $c->query('L10N'), - $c->query('Config'), - $c->query('EncryptionManager'), - $c->query('UserManager'), - $c->query('DatabaseConnection'), $c->query('SettingsManager') ); }); From acddf9f3efc45b64e05d8427aaecf1169c8bd98e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 13:21:59 +0200 Subject: [PATCH 39/43] final db indexes --- db_structure.xml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/db_structure.xml b/db_structure.xml index b4c231a924838..77f6d7689863f 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -2008,13 +2008,22 @@ admin_sections_id_index - true + true id ascending + + admin_sections_class + true + + class + ascending + + + @@ -2060,13 +2069,31 @@ admin_settings_id_index - true + true id ascending + + admin_settings_class + true + + class + ascending + + + + + admin_settings_section + false + + section + ascending + + + From 3452ac8db30009ba6e024cba842d5c213e42eed8 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 17:59:21 +0200 Subject: [PATCH 40/43] fix missing parameters in sharing settings page --- lib/private/Settings/Admin/Sharing.php | 23 +++++++++++++++++------ settings/templates/admin/sharing.php | 2 -- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index e110a3d81b7bb..8d3ddc9b3b55a 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -23,9 +23,11 @@ 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 */ @@ -48,12 +50,21 @@ public function getForm() { $parameters = [ // Built-In Sharing - '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, + '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, ''); diff --git a/settings/templates/admin/sharing.php b/settings/templates/admin/sharing.php index c81f7e2ae1c6b..b8f8e92024627 100644 --- a/settings/templates/admin/sharing.php +++ b/settings/templates/admin/sharing.php @@ -104,6 +104,4 @@ />

    - -
    From f27de220b6ae6e0d22d7b589141e9dba840b7546 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 18:11:59 +0200 Subject: [PATCH 41/43] add missing encryption modules to settings --- lib/private/Settings/Admin/Encryption.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php index 69c6bd17f0313..6e93407f1a391 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -48,11 +48,24 @@ public function __construct(Manager $manager, IUserManager $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, ''); From 126ab0e4aef07e6e5902964541d9476c0a3ab560 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 18:26:16 +0200 Subject: [PATCH 42/43] for new we cannot have nested settings, default module is only appended if available --- apps/encryption/templates/settings-admin.php | 1 + settings/templates/admin/encryption.php | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) 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/settings/templates/admin/encryption.php b/settings/templates/admin/encryption.php index d4c3be8b2c870..4b6d9045689bc 100644 --- a/settings/templates/admin/encryption.php +++ b/settings/templates/admin/encryption.php @@ -72,8 +72,6 @@
    - -
    From a6b9aba245937c982dd917fbc3710b664862fd6e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 18:59:45 +0200 Subject: [PATCH 43/43] adjust tests to latest changes --- tests/lib/Settings/Admin/EncryptionTest.php | 10 ++ tests/lib/Settings/Admin/SharingTest.php | 128 +++++++++++++++++--- 2 files changed, 118 insertions(+), 20 deletions(-) diff --git a/tests/lib/Settings/Admin/EncryptionTest.php b/tests/lib/Settings/Admin/EncryptionTest.php index f9763d85c1f63..a282b059c921e 100644 --- a/tests/lib/Settings/Admin/EncryptionTest.php +++ b/tests/lib/Settings/Admin/EncryptionTest.php @@ -71,6 +71,10 @@ public function testGetFormWithOnlyOneBackend($enabled) { ->expects($this->once()) ->method('isReady') ->willReturn($enabled); + $this->manager + ->expects($this->once()) + ->method('getEncryptionModules') + ->willReturn([]); $this->userManager ->expects($this->once()) ->method('getBackends') @@ -82,6 +86,7 @@ public function testGetFormWithOnlyOneBackend($enabled) { 'encryptionEnabled' => $enabled, 'encryptionReady' => $enabled, 'externalBackendsEnabled' => false, + 'encryptionModules' => [] ], '' ); @@ -101,6 +106,10 @@ public function testGetFormWithMultipleBackends($enabled) { ->expects($this->once()) ->method('isReady') ->willReturn($enabled); + $this->manager + ->expects($this->once()) + ->method('getEncryptionModules') + ->willReturn([]); $this->userManager ->expects($this->once()) ->method('getBackends') @@ -112,6 +121,7 @@ public function testGetFormWithMultipleBackends($enabled) { 'encryptionEnabled' => $enabled, 'encryptionReady' => $enabled, 'externalBackendsEnabled' => true, + 'encryptionModules' => [] ], '' ); diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php index 261e631363a4e..38ab7614d1cc5 100644 --- a/tests/lib/Settings/Admin/SharingTest.php +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -52,25 +52,60 @@ public function testGetFormWithoutExcludedGroups() { $this->config ->expects($this->at(1)) ->method('getAppValue') - ->with('core', 'shareapi_enabled', 'yes') + ->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(3)) + ->expects($this->at(10)) ->method('getAppValue') ->with('core', 'shareapi_expire_after_n_days', '7') ->willReturn('7'); $this->config - ->expects($this->at(4)) + ->expects($this->at(11)) ->method('getAppValue') ->with('core', 'shareapi_enforce_expire_date', 'no') ->willReturn('no'); $this->config - ->expects($this->at(5)) + ->expects($this->at(12)) ->method('getAppValue') ->with('core', 'shareapi_exclude_groups', 'no') ->willReturn('no'); @@ -79,12 +114,21 @@ public function testGetFormWithoutExcludedGroups() { 'settings', 'admin/sharing', [ - 'shareAPIEnabled' => 'yes', - 'shareDefaultExpireDateSet' => 'no', - 'shareExpireAfterNDays' => '7', - 'shareEnforceExpireDate' => 'no', - 'shareExcludeGroups' => false, - 'shareExcludedGroupsList' => '', + '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' => '', ], '' ); @@ -101,25 +145,60 @@ public function testGetFormWithExcludedGroups() { $this->config ->expects($this->at(1)) ->method('getAppValue') - ->with('core', 'shareapi_enabled', 'yes') + ->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(3)) + ->expects($this->at(10)) ->method('getAppValue') ->with('core', 'shareapi_expire_after_n_days', '7') ->willReturn('7'); $this->config - ->expects($this->at(4)) + ->expects($this->at(11)) ->method('getAppValue') ->with('core', 'shareapi_enforce_expire_date', 'no') ->willReturn('no'); $this->config - ->expects($this->at(5)) + ->expects($this->at(12)) ->method('getAppValue') ->with('core', 'shareapi_exclude_groups', 'no') ->willReturn('yes'); @@ -128,12 +207,21 @@ public function testGetFormWithExcludedGroups() { 'settings', 'admin/sharing', [ - 'shareAPIEnabled' => 'yes', - 'shareDefaultExpireDateSet' => 'no', - 'shareExpireAfterNDays' => '7', - 'shareEnforceExpireDate' => 'no', - 'shareExcludeGroups' => true, - 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers', + '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', ], '' );