Skip to content

Commit

Permalink
Merge pull request #1940 from nextcloud/new-appstore
Browse files Browse the repository at this point in the history
Use new appstore API
  • Loading branch information
stp-ip authored Nov 2, 2016
2 parents 23dd62b + 0eeef26 commit e81d04c
Show file tree
Hide file tree
Showing 46 changed files with 2,228 additions and 2,556 deletions.
3 changes: 2 additions & 1 deletion apps/files_sharing/tests/UpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ protected function tearDown() {
*/
function testDeleteParentFolder() {
$status = \OC_App::isEnabled('files_trashbin');
\OC_App::enable('files_trashbin');
(new \OC_App())->enable('files_trashbin');


\OCA\Files_Trashbin\Trashbin::registerHooks();

Expand Down
9 changes: 2 additions & 7 deletions apps/provisioning_api/lib/Controller/AppsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,20 @@
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
IAppManager $appManager
) {
parent::__construct($appName, $request);

$this->appManager = $appManager;
$this->ocsClient = $ocsClient;
}

/**
Expand All @@ -64,7 +59,7 @@ public function __construct(
* @throws OCSException
*/
public function getApps($filter = null) {
$apps = OC_App::listAllApps(false, true, $this->ocsClient);
$apps = (new OC_App())->listAllApps();
$list = [];
foreach($apps as $app) {
$list[] = $app['id'];
Expand Down
20 changes: 3 additions & 17 deletions apps/provisioning_api/tests/Controller/AppsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
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()
Expand All @@ -68,8 +63,7 @@ protected function setUp() {
$this->api = new AppsController(
'provisioning_api',
$request,
$this->appManager,
$this->ocsClient
$this->appManager
);
}

Expand All @@ -88,18 +82,14 @@ public function testGetAppInfoOnBadAppID() {
}

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']));
$this->assertEquals(count((new \OC_App())->listAllApps()), count($data['apps']));
}

public function testGetAppsEnabled() {
Expand All @@ -109,13 +99,9 @@ public function testGetAppsEnabled() {
}

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);
$apps = (new \OC_App)->listAllApps();
$list = array();
foreach($apps as $app) {
$list[] = $app['id'];
Expand Down
3 changes: 1 addition & 2 deletions apps/updatenotification/lib/Notification/BackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace OCA\UpdateNotification\Notification;


use OC\BackgroundJob\TimedJob;
use OC\Installer;
use OC\Updater\VersionCheck;
Expand Down Expand Up @@ -215,6 +214,6 @@ protected function getChannel() {
* @return string|false
*/
protected function isUpdateAvailable($app) {
return Installer::isUpdateAvailable($app);
return Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher());
}
}
14 changes: 0 additions & 14 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,20 +673,6 @@
*/
'appstoreenabled' => true,

/**
* The URL of the appstore to use.
*/
'appstoreurl' => 'https://api.owncloud.com/v1',

/**
* Whether to show experimental apps in the appstore interface
*
* Experimental apps are not checked for security issues and are new or known
* to be unstable and under heavy development. Installing these can cause data
* loss or security breaches.
*/
'appstore.experimental.enabled' => false,

/**
* Use the ``apps_paths`` parameter to set the location of the Apps directory,
* which should be scanned for available apps, and where user-specific apps
Expand Down
5 changes: 3 additions & 2 deletions core/Command/App/Enable.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
}

$groups = $input->getOption('groups');
$appClass = new \OC_App();
if (empty($groups)) {
\OC_App::enable($appId);
$appClass->enable($appId);
$output->writeln($appId . ' enabled');
} else {
\OC_App::enable($appId, $groups);
$appClass->enable($appId, $groups);
$output->writeln($appId . ' enabled for groups: ' . implode(', ', $groups));
}
return 0;
Expand Down
6 changes: 5 additions & 1 deletion lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
'OC\\AppFramework\\Utility\\TimeFactory' => $baseDir . '/lib/private/AppFramework/Utility/TimeFactory.php',
'OC\\AppHelper' => $baseDir . '/lib/private/AppHelper.php',
'OC\\App\\AppManager' => $baseDir . '/lib/private/App/AppManager.php',
'OC\\App\\AppStore\\Fetcher\\AppFetcher' => $baseDir . '/lib/private/App/AppStore/Fetcher/AppFetcher.php',
'OC\\App\\AppStore\\Fetcher\\CategoryFetcher' => $baseDir . '/lib/private/App/AppStore/Fetcher/CategoryFetcher.php',
'OC\\App\\AppStore\\Fetcher\\Fetcher' => $baseDir . '/lib/private/App/AppStore/Fetcher/Fetcher.php',
'OC\\App\\AppStore\\Version\\Version' => $baseDir . '/lib/private/App/AppStore/Version/Version.php',
'OC\\App\\AppStore\\Version\\VersionParser' => $baseDir . '/lib/private/App/AppStore/Version/VersionParser.php',
'OC\\App\\CodeChecker\\AbstractCheck' => $baseDir . '/lib/private/App/CodeChecker/AbstractCheck.php',
'OC\\App\\CodeChecker\\CodeChecker' => $baseDir . '/lib/private/App/CodeChecker/CodeChecker.php',
'OC\\App\\CodeChecker\\DeprecationCheck' => $baseDir . '/lib/private/App/CodeChecker/DeprecationCheck.php',
Expand Down Expand Up @@ -602,7 +607,6 @@
'OC\\Notification\\Action' => $baseDir . '/lib/private/Notification/Action.php',
'OC\\Notification\\Manager' => $baseDir . '/lib/private/Notification/Manager.php',
'OC\\Notification\\Notification' => $baseDir . '/lib/private/Notification/Notification.php',
'OC\\OCSClient' => $baseDir . '/lib/private/OCSClient.php',
'OC\\OCS\\CoreCapabilities' => $baseDir . '/lib/private/OCS/CoreCapabilities.php',
'OC\\OCS\\Exception' => $baseDir . '/lib/private/OCS/Exception.php',
'OC\\OCS\\Person' => $baseDir . '/lib/private/OCS/Person.php',
Expand Down
6 changes: 5 additions & 1 deletion lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\AppFramework\\Utility\\TimeFactory' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/TimeFactory.php',
'OC\\AppHelper' => __DIR__ . '/../../..' . '/lib/private/AppHelper.php',
'OC\\App\\AppManager' => __DIR__ . '/../../..' . '/lib/private/App/AppManager.php',
'OC\\App\\AppStore\\Fetcher\\AppFetcher' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Fetcher/AppFetcher.php',
'OC\\App\\AppStore\\Fetcher\\CategoryFetcher' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Fetcher/CategoryFetcher.php',
'OC\\App\\AppStore\\Fetcher\\Fetcher' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Fetcher/Fetcher.php',
'OC\\App\\AppStore\\Version\\Version' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Version/Version.php',
'OC\\App\\AppStore\\Version\\VersionParser' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Version/VersionParser.php',
'OC\\App\\CodeChecker\\AbstractCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/AbstractCheck.php',
'OC\\App\\CodeChecker\\CodeChecker' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/CodeChecker.php',
'OC\\App\\CodeChecker\\DeprecationCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/DeprecationCheck.php',
Expand Down Expand Up @@ -632,7 +637,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Notification\\Action' => __DIR__ . '/../../..' . '/lib/private/Notification/Action.php',
'OC\\Notification\\Manager' => __DIR__ . '/../../..' . '/lib/private/Notification/Manager.php',
'OC\\Notification\\Notification' => __DIR__ . '/../../..' . '/lib/private/Notification/Notification.php',
'OC\\OCSClient' => __DIR__ . '/../../..' . '/lib/private/OCSClient.php',
'OC\\OCS\\CoreCapabilities' => __DIR__ . '/../../..' . '/lib/private/OCS/CoreCapabilities.php',
'OC\\OCS\\Exception' => __DIR__ . '/../../..' . '/lib/private/OCS/Exception.php',
'OC\\OCS\\Person' => __DIR__ . '/../../..' . '/lib/private/OCS/Person.php',
Expand Down
56 changes: 56 additions & 0 deletions lib/private/App/AppStore/Fetcher/AppFetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
*
* @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 OC\App\AppStore\Fetcher;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Http\Client\IClientService;
use OCP\IConfig;

class AppFetcher extends Fetcher {
/**
* @param IAppData $appData
* @param IClientService $clientService
* @param ITimeFactory $timeFactory
* @param IConfig $config;
*/
public function __construct(IAppData $appData,
IClientService $clientService,
ITimeFactory $timeFactory,
IConfig $config) {
parent::__construct(
$appData,
$clientService,
$timeFactory
);

$this->fileName = 'apps.json';

$versionArray = \OC_Util::getVersion();
$this->endpointUrl = sprintf(
'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json',
$versionArray[0],
$versionArray[1],
$versionArray[2]
);
}
}
45 changes: 45 additions & 0 deletions lib/private/App/AppStore/Fetcher/CategoryFetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
*
* @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 OC\App\AppStore\Fetcher;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Http\Client\IClientService;

class CategoryFetcher extends Fetcher {
/**
* @param IAppData $appData
* @param IClientService $clientService
* @param ITimeFactory $timeFactory
*/
public function __construct(IAppData $appData,
IClientService $clientService,
ITimeFactory $timeFactory) {
parent::__construct(
$appData,
$clientService,
$timeFactory
);
$this->fileName = 'categories.json';
$this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json';
}
}
92 changes: 92 additions & 0 deletions lib/private/App/AppStore/Fetcher/Fetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
*
* @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 OC\App\AppStore\Fetcher;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Http\Client\IClientService;

abstract class Fetcher {
const INVALIDATE_AFTER_SECONDS = 300;

/** @var IAppData */
private $appData;
/** @var IClientService */
private $clientService;
/** @var ITimeFactory */
private $timeFactory;
/** @var string */
protected $fileName;
/** @var string */
protected $endpointUrl;

/**
* @param IAppData $appData
* @param IClientService $clientService
* @param ITimeFactory $timeFactory
*/
public function __construct(IAppData $appData,
IClientService $clientService,
ITimeFactory $timeFactory) {
$this->appData = $appData;
$this->clientService = $clientService;
$this->timeFactory = $timeFactory;
}

/**
* Returns the array with the categories on the appstore server
*
* @return array
*/
public function get() {
$rootFolder = $this->appData->getFolder('/');

try {
// File does already exists
$file = $rootFolder->getFile($this->fileName);
$jsonBlob = json_decode($file->getContent(), true);
if(is_array($jsonBlob)) {
// If the timestamp is older than 300 seconds request the files new
if((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
return $jsonBlob['data'];
}
}
} catch (NotFoundException $e) {
// File does not already exists
$file = $rootFolder->newFile($this->fileName);
}

// Refresh the file content
$client = $this->clientService->newClient();
try {
$response = $client->get($this->endpointUrl);
$responseJson = [];
$responseJson['data'] = json_decode($response->getBody(), true);
$responseJson['timestamp'] = $this->timeFactory->getTime();
$file->putContent(json_encode($responseJson));
return json_decode($file->getContent(), true)['data'];
} catch (\Exception $e) {
return [];
}
}
}
Loading

0 comments on commit e81d04c

Please sign in to comment.