aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-06-05 15:31:14 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2025-06-05 15:39:25 +0200
commitbf340a576fcaf17cf0608b9e6d56f8200e758f59 (patch)
treeed0729b06762a35b7b56f15706157d9b612bb801
parentd6a53ceab022271550b68188ed85069b39b0738f (diff)
downloadnextcloud-server-bf340a576fcaf17cf0608b9e6d56f8200e758f59.tar.gz
nextcloud-server-bf340a576fcaf17cf0608b9e6d56f8200e758f59.zip
fix: Do not enable applications which are not installed yet
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/provisioning_api/lib/Controller/AppsController.php13
-rw-r--r--apps/provisioning_api/tests/Controller/AppsControllerTest.php11
-rw-r--r--lib/private/App/AppManager.php9
3 files changed, 32 insertions, 1 deletions
diff --git a/apps/provisioning_api/lib/Controller/AppsController.php b/apps/provisioning_api/lib/Controller/AppsController.php
index 4d32584591b..b2a3f1a24f9 100644
--- a/apps/provisioning_api/lib/Controller/AppsController.php
+++ b/apps/provisioning_api/lib/Controller/AppsController.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);
diff --git a/apps/provisioning_api/tests/Controller/AppsControllerTest.php b/apps/provisioning_api/tests/Controller/AppsControllerTest.php
index f56be7c4c36..f95daeae7d3 100644
--- a/apps/provisioning_api/tests/Controller/AppsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/AppsControllerTest.php
@@ -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,
);
}
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php
index 413dc6ccd46..18f29114d0e 100644
--- a/lib/private/App/AppManager.php
+++ b/lib/private/App/AppManager.php
@@ -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);
}