Browse Source

[provisioning_api] Move part of apps to OCP

tags/v8.2beta1
Roeland Jago Douma 9 years ago
parent
commit
a4822f9f9a

+ 3
- 1
apps/provisioning_api/appinfo/routes.php View File

@@ -56,7 +56,9 @@ API::register('delete', '/cloud/groups/{groupid}', [$groups, 'deleteGroup'], 'pr
API::register('get', '/cloud/groups/{groupid}/subadmins', [$groups, 'getSubAdminsOfGroup'], 'provisioning_api', API::ADMIN_AUTH);

// Apps
$apps = new \OCA\Provisioning_API\Apps();
$apps = new \OCA\Provisioning_API\Apps(
\OC::$server->getAppManager()
);
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);

+ 14
- 7
apps/provisioning_api/lib/apps.php View File

@@ -28,7 +28,14 @@ use \OC_App;

class Apps {

public static function getApps($parameters){
/** @var \OCP\App\IAppManager */
private $appManager;

public function __construct(\OCP\App\IAppManager $appManager) {
$this->appManager = $appManager;
}

public function getApps($parameters){
$apps = OC_App::listAllApps();
$list = array();
foreach($apps as $app) {
@@ -55,9 +62,9 @@ class Apps {
}
}

public static function getAppInfo($parameters){
public function getAppInfo($parameters){
$app = $parameters['appid'];
$info = OC_App::getAppInfo($app);
$info = \OCP\App::getAppInfo($app);
if(!is_null($info)) {
return new OC_OCS_Result(OC_App::getAppInfo($app));
} else {
@@ -65,15 +72,15 @@ class Apps {
}
}

public static function enable($parameters){
public function enable($parameters){
$app = $parameters['appid'];
OC_App::enable($app);
$this->appManager->enableApp($app);
return new OC_OCS_Result(null, 100);
}

public static function disable($parameters){
public function disable($parameters){
$app = $parameters['appid'];
OC_App::disable($app);
$this->appManager->disableApp($app);
return new OC_OCS_Result(null, 100);
}


+ 12
- 5
apps/provisioning_api/tests/appstest.php View File

@@ -25,8 +25,15 @@
namespace OCA\Provisioning_API\Tests;

class AppsTest extends TestCase {
public function setup() {
parent::setup();
$this->appManager = \OC::$server->getAppManager();
$this->api = new \OCA\Provisioning_API\Apps($this->appManager);
}

public function testGetAppInfo() {
$result = \OCA\provisioning_API\Apps::getAppInfo(array('appid' => 'provisioning_api'));
$result = $this->api->getAppInfo(['appid' => 'provisioning_api']);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());

@@ -34,7 +41,7 @@ class AppsTest extends TestCase {

public function testGetAppInfoOnBadAppID() {

$result = \OCA\provisioning_API\Apps::getAppInfo(array('appid' => 'not_provisioning_api'));
$result = $this->api->getAppInfo(['appid' => 'not_provisioning_api']);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(\OCP\API::RESPOND_NOT_FOUND, $result->getStatusCode());
@@ -47,7 +54,7 @@ class AppsTest extends TestCase {
\OC_Group::addToGroup($user, 'admin');
self::loginAsUser($user);

$result = \OCA\provisioning_API\Apps::getApps(array());
$result = $this->api->getApps([]);

$this->assertTrue($result->succeeded());
$data = $result->getData();
@@ -58,7 +65,7 @@ class AppsTest extends TestCase {
public function testGetAppsEnabled() {

$_GET['filter'] = 'enabled';
$result = \OCA\provisioning_API\Apps::getApps(array('filter' => 'enabled'));
$result = $this->api->getApps(['filter' => 'enabled']);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps']));
@@ -68,7 +75,7 @@ class AppsTest extends TestCase {
public function testGetAppsDisabled() {

$_GET['filter'] = 'disabled';
$result = \OCA\provisioning_API\Apps::getApps(array('filter' => 'disabled'));
$result = $this->api->getApps(['filter' => 'disabled']);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$apps = \OC_App::listAllApps();

Loading…
Cancel
Save