Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 20 additions & 9 deletions apps/provisioning_api/lib/Controller/AppConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

use OC\AppConfig;
use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException;
use OC\Config\ConfigManager;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\Config\ValueType;
use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IAppConfig;
use OCP\IGroupManager;
Expand All @@ -37,6 +39,7 @@ public function __construct(
private IGroupManager $groupManager,
private IManager $settingManager,
private IAppManager $appManager,
private readonly ConfigManager $configManager,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -130,19 +133,27 @@ public function setValue(string $app, string $key, string $value): DataResponse
}

$type = null;
try {
$configDetails = $this->appConfig->getDetails($app, $key);
$type = $configDetails['type'];
} catch (AppConfigUnknownKeyException) {

// checking expected type from lexicon
$keyDetails = $this->appConfig->getKeyDetails($app, $key);
if (array_key_exists('valueType', $keyDetails)) {
$type = $keyDetails['valueType'];
} else {
// if no details from lexicon, get from eventual current value in database
try {
$configDetails = $this->appConfig->getDetails($app, $key);
$type = $configDetails['type'];
} catch (AppConfigUnknownKeyException) {
}
}

/** @psalm-suppress InternalMethod */
match ($type) {
IAppConfig::VALUE_BOOL => $this->appConfig->setValueBool($app, $key, (bool)$value),
IAppConfig::VALUE_FLOAT => $this->appConfig->setValueFloat($app, $key, (float)$value),
IAppConfig::VALUE_INT => $this->appConfig->setValueInt($app, $key, (int)$value),
IAppConfig::VALUE_STRING => $this->appConfig->setValueString($app, $key, $value),
IAppConfig::VALUE_ARRAY => $this->appConfig->setValueArray($app, $key, \json_decode($value, true)),
IAppConfig::VALUE_BOOL, ValueType::BOOL => $this->appConfig->setValueBool($app, $key, $this->configManager->convertToBool($value)),
IAppConfig::VALUE_FLOAT, ValueType::FLOAT => $this->appConfig->setValueFloat($app, $key, $this->configManager->convertToFloat($value)),
IAppConfig::VALUE_INT, ValueType::INT => $this->appConfig->setValueInt($app, $key, $this->configManager->convertToInt($value)),
IAppConfig::VALUE_STRING, ValueType::STRING => $this->appConfig->setValueString($app, $key, $value),
IAppConfig::VALUE_ARRAY, ValueType::ARRAY => $this->appConfig->setValueArray($app, $key, $this->configManager->convertToArray($value)),
default => $this->appConfig->setValueMixed($app, $key, $value),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OCA\Provisioning_API\Tests\Controller;

use OC\AppConfig;
use OC\Config\ConfigManager;
use OCA\Provisioning_API\Controller\AppConfigController;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
Expand Down Expand Up @@ -38,6 +39,7 @@ class AppConfigControllerTest extends TestCase {
private IManager&MockObject $settingManager;
private IGroupManager&MockObject $groupManager;
private IAppManager $appManager;
private ConfigManager $configManager;

protected function setUp(): void {
parent::setUp();
Expand All @@ -48,6 +50,7 @@ protected function setUp(): void {
$this->settingManager = $this->createMock(IManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->appManager = Server::get(IAppManager::class);
$this->configManager = Server::get(ConfigManager::class);
}

/**
Expand All @@ -67,6 +70,7 @@ protected function getInstance(array $methods = []) {
$this->groupManager,
$this->settingManager,
$this->appManager,
$this->configManager,
);
} else {
return $this->getMockBuilder(AppConfigController::class)
Expand All @@ -79,6 +83,7 @@ protected function getInstance(array $methods = []) {
$this->groupManager,
$this->settingManager,
$this->appManager,
$this->configManager,
])
->onlyMethods($methods)
->getMock();
Expand Down
Loading