Commit fe8d45e3 authored by Thomas Müller's avatar Thomas Müller Committed by GitHub
Browse files

Drop apps management - use the market app. In addition there is an admin...

Drop apps management - use the market app. In addition there is an admin section for local app mgmt (#26763)
parent e4070574
...@@ -68,10 +68,7 @@ API::register('delete', '/cloud/groups/{groupid}', [$groups, 'deleteGroup'], 'pr ...@@ -68,10 +68,7 @@ API::register('delete', '/cloud/groups/{groupid}', [$groups, 'deleteGroup'], 'pr
API::register('get', '/cloud/groups/{groupid}/subadmins', [$groups, 'getSubAdminsOfGroup'], 'provisioning_api', API::ADMIN_AUTH); API::register('get', '/cloud/groups/{groupid}/subadmins', [$groups, 'getSubAdminsOfGroup'], 'provisioning_api', API::ADMIN_AUTH);
// Apps // Apps
$apps = new Apps( $apps = new Apps(\OC::$server->getAppManager());
\OC::$server->getAppManager(),
\OC::$server->getOcsClient()
);
API::register('get', '/cloud/apps', [$apps, 'getApps'], 'provisioning_api', API::ADMIN_AUTH); 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('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('post', '/cloud/apps/{appid}', [$apps, 'enable'], 'provisioning_api', API::ADMIN_AUTH);
......
...@@ -25,23 +25,18 @@ ...@@ -25,23 +25,18 @@
namespace OCA\Provisioning_API; namespace OCA\Provisioning_API;
use OC\OCSClient;
use \OC_OCS_Result; use \OC_OCS_Result;
use \OC_App; use \OC_App;
class Apps { class Apps {
/** @var \OCP\App\IAppManager */ /** @var \OCP\App\IAppManager */
private $appManager; private $appManager;
/** @var OCSClient */
private $ocsClient;
/** /**
* @param \OCP\App\IAppManager $appManager * @param \OCP\App\IAppManager $appManager
*/ */
public function __construct(\OCP\App\IAppManager $appManager, public function __construct(\OCP\App\IAppManager $appManager) {
OCSClient $ocsClient) {
$this->appManager = $appManager; $this->appManager = $appManager;
$this->ocsClient = $ocsClient;
} }
/** /**
...@@ -49,7 +44,7 @@ class Apps { ...@@ -49,7 +44,7 @@ class Apps {
* @return OC_OCS_Result * @return OC_OCS_Result
*/ */
public function getApps($parameters) { public function getApps($parameters) {
$apps = OC_App::listAllApps(false, true, $this->ocsClient); $apps = OC_App::listAllApps(false, true);
$list = []; $list = [];
foreach($apps as $app) { foreach($apps as $app) {
$list[] = $app['id']; $list[] = $app['id'];
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
namespace OCA\Provisioning_API\Tests; namespace OCA\Provisioning_API\Tests;
use OC\OCSClient;
use OCA\Provisioning_API\Apps; use OCA\Provisioning_API\Apps;
use OCP\API; use OCP\API;
use OCP\App\IAppManager; use OCP\App\IAppManager;
...@@ -47,8 +46,6 @@ class AppsTest extends TestCase { ...@@ -47,8 +46,6 @@ class AppsTest extends TestCase {
private $api; private $api;
/** @var IUserSession */ /** @var IUserSession */
private $userSession; private $userSession;
/** @var OCSClient|\PHPUnit_Framework_MockObject_MockObject */
private $ocsClient;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
...@@ -56,11 +53,7 @@ class AppsTest extends TestCase { ...@@ -56,11 +53,7 @@ class AppsTest extends TestCase {
$this->appManager = \OC::$server->getAppManager(); $this->appManager = \OC::$server->getAppManager();
$this->groupManager = \OC::$server->getGroupManager(); $this->groupManager = \OC::$server->getGroupManager();
$this->userSession = \OC::$server->getUserSession(); $this->userSession = \OC::$server->getUserSession();
$this->ocsClient = $this->getMockBuilder('OC\OCSClient') $this->api = new Apps($this->appManager);
->disableOriginalConstructor()
->getMock();
$this->api = new Apps($this->appManager, $this->ocsClient);
} }
public function testGetAppInfo() { public function testGetAppInfo() {
...@@ -77,10 +70,6 @@ class AppsTest extends TestCase { ...@@ -77,10 +70,6 @@ class AppsTest extends TestCase {
} }
public function testGetApps() { public function testGetApps() {
$this->ocsClient
->expects($this->any())
->method($this->anything())
->will($this->returnValue(null));
$user = $this->generateUsers(); $user = $this->generateUsers();
$this->groupManager->get('admin')->addUser($user); $this->groupManager->get('admin')->addUser($user);
$this->userSession->setUser($user); $this->userSession->setUser($user);
...@@ -89,7 +78,7 @@ class AppsTest extends TestCase { ...@@ -89,7 +78,7 @@ class AppsTest extends TestCase {
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
$data = $result->getData(); $data = $result->getData();
$this->assertEquals(count(\OC_App::listAllApps(false, true, $this->ocsClient)), count($data['apps'])); $this->assertEquals(count(\OC_App::listAllApps(false, true)), count($data['apps']));
} }
public function testGetAppsEnabled() { public function testGetAppsEnabled() {
...@@ -101,15 +90,11 @@ class AppsTest extends TestCase { ...@@ -101,15 +90,11 @@ class AppsTest extends TestCase {
} }
public function testGetAppsDisabled() { public function testGetAppsDisabled() {
$this->ocsClient
->expects($this->any())
->method($this->anything())
->will($this->returnValue(null));
$_GET['filter'] = 'disabled'; $_GET['filter'] = 'disabled';
$result = $this->api->getApps(['filter' => 'disabled']); $result = $this->api->getApps(['filter' => 'disabled']);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
$data = $result->getData(); $data = $result->getData();
$apps = \OC_App::listAllApps(false, true, $this->ocsClient); $apps = \OC_App::listAllApps(false, true);
$list = []; $list = [];
foreach($apps as $app) { foreach($apps as $app) {
$list[] = $app['id']; $list[] = $app['id'];
......
...@@ -81,7 +81,6 @@ class BackgroundJob extends TimedJob { ...@@ -81,7 +81,6 @@ class BackgroundJob extends TimedJob {
protected function run($argument) { protected function run($argument) {
$this->checkCoreUpdate(); $this->checkCoreUpdate();
$this->checkAppUpdates();
} }
/** /**
...@@ -102,20 +101,6 @@ class BackgroundJob extends TimedJob { ...@@ -102,20 +101,6 @@ class BackgroundJob extends TimedJob {
} }
} }
/**
* Check all installed apps for updates
*/
protected function checkAppUpdates() {
$apps = $this->appManager->getInstalledApps();
foreach ($apps as $app) {
$update = $this->isUpdateAvailable($app);
if ($update !== false) {
$url = $this->urlGenerator->linkToRouteAbsolute('settings.AppSettings.viewApps') . '#app-' . $app;
$this->createNotifications($app, $update, $url);
}
}
}
/** /**
* Create notifications for this app version * Create notifications for this app version
* *
...@@ -202,12 +187,4 @@ class BackgroundJob extends TimedJob { ...@@ -202,12 +187,4 @@ class BackgroundJob extends TimedJob {
protected function getChannel() { protected function getChannel() {
return \OC_Util::getChannel(); return \OC_Util::getChannel();
} }
/**
* @param string $app
* @return string|false
*/
protected function isUpdateAvailable($app) {
return Installer::isUpdateAvailable($app);
}
} }
...@@ -88,15 +88,10 @@ class BackgroundJobTest extends TestCase { ...@@ -88,15 +88,10 @@ class BackgroundJobTest extends TestCase {
} }
public function testRun() { public function testRun() {
$job = $this->getJob([ $job = $this->getJob(['checkCoreUpdate']);
'checkCoreUpdate',
'checkAppUpdates',
]);
$job->expects($this->once()) $job->expects($this->once())
->method('checkCoreUpdate'); ->method('checkCoreUpdate');
$job->expects($this->once())
->method('checkAppUpdates');
$this->invokePrivate($job, 'run', [null]); $this->invokePrivate($job, 'run', [null]);
} }
...@@ -174,54 +169,6 @@ class BackgroundJobTest extends TestCase { ...@@ -174,54 +169,6 @@ class BackgroundJobTest extends TestCase {
$this->invokePrivate($job, 'checkCoreUpdate'); $this->invokePrivate($job, 'checkCoreUpdate');
} }
public function dataCheckAppUpdates() {
return [
[
['app1', 'app2'],
[
['app1', false],
['app2', '1.9.2'],
],
[
['app2', '1.9.2', 'apps-url#app-app2'],
],
],
];
}
/**
* @dataProvider dataCheckAppUpdates
*
* @param string[] $apps
* @param array $isUpdateAvailable
* @param array $notifications
*/
public function testCheckAppUpdates(array $apps, array $isUpdateAvailable, array $notifications) {
$job = $this->getJob([
'isUpdateAvailable',
'createNotifications',
]);
$this->appManager->expects($this->once())
->method('getInstalledApps')
->willReturn($apps);
$job->expects($this->exactly(sizeof($apps)))
->method('isUpdateAvailable')
->willReturnMap($isUpdateAvailable);
$this->urlGenerator->expects($this->exactly(sizeof($notifications)))
->method('linkToRouteAbsolute')
->with('settings.AppSettings.viewApps')
->willReturn('apps-url');
$mockedMethod = $job->expects($this->exactly(sizeof($notifications)))
->method('createNotifications');
call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
$this->invokePrivate($job, 'checkAppUpdates');
}
public function dataCreateNotifications() { public function dataCreateNotifications() {
return [ return [
['app1', '1.0.0', 'link1', '1.0.0', false, false, null, null], ['app1', '1.0.0', 'link1', '1.0.0', false, false, null, null],
......
...@@ -122,22 +122,6 @@ ...@@ -122,22 +122,6 @@
</a> </a>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
<?php
/* show "More apps" link to app administration directly in app navigation, as last entry */
if(OC_User::isAdminUser(OC_User::getUser())):
?>
<li id="apps-management">
<a href="<?php print_unescaped(\OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')); ?>" tabindex="4"
<?php if( $_['appsmanagement_active'] ): ?> class="active"<?php endif; ?>>
<img class="app-icon" alt="" src="<?php print_unescaped(image_path('settings', 'apps.svg')); ?>">
<div class="icon-loading-dark" style="display:none;"></div>
<span>
<?php p($l->t('Apps')); ?>
</span>
</a>
</li>
<?php endif; ?>
</ul> </ul>
</div> </div>
</div></nav> </div></nav>
......
...@@ -238,36 +238,6 @@ class Installer { ...@@ -238,36 +238,6 @@ class Installer {
return OC_App::updateApp($info['id']); return OC_App::updateApp($info['id']);
} }
/**
* update an app by it's id
*
* @param integer $ocsId
* @return bool
* @throws \Exception
*/
public static function updateAppByOCSId($ocsId) {
$ocsClient = new OCSClient(
\OC::$server->getHTTPClientService(),
\OC::$server->getConfig(),
\OC::$server->getLogger()
);
$appData = $ocsClient->getApplication($ocsId, \OCP\Util::getVersion());
$download = $ocsClient->getApplicationDownload($ocsId, \OCP\Util::getVersion());
if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') {
$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
$info = [
'source' => 'http',
'href' => $download['downloadlink'],
'appdata' => $appData
];
} else {
throw new \Exception('Could not fetch app info!');
}
return self::updateApp($info);
}
/** /**
* @param array $data * @param array $data
* @return array * @return array
...@@ -417,52 +387,6 @@ class Installer { ...@@ -417,52 +387,6 @@ class Installer {
return $info; return $info;
} }
/**
* Check if an update for the app is available
* @param string $app
* @return string|false false or the version number of the update
*
* The function will check if an update for a version is available
*/
public static function isUpdateAvailable( $app ) {
static $isInstanceReadyForUpdates = null;
if ($isInstanceReadyForUpdates === null) {
$installPath = OC_App::getInstallPath();
if ($installPath === false || $installPath === null) {
$isInstanceReadyForUpdates = false;
} else {
$isInstanceReadyForUpdates = true;
}
}
if ($isInstanceReadyForUpdates === false) {
return false;
}
$ocsid=\OC::$server->getAppConfig()->getValue( $app, 'ocsid', '');
if($ocsid<>'') {
$ocsClient = new OCSClient(
\OC::$server->getHTTPClientService(),
\OC::$server->getConfig(),
\OC::$server->getLogger()
);
$ocsdata = $ocsClient->getApplication($ocsid, \OCP\Util::getVersion());
$ocsversion= (string) $ocsdata['version'];
$currentversion=OC_App::getAppVersion($app);
if (version_compare($ocsversion, $currentversion, '>')) {
return($ocsversion);
}else{
return false;
}
}else{
return false;
}
}
/** /**
* Check if app is already downloaded * Check if app is already downloaded
* @param string $name name of the application to remove * @param string $name name of the application to remove
......
<?php
/**
* @author Bart Visscher <bartv@thisnet.nl>
* @author Brice Maron <brice@bmaron.net>
* @author Felix Moeller <mail@felixmoeller.de>
* @author Frank Karlitschek <frank@karlitschek.de>
* @author Jarrett <JetUni@users.noreply.github.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Kamil Domanski <kdomanski@kdemail.net>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin McCorkell <robin@mccorkell.me.uk>
* @author Sam Tuke <mail@samtuke.com>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
* @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 OC;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ILogger;
/**
* Class OCSClient is a class for communication with the ownCloud appstore
*
* @package OC
*/
class OCSClient {
/** @var IClientService */
private $httpClientService;
/** @var IConfig */
private $config;
/** @var ILogger */
private $logger;
/**
* @param IClientService $httpClientService
* @param IConfig $config
* @param ILogger $logger
*/
public function __construct(IClientService $httpClientService,
IConfig $config,
ILogger $logger) {
$this->httpClientService = $httpClientService;
$this->config = $config;
$this->logger = $logger;
}
/**
* Returns whether the AppStore is enabled (i.e. because the AppStore is disabled for EE)
*
* @return bool
*/
public function isAppStoreEnabled() {
// For a regular edition default to true, all others default to false
$default = false;
if (\OC_Util::getEditionString() === '') {
$default = true;
}
return $this->config->getSystemValue('appstoreenabled', $default) === true;
}
/**
* Get the url of the OCS AppStore server.
*
* @return string of the AppStore server
*/
private function getAppStoreUrl() {
return $this->config->getSystemValue('appstoreurl', 'https://api.owncloud.com/v1');
}
/**
* @param string $body
* @param string $action
* @return null|\SimpleXMLElement
*/
private function loadData($body, $action) {
$loadEntities = libxml_disable_entity_loader(true);
$data = @simplexml_load_string($body);
libxml_disable_entity_loader($loadEntities);
if($data === false) {
libxml_clear_errors();
$this->logger->error(
sprintf('Could not get %s, content was no valid XML', $action),
[
'app' => 'core',
]
);
return null;
}
return $data;
}
/**
* Get all the categories from the OCS server
*
* @param array $targetVersion The target ownCloud version
* @return array|null an array of category ids or null
* @note returns NULL if config value appstoreenabled is set to false
* This function returns a list of all the application categories on the OCS server
*/
public function getCategories(array $targetVersion) {
if (!$this->isAppStoreEnabled()) {
return null;
}
$client = $this->httpClientService->newClient();
try {
$response = $client->get(
$this->getAppStoreUrl() . '/content/categories',
[
'timeout' => 20,
'query' => [
'version' => implode('x', $targetVersion),
],
]
);
} catch(\Exception $e) {
$this->logger->error(
sprintf('Could not get categories: %s', $e->getMessage()),
[
'app' => 'core',
]
);
return null;
}
$data = $this->loadData($response->getBody(), 'categories');
if($data === null) {
return null;
}
$tmp = $data->data;
$cats = [];
foreach ($tmp->category as $value) {
$id = (int)$value->id;
$name = (string)$value->name;
$cats[$id] = $name;
}
return $cats;
}
/**
* Get all the applications from the OCS server
* @param array $categories
* @param int $page
* @param string $filter
* @param array $targetVersion The target ownCloud version
* @return array An array of application data
*/
public function getApplications(array $categories, $page, $filter, array $targetVersion) {
if (!$this->isAppStoreEnabled()) {
return [];