Skip to content

Commit 139b932

Browse files
Merge pull request #47410 from nextcloud/backport/47409/stable29
[stable29] fix(provisioning): Support setting new app configs as well
2 parents c70b3ef + 1b405aa commit 139b932

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

apps/provisioning_api/lib/Controller/AppConfigController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\AppFramework\Http;
3333
use OCP\AppFramework\Http\DataResponse;
3434
use OCP\AppFramework\OCSController;
35+
use OCP\Exceptions\AppConfigUnknownKeyException;
3536
use OCP\IAppConfig;
3637
use OCP\IGroupManager;
3738
use OCP\IL10N;
@@ -143,9 +144,15 @@ public function setValue(string $app, string $key, string $value): DataResponse
143144
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN);
144145
}
145146

146-
$configDetails = $this->appConfig->getDetails($app, $key);
147+
$type = null;
148+
try {
149+
$configDetails = $this->appConfig->getDetails($app, $key);
150+
$type = $configDetails['type'];
151+
} catch (AppConfigUnknownKeyException) {
152+
}
153+
147154
/** @psalm-suppress InternalMethod */
148-
match ($configDetails['type']) {
155+
match ($type) {
149156
IAppConfig::VALUE_BOOL => $this->appConfig->setValueBool($app, $key, (bool)$value),
150157
IAppConfig::VALUE_FLOAT => $this->appConfig->setValueFloat($app, $key, (float)$value),
151158
IAppConfig::VALUE_INT => $this->appConfig->setValueInt($app, $key, (int)$value),

apps/provisioning_api/tests/Controller/AppConfigControllerTest.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCA\Provisioning_API\Controller\AppConfigController;
3030
use OCP\AppFramework\Http;
3131
use OCP\AppFramework\Http\DataResponse;
32+
use OCP\Exceptions\AppConfigUnknownKeyException;
3233
use OCP\IAppConfig;
3334
use OCP\IGroupManager;
3435
use OCP\IL10N;
@@ -212,6 +213,7 @@ public function dataSetValue() {
212213
['app2', 'key', '42', null, null, Http::STATUS_OK, IAppConfig::VALUE_STRING],
213214
['app2', 'key', 'secret', null, null, Http::STATUS_OK, IAppConfig::VALUE_STRING | IAppConfig::VALUE_SENSITIVE],
214215
['app2', 'key', json_encode([4, 2]), null, null, Http::STATUS_OK, IAppConfig::VALUE_ARRAY],
216+
['app2', 'key', json_encode([4, 2]), null, null, Http::STATUS_OK, new AppConfigUnknownKeyException()],
215217
];
216218
}
217219

@@ -222,9 +224,9 @@ public function dataSetValue() {
222224
* @param string|null $value
223225
* @param \Exception|null $appThrows
224226
* @param \Exception|null $keyThrows
225-
* @param int $status
227+
* @param int|\Throwable $status
226228
*/
227-
public function testSetValue($app, $key, $value, $appThrows, $keyThrows, $status, int $type = IAppConfig::VALUE_MIXED) {
229+
public function testSetValue($app, $key, $value, $appThrows, $keyThrows, $status, int|\Throwable $type = IAppConfig::VALUE_MIXED) {
228230
$adminUser = $this->createMock(IUser::class);
229231
$adminUser->expects($this->once())
230232
->method('getUid')
@@ -267,18 +269,25 @@ public function testSetValue($app, $key, $value, $appThrows, $keyThrows, $status
267269
->method('verifyConfigKey')
268270
->with($app, $key);
269271

270-
$this->appConfig->expects($this->once())
271-
->method('getDetails')
272-
->with($app, $key)
273-
->willReturn([
274-
'app' => $app,
275-
'key' => $key,
276-
'value' => '', // 🤷
277-
'type' => $type,
278-
'lazy' => false,
279-
'typeString' => (string)$type, // this is not accurate, but acceptable
280-
'sensitive' => ($type & IAppConfig::VALUE_SENSITIVE) !== 0,
281-
]);
272+
if ($type instanceof \Throwable) {
273+
$this->appConfig->expects($this->once())
274+
->method('getDetails')
275+
->with($app, $key)
276+
->willThrowException($type);
277+
} else {
278+
$this->appConfig->expects($this->once())
279+
->method('getDetails')
280+
->with($app, $key)
281+
->willReturn([
282+
'app' => $app,
283+
'key' => $key,
284+
'value' => '', // 🤷
285+
'type' => $type,
286+
'lazy' => false,
287+
'typeString' => (string)$type, // this is not accurate, but acceptable
288+
'sensitive' => ($type & IAppConfig::VALUE_SENSITIVE) !== 0,
289+
]);
290+
}
282291

283292
$configValueSetter = match ($type) {
284293
IAppConfig::VALUE_BOOL => 'setValueBool',

0 commit comments

Comments
 (0)