Skip to content

Commit 59dfd2b

Browse files
hamza221backportbot[bot]
authored andcommitted
fix: unify allowSocialSync frontend type
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent 3dcac51 commit 59dfd2b

4 files changed

Lines changed: 55 additions & 21 deletions

File tree

lib/AppInfo/Application.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
class Application extends App implements IBootstrap {
2323
public const APP_ID = 'contacts';
2424

25-
public const AVAIL_SETTINGS = [
26-
'allowSocialSync' => 'yes',
27-
];
28-
2925
public function __construct() {
3026
parent::__construct(self::APP_ID);
3127
}

lib/Settings/AdminSettings.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,25 @@
88
namespace OCA\Contacts\Settings;
99

1010
use OCA\Contacts\AppInfo\Application;
11+
use OCA\Contacts\Service\SocialApiService;
1112
use OCP\AppFramework\Http\TemplateResponse;
1213
use OCP\AppFramework\Services\IInitialState;
13-
use OCP\IConfig;
1414
use OCP\Settings\ISettings;
1515

1616
class AdminSettings implements ISettings {
17-
protected $appName;
18-
19-
/**
20-
* Admin constructor.
21-
*
22-
* @param IConfig $config
23-
* @param IL10N $l
24-
*/
2517
public function __construct(
26-
private IConfig $config,
2718
private IInitialState $initialState,
19+
private SocialApiService $socialApiService,
2820
) {
29-
$this->appName = Application::APP_ID;
3021
}
3122

3223
/**
3324
* @return TemplateResponse
3425
*/
3526
#[\Override]
3627
public function getForm() {
37-
foreach (Application::AVAIL_SETTINGS as $key => $default) {
38-
$data = $this->config->getAppValue($this->appName, $key, $default);
39-
$this->initialState->provideInitialState($key, $data);
40-
}
41-
return new TemplateResponse($this->appName, 'settings/admin');
28+
$this->initialState->provideInitialState('allowSocialSync', $this->socialApiService->syncAllowedByAdmin());
29+
return new TemplateResponse(Application::APP_ID, 'settings/admin');
4230
}
4331

4432
/**

src/components/AdminSettings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
name: 'AdminSettings',
2727
data() {
2828
return {
29-
allowSocialSync: loadState('contacts', 'allowSocialSync', false),
29+
allowSocialSync: loadState('contacts', 'allowSocialSync', true),
3030
}
3131
},
3232
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OCA\Contacts\Settings;
9+
10+
use ChristophWurst\Nextcloud\Testing\TestCase;
11+
use OCA\Contacts\Service\SocialApiService;
12+
use OCP\AppFramework\Http\TemplateResponse;
13+
use OCP\AppFramework\Services\IInitialState;
14+
use PHPUnit\Framework\Attributes\DataProvider;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
17+
class AdminSettingsTest extends TestCase {
18+
private AdminSettings $settings;
19+
20+
/** @var IInitialState|MockObject */
21+
private $initialState;
22+
23+
/** @var SocialApiService|MockObject */
24+
private $socialApiService;
25+
26+
protected function setUp(): void {
27+
parent::setUp();
28+
$this->initialState = $this->createMock(IInitialState::class);
29+
$this->socialApiService = $this->createMock(SocialApiService::class);
30+
$this->settings = new AdminSettings($this->initialState, $this->socialApiService);
31+
}
32+
33+
public static function allowSocialSyncProvider(): array {
34+
return [[true], [false]];
35+
}
36+
37+
#[DataProvider('allowSocialSyncProvider')]
38+
public function testGetFormProvidesBooleanInitialState(bool $allowed): void {
39+
$this->socialApiService
40+
->method('syncAllowedByAdmin')
41+
->willReturn($allowed);
42+
$this->initialState
43+
->expects($this->once())
44+
->method('provideInitialState')
45+
->with('allowSocialSync', $allowed);
46+
47+
$form = $this->settings->getForm();
48+
$this->assertInstanceOf(TemplateResponse::class, $form);
49+
}
50+
}

0 commit comments

Comments
 (0)