From ceeb44bd04f2606bea4c94107850157719127581 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 8 Aug 2016 23:31:26 +0200 Subject: 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 + settings/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 b0984dcf624..dac4f62879d 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 00000000000..11e2627dedd --- /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 00000000000..a10bd7cbb93 --- /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 46bad216822..735f83fedec 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 04c91ea494f..f6955be8e06 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 eed97e18d94..a4300785002 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -135,6 +135,7 @@ class Installer { } \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 d5808d7f17c..53c8ee84924 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -722,6 +722,17 @@ class Server extends ServerContainer implements IServerContainer { 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 @@ class Server extends ServerContainer implements IServerContainer { 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 00000000000..38197f71143 --- /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 00000000000..ead55810ec1 --- /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 00000000000..c0f3584c0af --- /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 00000000000..7fefa4008a0 --- /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 00000000000..a0465f5e3ca --- /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 00000000000..b7d02ddd340 --- /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 00000000000..2ea614b365e --- /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 5395d1daeee..39f2f1a0efe 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -471,7 +471,7 @@ class OC_App { $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 @@ class OC_App { 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 00000000000..ce52e3da725 --- /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 00000000000..ba0d9da59a3 --- /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 00000000000..7802c9b5d6c --- /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 00000000000..f1b772e1cde --- /dev/null +++ b/reset.php @@ -0,0 +1,5 @@ +setPassword('master', 'master'); diff --git a/settings/Application.php b/settings/Application.php index 6db5e2aabf6..09ca0807e63 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -32,6 +32,7 @@ namespace OC\Settings; 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 @@ class Application extends App { $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 @@ class Application extends App { $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 00000000000..68707addfe4 --- /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 13e7e443621..0441c507f34 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -290,7 +290,7 @@ class CheckSetupController extends Controller { 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 a458c813c11..00000000000 --- 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 94732b3192a..f77da543e10 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -64,6 +64,8 @@ $application->registerRoutes($this, [ ['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 @@ $this->create('settings_personal', '/settings/personal') ->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 74fe585962d..00000000000 --- 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 00000000000..d4c3be8b2c8 --- /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 00000000000..e0fee1555a3 --- /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 00000000000..2f60629c42a --- /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 00000000000..1bf068de392 --- /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 00000000000..c81f7e2ae1c --- /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 00000000000..e924a96dead --- /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'));?>

+ +
-- cgit v1.2.3 From 9d9c5405445f609120ef14fa320948444b40ef8b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 9 Aug 2016 22:43:29 +0200 Subject: 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 f6955be8e06..b4c231a9248 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -2059,7 +2059,7 @@ - admin_sections_id_index + admin_settings_id_index true id -- cgit v1.2.3 From 97df444d92fff2756572bf1901cd2ca112ea571e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 9 Aug 2016 22:47:05 +0200 Subject: 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 f1b772e1cde..00000000000 --- a/reset.php +++ /dev/null @@ -1,5 +0,0 @@ -setPassword('master', 'master'); -- cgit v1.2.3 From 518545fc2fc93f31d1885f143a0386c5449679f4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 9 Aug 2016 23:30:07 +0200 Subject: Fallback for legacy settings. They are placed into Additional Settings --- apps/user_ldap/settings.php | 75 ------------------------- settings/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 f20f873e134..00000000000 --- 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 68707addfe4..b6a6e74705f 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -83,6 +83,10 @@ class AdminSettingsController extends Controller { } private function getSettings($section) { + if($section === 'additional') { + return $this->getLegacyForms(); + } + $settings = $this->settingsManager->getAdminSettings($section); $html = ''; foreach ($settings as $prioritizedSettings) { @@ -95,6 +99,33 @@ class AdminSettingsController extends Controller { 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 00000000000..c4e70dbddb2 --- /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'));?>

+ +
+ +
-- cgit v1.2.3 From 1eb8b951c2eb6388efdd628c878110d78ae4e77d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 10 Aug 2016 15:21:25 +0200 Subject: 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 ++-- settings/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 81c7a8fb557..00000000000 --- 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 4070e90f221..2fe400a3587 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 ada04bdd68c..5f137120435 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -34,8 +34,9 @@ use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IRequest; use OCP\Security\ISecureRandom; +use OCP\Settings\IAdmin; -class AdminController extends Controller { +class AdminController extends Controller implements IAdmin { /** @var IJobList */ private $jobList; /** @var ISecureRandom */ @@ -144,4 +145,29 @@ class AdminController extends Controller { return new DataResponse($newToken); } + + /** + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered + */ + public function getForm() { + return $this->displayPanel(); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'server'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 5; + } } diff --git a/apps/user_ldap/appinfo/info.xml b/apps/user_ldap/appinfo/info.xml index dac4f62879d..b16824925c0 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 11e2627dedd..f155f1cec8d 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 @@ class Admin implements IAdmin { } /** - * @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 a1511071af4..eb4c7b99127 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -49,6 +49,9 @@ script('user_ldap', [ style('user_ldap', 'settings'); +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + ?>
@@ -56,20 +59,24 @@ style('user_ldap', 'settings');
- '.$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 66ca59d26e2..5ddfebc2c7f 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -124,6 +124,10 @@ class DIContainer extends SimpleContainer implements IAppContainer { 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 38197f71143..331ddf54520 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 @@ class Encryption implements IAdmin { } /** - * @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 @@ class Encryption implements IAdmin { '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 ead55810ec1..b05ea93388d 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 @@ class Logging implements IAdmin { } /** - * @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 @@ class Logging implements IAdmin { '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 c0f3584c0af..ee2da154da2 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -26,10 +26,10 @@ namespace OC\Settings\Admin; 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 @@ class Server implements IAdmin { } /** - * @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 @@ class Server implements IAdmin { '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 7fefa4008a0..088021f9057 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 @@ class Sharing implements IAdmin { } /** - * @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 @@ class Sharing implements IAdmin { '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 a0465f5e3ca..331c33db1c1 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 @@ class TipsTricks implements IAdmin { } /** - * @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 39f2f1a0efe..bba4f59555e 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -1200,6 +1200,7 @@ class OC_App { } 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 ce52e3da725..74977256a18 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 b6a6e74705f..f27bdd3ec33 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -92,8 +92,8 @@ class AdminSettingsController extends Controller { 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 e6298ae238f..7787884db7a 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'; -- cgit v1.2.3 From 0fc34c99f4e1dbe26e5074102f48f75d70fe97d0 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 00:45:15 +0200 Subject: 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 a4300785002..eed97e18d94 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -135,7 +135,6 @@ class Installer { } \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 bba4f59555e..802c4b908b4 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -1162,6 +1162,12 @@ class OC_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) ) { -- cgit v1.2.3 From f3b15a9ab97ce4498bafc731dc24350e98a7cb51 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 01:41:18 +0200 Subject: 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 83f4107384d..539f9f116d2 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 bba522fbc8c..a43646d86d9 100644 --- a/apps/encryption/lib/AppInfo/Application.php +++ b/apps/encryption/lib/AppInfo/Application.php @@ -269,7 +269,6 @@ class Application extends \OCP\AppFramework\App { public function registerSettings() { // Register settings scripts - App::registerAdmin('encryption', 'settings/settings-admin'); App::registerPersonal('encryption', 'settings/settings-personal'); } } diff --git a/apps/encryption/lib/Settings/Admin.php b/apps/encryption/lib/Settings/Admin.php new file mode 100644 index 00000000000..71a365caee1 --- /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 a424ea03874..00000000000 --- 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 b7d02ddd340..fa762003c1d 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -104,8 +104,10 @@ class Manager implements IManager { ); return; } - if(!$this->hasAdminSection($section)) { + if(!$this->hasAdminSection(get_class($section))) { $this->addAdminSection($section); + } else { + $this->updateAdminSection($section); } } @@ -134,20 +136,64 @@ class Manager implements IManager { $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 @@ class Manager implements IManager { } try { + /** @var IAdmin $settings */ $settings = $this->query($settingsClassName); } catch (QueryException $e) { // cancel @@ -177,8 +224,10 @@ class Manager implements IManager { ); 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 802c4b908b4..4144f3f6cf5 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -345,6 +345,12 @@ class OC_App { } 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']); + } } /** -- cgit v1.2.3 From 14ddf9d923ba78a9b938d6eb6050d71aaef22ed6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 14:48:21 +0200 Subject: 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 ++++----- lib/public/Settings/IAdmin.php | 48 -------------------- lib/public/Settings/ISettings.php | 51 ++++++++++++++++++++++ settings/Controller/AdminSettingsController.php | 2 +- 12 files changed, 78 insertions(+), 75 deletions(-) delete mode 100644 lib/public/Settings/IAdmin.php create mode 100644 lib/public/Settings/ISettings.php diff --git a/apps/encryption/lib/Settings/Admin.php b/apps/encryption/lib/Settings/Admin.php index 71a365caee1..2faa118e2a2 100644 --- a/apps/encryption/lib/Settings/Admin.php +++ b/apps/encryption/lib/Settings/Admin.php @@ -33,10 +33,10 @@ use OCP\ILogger; 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 5f137120435..3c6ab463059 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -34,9 +34,9 @@ use OCP\IDateTimeFormatter; 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 f155f1cec8d..606cfe6cf01 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\Configuration; 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 331ddf54520..ceae5aa6d3f 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -26,9 +26,9 @@ namespace OC\Settings\Admin; 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 b05ea93388d..3097070577d 100644 --- a/lib/private/Settings/Admin/Logging.php +++ b/lib/private/Settings/Admin/Logging.php @@ -26,9 +26,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\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 ee2da154da2..4f1edcf4691 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -29,9 +29,9 @@ use Doctrine\DBAL\Platforms\SqlitePlatform; 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 088021f9057..d186dbed981 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -25,9 +25,9 @@ namespace OC\Settings\Admin; 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 331c33db1c1..217ddacd443 100644 --- a/lib/private/Settings/Admin/TipsTricks.php +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -25,9 +25,9 @@ namespace OC\Settings\Admin; 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 fa762003c1d..4c96dd07fde 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -30,7 +30,7 @@ use OCP\IDBConnection; 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 @@ class Manager implements IManager { ]); } - 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 @@ class Manager implements IManager { $query->execute(); } - private function updateAdminSettings(IAdmin $settings) { + private function updateAdminSettings(ISettings $settings) { $this->update( self::TABLE_ADMIN_SETTINGS, 'class', @@ -210,14 +210,14 @@ class Manager implements IManager { } 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 @@ class Manager implements IManager { $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/IAdmin.php deleted file mode 100644 index 74977256a18..00000000000 --- a/lib/public/Settings/IAdmin.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * @author Arthur Schiwon - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -namespace OCP\Settings; - -use OCP\AppFramework\Http\TemplateResponse; - -interface IAdmin { - - /** - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered - */ - public function getForm(); - - /** - * @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/ISettings.php b/lib/public/Settings/ISettings.php new file mode 100644 index 00000000000..07d265a533e --- /dev/null +++ b/lib/public/Settings/ISettings.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; + +use OCP\AppFramework\Http\TemplateResponse; + +interface ISettings { + + /** + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered + * @since 9.1 + */ + public function getForm(); + + /** + * @return string the section ID, e.g. 'sharing' + * @since 9.1 + */ + public function getSection(); + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + * @since 9.1 + */ + public function getPriority(); +} diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index f27bdd3ec33..271aa05265b 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -91,7 +91,7 @@ class AdminSettingsController extends Controller { $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(); } -- cgit v1.2.3 From 5696c8aa3515b6283575cb3f887a1107b368bf2c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 15:13:40 +0200 Subject: adjust federatedfilesharing --- apps/federatedfilesharing/appinfo/info.xml | 5 +- .../lib/AppInfo/Application.php | 1 - apps/federatedfilesharing/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 2a80bd54da3..984235f0851 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 b4ddc6cfe04..b767a322505 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -40,7 +40,6 @@ class Application extends App { * register personal and admin settings page */ public function registerSettings() { - \OCP\App::registerAdmin('federatedfilesharing', 'settings-admin'); \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); } diff --git a/apps/federatedfilesharing/lib/Settings/Admin.php b/apps/federatedfilesharing/lib/Settings/Admin.php new file mode 100644 index 00000000000..64619e329f3 --- /dev/null +++ b/apps/federatedfilesharing/lib/Settings/Admin.php @@ -0,0 +1,69 @@ + + * + * @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 5ccd223b0a3..00000000000 --- 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 5d2eb04c170..aa2f551e18d 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: adjust files_external --- apps/files_external/appinfo/info.xml | 7 +- apps/files_external/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 43f06d60843..e4433880d3a 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 a32a3a26c7f..06c163419f0 100644 --- a/apps/files_external/lib/AppInfo/Application.php +++ b/apps/files_external/lib/AppInfo/Application.php @@ -68,10 +68,6 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide * Register settings templates */ public function registerSettings() { - $container = $this->getContainer(); - $backendService = $container->query('OCA\\Files_External\\Service\\BackendService'); - - \OCP\App::registerAdmin('files_external', 'settings'); \OCP\App::registerPersonal('files_external', 'personal'); } diff --git a/apps/files_external/lib/Settings/Admin.php b/apps/files_external/lib/Settings/Admin.php new file mode 100644 index 00000000000..eebfd712874 --- /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 00000000000..850b04251a6 --- /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 cb9ee5ccde0..00000000000 --- 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 5ddfebc2c7f..4e3cac6d1ea 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -310,6 +310,24 @@ class DIContainer extends SimpleContainer implements IAppContainer { 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 -- cgit v1.2.3 From ce6ad5de25795e49564f3d4b53f52e13e1a52fc7 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 16:37:11 +0200 Subject: 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 eed97e18d94..1c45679cd32 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -593,6 +593,11 @@ class Installer { 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']; } -- cgit v1.2.3 From e8ea67139b8ba1b485716ffbae4cbd4d56f9924e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 16:42:37 +0200 Subject: 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 0f49d2525e5..f5bcf345669 100644 --- a/apps/updatenotification/appinfo/app.php +++ b/apps/updatenotification/appinfo/app.php @@ -38,7 +38,6 @@ if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) { \OCP\Util::addScript('updatenotification', 'notification'); OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'getJavaScript'); } - \OC_App::registerAdmin('updatenotification', 'admin'); } } -- cgit v1.2.3 From 36c1b7eb310bb072bbed7303d51b74794b330f57 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 17:29:58 +0200 Subject: 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 5ef506e5acd..fc64c2452ba 100644 --- a/apps/theming/appinfo/app.php +++ b/apps/theming/appinfo/app.php @@ -23,8 +23,6 @@ * */ -\OCP\App::registerAdmin('theming', 'settings/settings-admin'); - $linkToCSS = \OC::$server->getURLGenerator()->linkToRoute( 'theming.Theming.getStylesheet', [ diff --git a/apps/theming/appinfo/info.xml b/apps/theming/appinfo/info.xml index 8ae1d3eb73a..423d11d2aef 100644 --- a/apps/theming/appinfo/info.xml +++ b/apps/theming/appinfo/info.xml @@ -5,7 +5,7 @@ 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 00000000000..07dfe75ec60 --- /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 00000000000..cffbb8901c8 --- /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 8ef499789e8..00000000000 --- 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 4c96dd07fde..01beb47879b 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -255,7 +255,6 @@ class Manager implements IManager { 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)], -- cgit v1.2.3 From 30ff3ad45b8eeb09e3c96386d51474c6f74cde34 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 18:39:16 +0200 Subject: 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 ++++++++++++++++++++++++++++ apps/files/lib/Settings/Section.php | 67 ++++++++++++++++++++ apps/files_external/appinfo/info.xml | 3 +- apps/files_external/lib/Settings/Admin.php | 4 +- apps/files_external/lib/Settings/Section.php | 67 -------------------- 8 files changed, 169 insertions(+), 125 deletions(-) delete mode 100644 apps/files/admin.php create mode 100644 apps/files/lib/Settings/Admin.php create mode 100644 apps/files/lib/Settings/Section.php delete mode 100644 apps/files_external/lib/Settings/Section.php diff --git a/apps/files/admin.php b/apps/files/admin.php deleted file mode 100644 index ad7b16a3a23..00000000000 --- a/apps/files/admin.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @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 850c335c27d..afb327e24ba 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -26,8 +26,6 @@ * along with this program. If not, see * */ -\OCP\App::registerAdmin('files', 'admin'); - $l = \OC::$server->getL10N('files'); \OC::$server->getNavigationManager()->add(function () { diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml index 8b26a6af711..c1666af6348 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 00000000000..d0a691ffe66 --- /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/lib/Settings/Section.php b/apps/files/lib/Settings/Section.php new file mode 100644 index 00000000000..2323870cf97 --- /dev/null +++ b/apps/files/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\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 'files'; + } + + /** + * 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('Files & Storages'); + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the settings navigation. The sections are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + * + * E.g.: 70 + */ + public function getPriority() { + return 10; + } +} diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index e4433880d3a..cd52c39b30e 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 eebfd712874..102680d0341 100644 --- a/apps/files_external/lib/Settings/Admin.php +++ b/apps/files_external/lib/Settings/Admin.php @@ -79,7 +79,7 @@ class Admin implements ISettings { * @return string the section ID, e.g. 'sharing' */ public function getSection() { - return 'externalstorage'; + return 'files'; } /** @@ -90,7 +90,7 @@ class Admin implements ISettings { * E.g.: 70 */ public function getPriority() { - return 5; + return 40; } } diff --git a/apps/files_external/lib/Settings/Section.php b/apps/files_external/lib/Settings/Section.php deleted file mode 100644 index 850b04251a6..00000000000 --- a/apps/files_external/lib/Settings/Section.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * @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; - } -} -- cgit v1.2.3 From c0a2a1ff64633bc2a15e4f2fa28b57f708616255 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 18:40:19 +0200 Subject: 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 10cc003a3f5..caacbea5619 100644 --- a/apps/user_ldap/appinfo/app.php +++ b/apps/user_ldap/appinfo/app.php @@ -27,8 +27,6 @@ * */ -OCP\App::registerAdmin('user_ldap', 'settings'); - $helper = new \OCA\User_LDAP\Helper(); $configPrefixes = $helper->getServerConfigurationPrefixes(true); $ldapWrapper = new OCA\User_LDAP\LDAP(); -- cgit v1.2.3 From 3f9e1b3b45aa7a9c588e3023aeb9f99b28f714cf Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 18:53:45 +0200 Subject: 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 92b64b9c058..6c53810dd2c 100644 --- a/apps/federation/appinfo/app.php +++ b/apps/federation/appinfo/app.php @@ -23,5 +23,4 @@ namespace OCA\Federation\AppInfo; $app = new Application(); -$app->registerSettings(); $app->registerHooks(); diff --git a/apps/federation/appinfo/info.xml b/apps/federation/appinfo/info.xml index b8d697a4db2..da65fef2446 100644 --- a/apps/federation/appinfo/info.xml +++ b/apps/federation/appinfo/info.xml @@ -5,7 +5,7 @@ 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 5d8da05c8e1..cdc6145dfb4 100644 --- a/apps/federation/lib/AppInfo/Application.php +++ b/apps/federation/lib/AppInfo/Application.php @@ -51,13 +51,6 @@ class Application extends \OCP\AppFramework\App { $this->registerMiddleware(); } - /** - * register setting scripts - */ - public function registerSettings() { - App::registerAdmin('federation', 'settings/settings-admin'); - } - private function registerService() { $container = $this->getContainer(); diff --git a/apps/federation/lib/Settings/Admin.php b/apps/federation/lib/Settings/Admin.php new file mode 100644 index 00000000000..eccb3237f7d --- /dev/null +++ b/apps/federation/lib/Settings/Admin.php @@ -0,0 +1,69 @@ + + * + * @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 aa21a1e9920..00000000000 --- 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(); -- cgit v1.2.3 From 3dfdc8e3117e9284e93631b73859e588fdfd0875 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 19:03:43 +0200 Subject: 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 45ea577e8ab..00000000000 --- 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 5a365c4ef15..af91e5fdbcd 100644 --- a/apps/systemtags/appinfo/app.php +++ b/apps/systemtags/appinfo/app.php @@ -78,9 +78,6 @@ $mapperListener = function(MapperEvent $event) use ($activityManager) { $eventDispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener); $eventDispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); -$app = new \OCA\SystemTags\AppInfo\Application(); -$app->registerAdminPage(); - $l = \OC::$server->getL10N('systemtags'); \OCA\Files\App::getNavigationManager()->add( diff --git a/apps/systemtags/appinfo/info.xml b/apps/systemtags/appinfo/info.xml index 5eced10b710..46bb9278838 100644 --- a/apps/systemtags/appinfo/info.xml +++ b/apps/systemtags/appinfo/info.xml @@ -7,7 +7,7 @@ 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 7cd49d6424b..00000000000 --- 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 00000000000..351c2264397 --- /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 01beb47879b..769ef71e955 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -254,7 +254,7 @@ class Manager implements IManager { $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)], -- cgit v1.2.3 From 8f12f5df15158a463ac2d0e2b7350ad3ca871a1d Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 11 Aug 2016 19:28:24 +0200 Subject: 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 ba0d9da59a3..c0170c43bb8 100644 --- a/lib/public/Settings/IManager.php +++ b/lib/public/Settings/IManager.php @@ -52,6 +52,7 @@ interface IManager { * 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 @@ interface IManager { * * @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 7802c9b5d6c..2905b087c32 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 @@ interface ISection { * integration'. Use the L10N service to translate it. * * @return string + * @since 9.1 */ public function getName(); @@ -46,6 +48,7 @@ interface ISection { * the priority values. It is required to return a value between 0 and 99. * * E.g.: 70 + * @since 9.1 */ public function getPriority(); } -- cgit v1.2.3 From 225eb27bcac1e710a4aba723483745bb3677460f Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 11 Aug 2016 19:33:37 +0200 Subject: 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 c0170c43bb8..8aa7a9ac248 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 2905b087c32..5edf5de0ca4 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 07d265a533e..611bb713b33 100644 --- a/lib/public/Settings/ISettings.php +++ b/lib/public/Settings/ISettings.php @@ -25,6 +25,9 @@ namespace OCP\Settings; use OCP\AppFramework\Http\TemplateResponse; +/** + * @since 9.1 + */ interface ISettings { /** -- cgit v1.2.3 From 82bf4796f9eafab5d6353f16b2b29b5f60dc34e4 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 11 Aug 2016 19:39:32 +0200 Subject: 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 1bf068de392..43df787d519 100644 --- a/settings/templates/admin/server.php +++ b/settings/templates/admin/server.php @@ -38,14 +38,14 @@ $mail_smtpsecure = [ ]; $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 @@ if ($_['mail_smtpmode'] == 'qmail') { -- cgit v1.2.3 From ac04ba6784ca2f0f19649bf726545525c493e493 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 13:23:14 +0200 Subject: 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 351c2264397..ed72e17cf50 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 1c45679cd32..3d8a923417a 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -594,7 +594,8 @@ class Installer { 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 df76c5b89f0..c786a1fc53d 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -348,7 +348,8 @@ class OC_App { $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 @@ class OC_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 @@ class OC_App { } 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']); } -- cgit v1.2.3 From 18fd8ff70cb00a886b86dd8e540f40be1ee4d735 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 12 Aug 2016 15:30:35 +0200 Subject: rename "Tenmplate" to "ThemingDefaults" to make the auto loader happy" --- apps/theming/lib/Settings/Admin.php | 4 +- apps/theming/lib/Template.php | 171 ------------- apps/theming/lib/ThemingDefaults.php | 166 +++++++++++++ apps/theming/tests/TemplateTest.php | 371 ---------------------------- apps/theming/tests/ThemingDefaultsTest.php | 372 +++++++++++++++++++++++++++++ lib/private/Server.php | 4 +- 6 files changed, 542 insertions(+), 546 deletions(-) delete mode 100644 apps/theming/lib/Template.php create mode 100644 apps/theming/lib/ThemingDefaults.php delete mode 100644 apps/theming/tests/TemplateTest.php create mode 100644 apps/theming/tests/ThemingDefaultsTest.php diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index 07dfe75ec60..03356c11383 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/Template.php deleted file mode 100644 index 25730aad95b..00000000000 --- a/apps/theming/lib/Template.php +++ /dev/null @@ -1,171 +0,0 @@ - - * @copyright Copyright (c) 2016 Lukas Reschke - * - * @author Bjoern Schiessle - * @author Joas Schilling - * @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; - -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 { - /** @var IConfig */ - private $config; - /** @var IL10N */ - private $l; - /** @var IURLGenerator */ - private $urlGenerator; - /** @var string */ - private $name; - /** @var string */ - private $url; - /** @var string */ - private $slogan; - /** @var string */ - private $color; - - /** - * Template constructor. - * - * @param IConfig $config - * @param IL10N $l - * @param IURLGenerator $urlGenerator - * @param \OC_Defaults $defaults - */ - public function __construct(IConfig $config, - IL10N $l, - IURLGenerator $urlGenerator, - \OC_Defaults $defaults - ) { - parent::__construct(); - $this->config = $config; - $this->l = $l; - $this->urlGenerator = $urlGenerator; - - $this->name = $defaults->getName(); - $this->url = $defaults->getBaseUrl(); - $this->slogan = $defaults->getSlogan(); - $this->color = $defaults->getMailHeaderColor(); - } - - public function getName() { - return $this->config->getAppValue('theming', 'name', $this->name); - } - - public function getHTMLName() { - return $this->config->getAppValue('theming', 'name', $this->name); - } - - public function getTitle() { - return $this->config->getAppValue('theming', 'name', $this->name); - } - - public function getEntity() { - return $this->config->getAppValue('theming', 'name', $this->name); - } - - public function getBaseUrl() { - return $this->config->getAppValue('theming', 'url', $this->url); - } - - public function getSlogan() { - return $this->config->getAppValue('theming', 'slogan', $this->slogan); - } - - public function getShortFooter() { - $slogan = $this->getSlogan(); - $footer = '' .$this->getEntity() . ''. - ($slogan !== '' ? ' – ' . $slogan : ''); - - return $footer; - } - - /** - * Color that is used for the header as well as for mail headers - * - * @return string - */ - public function getMailHeaderColor() { - return $this->config->getAppValue('theming', 'color', $this->color); - } - - /** - * Increases the cache buster key - */ - private function increaseCacheBuster() { - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); - } - - /** - * Update setting in the database - * - * @param string $setting - * @param string $value - */ - public function set($setting, $value) { - $this->config->setAppValue('theming', $setting, $value); - $this->increaseCacheBuster(); - } - - /** - * Revert settings to the default value - * - * @param string $setting setting which should be reverted - * @return string default value - */ - public function undo($setting) { - $this->config->deleteAppValue('theming', $setting); - $this->increaseCacheBuster(); - - switch ($setting) { - case 'name': - $returnValue = $this->getEntity(); - break; - case 'url': - $returnValue = $this->getBaseUrl(); - break; - case 'slogan': - $returnValue = $this->getSlogan(); - break; - case 'color': - $returnValue = $this->getMailHeaderColor(); - break; - default: - $returnValue = ''; - break; - } - - return $returnValue; - } -} diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php new file mode 100644 index 00000000000..a7af208b96d --- /dev/null +++ b/apps/theming/lib/ThemingDefaults.php @@ -0,0 +1,166 @@ + + * + * @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; + + + + +use OCP\IConfig; +use OCP\IL10N; +use OCP\IURLGenerator; + + +class ThemingDefaults extends \OC_Defaults { + + /** @var IConfig */ + private $config; + /** @var IL10N */ + private $l; + /** @var IURLGenerator */ + private $urlGenerator; + /** @var string */ + private $name; + /** @var string */ + private $url; + /** @var string */ + private $slogan; + /** @var string */ + private $color; + + /** + * Template constructor. + * + * @param IConfig $config + * @param IL10N $l + * @param IURLGenerator $urlGenerator + * @param \OC_Defaults $defaults + */ + public function __construct(IConfig $config, + IL10N $l, + IURLGenerator $urlGenerator, + \OC_Defaults $defaults + ) { + parent::__construct(); + $this->config = $config; + $this->l = $l; + $this->urlGenerator = $urlGenerator; + + $this->name = $defaults->getName(); + $this->url = $defaults->getBaseUrl(); + $this->slogan = $defaults->getSlogan(); + $this->color = $defaults->getMailHeaderColor(); + } + + public function getName() { + return $this->config->getAppValue('theming', 'name', $this->name); + } + + public function getHTMLName() { + return $this->config->getAppValue('theming', 'name', $this->name); + } + + public function getTitle() { + return $this->config->getAppValue('theming', 'name', $this->name); + } + + public function getEntity() { + return $this->config->getAppValue('theming', 'name', $this->name); + } + + public function getBaseUrl() { + return $this->config->getAppValue('theming', 'url', $this->url); + } + + public function getSlogan() { + return $this->config->getAppValue('theming', 'slogan', $this->slogan); + } + + public function getShortFooter() { + $slogan = $this->getSlogan(); + $footer = '' .$this->getEntity() . ''. + ($slogan !== '' ? ' – ' . $slogan : ''); + + return $footer; + } + + /** + * Color that is used for the header as well as for mail headers + * + * @return string + */ + public function getMailHeaderColor() { + return $this->config->getAppValue('theming', 'color', $this->color); + } + + /** + * Increases the cache buster key + */ + private function increaseCacheBuster() { + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); + } + + /** + * Update setting in the database + * + * @param string $setting + * @param string $value + */ + public function set($setting, $value) { + $this->config->setAppValue('theming', $setting, $value); + $this->increaseCacheBuster(); + } + + /** + * Revert settings to the default value + * + * @param string $setting setting which should be reverted + * @return string default value + */ + public function undo($setting) { + $this->config->deleteAppValue('theming', $setting); + $this->increaseCacheBuster(); + + switch ($setting) { + case 'name': + $returnValue = $this->getEntity(); + break; + case 'url': + $returnValue = $this->getBaseUrl(); + break; + case 'slogan': + $returnValue = $this->getSlogan(); + break; + case 'color': + $returnValue = $this->getMailHeaderColor(); + break; + default: + $returnValue = ''; + break; + } + + return $returnValue; + } + +} diff --git a/apps/theming/tests/TemplateTest.php b/apps/theming/tests/TemplateTest.php deleted file mode 100644 index c3c792657ec..00000000000 --- a/apps/theming/tests/TemplateTest.php +++ /dev/null @@ -1,371 +0,0 @@ - - * - * @author Joas Schilling - * @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; - -use OCA\Theming\Template; -use OCP\IConfig; -use OCP\IL10N; -use OCP\IURLGenerator; -use Test\TestCase; - -class TemplateTest extends TestCase { - /** @var IConfig */ - private $config; - /** @var IL10N */ - private $l10n; - /** @var IURLGenerator */ - private $urlGenerator; - /** @var \OC_Defaults */ - private $defaults; - /** @var Template */ - private $template; - - public function setUp() { - $this->config = $this->getMock('\\OCP\\IConfig'); - $this->l10n = $this->getMock('\\OCP\\IL10N'); - $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator'); - $this->defaults = $this->getMockBuilder('\\OC_Defaults') - ->disableOriginalConstructor() - ->getMock(); - $this->defaults - ->expects($this->at(0)) - ->method('getName') - ->willReturn('Nextcloud'); - $this->defaults - ->expects($this->at(1)) - ->method('getBaseUrl') - ->willReturn('https://nextcloud.com/'); - $this->defaults - ->expects($this->at(2)) - ->method('getSlogan') - ->willReturn('Safe Data'); - $this->defaults - ->expects($this->at(3)) - ->method('getMailHeaderColor') - ->willReturn('#000'); - $this->template = new Template( - $this->config, - $this->l10n, - $this->urlGenerator, - $this->defaults - ); - - return parent::setUp(); - } - - public function testGetNameWithDefault() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('Nextcloud'); - - $this->assertEquals('Nextcloud', $this->template->getName()); - } - - public function testGetNameWithCustom() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('MyCustomCloud'); - - $this->assertEquals('MyCustomCloud', $this->template->getName()); - } - - public function testGetHTMLNameWithDefault() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('Nextcloud'); - - $this->assertEquals('Nextcloud', $this->template->getHTMLName()); - } - - public function testGetHTMLNameWithCustom() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('MyCustomCloud'); - - $this->assertEquals('MyCustomCloud', $this->template->getHTMLName()); - } - - public function testGetTitleWithDefault() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('Nextcloud'); - - $this->assertEquals('Nextcloud', $this->template->getTitle()); - } - - public function testGetTitleWithCustom() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('MyCustomCloud'); - - $this->assertEquals('MyCustomCloud', $this->template->getTitle()); - } - - - public function testGetEntityWithDefault() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('Nextcloud'); - - $this->assertEquals('Nextcloud', $this->template->getEntity()); - } - - public function testGetEntityWithCustom() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('MyCustomCloud'); - - $this->assertEquals('MyCustomCloud', $this->template->getEntity()); - } - - public function testGetBaseUrlWithDefault() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'url', 'https://nextcloud.com/') - ->willReturn('https://nextcloud.com/'); - - $this->assertEquals('https://nextcloud.com/', $this->template->getBaseUrl()); - } - - public function testGetBaseUrlWithCustom() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'url', 'https://nextcloud.com/') - ->willReturn('https://example.com/'); - - $this->assertEquals('https://example.com/', $this->template->getBaseUrl()); - } - - public function testGetSloganWithDefault() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'slogan', 'Safe Data') - ->willReturn('Safe Data'); - - $this->assertEquals('Safe Data', $this->template->getSlogan()); - } - - public function testGetSloganWithCustom() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'slogan', 'Safe Data') - ->willReturn('My custom Slogan'); - - $this->assertEquals('My custom Slogan', $this->template->getSlogan()); - } - - public function testGetShortFooter() { - $this->config - ->expects($this->exactly(3)) - ->method('getAppValue') - ->willReturnMap([ - ['theming', 'url', 'https://nextcloud.com/', 'url'], - ['theming', 'name', 'Nextcloud', 'Name'], - ['theming', 'slogan', 'Safe Data', 'Slogan'], - ]); - - $this->assertEquals('Name – Slogan', $this->template->getShortFooter()); - } - - public function testGetShortFooterEmptySlogan() { - $this->config - ->expects($this->exactly(3)) - ->method('getAppValue') - ->willReturnMap([ - ['theming', 'url', 'https://nextcloud.com/', 'url'], - ['theming', 'name', 'Nextcloud', 'Name'], - ['theming', 'slogan', 'Safe Data', ''], - ]); - - $this->assertEquals('Name', $this->template->getShortFooter()); - } - - public function testGetMailHeaderColorWithDefault() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'color', '#000') - ->willReturn('#000'); - - $this->assertEquals('#000', $this->template->getMailHeaderColor()); - } - - public function testGetMailHeaderColorWithCustom() { - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('theming', 'color', '#000') - ->willReturn('#fff'); - - $this->assertEquals('#fff', $this->template->getMailHeaderColor()); - } - - public function testSet() { - $this->config - ->expects($this->at(0)) - ->method('setAppValue') - ->with('theming', 'MySetting', 'MyValue'); - $this->config - ->expects($this->at(1)) - ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('theming', 'cachebuster', 16); - - $this->template->set('MySetting', 'MyValue'); - } - - public function testUndoName() { - $this->config - ->expects($this->at(0)) - ->method('deleteAppValue') - ->with('theming', 'name'); - $this->config - ->expects($this->at(1)) - ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('theming', 'cachebuster', 16); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('Nextcloud'); - - $this->assertSame('Nextcloud', $this->template->undo('name')); - } - - public function testUndoBaseUrl() { - $this->config - ->expects($this->at(0)) - ->method('deleteAppValue') - ->with('theming', 'url'); - $this->config - ->expects($this->at(1)) - ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('theming', 'cachebuster', 16); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('theming', 'url', 'https://nextcloud.com/') - ->willReturn('https://nextcloud.com/'); - - $this->assertSame('https://nextcloud.com/', $this->template->undo('url')); - } - - public function testUndoSlogan() { - $this->config - ->expects($this->at(0)) - ->method('deleteAppValue') - ->with('theming', 'slogan'); - $this->config - ->expects($this->at(1)) - ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('theming', 'cachebuster', 16); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('theming', 'slogan', 'Safe Data') - ->willReturn('Safe Data'); - - $this->assertSame('Safe Data', $this->template->undo('slogan')); - } - - public function testUndoColor() { - $this->config - ->expects($this->at(0)) - ->method('deleteAppValue') - ->with('theming', 'color'); - $this->config - ->expects($this->at(1)) - ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('theming', 'cachebuster', 16); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('theming', 'color', '#000') - ->willReturn('#000'); - - $this->assertSame('#000', $this->template->undo('color')); - } - - public function testUndoDefaultAction() { - $this->config - ->expects($this->at(0)) - ->method('deleteAppValue') - ->with('theming', 'defaultitem'); - $this->config - ->expects($this->at(1)) - ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('theming', 'cachebuster', 16); - - $this->assertSame('', $this->template->undo('defaultitem')); - } -} diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php new file mode 100644 index 00000000000..34402825316 --- /dev/null +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -0,0 +1,372 @@ + + * + * @author Joas Schilling + * @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; + +use OCA\Theming\Template; +use OCA\Theming\ThemingDefaults; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IURLGenerator; +use Test\TestCase; + +class ThemingDefaultsTest extends TestCase { + /** @var IConfig */ + private $config; + /** @var IL10N */ + private $l10n; + /** @var IURLGenerator */ + private $urlGenerator; + /** @var \OC_Defaults */ + private $defaults; + /** @var Template */ + private $template; + + public function setUp() { + $this->config = $this->getMock('\\OCP\\IConfig'); + $this->l10n = $this->getMock('\\OCP\\IL10N'); + $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator'); + $this->defaults = $this->getMockBuilder('\\OC_Defaults') + ->disableOriginalConstructor() + ->getMock(); + $this->defaults + ->expects($this->at(0)) + ->method('getName') + ->willReturn('Nextcloud'); + $this->defaults + ->expects($this->at(1)) + ->method('getBaseUrl') + ->willReturn('https://nextcloud.com/'); + $this->defaults + ->expects($this->at(2)) + ->method('getSlogan') + ->willReturn('Safe Data'); + $this->defaults + ->expects($this->at(3)) + ->method('getMailHeaderColor') + ->willReturn('#000'); + $this->template = new ThemingDefaults( + $this->config, + $this->l10n, + $this->urlGenerator, + $this->defaults + ); + + return parent::setUp(); + } + + public function testGetNameWithDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('Nextcloud'); + + $this->assertEquals('Nextcloud', $this->template->getName()); + } + + public function testGetNameWithCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('MyCustomCloud'); + + $this->assertEquals('MyCustomCloud', $this->template->getName()); + } + + public function testGetHTMLNameWithDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('Nextcloud'); + + $this->assertEquals('Nextcloud', $this->template->getHTMLName()); + } + + public function testGetHTMLNameWithCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('MyCustomCloud'); + + $this->assertEquals('MyCustomCloud', $this->template->getHTMLName()); + } + + public function testGetTitleWithDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('Nextcloud'); + + $this->assertEquals('Nextcloud', $this->template->getTitle()); + } + + public function testGetTitleWithCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('MyCustomCloud'); + + $this->assertEquals('MyCustomCloud', $this->template->getTitle()); + } + + + public function testGetEntityWithDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('Nextcloud'); + + $this->assertEquals('Nextcloud', $this->template->getEntity()); + } + + public function testGetEntityWithCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('MyCustomCloud'); + + $this->assertEquals('MyCustomCloud', $this->template->getEntity()); + } + + public function testGetBaseUrlWithDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'url', 'https://nextcloud.com/') + ->willReturn('https://nextcloud.com/'); + + $this->assertEquals('https://nextcloud.com/', $this->template->getBaseUrl()); + } + + public function testGetBaseUrlWithCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'url', 'https://nextcloud.com/') + ->willReturn('https://example.com/'); + + $this->assertEquals('https://example.com/', $this->template->getBaseUrl()); + } + + public function testGetSloganWithDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'slogan', 'Safe Data') + ->willReturn('Safe Data'); + + $this->assertEquals('Safe Data', $this->template->getSlogan()); + } + + public function testGetSloganWithCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'slogan', 'Safe Data') + ->willReturn('My custom Slogan'); + + $this->assertEquals('My custom Slogan', $this->template->getSlogan()); + } + + public function testGetShortFooter() { + $this->config + ->expects($this->exactly(3)) + ->method('getAppValue') + ->willReturnMap([ + ['theming', 'url', 'https://nextcloud.com/', 'url'], + ['theming', 'name', 'Nextcloud', 'Name'], + ['theming', 'slogan', 'Safe Data', 'Slogan'], + ]); + + $this->assertEquals('Name – Slogan', $this->template->getShortFooter()); + } + + public function testGetShortFooterEmptySlogan() { + $this->config + ->expects($this->exactly(3)) + ->method('getAppValue') + ->willReturnMap([ + ['theming', 'url', 'https://nextcloud.com/', 'url'], + ['theming', 'name', 'Nextcloud', 'Name'], + ['theming', 'slogan', 'Safe Data', ''], + ]); + + $this->assertEquals('Name', $this->template->getShortFooter()); + } + + public function testGetMailHeaderColorWithDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'color', '#000') + ->willReturn('#000'); + + $this->assertEquals('#000', $this->template->getMailHeaderColor()); + } + + public function testGetMailHeaderColorWithCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'color', '#000') + ->willReturn('#fff'); + + $this->assertEquals('#fff', $this->template->getMailHeaderColor()); + } + + public function testSet() { + $this->config + ->expects($this->at(0)) + ->method('setAppValue') + ->with('theming', 'MySetting', 'MyValue'); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('theming', 'cachebuster', '0') + ->willReturn('15'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('theming', 'cachebuster', 16); + + $this->template->set('MySetting', 'MyValue'); + } + + public function testUndoName() { + $this->config + ->expects($this->at(0)) + ->method('deleteAppValue') + ->with('theming', 'name'); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('theming', 'cachebuster', '0') + ->willReturn('15'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('theming', 'cachebuster', 16); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('Nextcloud'); + + $this->assertSame('Nextcloud', $this->template->undo('name')); + } + + public function testUndoBaseUrl() { + $this->config + ->expects($this->at(0)) + ->method('deleteAppValue') + ->with('theming', 'url'); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('theming', 'cachebuster', '0') + ->willReturn('15'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('theming', 'cachebuster', 16); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('theming', 'url', 'https://nextcloud.com/') + ->willReturn('https://nextcloud.com/'); + + $this->assertSame('https://nextcloud.com/', $this->template->undo('url')); + } + + public function testUndoSlogan() { + $this->config + ->expects($this->at(0)) + ->method('deleteAppValue') + ->with('theming', 'slogan'); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('theming', 'cachebuster', '0') + ->willReturn('15'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('theming', 'cachebuster', 16); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('theming', 'slogan', 'Safe Data') + ->willReturn('Safe Data'); + + $this->assertSame('Safe Data', $this->template->undo('slogan')); + } + + public function testUndoColor() { + $this->config + ->expects($this->at(0)) + ->method('deleteAppValue') + ->with('theming', 'color'); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('theming', 'cachebuster', '0') + ->willReturn('15'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('theming', 'cachebuster', 16); + $this->config + ->expects($this->at(3)) + ->method('getAppValue') + ->with('theming', 'color', '#000') + ->willReturn('#000'); + + $this->assertSame('#000', $this->template->undo('color')); + } + + public function testUndoDefaultAction() { + $this->config + ->expects($this->at(0)) + ->method('deleteAppValue') + ->with('theming', 'defaultitem'); + $this->config + ->expects($this->at(1)) + ->method('getAppValue') + ->with('theming', 'cachebuster', '0') + ->willReturn('15'); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('theming', 'cachebuster', 16); + + $this->assertSame('', $this->template->undo('defaultitem')); + } +} diff --git a/lib/private/Server.php b/lib/private/Server.php index 53c8ee84924..2bbc4871d08 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -82,7 +82,7 @@ use OC\Security\SecureRandom; 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 @@ class Server extends ServerContainer implements IServerContainer { } if ($classExists && $this->getConfig()->getSystemValue('installed', false) && $this->getAppManager()->isInstalled('theming')) { - return new Template( + return new ThemingDefaults( $this->getConfig(), $this->getL10N('theming'), $this->getURLGenerator(), -- cgit v1.2.3 From 0c15081279a56d382400622e3c066584421cb67c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 16:00:39 +0200 Subject: 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 0db4dfe0627..8d3e2a5f2e2 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -27,7 +27,7 @@ namespace OCA\Theming\Controller; -use OCA\Theming\Template; +use OCA\Theming\ThemingDefaults; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataDownloadResponse; @@ -48,7 +48,7 @@ use OCA\Theming\Util; * @package OCA\Theming\Controller */ class ThemingController extends Controller { - /** @var Template */ + /** @var ThemingDefaults */ private $template; /** @var Util */ private $util; @@ -67,7 +67,7 @@ class ThemingController extends Controller { * @param string $appName * @param IRequest $request * @param IConfig $config - * @param Template $template + * @param ThemingDefaults $template * @param Util $util * @param ITimeFactory $timeFactory * @param IL10N $l @@ -77,7 +77,7 @@ class ThemingController extends Controller { $appName, IRequest $request, IConfig $config, - Template $template, + ThemingDefaults $template, Util $util, ITimeFactory $timeFactory, IL10N $l, diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index 03356c11383..8aba4696e00 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 a7af208b96d..7b846919db3 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 -- cgit v1.2.3 From 9aa6b99a567403c6a3749814033b0e2f600a876f Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 16:52:20 +0200 Subject: 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 2bbc4871d08..05f25a7be80 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -729,7 +729,8 @@ class Server extends ServerContainer implements IServerContainer { $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 4f1edcf4691..0c72983a887 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -26,9 +26,13 @@ namespace OC\Settings\Admin; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\SqlitePlatform; +use OC\Lock\DBLockingProvider; +use OC\Lock\NoopLockingProvider; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IL10N; +use OCP\Lock\ILockingProvider; use OCP\Settings\ISettings; class Server implements ISettings { @@ -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 @@ class Server implements ISettings { $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 769ef71e955..7e22d0a3b8c 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -30,6 +30,7 @@ use OCP\IDBConnection; use OCP\IL10N; use OCP\ILogger; use OCP\IUserManager; +use OCP\Lock\ILockingProvider; use OCP\Settings\ISettings; use OCP\Settings\IManager; use OCP\Settings\ISection; @@ -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 @@ class Manager implements IManager { $this->config = $config; $this->encryptionManager = $encryptionManager; $this->userManager = $userManager; + $this->lockingProvider = $lockingProvider; } /** @@ -85,6 +90,9 @@ class Manager implements IManager { } } + /** + * @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 @@ class Manager implements IManager { 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') { -- cgit v1.2.3 From 0fdf801c25c6a983c367e9c8be79c81c58df980b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 16:58:59 +0200 Subject: 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 81b6b886c9f..2662cb16e0f 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 34402825316..6ef7deea152 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() { -- cgit v1.2.3 From 90e58b7fb3aae0db4d5017a93e04e37387c4fb30 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 12 Aug 2016 17:08:32 +0200 Subject: 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 271aa05265b..3efe481ca9e 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -72,7 +72,7 @@ class AdminSettingsController extends Controller { $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 @@ class AdminSettingsController extends Controller { 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 e0fee1555a3..1d9f6dc7a78 100644 --- a/settings/templates/admin/frame.php +++ b/settings/templates/admin/frame.php @@ -36,7 +36,8 @@ vendor_style('select2/select2'); 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))); } }?> -- cgit v1.2.3 From 7a2b96c7e65eaaf58e0ad77b91532df0a2b6da5d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:06:10 +0200 Subject: 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 2323870cf97..0a1ddcab6fd 100644 --- a/apps/files/lib/Settings/Section.php +++ b/apps/files/lib/Settings/Section.php @@ -51,7 +51,7 @@ class Section implements ISection { * @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 a10bd7cbb93..82d8d0c84fa 100644 --- a/apps/user_ldap/lib/Settings/Section.php +++ b/apps/user_ldap/lib/Settings/Section.php @@ -51,7 +51,7 @@ class Section implements ISection { * @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 7e22d0a3b8c..4b1b5befb21 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -260,13 +260,13 @@ class Manager implements IManager { // 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(); -- cgit v1.2.3 From a133e7970d766d9bb54da678174ef3dd53270357 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:29:39 +0200 Subject: make updatenotification settings appear as if it is part of the version part in server settings --- apps/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 3c6ab463059..ebb3fa642f1 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -168,6 +168,6 @@ class AdminController extends Controller implements ISettings { * 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 b1cc76534e3..3c3d6cbd4cd 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 b006f1f5656..b40b7a17904 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 43df787d519..1e24043b3dc 100644 --- a/settings/templates/admin/server.php +++ b/settings/templates/admin/server.php @@ -319,6 +319,7 @@ if ($_['mail_smtpmode'] == 'qmail') {
    +

    t('Version'));?>

    getTitle()); ?>

    -- cgit v1.2.3 From b99ecb3c235436bbdf50952b502465ba440d57bc Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:33:09 +0200 Subject: 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 ed72e17cf50..fbdec8741f7 100644 --- a/apps/systemtags/lib/Settings/Admin.php +++ b/apps/systemtags/lib/Settings/Admin.php @@ -39,7 +39,7 @@ class Admin implements ISettings { * @return string the section ID, e.g. 'sharing' */ public function getSection() { - return 'collaboration'; + return 'sharing'; } /** @@ -50,7 +50,7 @@ class Admin implements ISettings { * 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 4b1b5befb21..21400a9805a 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -262,7 +262,6 @@ class Manager implements IManager { $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)], -- cgit v1.2.3 From d2fcac8300ba18e001fa3a2ae4d422331b24c953 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:36:32 +0200 Subject: 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 aa2f551e18d..c454eeba17b 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: 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/lib/Settings/Section.php | 67 ------------ apps/files_external/appinfo/info.xml | 1 + apps/files_external/lib/Settings/Admin.php | 2 +- apps/files_external/lib/Settings/Section.php | 67 ++++++++++++ lib/private/Settings/Admin/Additional.php | 86 +++++++++++++++ lib/private/Settings/Admin/Server.php | 13 --- lib/private/Settings/Manager.php | 5 + settings/Controller/AdminSettingsController.php | 14 +-- settings/templates/admin/additional-mail.php | 140 ++++++++++++++++++++++++ settings/templates/admin/additional.php | 13 +-- settings/templates/admin/server.php | 111 ------------------- 13 files changed, 313 insertions(+), 209 deletions(-) delete mode 100644 apps/files/lib/Settings/Section.php create mode 100644 apps/files_external/lib/Settings/Section.php 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 c1666af6348..513940f73a9 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 d0a691ffe66..9ec23d47517 100644 --- a/apps/files/lib/Settings/Admin.php +++ b/apps/files/lib/Settings/Admin.php @@ -76,7 +76,7 @@ class Admin implements ISettings { * @return string the section ID, e.g. 'sharing' */ public function getSection() { - return 'files'; + return 'additional'; } /** diff --git a/apps/files/lib/Settings/Section.php b/apps/files/lib/Settings/Section.php deleted file mode 100644 index 0a1ddcab6fd..00000000000 --- a/apps/files/lib/Settings/Section.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * @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 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 'files'; - } - - /** - * 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('Files & storages'); - } - - /** - * @return int whether the form should be rather on the top or bottom of - * the settings navigation. The sections are arranged in ascending order of - * the priority values. It is required to return a value between 0 and 99. - * - * E.g.: 70 - */ - public function getPriority() { - return 10; - } -} diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index cd52c39b30e..60131759880 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 102680d0341..54711443f89 100644 --- a/apps/files_external/lib/Settings/Admin.php +++ b/apps/files_external/lib/Settings/Admin.php @@ -79,7 +79,7 @@ class Admin implements ISettings { * @return string the section ID, e.g. 'sharing' */ public function getSection() { - return 'files'; + return 'externalstorages'; } /** diff --git a/apps/files_external/lib/Settings/Section.php b/apps/files_external/lib/Settings/Section.php new file mode 100644 index 00000000000..4b4bac93d29 --- /dev/null +++ b/apps/files_external/lib/Settings/Section.php @@ -0,0 +1,67 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Files_External\Settings; + +use OCP\IL10N; +use OCP\Settings\ISection; + +class Section implements ISection { + /** @var IL10N */ + private $l; + + public function __construct(IL10N $l) { + $this->l = $l; + } + + /** + * returns the ID of the section. It is supposed to be a lower case string, + * e.g. 'ldap' + * + * @returns string + */ + public function getID() { + return 'externalstorages'; + } + + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + */ + public function getName() { + return $this->l->t('External storages'); + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the settings navigation. The sections are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + * + * E.g.: 70 + */ + public function getPriority() { + return 10; + } +} diff --git a/lib/private/Settings/Admin/Additional.php b/lib/private/Settings/Admin/Additional.php new file mode 100644 index 00000000000..106f0f65b8a --- /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 0c72983a887..20c3a6d7557 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -119,19 +119,6 @@ class Server implements ISettings { '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 21400a9805a..fd360ede7f0 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -308,6 +308,11 @@ class Manager implements IManager { $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 3efe481ca9e..3954497443b 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -34,6 +34,7 @@ use OCP\INavigationManager; use OCP\IRequest; use OCP\IUserManager; use OCP\Settings\IManager as ISettingsManager; +use OCP\Template; /** * @package OC\Settings\Controller @@ -83,12 +84,8 @@ class AdminSettingsController extends Controller { } 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 @@ class AdminSettingsController extends Controller { $html .= $form->renderAs('')->render(); } } + if($section === 'additional') { + $html .= $this->getLegacyForms(); + } return ['content' => $html]; } @@ -120,10 +120,10 @@ class AdminSettingsController extends Controller { ); }, $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 00000000000..88eec421ec5 --- /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 c4e70dbddb2..2ad2c5af4e5 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 1e24043b3dc..a15705a90e2 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 @@ if ($_['mail_smtpmode'] == 'qmail') {

    -
    -
    -

    t('Email server'));?>

    - - -

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

    - -

    - - - - - -

    - -

    - - ' />@ - ' /> -

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

    t('Version'));?>

    -- cgit v1.2.3 From 8188bb4509e62e67c8f65d6b449e9084dd7cf5a4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 01:26:11 +0200 Subject: simplify encryption manager fetching in DIContainer --- .../AppFramework/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 4e3cac6d1ea..22bcc004626 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -310,22 +310,8 @@ class DIContainer extends SimpleContainer implements IAppContainer { 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(); }); -- cgit v1.2.3 From 75a73a5a7301f203a962a17f6b2b8b90078c1884 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 15 Aug 2016 13:38:02 +0200 Subject: 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 22bcc004626..77192847867 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -152,6 +152,10 @@ class DIContainer extends SimpleContainer implements IAppContainer { 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 05f25a7be80..245bbb338e2 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1289,6 +1289,11 @@ class Server extends ServerContainer implements IServerContainer { return $this->query('MountManager'); } + /** @return \OCP\Files\Config\IUserMountCache */ + function getUserMountCache() { + return $this->query('UserMountCache'); + } + /** * Get the MimeTypeDetector * -- cgit v1.2.3 From 8a7a0f328746230dd896ccc53b3ada271a91b930 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 16:24:56 +0200 Subject: 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 ++++++++ apps/files_external/tests/Settings/AdminTest.php | 109 ++++++++++ apps/files_external/tests/Settings/SectionTest.php | 62 ++++++ apps/systemtags/tests/Settings/AdminTest.php | 52 +++++ apps/theming/lib/Settings/Admin.php | 9 +- .../tests/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 +- settings/Controller/AdminSettingsController.php | 32 ++- tests/Core/Templates/TemplatesTest.php | 2 +- .../Controller/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 00000000000..5b0b577e058 --- /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 00000000000..e082e7bff23 --- /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 00000000000..78cb7201dcd --- /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 00000000000..c536377af93 --- /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 00000000000..1918e800c9b --- /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 00000000000..9ab456fe307 --- /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 00000000000..b1faf82cf25 --- /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 8aba4696e00..1f79449e658 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -31,20 +31,19 @@ use OCP\IURLGenerator; use OCP\Settings\ISettings; class Admin implements ISettings { - /** @var IConfig */ private $config; - /** @var IL10N */ private $l; - /** @var ThemingDefaults */ private $themingDefaults; - /** @var IURLGenerator */ private $urlGenerator; - public function __construct(IConfig $config, IL10N $l, ThemingDefaults $themingDefaults, IURLGenerator $urlGenerator) { + 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 2662cb16e0f..688e3d62bff 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -33,6 +33,7 @@ use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; use Test\TestCase; +use OCA\Theming\ThemingDefaults; class ThemingControllerTest extends TestCase { /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..ff42c6997a6 --- /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 00000000000..e8a9a217f1f --- /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 0343542ef41..a4398715885 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 @@ class AdminControllerTest extends TestCase { $expected = new DataResponse('MyGeneratedToken'); $this->assertEquals($expected, $this->adminController->createCredentials()); } + + public function testGetSection() { + $this->assertSame('server', $this->adminController->getSection()); + } + + public function testGetPriority() { + $this->assertSame(1, $this->adminController->getPriority()); + } } diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php index 606cfe6cf01..ca7db66c788 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -31,10 +31,12 @@ use OCP\Settings\ISettings; use OCP\Template; class Admin implements ISettings { - /** @var IL10N */ private $l; + /** + * @param IL10N $l + */ public function __construct(IL10N $l) { $this->l = $l; } @@ -84,10 +86,4 @@ class Admin implements ISettings { 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 00000000000..e92684f3ce4 --- /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 00000000000..b5b1f97ce3c --- /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 106f0f65b8a..d133e4737a7 100644 --- a/lib/private/Settings/Admin/Additional.php +++ b/lib/private/Settings/Admin/Additional.php @@ -36,10 +36,12 @@ use OCP\Lock\ILockingProvider; use OCP\Settings\ISettings; class Additional implements ISettings { - /** @var IConfig */ private $config; + /** + * @param IConfig $config + */ public function __construct(IConfig $config) { $this->config = $config; } diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php index ceae5aa6d3f..69c6bd17f03 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 3097070577d..407248ac4b1 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 20c3a6d7557..6b381ab48ed 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -36,20 +36,25 @@ use OCP\Lock\ILockingProvider; use OCP\Settings\ISettings; class Server implements ISettings { - /** @var IDBConnection|Connection */ private $db; - /** @var IConfig */ private $config; - /** @var ILockingProvider */ private $lockingProvider; - /** @var IL10N */ private $l; - 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 d186dbed981..e110a3d81b7 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 @@ class Sharing implements ISettings { * @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 217ddacd443..fd0fd595844 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 fd360ede7f0..1304a60949e 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 @@ class Manager implements IManager { ]); } - 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 @@ class Manager implements IManager { 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 @@ class Manager implements IManager { } /** - * returns a list of the admin sections - * - * @return ISection[] + * @inheritdoc */ public function getAdminSections() { $query = $this->dbc->getQueryBuilder(); @@ -347,11 +356,12 @@ class Manager implements IManager { 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 2ea614b365e..b3cf242279f 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 3954497443b..ef70caf5690 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 @@ use OCP\Template; * @package OC\Settings\Controller */ class AdminSettingsController extends Controller { - /** @var INavigationManager */ private $navigationManager; - /** @var ISettingsManager */ private $settingsManager; + /** + * @param string $appName + * @param IRequest $request + * @param INavigationManager $navigationManager + * @param ISettingsManager $settingsManager + */ public function __construct( $appName, IRequest $request, INavigationManager $navigationManager, - IL10N $l, - IConfig $config, - EncryptionManager $encryptionManager, - IUserManager $userManager, - IDBConnection $db, ISettingsManager $settingsManager ) { parent::__construct($appName, $request); @@ -79,10 +73,10 @@ class AdminSettingsController extends Controller { 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 @@ class AdminSettingsController extends Controller { return ['content' => $html]; } + /** + * @return bool|string + */ private function getLegacyForms() { $forms = \OC_App::getForms('admin'); @@ -133,6 +130,7 @@ class AdminSettingsController extends Controller { 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 03565411a13..cd1502fd22c 100644 --- a/tests/Core/Templates/TemplatesTest.php +++ b/tests/Core/Templates/TemplatesTest.php @@ -13,7 +13,7 @@ class TemplatesTest extends \Test\TestCase { 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 00000000000..86950c9aa9d --- /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 f48e9c04f3d..63c8141cedd 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -29,6 +29,7 @@ use OCP\AppFramework\Http\RedirectResponse; 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 @@ class CheckSetupControllerTest extends TestCase { })); $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 @@ class CheckSetupControllerTest extends TestCase { $this->util, $this->l10n, $this->checker, + $this->logger ]) ->setMethods(['getCurlVersion'])->getMock(); } @@ -373,7 +378,8 @@ class CheckSetupControllerTest extends TestCase { $this->urlGenerator, $this->util, $this->l10n, - $this->checker + $this->checker, + $this->logger ]) ->setMethods(null)->getMock(); @@ -612,7 +618,7 @@ class CheckSetupControllerTest extends TestCase { $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 00000000000..178d7550614 --- /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 00000000000..a68b40ae11b --- /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 00000000000..10a94f1c59c --- /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 00000000000..5a4fa22920f --- /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 00000000000..7aec187d372 --- /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 00000000000..afa053e8337 --- /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 00000000000..01e226225be --- /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 00000000000..422b931bb4b --- /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()); + } +} -- cgit v1.2.3 From 7ffb7b0d846241c8cc6b45a3c85b2374c6d026ae Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 16:43:22 +0200 Subject: 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 +-- apps/files_external/tests/Settings/AdminTest.php | 8 ++--- apps/files_external/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 +- .../Controller/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 5b0b577e058..93896585dad 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 e082e7bff23..60fadca7b56 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 78cb7201dcd..758bda6bc5e 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 c536377af93..1ab8a992879 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 1918e800c9b..fdf9680e7c3 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 9ab456fe307..b5dfb28b382 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 ff42c6997a6..18c2064e8ce 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 e8a9a217f1f..3a3a4375236 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 a4398715885..cf99679e680 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 e92684f3ce4..4ac5a14f58b 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 b5b1f97ce3c..2d2165b8e56 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 86950c9aa9d..6c93bca0d68 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 @@ class AdminSettingsControllerTest extends TestCase { ->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 63c8141cedd..770d5a4934e 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -98,7 +98,7 @@ class CheckSetupControllerTest extends TestCase { })); $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 178d7550614..3a99893cf7c 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 a68b40ae11b..f9763d85c1f 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 10a94f1c59c..181553d3894 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 5a4fa22920f..874422307e0 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 7aec187d372..261e631363a 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 afa053e8337..0e8857b56d0 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 01e226225be..cd5100eff6d 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 @@ class ManagerTest extends TestCase { } 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 @@ class ManagerTest extends TestCase { ->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 @@ class ManagerTest extends TestCase { ->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 @@ class ManagerTest extends TestCase { } 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 @@ class ManagerTest extends TestCase { ->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 @@ class ManagerTest extends TestCase { } 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 @@ class ManagerTest extends TestCase { ->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 @@ class ManagerTest extends TestCase { ->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') -- cgit v1.2.3 From 9edca39b49f6b7fcfc4e43b61b88204222ad5e91 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 15 Aug 2016 20:03:19 +0200 Subject: 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 3457a74e989..9e56bc09f01 100644 --- a/lib/base.php +++ b/lib/base.php @@ -725,6 +725,7 @@ class OC { self::registerLogRotate(); self::registerEncryptionWrapper(); self::registerEncryptionHooks(); + self::registerSettingsHooks(); //make sure temporary files are cleaned up $tmpManager = \OC::$server->getTempManager(); @@ -803,6 +804,14 @@ class OC { } } + 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 1304a60949e..8fdc7fefbb3 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -93,6 +93,25 @@ class Manager implements IManager { } } + /** + * 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 @@ class Manager implements IManager { 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 8aa7a9ac248..cba4efbd037 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 * -- cgit v1.2.3 From 208e551216c955e326d41868956a46a03e8047e3 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 00:52:41 +0200 Subject: 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 9e56bc09f01..a69a4dffef8 100644 --- a/lib/base.php +++ b/lib/base.php @@ -810,6 +810,14 @@ class OC { /** @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 8fdc7fefbb3..7574695d709 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -112,6 +112,37 @@ class Manager implements IManager { } } + 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 00000000000..fbee95c8879 --- /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 c786a1fc53d..ceb36449bf0 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -51,6 +51,7 @@ use OC\App\Platform; 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 @@ class OC_App { $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 a70345b62fd..b25ea55aee6 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 cba4efbd037..a406915ad09 100644 --- a/lib/public/Settings/IManager.php +++ b/lib/public/Settings/IManager.php @@ -64,6 +64,21 @@ interface IManager { */ 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 * -- cgit v1.2.3 From d96e8f5810045fd1ff15f7371f9d5cc711cbd717 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 00:53:32 +0200 Subject: 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 09ca0807e63..eceb2b6937c 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -184,11 +184,6 @@ class Application extends App { $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') ); }); -- cgit v1.2.3 From 83ba2f2e90c24dcfe7eb62532fd28a0b5156e0f8 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 13:21:59 +0200 Subject: 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 b4c231a9248..77f6d768986 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 + + + -- cgit v1.2.3 From 58530ab42f7b089351dcd931de1f2f048ff4b23b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 17:59:21 +0200 Subject: 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 e110a3d81b7..8d3ddc9b3b5 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 @@ class Sharing implements ISettings { $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 c81f7e2ae1c..b8f8e920246 100644 --- a/settings/templates/admin/sharing.php +++ b/settings/templates/admin/sharing.php @@ -104,6 +104,4 @@ />

    - -
    -- cgit v1.2.3 From f76b64d3d7e5803008e0dbc29fdf1bcf29f0811e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 18:11:59 +0200 Subject: 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 69c6bd17f03..6e93407f1a3 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -48,11 +48,24 @@ class Encryption implements ISettings { * @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, ''); -- cgit v1.2.3 From 4946cc220de5926ef86dc8557ffb5c990f6482d3 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 18:26:16 +0200 Subject: 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 5c551267ff5..405dbaf703f 100644 --- a/apps/encryption/templates/settings-admin.php +++ b/apps/encryption/templates/settings-admin.php @@ -6,6 +6,7 @@ script('core', 'multiselect'); style('encryption', 'settings-admin'); ?>
    +

    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 d4c3be8b2c8..4b6d9045689 100644 --- a/settings/templates/admin/encryption.php +++ b/settings/templates/admin/encryption.php @@ -72,8 +72,6 @@
    - -
    -- cgit v1.2.3 From 4943441bde11e78827fdeb599ca4cd7b783672ce Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 16 Aug 2016 18:59:45 +0200 Subject: 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 f9763d85c1f..a282b059c92 100644 --- a/tests/lib/Settings/Admin/EncryptionTest.php +++ b/tests/lib/Settings/Admin/EncryptionTest.php @@ -71,6 +71,10 @@ class EncryptionTest extends TestCase { ->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 @@ class EncryptionTest extends TestCase { 'encryptionEnabled' => $enabled, 'encryptionReady' => $enabled, 'externalBackendsEnabled' => false, + 'encryptionModules' => [] ], '' ); @@ -101,6 +106,10 @@ class EncryptionTest extends TestCase { ->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 @@ class EncryptionTest extends TestCase { 'encryptionEnabled' => $enabled, 'encryptionReady' => $enabled, 'externalBackendsEnabled' => true, + 'encryptionModules' => [] ], '' ); diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php index 261e631363a..38ab7614d1c 100644 --- a/tests/lib/Settings/Admin/SharingTest.php +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -52,25 +52,60 @@ class SharingTest extends TestCase { $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 @@ class SharingTest extends TestCase { '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 @@ class SharingTest extends TestCase { $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 @@ class SharingTest extends TestCase { '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', ], '' ); -- cgit v1.2.3