fix: Do not enable applications which are not installed yet

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/53352/head
Côme Chilliet 4 months ago
parent d6a53ceab0
commit bf340a576f
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
  1. 13
      apps/provisioning_api/lib/Controller/AppsController.php
  2. 11
      apps/provisioning_api/tests/Controller/AppsControllerTest.php
  3. 9
      lib/private/App/AppManager.php

@ -8,6 +8,7 @@ declare(strict_types=1);
*/
namespace OCA\Provisioning_API\Controller;
use OC\Installer;
use OC_App;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
@ -16,6 +17,7 @@ use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCSController;
use OCP\IAppConfig;
use OCP\IRequest;
class AppsController extends OCSController {
@ -23,6 +25,8 @@ class AppsController extends OCSController {
string $appName,
IRequest $request,
private IAppManager $appManager,
private Installer $installer,
private IAppConfig $appConfig,
) {
parent::__construct($appName, $request);
}
@ -108,6 +112,15 @@ class AppsController extends OCSController {
public function enable(string $app): DataResponse {
try {
$app = $this->verifyAppId($app);
if (!$this->installer->isDownloaded($app)) {
$this->installer->downloadApp($app);
}
if ($this->appConfig->getValueString($app, 'installed_version', '') === '') {
$this->installer->installApp($app);
}
$this->appManager->enableApp($app);
} catch (\InvalidArgumentException $e) {
throw new OCSException($e->getMessage(), OCSController::RESPOND_UNAUTHORISED);

@ -7,14 +7,17 @@
*/
namespace OCA\Provisioning_API\Tests\Controller;
use OC\Installer;
use OCA\Provisioning_API\Controller\AppsController;
use OCA\Provisioning_API\Tests\TestCase;
use OCP\App\IAppManager;
use OCP\AppFramework\OCS\OCSException;
use OCP\IAppConfig;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Class AppsTest
@ -25,6 +28,8 @@ use OCP\Server;
*/
class AppsControllerTest extends TestCase {
private IAppManager $appManager;
private IAppConfig&MockObject $appConfig;
private Installer&MockObject $installer;
private AppsController $api;
private IUserSession $userSession;
@ -34,13 +39,17 @@ class AppsControllerTest extends TestCase {
$this->appManager = Server::get(IAppManager::class);
$this->groupManager = Server::get(IGroupManager::class);
$this->userSession = Server::get(IUserSession::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->installer = $this->createMock(Installer::class);
$request = $this->createMock(IRequest::class);
$this->api = new AppsController(
'provisioning_api',
$request,
$this->appManager
$this->appManager,
$this->installer,
$this->appConfig,
);
}

@ -545,11 +545,16 @@ class AppManager implements IAppManager {
* @param string $appId
* @param bool $forceEnable
* @throws AppPathNotFoundException
* @throws \InvalidArgumentException if the application is not installed yet
*/
public function enableApp(string $appId, bool $forceEnable = false): void {
// Check if app exists
$this->getAppPath($appId);
if ($this->config->getAppValue($appId, 'installed_version', '') === '') {
throw new \InvalidArgumentException("$appId is not installed, cannot be enabled.");
}
if ($forceEnable) {
$this->overwriteNextcloudRequirement($appId);
}
@ -596,6 +601,10 @@ class AppManager implements IAppManager {
throw new \InvalidArgumentException("$appId can't be enabled for groups.");
}
if ($this->config->getAppValue($appId, 'installed_version', '') === '') {
throw new \InvalidArgumentException("$appId is not installed, cannot be enabled.");
}
if ($forceEnable) {
$this->overwriteNextcloudRequirement($appId);
}

Loading…
Cancel
Save