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
This commit is contained in:
Arthur Schiwon 2016-08-19 17:44:24 +02:00
parent cc80df9e8e
commit ff2f5ecbf7
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
7 changed files with 91 additions and 12 deletions

View File

@ -39,7 +39,7 @@ class Admin implements ISettings {
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'additional';
return 'workflow';
}
/**

View File

@ -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() {

View File

@ -5,7 +5,7 @@
<description></description>
<licence>AGPL</licence>
<author>Morris Jobke</author>
<version>1.0.0</version>
<version>1.0.1</version>
<namespace>WorkflowEngine</namespace>
<category>other</category>
@ -20,4 +20,8 @@
<dependencies>
<owncloud min-version="9.1" max-version="9.1" />
</dependencies>
<settings>
<admin-section>OCA\WorkflowEngine\Settings\Section</admin-section>
</settings>
</info>

View File

@ -0,0 +1,57 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @author Lukas Reschke <lukas@statuscode.ch>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@ -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;
}
/**

View File

@ -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']] = [];

View File

@ -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