From ff2f5ecbf7fc8aafe03bbb88a22d3761fd277893 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 19 Aug 2016 17:44:24 +0200 Subject: [PATCH] Backport Workflow section + hidden empty sections #995 to stabble10 add section to worklfowengine enlist only registered sections that also have settings registered to adjust test Move admin settings to workflow section fix wrong var name Save the container with the app's namespace so we can resolve it --- apps/systemtags/lib/Settings/Admin.php | 2 +- apps/systemtags/tests/Settings/AdminTest.php | 2 +- apps/workflowengine/appinfo/info.xml | 6 ++- apps/workflowengine/lib/Settings/Section.php | 57 ++++++++++++++++++++ lib/private/ServerContainer.php | 3 +- lib/private/Settings/Manager.php | 14 +++-- tests/lib/Settings/ManagerTest.php | 19 +++++-- 7 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 apps/workflowengine/lib/Settings/Section.php diff --git a/apps/systemtags/lib/Settings/Admin.php b/apps/systemtags/lib/Settings/Admin.php index c8d986414e..9e21dafed8 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 'additional'; + return 'workflow'; } /** diff --git a/apps/systemtags/tests/Settings/AdminTest.php b/apps/systemtags/tests/Settings/AdminTest.php index 174fd38215..d768ad8627 100644 --- a/apps/systemtags/tests/Settings/AdminTest.php +++ b/apps/systemtags/tests/Settings/AdminTest.php @@ -43,7 +43,7 @@ class AdminTest extends TestCase { } public function testGetSection() { - $this->assertSame('additional', $this->admin->getSection()); + $this->assertSame('workflow', $this->admin->getSection()); } public function testGetPriority() { diff --git a/apps/workflowengine/appinfo/info.xml b/apps/workflowengine/appinfo/info.xml index cc4118cb4c..751756fe5e 100644 --- a/apps/workflowengine/appinfo/info.xml +++ b/apps/workflowengine/appinfo/info.xml @@ -5,7 +5,7 @@ AGPL Morris Jobke - 1.0.0 + 1.0.1 WorkflowEngine other @@ -20,4 +20,8 @@ + + + OCA\WorkflowEngine\Settings\Section + diff --git a/apps/workflowengine/lib/Settings/Section.php b/apps/workflowengine/lib/Settings/Section.php new file mode 100644 index 0000000000..df8bb80713 --- /dev/null +++ b/apps/workflowengine/lib/Settings/Section.php @@ -0,0 +1,57 @@ + + * + * @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\WorkflowEngine\Settings; + +use OCP\IL10N; +use OCP\Settings\ISection; + +class Section implements ISection { + /** @var IL10N */ + private $l; + + public function __construct(IL10N $l) { + $this->l = $l; + } + + /** + * {@inheritdoc} + */ + public function getID() { + return 'workflow'; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return $this->l->t('Workflow'); + } + + /** + * {@inheritdoc} + */ + public function getPriority() { + return 55; + } +} diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index 1bab2587e8..df0293addf 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -23,6 +23,7 @@ namespace OC; +use OC\AppFramework\App; use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Utility\SimpleContainer; use OCP\AppFramework\QueryException; @@ -49,7 +50,7 @@ class ServerContainer extends SimpleContainer { * @param DIContainer $container */ public function registerAppContainer($appName, DIContainer $container) { - $this->appContainers[$appName] = $container; + $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container; } /** diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 7574695d70..df2f52f816 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -107,7 +107,7 @@ class Manager implements IManager { 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])) { + if(isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { $this->remove(self::TABLE_ADMIN_SETTINGS, $appInfo['settings'][IManager::KEY_ADMIN_SETTINGS]); } } @@ -327,10 +327,6 @@ class Manager implements IManager { * @inheritdoc */ public function getAdminSections() { - $query = $this->dbc->getQueryBuilder(); - $query->select(['class', 'priority']) - ->from(self::TABLE_ADMIN_SECTIONS); - // built-in sections $sections = [ 0 => [new Section('server', $this->l->t('Server settings'), 0)], @@ -341,7 +337,15 @@ class Manager implements IManager { 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0)], ]; + $query = $this->dbc->getQueryBuilder(); + $query->selectDistinct('s.class') + ->addSelect('s.priority') + ->from(self::TABLE_ADMIN_SECTIONS, 's') + ->from(self::TABLE_ADMIN_SETTINGS, 'f') + ->where($query->expr()->eq('s.id', 'f.section')) + ; $result = $query->execute(); + while($row = $result->fetch()) { if(!isset($sections[$row['priority']])) { $sections[$row['priority']] = []; diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index cd5100eff6..942a2bb63e 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -136,15 +136,28 @@ class ManagerTest extends TestCase { public function testGetAdminSections() { $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); + $expr = $this->getMockBuilder('OCP\DB\QueryBuilder\IExpressionBuilder')->getMock(); $qb ->expects($this->once()) - ->method('select') - ->with(['class', 'priority']) + ->method('selectDistinct') + ->with('s.class') ->willReturn($qb); $qb ->expects($this->once()) + ->method('addSelect') + ->with('s.priority') + ->willReturn($qb); + $qb + ->expects($this->exactly(2)) ->method('from') - ->with('admin_sections') + ->willReturn($qb); + $qb + ->expects($this->once()) + ->method('expr') + ->willReturn($expr); + $qb + ->expects($this->once()) + ->method('where') ->willReturn($qb); $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); $qb