Skip to content
Draft
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
4 changes: 0 additions & 4 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
class Application extends App implements IBootstrap {
public const APP_ID = 'contacts';

public const AVAIL_SETTINGS = [
'allowSocialSync' => 'yes',
];

public function __construct() {
parent::__construct(self::APP_ID);
}
Expand Down
10 changes: 1 addition & 9 deletions lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@
namespace OCA\Contacts\Settings;

use OCA\Contacts\AppInfo\Application;
use OCA\Contacts\Service\SocialApiService;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\Settings\ISettings;

class AdminSettings implements ISettings {
protected $appName;

/**
* Admin constructor.
*
* @param IConfig $config
* @param IL10N $l
*/
public function __construct(
private IConfig $config,
private IInitialStateService $initialStateService,
) {
$this->appName = Application::APP_ID;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
name: 'AdminSettings',
data() {
return {
allowSocialSync: loadState('contacts', 'allowSocialSync') === 'yes',
allowSocialSync: loadState('contacts', 'allowSocialSync', true),
}
},

Expand Down
6 changes: 3 additions & 3 deletions src/components/AppNavigation/ContactsSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<AppSettingsSection id="general" :name="t('contacts', 'General')">
<SettingsSortContacts />

<NcFormBox>
<NcFormBox v-if="allowSocialSync">
<NcFormBoxSwitch
v-model="enableSocialSync"
:label="t('contacts', 'Update avatars from social media')"
Expand Down Expand Up @@ -76,8 +76,8 @@ export default {

data() {
return {
allowSocialSync: loadState('contacts', 'allowSocialSync') !== 'no',
enableSocialSync: loadState('contacts', 'enableSocialSync') !== 'no',
allowSocialSync: loadState('contacts', 'allowSocialSync', true),
enableSocialSync: loadState('contacts', 'enableSocialSync', false),
enableSocialSyncLoading: false,
showSettings: false,
}
Expand Down
50 changes: 50 additions & 0 deletions tests/unit/Settings/AdminSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Contacts\Settings;

use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Contacts\Service\SocialApiService;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;

class AdminSettingsTest extends TestCase {
private AdminSettings $settings;

/** @var IInitialState|MockObject */
private $initialState;

/** @var SocialApiService|MockObject */
private $socialApiService;

protected function setUp(): void {
parent::setUp();
$this->initialState = $this->createMock(IInitialState::class);
$this->socialApiService = $this->createMock(SocialApiService::class);
$this->settings = new AdminSettings($this->initialState, $this->socialApiService);
}

public static function allowSocialSyncProvider(): array {
return [[true], [false]];
}

#[DataProvider('allowSocialSyncProvider')]
public function testGetFormProvidesBooleanInitialState(bool $allowed): void {
$this->socialApiService
->method('syncAllowedByAdmin')
->willReturn($allowed);
$this->initialState
->expects($this->once())
->method('provideInitialState')
->with('allowSocialSync', $allowed);

$form = $this->settings->getForm();
$this->assertInstanceOf(TemplateResponse::class, $form);
}
}