Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/provisioning_api/lib/Controller/AppsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace OCA\Provisioning_API\Controller;

use OC\Installer;
use OC_App;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
Expand All @@ -16,13 +17,16 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCSController;
use OCP\IAppConfig;
use OCP\IRequest;

class AppsController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
private IAppManager $appManager,
private Installer $installer,
private IAppConfig $appConfig,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -108,6 +112,15 @@ public function getAppInfo(string $app): DataResponse {
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);
Expand Down
11 changes: 10 additions & 1 deletion apps/provisioning_api/tests/Controller/AppsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +28,8 @@
*/
class AppsControllerTest extends TestCase {
private IAppManager $appManager;
private IAppConfig&MockObject $appConfig;
private Installer&MockObject $installer;
private AppsController $api;
private IUserSession $userSession;

Expand All @@ -34,13 +39,17 @@ protected function setUp(): void {
$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,
);
}

Expand Down
2 changes: 2 additions & 0 deletions build/integration/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ HIDE_OC_LOGS=$2
INSTALLED=$($OCC status | grep installed: | cut -d " " -f 5)

if [ "$INSTALLED" == "true" ]; then
# Disable appstore to avoid spamming from CI
$OCC config:system:set appstoreenabled --value=false --type=boolean
# Disable bruteforce protection because the integration tests do trigger them
$OCC config:system:set auth.bruteforce.protection.enabled --value false --type bool
# Disable rate limit protection because the integration tests do trigger them
Expand Down
9 changes: 9 additions & 0 deletions lib/private/App/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,16 @@ public function isAppLoaded(string $app): bool {
* @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);
}
Expand Down Expand Up @@ -596,6 +601,10 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab
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);
}
Expand Down
Loading