From 1eb8b951c2eb6388efdd628c878110d78ae4e77d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 10 Aug 2016 15:21:25 +0200 Subject: [PATCH] more admin page splitup improvements * bump version to ensure tables are created * make updatenotification app use settings api * change IAdmin::render() to getForm() and change return type from Template to TemplateResponse * adjust User_LDAP accordingly, as well as built-in forms * add IDateTimeFormatter to AppFramework/DependencyInjection/DIContainer.php. This is important so that \OC::$server->query() is able to resolve the constructor parameters. We should ensure that all OCP/* stuff that is available from \OC::$server is available here. Kudos to @LukasReschke * make sure apps that have settings info in their info.xml are loaded before triggering adding the settings setup method --- apps/updatenotification/admin.php | 26 ------------ apps/updatenotification/appinfo/info.xml | 6 ++- .../lib/Controller/AdminController.php | 28 ++++++++++++- apps/user_ldap/appinfo/info.xml | 4 +- apps/user_ldap/lib/Settings/Admin.php | 40 +++++-------------- apps/user_ldap/templates/settings.php | 29 +++++++++----- .../DependencyInjection/DIContainer.php | 4 ++ lib/private/Settings/Admin/Encryption.php | 12 ++---- lib/private/Settings/Admin/Logging.php | 12 ++---- lib/private/Settings/Admin/Server.php | 12 ++---- lib/private/Settings/Admin/Sharing.php | 12 ++---- lib/private/Settings/Admin/TipsTricks.php | 12 ++---- lib/private/legacy/app.php | 1 + lib/public/Settings/IAdmin.php | 6 +-- .../Controller/AdminSettingsController.php | 4 +- version.php | 2 +- 16 files changed, 92 insertions(+), 118 deletions(-) delete mode 100644 apps/updatenotification/admin.php diff --git a/apps/updatenotification/admin.php b/apps/updatenotification/admin.php deleted file mode 100644 index 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'; -- 2.39.5