Browse Source

Fix link to calendar user docs in groupware settings

Closes #31617

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
tags/v24.0.0beta1
Thomas Citharel 2 years ago
parent
commit
9c07e47c78

+ 6
- 1
apps/dav/lib/Settings/CalDAVSettings.php View File

@@ -29,6 +29,7 @@ use OCA\DAV\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\IURLGenerator;
use OCP\Settings\IDelegatedSettings;

class CalDAVSettings implements IDelegatedSettings {
@@ -39,6 +40,8 @@ class CalDAVSettings implements IDelegatedSettings {
/** @var IInitialState */
private $initialState;

private IURLGenerator $urlGenerator;

private const defaults = [
'sendInvitations' => 'yes',
'generateBirthdayCalendar' => 'yes',
@@ -52,12 +55,14 @@ class CalDAVSettings implements IDelegatedSettings {
* @param IConfig $config
* @param IInitialState $initialState
*/
public function __construct(IConfig $config, IInitialState $initialState) {
public function __construct(IConfig $config, IInitialState $initialState, IURLGenerator $urlGenerator) {
$this->config = $config;
$this->initialState = $initialState;
$this->urlGenerator = $urlGenerator;
}

public function getForm(): TemplateResponse {
$this->initialState->provideInitialState('userSyncCalendarsDocUrl', $this->urlGenerator->linkToDocs('user-sync-calendars'));
foreach (self::defaults as $key => $default) {
$value = $this->config->getAppValue(Application::APP_ID, $key, $default);
$this->initialState->provideInitialState($key, $value === 'yes');

+ 5
- 0
apps/dav/src/views/CalDavSettings.spec.js View File

@@ -13,6 +13,11 @@ jest.mock('@nextcloud/router', () => {
},
}
})
jest.mock('@nextcloud/initial-state', () => {
return {
loadState: jest.fn(() => 'https://docs.nextcloud.com/server/23/go.php?to=user-sync-calendars'),
}
})

describe('CalDavSettings', () => {
const originalOC = global.OC

+ 4
- 1
apps/dav/src/views/CalDavSettings.vue View File

@@ -73,6 +73,9 @@
<script>
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'

const userSyncCalendarsDocUrl = loadState('dav', 'userSyncCalendarsDocUrl', '#')

export default {
name: 'CalDavSettings',
@@ -84,7 +87,7 @@ export default {
)
return translated
.replace('{calendarappstoreopen}', '<a target="_blank" href="../apps/office/calendar">')
.replace('{calendardocopen}', '<a target="_blank" :href="userSyncCalendarsUrl" rel="noreferrer noopener">')
.replace('{calendardocopen}', `<a target="_blank" href="${userSyncCalendarsDocUrl}" rel="noreferrer noopener">`)
.replace(/\{linkclose\}/g, '</a>')
},
sendInvitationsHelpText() {

+ 1
- 1
apps/dav/src/views/__snapshots__/CalDavSettings.spec.js.snap View File

@@ -21,7 +21,7 @@ exports[`CalDavSettings interactions 1`] = `
</a>
, or
<a
:href="userSyncCalendarsUrl"
href="https://docs.nextcloud.com/server/23/go.php?to=user-sync-calendars"
rel="noreferrer noopener"
target="_blank"
>

+ 18
- 5
apps/dav/tests/unit/Settings/CalDAVSettingsTest.php View File

@@ -26,27 +26,34 @@
namespace OCA\DAV\Tests\Unit\DAV\Settings;

use OCA\DAV\Settings\CalDAVSettings;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class CalDAVSettingsTest extends TestCase {

/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
/** @var IConfig|MockObject */
private $config;

/** @var OCP\AppFramework\Services\IInitialState|\PHPUnit\Framework\MockObject\MockObject */
/** @var IInitialState|MockObject */
private $initialState;

/** @var IURLGenerator|MockObject */
private $urlGenerator;

/** @var CalDAVSettings */
private $settings;
private CalDAVSettings $settings;

protected function setUp(): void {
parent::setUp();

$this->config = $this->createMock(IConfig::class);
$this->initialState = $this->createMock(IInitialState::class);
$this->settings = new CalDAVSettings($this->config, $this->initialState);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator);
}

public function testGetForm() {
@@ -58,8 +65,14 @@ class CalDAVSettingsTest extends TestCase {
['dav', 'sendEventRemindersPush', 'no'],
)
->will($this->onConsecutiveCalls('yes', 'no', 'yes', 'yes'));
$this->urlGenerator
->expects($this->once())
->method('linkToDocs')
->with('user-sync-calendars')
->willReturn('Some docs URL');
$this->initialState->method('provideInitialState')
->withConsecutive(
['userSyncCalendarsDocUrl', 'Some docs URL'],
['sendInvitations', true],
['generateBirthdayCalendar', false],
['sendEventReminders', true],
@@ -67,7 +80,7 @@ class CalDAVSettingsTest extends TestCase {
);
$result = $this->settings->getForm();

$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $result);
$this->assertInstanceOf(TemplateResponse::class, $result);
}

public function testGetSection() {

+ 2
- 2
dist/dav-settings-admin-caldav.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/dav-settings-admin-caldav.js.map
File diff suppressed because it is too large
View File


Loading…
Cancel
Save