Skip to content

Commit 4bd0022

Browse files
committed
fixes
Signed-off-by: Maxence Lange <[email protected]>
1 parent 1da9fa0 commit 4bd0022

File tree

6 files changed

+110
-289
lines changed

6 files changed

+110
-289
lines changed

apps/provisioning_api/tests/Controller/AppConfigControllerTest.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
*/
2626
namespace OCA\Provisioning_API\Tests\Controller;
2727

28+
use OC\AppConfig;
2829
use OCA\Provisioning_API\Controller\AppConfigController;
2930
use OCP\AppFramework\Http;
3031
use OCP\AppFramework\Http\DataResponse;
3132
use OCP\IAppConfig;
32-
use OCP\IConfig;
3333
use OCP\IGroupManager;
3434
use OCP\IL10N;
3535
use OCP\IRequest;
@@ -45,8 +45,6 @@
4545
*/
4646
class AppConfigControllerTest extends TestCase {
4747

48-
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
49-
private $config;
5048
/** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */
5149
private $appConfig;
5250
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
@@ -61,8 +59,7 @@ class AppConfigControllerTest extends TestCase {
6159
protected function setUp(): void {
6260
parent::setUp();
6361

64-
$this->config = $this->createMock(IConfig::class);
65-
$this->appConfig = $this->createMock(IAppConfig::class);
62+
$this->appConfig = $this->createMock(AppConfig::class);
6663
$this->userSession = $this->createMock(IUserSession::class);
6764
$this->l10n = $this->createMock(IL10N::class);
6865
$this->groupManager = $this->createMock(IGroupManager::class);
@@ -80,7 +77,6 @@ protected function getInstance(array $methods = []) {
8077
return new AppConfigController(
8178
'provisioning_api',
8279
$request,
83-
$this->config,
8480
$this->appConfig,
8581
$this->userSession,
8682
$this->l10n,
@@ -92,7 +88,6 @@ protected function getInstance(array $methods = []) {
9288
->setConstructorArgs([
9389
'provisioning_api',
9490
$request,
95-
$this->config,
9691
$this->appConfig,
9792
$this->userSession,
9893
$this->l10n,
@@ -183,16 +178,13 @@ public function testGetValue($app, $key, $default, $return, $throws, $status) {
183178
->method('verifyAppId')
184179
->with($app)
185180
->willThrowException($throws);
186-
187-
$this->config->expects($this->never())
188-
->method('getAppValue');
189181
} else {
190182
$api->expects($this->once())
191183
->method('verifyAppId')
192184
->with($app);
193185

194-
$this->config->expects($this->once())
195-
->method('getAppValue')
186+
$this->appConfig->expects($this->once())
187+
->method('getValueMixed')
196188
->with($app, $key, $default)
197189
->willReturn($return);
198190
}
@@ -246,8 +238,8 @@ public function testSetValue($app, $key, $value, $appThrows, $keyThrows, $status
246238

247239
$api->expects($this->never())
248240
->method('verifyConfigKey');
249-
$this->config->expects($this->never())
250-
->method('setAppValue');
241+
$this->appConfig->expects($this->never())
242+
->method('setValueMixed');
251243
} elseif ($keyThrows instanceof \Exception) {
252244
$api->expects($this->once())
253245
->method('verifyAppId')
@@ -257,8 +249,8 @@ public function testSetValue($app, $key, $value, $appThrows, $keyThrows, $status
257249
->with($app, $key)
258250
->willThrowException($keyThrows);
259251

260-
$this->config->expects($this->never())
261-
->method('setAppValue');
252+
$this->appConfig->expects($this->never())
253+
->method('setValueMixed');
262254
} else {
263255
$api->expects($this->once())
264256
->method('verifyAppId')
@@ -267,8 +259,8 @@ public function testSetValue($app, $key, $value, $appThrows, $keyThrows, $status
267259
->method('verifyConfigKey')
268260
->with($app, $key);
269261

270-
$this->config->expects($this->once())
271-
->method('setAppValue')
262+
$this->appConfig->expects($this->once())
263+
->method('setValueMixed')
272264
->with($app, $key, $value);
273265
}
274266

@@ -310,8 +302,8 @@ public function testDeleteValue($app, $key, $appThrows, $keyThrows, $status) {
310302

311303
$api->expects($this->never())
312304
->method('verifyConfigKey');
313-
$this->config->expects($this->never())
314-
->method('deleteAppValue');
305+
$this->appConfig->expects($this->never())
306+
->method('deleteKey');
315307
} elseif ($keyThrows instanceof \Exception) {
316308
$api->expects($this->once())
317309
->method('verifyAppId')
@@ -321,8 +313,8 @@ public function testDeleteValue($app, $key, $appThrows, $keyThrows, $status) {
321313
->with($app, $key)
322314
->willThrowException($keyThrows);
323315

324-
$this->config->expects($this->never())
325-
->method('deleteAppValue');
316+
$this->appConfig->expects($this->never())
317+
->method('deleteKey');
326318
} else {
327319
$api->expects($this->once())
328320
->method('verifyAppId')
@@ -331,8 +323,8 @@ public function testDeleteValue($app, $key, $appThrows, $keyThrows, $status) {
331323
->method('verifyConfigKey')
332324
->with($app, $key);
333325

334-
$this->config->expects($this->once())
335-
->method('deleteAppValue')
326+
$this->appConfig->expects($this->once())
327+
->method('deleteKey')
336328
->with($app, $key);
337329
}
338330

core/Command/Config/App/GetConfig.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8383

8484
if ($input->getOption('details')) {
8585
$details = $this->appConfig->getDetails($appName, $configName);
86-
$format = $input->getOption('output') ?? 'plain';
87-
if ($format === 'json') {
88-
$output->writeln(json_encode($details));
89-
} elseif ($format === 'json_pretty') {
90-
$output->writeln(json_encode($details, JSON_PRETTY_PRINT));
91-
} else {
92-
$output->writeln('App: ' . $details['app'] ?? '');
93-
$output->writeln('Config Key: ' . $details['key'] ?? '');
94-
$output->writeln('Config Value: ' . $details['value'] ?? '');
95-
$output->writeln('Value type: ' . $details['typeString'] ?? '');
96-
$output->writeln('Lazy loaded: ' . (($details['lazy'] ?? false) ? 'Yes' : 'No'));
97-
$output->writeln('Sensitive: ' . (($details['sensitive'] ?? false) ? 'Yes' : 'No'));
98-
}
99-
86+
$details['type'] = $details['typeString'];
87+
unset($details['typeString']);
88+
$this->writeArrayInOutputFormat($input, $output, $details);
10089
return 0;
10190
}
10291

core/Command/Config/App/SetConfig.php

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
use Symfony\Component\Console\Question\Question;
3636

3737
class SetConfig extends Base {
38-
private InputInterface $input;
39-
private OutputInterface $output;
40-
4138
public function __construct(
4239
protected IAppConfig $appConfig,
4340
) {
@@ -97,8 +94,6 @@ protected function configure() {
9794
protected function execute(InputInterface $input, OutputInterface $output): int {
9895
$appName = $input->getArgument('app');
9996
$configName = $input->getArgument('name');
100-
$this->input = $input;
101-
$this->output = $output;
10297

10398
if (!($this->appConfig instanceof AppConfig)) {
10499
throw new \Exception('Only compatible with OC\AppConfig as it uses internal methods');
@@ -126,19 +121,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
126121
*/
127122
$updated = false;
128123
if (!$input->hasParameterOption('--value')) {
129-
if (!$input->getOption('lazy') && $this->appConfig->isLazy($appName, $configName) && $this->ask('NOT LAZY')) {
124+
if (!$input->getOption('lazy') && $this->appConfig->isLazy($appName, $configName) && $this->ask($input, $output, 'NOT LAZY')) {
130125
$updated = $this->appConfig->updateLazy($appName, $configName, false);
131126
}
132-
if ($input->getOption('lazy') && !$this->appConfig->isLazy($appName, $configName) && $this->ask('LAZY')) {
127+
if ($input->getOption('lazy') && !$this->appConfig->isLazy($appName, $configName) && $this->ask($input, $output, 'LAZY')) {
133128
$updated = $this->appConfig->updateLazy($appName, $configName, true) || $updated;
134129
}
135-
if (!$input->getOption('sensitive') && $this->appConfig->isSensitive($appName, $configName) && $this->ask('NOT SENSITIVE')) {
130+
if (!$input->getOption('sensitive') && $this->appConfig->isSensitive($appName, $configName) && $this->ask($input, $output, 'NOT SENSITIVE')) {
136131
$updated = $this->appConfig->updateSensitive($appName, $configName, false) || $updated;
137132
}
138-
if ($input->getOption('sensitive') && !$this->appConfig->isSensitive($appName, $configName) && $this->ask('SENSITIVE')) {
133+
if ($input->getOption('sensitive') && !$this->appConfig->isSensitive($appName, $configName) && $this->ask($input, $output, 'SENSITIVE')) {
139134
$updated = $this->appConfig->updateSensitive($appName, $configName, true) || $updated;
140135
}
141-
if ($typeString !== null && $type !== $this->appConfig->getValueType($appName, $configName) && $this->ask($typeString)) {
136+
if ($type !== null && $type !== $this->appConfig->getValueType($appName, $configName) && $typeString !== null && $this->ask($input, $output, $typeString)) {
142137
$updated = $this->appConfig->updateType($appName, $configName, $type) || $updated;
143138
}
144139
} else {
@@ -149,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
149144
*/
150145
try {
151146
$currType = $this->appConfig->getValueType($appName, $configName);
152-
if ($type === null || $type === $currType || !$this->ask($typeString)) {
147+
if ($typeString === null || $type === $currType || !$this->ask($input, $output, $typeString)) {
153148
$type = $currType;
154149
} else {
155150
$updated = $this->appConfig->updateType($appName, $configName, $type);
@@ -166,7 +161,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
166161
$lazy = $input->getOption('lazy');
167162
try {
168163
$currLazy = $this->appConfig->isLazy($appName, $configName);
169-
if ($lazy === null || $lazy === $currLazy || !$this->ask(($lazy) ? 'LAZY' : 'NOT LAZY')) {
164+
if ($lazy === null || $lazy === $currLazy || !$this->ask($input, $output, ($lazy) ? 'LAZY' : 'NOT LAZY')) {
170165
$lazy = $currLazy;
171166
}
172167
} catch (AppConfigUnknownKeyException) {
@@ -179,7 +174,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
179174
$sensitive = $input->getOption('sensitive');
180175
try {
181176
$currSensitive = $this->appConfig->isLazy($appName, $configName);
182-
if ($sensitive === null || $sensitive === $currSensitive || !$this->ask(($sensitive) ? 'LAZY' : 'NOT LAZY')) {
177+
if ($sensitive === null || $sensitive === $currSensitive || !$this->ask($input, $output, ($sensitive) ? 'LAZY' : 'NOT LAZY')) {
183178
$sensitive = $currSensitive;
184179
}
185180
} catch (AppConfigUnknownKeyException) {
@@ -249,26 +244,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
249244
return 0;
250245
}
251246

252-
private function ask(string $request): bool {
247+
private function ask(InputInterface $input, OutputInterface $output, string $request): bool {
253248
$helper = $this->getHelper('question');
254-
if ($this->input->getOption('no-interaction')) {
249+
if ($input->getOption('no-interaction')) {
255250
return true;
256251
}
257252

258-
$this->output->writeln(sprintf('You are about to set config value %s as <info>%s</info>',
259-
'<info>' . $this->input->getArgument('app') . '</info>/<info>' . $this->input->getArgument('name') . '</info>',
253+
$output->writeln(sprintf('You are about to set config value %s as <info>%s</info>',
254+
'<info>' . $input->getArgument('app') . '</info>/<info>' . $input->getArgument('name') . '</info>',
260255
strtoupper($request)
261256
));
262-
$this->output->writeln('');
263-
$this->output->writeln('<comment>This might break thing, affect performance on your instance or its security!</comment>');
257+
$output->writeln('');
258+
$output->writeln('<comment>This might break thing, affect performance on your instance or its security!</comment>');
264259

265260
$result = (strtolower((string)$helper->ask(
266-
$this->input,
267-
$this->output,
261+
$input,
262+
$output,
268263
new Question('<comment>Confirm this action by typing \'yes\'</comment>: '))) === 'yes');
269264

270-
$this->output->writeln(($result) ? 'done' : 'cancelled');
271-
$this->output->writeln('');
265+
$output->writeln(($result) ? 'done' : 'cancelled');
266+
$output->writeln('');
272267

273268
return $result;
274269
}

core/Migrations/Version29000Date20231126110901.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
use OCP\Migration\IOutput;
3232
use OCP\Migration\SimpleMigrationStep;
3333

34-
// Create new field in appconfig for the new IAppConfig API, including lazy grouping.
34+
/**
35+
* Create new fields for type and lazy loading in appconfig for the new IAppConfig API.
36+
*/
3537
class Version29000Date20231126110901 extends SimpleMigrationStep {
3638
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
3739
/** @var ISchemaWrapper $schema */

0 commit comments

Comments
 (0)