Skip to content

Commit f0e5825

Browse files
committed
fixup! refactor(config): replace IConfig with IAppConfig for improved type safety and clarity
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 95f1379 commit f0e5825

5 files changed

Lines changed: 20 additions & 14 deletions

File tree

lib/Controller/ConfigController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ public function updateAppConfig(string $configKey, mixed $configValue): DataResp
7272
} catch (\InvalidArgumentException $e) {
7373
return new DataResponse('Invalid value for ' . $configKey, Http::STATUS_BAD_REQUEST);
7474
}
75+
break;
7576

7677
case Constants::CONFIG_KEY_CREATIONALLOWEDGROUPS:
7778
try {
7879
$this->appConfig->setAppValueArray($configKey, $configValue);
7980
} catch (\InvalidArgumentException $e) {
8081
return new DataResponse('Invalid value for ' . $configKey, Http::STATUS_BAD_REQUEST);
8182
}
83+
break;
8284
}
8385

8486
return new DataResponse();

tests/Integration/Api/RespectAdminSettingsTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
namespace OCA\Forms\Tests\Integration\Api;
99

1010
use GuzzleHttp\Client;
11+
use OCA\Forms\AppInfo\Application;
1112
use OCA\Forms\Constants;
1213
use OCA\Forms\Tests\Integration\IntegrationBase;
13-
use OCP\AppFramework\Services\IAppConfig;
14+
use OCP\IAppConfig;
1415

1516
/**
1617
* This tests that the API respects all admin settings
@@ -223,7 +224,7 @@ public function testForbidUpdate(array $accessValue, array $adminConfigKeys): vo
223224
$config = \OCP\Server::get(IAppConfig::class);
224225
foreach ($adminConfigKeys as $key => $value) {
225226
if (is_array($value)) {
226-
$config->setAppValueArray($key, $value);
227+
$config->setAppValueArray(Application::APP_ID, $key, $value);
227228
} else {
228229
$bool = is_bool($value) ? $value : filter_var($value, FILTER_VALIDATE_BOOLEAN);
229230
$config->setAppValueBool($key, $bool);
@@ -326,7 +327,7 @@ public function testListFormsAllowed(): void {
326327
*/
327328
public function testListFormsNoAdminPermission(): void {
328329
// Disable global access
329-
\OCP\Server::get(IAppConfig::class)->setAppValueBool(Constants::CONFIG_KEY_ALLOWPERMITALL, false);
330+
\OCP\Server::get(IAppConfig::class)->setAppValueBool(Application::APP_ID, Constants::CONFIG_KEY_ALLOWPERMITALL, false);
330331

331332
$resp = $this->http->request(
332333
'GET',

tests/Integration/DB/SharedFormsTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
*/
99
namespace OCA\Forms\Tests\Integration\Db;
1010

11+
use OCA\Forms\AppInfo\Application;
1112
use OCA\Forms\Constants;
1213
use OCA\Forms\Db\FormMapper;
1314
use OCA\Forms\Tests\Integration\IntegrationBase;
14-
use OCP\AppFramework\Services\IAppConfig;
15+
use OCP\IAppConfig;
1516

1617
/**
1718
* @group DB
@@ -182,7 +183,7 @@ public function testShowNoSharedFormsIfDisabled(array $configValues) {
182183
$config = \OCP\Server::get(IAppConfig::class);
183184
foreach ($configValues as $key => $value) {
184185
if (is_array($value)) {
185-
$config->setAppValueArray($key, $value);
186+
$config->setAppValueArray(Application::APP_ID, $key, $value);
186187
} else {
187188
$bool = is_bool($value) ? $value : filter_var($value, FILTER_VALIDATE_BOOLEAN);
188189
$config->setAppValueBool($key, $bool);
@@ -204,7 +205,7 @@ public function testShowNoSharedFormsIfDisabled(array $configValues) {
204205
*/
205206
public function testAllowPublicAccessOnDeniedPublicVisibility(): void {
206207
$config = \OCP\Server::get(IAppConfig::class);
207-
$config->setAppValueBool(Constants::CONFIG_KEY_ALLOWSHOWTOALL, false);
208+
$config->setAppValueBool(Application::APP_ID, Constants::CONFIG_KEY_ALLOWSHOWTOALL, false);
208209

209210
$formMapper = \OCP\Server::get(FormMapper::class);
210211
$forms = $formMapper->findSharedForms('user1', filterShown: false);
@@ -223,7 +224,7 @@ public function testShowNoSharedFormsAccessIfDisabled(array $configValues): void
223224
$config = \OCP\Server::get(IAppConfig::class);
224225
foreach ($configValues as $key => $value) {
225226
if (is_array($value)) {
226-
$config->setAppValueArray($key, $value);
227+
$config->setAppValueArray(Application::APP_ID, $key, $value);
227228
} else {
228229
$bool = is_bool($value) ? $value : filter_var($value, FILTER_VALIDATE_BOOLEAN);
229230
$config->setAppValueBool($key, $bool);

tests/Integration/IntegrationBase.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
namespace OCA\Forms\Tests\Integration;
99

10+
use OCA\Forms\AppInfo\Application;
1011
use OCA\Forms\Constants;
11-
use OCP\AppFramework\Services\IAppConfig;
1212
use OCP\DB\QueryBuilder\IQueryBuilder;
13+
use OCP\IAppConfig;
1314
use OCP\IDBConnection;
1415
use OCP\IUserManager;
1516
use Test\TestCase;
@@ -18,7 +19,8 @@
1819
* @group DB
1920
*/
2021
class IntegrationBase extends TestCase {
21-
protected array $testForms;
22+
/** @var Array */
23+
protected $testForms;
2224

2325
/**
2426
* Users that are needed by this test case
@@ -33,9 +35,9 @@ class IntegrationBase extends TestCase {
3335
public function setUp(): void {
3436
parent::setUp();
3537

36-
$appConfig = \OCP\AppFramework\Services::get(IAppConfig::class);
38+
$config = \OCP\Server::get(IAppConfig::class);
3739
foreach (Constants::CONFIG_KEYS as $key) {
38-
$appConfig->deleteAppValue($key);
40+
$config->deleteKey(Application::APP_ID, $key);
3941
}
4042

4143
$userManager = \OCP\Server::get(IUserManager::class);

tests/Unit/Service/ConfigServiceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,20 @@ public static function dataCanCreateForms() {
182182
return [
183183
'notRestriced' => [
184184
'config' => [
185-
'restrictCreation' => 'false',
185+
'restrictCreation' => false,
186186
],
187187
'expected' => true
188188
],
189189
'restrictedGroupAllowed' => [
190190
'config' => [
191-
'restrictCreation' => 'true',
191+
'restrictCreation' => true,
192192
'creationAllowedGroups' => '["usersGroup","notUsersGroup"]'
193193
],
194194
'expected' => true
195195
],
196196
'restrictedNotInGroup' => [
197197
'config' => [
198-
'restrictCreation' => 'true',
198+
'restrictCreation' => true,
199199
'creationAllowedGroups' => '["notUsersGroup"]'
200200
],
201201
'expected' => false

0 commit comments

Comments
 (0)