Merge pull request #16 from nextcloud/admin-settings
move to new admin mechanism
This commit is contained in:
Коммит
70b894beb8
|
@ -5,7 +5,7 @@
|
|||
<description>An app for Nextcloud to control the access to files based on some conditions</description>
|
||||
<licence>AGPL</licence>
|
||||
<author>Morris Jobke</author>
|
||||
<version>1.1.0</version>
|
||||
<version>1.1.1</version>
|
||||
<namespace>FilesAccessControl</namespace>
|
||||
|
||||
<category>other</category>
|
||||
|
@ -20,4 +20,8 @@
|
|||
<dependencies>
|
||||
<owncloud min-version="9.2" max-version="9.2" />
|
||||
</dependencies>
|
||||
|
||||
<settings>
|
||||
<admin>OCA\FilesAccessControl\Settings\Admin</admin>
|
||||
</settings>
|
||||
</info>
|
||||
|
|
|
@ -37,8 +37,6 @@ class Application extends \OCP\AppFramework\App {
|
|||
*/
|
||||
public function registerHooksAndListeners() {
|
||||
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');
|
||||
|
||||
\OCP\App::registerAdmin('files_accesscontrol', 'settings/admin');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de>
|
||||
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
|
@ -19,48 +21,64 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace OCA\FilesAccessControl\Controller;
|
||||
namespace OCA\FilesAccessControl\Settings;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCA\FilesAccessControl\AppInfo\Application;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use OCP\Settings\ISettings;
|
||||
use OCP\Util;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class AdminController extends Controller {
|
||||
class Admin implements ISettings {
|
||||
|
||||
/** @var EventDispatcher */
|
||||
protected $eventDispatcher;
|
||||
/** @var IL10N */
|
||||
protected $l10n;
|
||||
private $l10n;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
* @param IL10N $l10n
|
||||
*/
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
IL10N $l10n) {
|
||||
parent::__construct($appName, $request);
|
||||
/** @var Application */
|
||||
private $app;
|
||||
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
/** @var EventDispatcherInterface */
|
||||
private $eventDispatcher;
|
||||
|
||||
public function __construct(IL10N $l10n, Application $app, EventDispatcherInterface $eventDispatcher) {
|
||||
$this->l10n = $l10n;
|
||||
$this->app = $app;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function index() {
|
||||
public function getForm() {
|
||||
$appName = $this->app->getContainer()->getAppName();
|
||||
$this->eventDispatcher->dispatch('OCP\WorkflowEngine::loadAdditionalSettingScripts');
|
||||
\OCP\Util::addScript($this->appName, 'admin');
|
||||
return new TemplateResponse('workflowengine', 'admin', [
|
||||
'appid' => $this->appName,
|
||||
Util::addScript($appName, 'admin');
|
||||
$parameters = [
|
||||
'appid' => $appName,
|
||||
'heading' => $this->l10n->t('File access control'),
|
||||
'description' => $this->l10n->t('Each rule group consists of one or more rules. A request matches a group if all rules evaluate to true. If a request matches at least one of the defined groups, the request is blocked and the file content can not be read or written.'),
|
||||
], 'blank');
|
||||
];
|
||||
|
||||
return new TemplateResponse('workflowengine', 'admin', $parameters, 'blank');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 70;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
$app = new \OCA\FilesAccessControl\AppInfo\Application();
|
||||
$container = $app->getContainer();
|
||||
/** @var \OCP\AppFramework\Http\TemplateResponse $response */
|
||||
$response = $container->query('OCA\FilesAccessControl\Controller\AdminController')->index();
|
||||
|
||||
return $response->render();
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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\FilesAccessControl\Controller\Test;
|
||||
|
||||
use OCA\FilesAccessControl\Controller\AdminController;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminControllerTest extends TestCase {
|
||||
|
||||
/** @var AdminController|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $controller;
|
||||
/** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $request;
|
||||
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $dispatcher;
|
||||
/** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $l;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->request = $this->getMockBuilder('OCP\IRequest')
|
||||
->getMock();
|
||||
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
|
||||
->getMock();
|
||||
$this->l = $this->getMockBuilder('OCP\IL10N')
|
||||
->getMock();
|
||||
$this->controller = new AdminController(
|
||||
'files_automatedtagging',
|
||||
$this->request,
|
||||
$this->dispatcher,
|
||||
$this->l
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function testIndex() {
|
||||
$this->dispatcher->expects($this->once())
|
||||
->method('dispatch')
|
||||
->with('OCP\WorkflowEngine::loadAdditionalSettingScripts');
|
||||
|
||||
$this->l->expects($this->exactly(2))
|
||||
->method('t')
|
||||
->willReturnArgument(1);
|
||||
|
||||
$response = $this->controller->index();
|
||||
|
||||
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $response);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>g
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @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\FilesAccessControl\Settings\Test;
|
||||
|
||||
use OCA\FilesAccessControl\AppInfo\Application;
|
||||
use OCA\FilesAccessControl\Settings\Admin;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
use OCP\IL10N;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var IL10N */
|
||||
protected $l;
|
||||
|
||||
/** @var Application */
|
||||
protected $app;
|
||||
|
||||
/** @var EventDispatcherInterface */
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var Admin */
|
||||
protected $admin;
|
||||
|
||||
/** @var IAppContainer */
|
||||
protected $container;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->l = $this->getMockBuilder('OCP\IL10N')
|
||||
->getMock();
|
||||
|
||||
$this->app = $this->getMockBuilder('OCA\FilesAccessControl\AppInfo\Application')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
|
||||
->getMock();
|
||||
|
||||
$this->container = $this->getMockBuilder('OCP\AppFramework\IAppContainer')->getMock();
|
||||
|
||||
$this->admin = new Admin($this->l, $this->app, $this->dispatcher);
|
||||
}
|
||||
|
||||
public function testGetForm() {
|
||||
$this->dispatcher->expects($this->once())
|
||||
->method('dispatch')
|
||||
->with('OCP\WorkflowEngine::loadAdditionalSettingScripts');
|
||||
|
||||
$this->l->expects($this->exactly(2))
|
||||
->method('t')
|
||||
->willReturnArgument(1);
|
||||
|
||||
$this->container->expects($this->once())
|
||||
->method('getAppName')
|
||||
->willReturn('files_accesscontrol');
|
||||
|
||||
$this->app->expects($this->once())
|
||||
->method('getContainer')
|
||||
->willReturn($this->container);
|
||||
|
||||
$result = $this->admin->getForm();
|
||||
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $result);
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче