$app = new \OCA\Provisioning_API\AppInfo\Application();
$app->registerRoutes($this, [
'ocs' => [
+ // Apps
+ ['root' => '/cloud', 'name' => 'Apps#getApps', 'url' => '/apps', 'verb' => 'GET'],
+ ['root' => '/cloud', 'name' => 'Apps#getAppInfo', 'url' => '/apps/{app}', 'verb' => 'GET'],
+ ['root' => '/cloud', 'name' => 'Apps#enable', 'url' => '/apps/{app}', 'verb' => 'POST'],
+ ['root' => '/cloud', 'name' => 'Apps#disable', 'url' => '/apps/{app}', 'verb' => 'DELETE'],
+
// Groups
['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'],
],
]);
-
-// Apps
-$apps = new Apps(
- \OC::$server->getAppManager(),
- \OC::$server->getOcsClient()
-);
-API::register('get', '/cloud/apps', [$apps, 'getApps'], 'provisioning_api', API::ADMIN_AUTH);
-API::register('get', '/cloud/apps/{appid}', [$apps, 'getAppInfo'], 'provisioning_api', API::ADMIN_AUTH);
-API::register('post', '/cloud/apps/{appid}', [$apps, 'enable'], 'provisioning_api', API::ADMIN_AUTH);
-API::register('delete', '/cloud/apps/{appid}', [$apps, 'disable'], 'provisioning_api', API::ADMIN_AUTH);
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Tom Needham <tom@owncloud.com>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OCA\Provisioning_API;
-
-use OC\OCSClient;
-use \OC_App;
-
-class Apps {
- /** @var \OCP\App\IAppManager */
- private $appManager;
- /** @var OCSClient */
- private $ocsClient;
-
- /**
- * @param \OCP\App\IAppManager $appManager
- */
- public function __construct(\OCP\App\IAppManager $appManager,
- OCSClient $ocsClient) {
- $this->appManager = $appManager;
- $this->ocsClient = $ocsClient;
- }
-
- /**
- * @param array $parameters
- * @return \OC\OCS\Result
- */
- public function getApps($parameters) {
- $apps = OC_App::listAllApps(false, true, $this->ocsClient);
- $list = [];
- foreach($apps as $app) {
- $list[] = $app['id'];
- }
- $filter = isset($_GET['filter']) ? $_GET['filter'] : false;
- if($filter){
- switch($filter){
- case 'enabled':
- return new \OC\OCS\Result(array('apps' => \OC_App::getEnabledApps()));
- break;
- case 'disabled':
- $enabled = OC_App::getEnabledApps();
- return new \OC\OCS\Result(array('apps' => array_diff($list, $enabled)));
- break;
- default:
- // Invalid filter variable
- return new \OC\OCS\Result(null, 101);
- break;
- }
-
- } else {
- return new \OC\OCS\Result(array('apps' => $list));
- }
- }
-
- /**
- * @param array $parameters
- * @return \OC\OCS\Result
- */
- public function getAppInfo($parameters) {
- $app = $parameters['appid'];
- $info = \OCP\App::getAppInfo($app);
- if(!is_null($info)) {
- return new \OC\OCS\Result(OC_App::getAppInfo($app));
- } else {
- return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The request app was not found');
- }
- }
-
- /**
- * @param array $parameters
- * @return \OC\OCS\Result
- */
- public function enable($parameters) {
- $app = $parameters['appid'];
- $this->appManager->enableApp($app);
- return new \OC\OCS\Result(null, 100);
- }
-
- /**
- * @param array $parameters
- * @return \OC\OCS\Result
- */
- public function disable($parameters) {
- $app = $parameters['appid'];
- $this->appManager->disableApp($app);
- return new \OC\OCS\Result(null, 100);
- }
-
-}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ *
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Tom Needham <tom@owncloud.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Provisioning_API\Controller;
+
+use OC\OCSClient;
+use \OC_App;
+use OCP\App\IAppManager;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSException;
+use OCP\AppFramework\OCS\OCSNotFoundException;
+use OCP\AppFramework\OCSController;
+use OCP\IRequest;
+
+class AppsController extends OCSController {
+ /** @var \OCP\App\IAppManager */
+ private $appManager;
+ /** @var OCSClient */
+ private $ocsClient;
+
+ /**
+ * @param string $appName
+ * @param IRequest $request
+ * @param IAppManager $appManager
+ * @param OCSClient $ocsClient
+ */
+ public function __construct(
+ $appName,
+ IRequest $request,
+ IAppManager $appManager,
+ OCSClient $ocsClient
+ ) {
+ parent::__construct($appName, $request);
+
+ $this->appManager = $appManager;
+ $this->ocsClient = $ocsClient;
+ }
+
+ /**
+ * @param string $filter
+ * @return DataResponse
+ * @throws OCSException
+ */
+ public function getApps($filter = null) {
+ $apps = OC_App::listAllApps(false, true, $this->ocsClient);
+ $list = [];
+ foreach($apps as $app) {
+ $list[] = $app['id'];
+ }
+ if($filter){
+ switch($filter){
+ case 'enabled':
+ return new DataResponse(['apps' => \OC_App::getEnabledApps()]);
+ break;
+ case 'disabled':
+ $enabled = OC_App::getEnabledApps();
+ return new DataResponse(['apps' => array_diff($list, $enabled)]);
+ break;
+ default:
+ // Invalid filter variable
+ throw new OCSException('', 101);
+ }
+
+ } else {
+ return new DataResponse(['apps' => $list]);
+ }
+ }
+
+ /**
+ * @param string $app
+ * @return DataResponse
+ * @throws OCSNotFoundException
+ */
+ public function getAppInfo($app) {
+ $info = \OCP\App::getAppInfo($app);
+ if(!is_null($info)) {
+ return new DataResponse(OC_App::getAppInfo($app));
+ } else {
+ throw new OCSException('The request app was not found', \OCP\API::RESPOND_NOT_FOUND);
+ }
+ }
+
+ /**
+ * @param string $app
+ * @return DataResponse
+ */
+ public function enable($app) {
+ $this->appManager->enableApp($app);
+ return new DataResponse();
+ }
+
+ /**
+ * @param string $app
+ * @return DataResponse
+ */
+ public function disable($app) {
+ $this->appManager->disableApp($app);
+ return new DataResponse();
+ }
+
+}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Tom Needham <tom@owncloud.com>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OCA\Provisioning_API\Tests;
-
-
-use OC\OCSClient;
-use OCA\Provisioning_API\Apps;
-use OCP\API;
-use OCP\App\IAppManager;
-use OCP\IUserSession;
-
-/**
- * Class AppsTest
- *
- * @group DB
- *
- * @package OCA\Provisioning_API\Tests
- */
-class AppsTest extends TestCase {
- /** @var IAppManager */
- private $appManager;
- /** @var Apps */
- private $api;
- /** @var IUserSession */
- private $userSession;
- /** @var OCSClient|\PHPUnit_Framework_MockObject_MockObject */
- private $ocsClient;
-
- protected function setUp() {
- parent::setUp();
-
- $this->appManager = \OC::$server->getAppManager();
- $this->groupManager = \OC::$server->getGroupManager();
- $this->userSession = \OC::$server->getUserSession();
- $this->ocsClient = $this->getMockBuilder('OC\OCSClient')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->api = new Apps($this->appManager, $this->ocsClient);
- }
-
- public function testGetAppInfo() {
- $result = $this->api->getAppInfo(['appid' => 'provisioning_api']);
- $this->assertInstanceOf('\OC\OCS\Result', $result);
- $this->assertTrue($result->succeeded());
- }
-
- public function testGetAppInfoOnBadAppID() {
- $result = $this->api->getAppInfo(['appid' => 'not_provisioning_api']);
- $this->assertInstanceOf('\OC\OCS\Result', $result);
- $this->assertFalse($result->succeeded());
- $this->assertEquals(API::RESPOND_NOT_FOUND, $result->getStatusCode());
- }
-
- public function testGetApps() {
- $this->ocsClient
- ->expects($this->any())
- ->method($this->anything())
- ->will($this->returnValue(null));
- $user = $this->generateUsers();
- $this->groupManager->get('admin')->addUser($user);
- $this->userSession->setUser($user);
-
- $result = $this->api->getApps([]);
-
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals(count(\OC_App::listAllApps(false, true, $this->ocsClient)), count($data['apps']));
- }
-
- public function testGetAppsEnabled() {
- $_GET['filter'] = 'enabled';
- $result = $this->api->getApps(['filter' => 'enabled']);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps']));
- }
-
- public function testGetAppsDisabled() {
- $this->ocsClient
- ->expects($this->any())
- ->method($this->anything())
- ->will($this->returnValue(null));
- $_GET['filter'] = 'disabled';
- $result = $this->api->getApps(['filter' => 'disabled']);
- $this->assertTrue($result->succeeded());
- $data = $result->getData();
- $apps = \OC_App::listAllApps(false, true, $this->ocsClient);
- $list = array();
- foreach($apps as $app) {
- $list[] = $app['id'];
- }
- $disabled = array_diff($list, \OC_App::getEnabledApps());
- $this->assertEquals(count($disabled), count($data['apps']));
- }
-
- public function testGetAppsInvalidFilter() {
- $_GET['filter'] = 'foo';
- $result = $this->api->getApps([]);
- $this->assertFalse($result->succeeded());
- $this->assertEquals(101, $result->getStatusCode());
- }
-}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Tom Needham <tom@owncloud.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Provisioning_API\Tests\Controller;
+
+
+use OC\OCSClient;
+use OCA\Provisioning_API\Controller\AppsController;
+use OCP\API;
+use OCP\App\IAppManager;
+use OCP\IUserSession;
+
+/**
+ * Class AppsTest
+ *
+ * @group DB
+ *
+ * @package OCA\Provisioning_API\Tests
+ */
+class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
+ /** @var IAppManager */
+ private $appManager;
+ /** @var AppsController */
+ private $api;
+ /** @var IUserSession */
+ private $userSession;
+ /** @var OCSClient|\PHPUnit_Framework_MockObject_MockObject */
+ private $ocsClient;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->appManager = \OC::$server->getAppManager();
+ $this->groupManager = \OC::$server->getGroupManager();
+ $this->userSession = \OC::$server->getUserSession();
+ $this->ocsClient = $this->getMockBuilder('OC\OCSClient')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $request = $this->getMockBuilder('OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->api = new AppsController(
+ 'provisioning_api',
+ $request,
+ $this->appManager,
+ $this->ocsClient
+ );
+ }
+
+ public function testGetAppInfo() {
+ $result = $this->api->getAppInfo('provisioning_api');
+ $expected = \OC_App::getAppInfo('provisioning_api');
+ $this->assertEquals($expected, $result->getData());
+ }
+
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSException
+ * @expectedExceptionCode 998
+ */
+ public function testGetAppInfoOnBadAppID() {
+ $this->api->getAppInfo('not_provisioning_api');
+ }
+
+ public function testGetApps() {
+ $this->ocsClient
+ ->expects($this->any())
+ ->method($this->anything())
+ ->will($this->returnValue(null));
+ $user = $this->generateUsers();
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
+
+ $result = $this->api->getApps();
+
+ $data = $result->getData();
+ $this->assertEquals(count(\OC_App::listAllApps(false, true, $this->ocsClient)), count($data['apps']));
+ }
+
+ public function testGetAppsEnabled() {
+ $result = $this->api->getApps('enabled');
+ $data = $result->getData();
+ $this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps']));
+ }
+
+ public function testGetAppsDisabled() {
+ $this->ocsClient
+ ->expects($this->any())
+ ->method($this->anything())
+ ->will($this->returnValue(null));
+ $result = $this->api->getApps('disabled');
+ $data = $result->getData();
+ $apps = \OC_App::listAllApps(false, true, $this->ocsClient);
+ $list = array();
+ foreach($apps as $app) {
+ $list[] = $app['id'];
+ }
+ $disabled = array_diff($list, \OC_App::getEnabledApps());
+ $this->assertEquals(count($disabled), count($data['apps']));
+ }
+
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSException
+ * @expectedExceptionCode 101
+ */
+ public function testGetAppsInvalidFilter() {
+ $this->api->getApps('foo');
+ }
+}