Skip to content

Commit 84ae070

Browse files
authored
Merge pull request #31621 from nextcloud/fix-link-to-calendar-docs-in-groupware-settings
Fix link to calendar user docs in groupware settings
2 parents b85bdf4 + 9c07e47 commit 84ae070

File tree

7 files changed

+37
-11
lines changed

7 files changed

+37
-11
lines changed

apps/dav/lib/Settings/CalDAVSettings.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\AppFramework\Http\TemplateResponse;
3030
use OCP\IConfig;
3131
use OCP\AppFramework\Services\IInitialState;
32+
use OCP\IURLGenerator;
3233
use OCP\Settings\IDelegatedSettings;
3334

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

43+
private IURLGenerator $urlGenerator;
44+
4245
private const defaults = [
4346
'sendInvitations' => 'yes',
4447
'generateBirthdayCalendar' => 'yes',
@@ -52,12 +55,14 @@ class CalDAVSettings implements IDelegatedSettings {
5255
* @param IConfig $config
5356
* @param IInitialState $initialState
5457
*/
55-
public function __construct(IConfig $config, IInitialState $initialState) {
58+
public function __construct(IConfig $config, IInitialState $initialState, IURLGenerator $urlGenerator) {
5659
$this->config = $config;
5760
$this->initialState = $initialState;
61+
$this->urlGenerator = $urlGenerator;
5862
}
5963

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

apps/dav/src/views/CalDavSettings.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jest.mock('@nextcloud/router', () => {
1313
},
1414
}
1515
})
16+
jest.mock('@nextcloud/initial-state', () => {
17+
return {
18+
loadState: jest.fn(() => 'https://docs.nextcloud.com/server/23/go.php?to=user-sync-calendars'),
19+
}
20+
})
1621

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

apps/dav/src/views/CalDavSettings.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
<script>
7474
import axios from '@nextcloud/axios'
7575
import { generateUrl } from '@nextcloud/router'
76+
import { loadState } from '@nextcloud/initial-state'
77+
78+
const userSyncCalendarsDocUrl = loadState('dav', 'userSyncCalendarsDocUrl', '#')
7679
7780
export default {
7881
name: 'CalDavSettings',
@@ -84,7 +87,7 @@ export default {
8487
)
8588
return translated
8689
.replace('{calendarappstoreopen}', '<a target="_blank" href="../apps/office/calendar">')
87-
.replace('{calendardocopen}', '<a target="_blank" :href="userSyncCalendarsUrl" rel="noreferrer noopener">')
90+
.replace('{calendardocopen}', `<a target="_blank" href="${userSyncCalendarsDocUrl}" rel="noreferrer noopener">`)
8891
.replace(/\{linkclose\}/g, '</a>')
8992
},
9093
sendInvitationsHelpText() {

apps/dav/src/views/__snapshots__/CalDavSettings.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exports[`CalDavSettings interactions 1`] = `
2121
</a>
2222
, or
2323
<a
24-
:href="userSyncCalendarsUrl"
24+
href="https://docs.nextcloud.com/server/23/go.php?to=user-sync-calendars"
2525
rel="noreferrer noopener"
2626
target="_blank"
2727
>

apps/dav/tests/unit/Settings/CalDAVSettingsTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,34 @@
2626
namespace OCA\DAV\Tests\Unit\DAV\Settings;
2727

2828
use OCA\DAV\Settings\CalDAVSettings;
29+
use OCP\AppFramework\Http\TemplateResponse;
2930
use OCP\IConfig;
3031
use OCP\AppFramework\Services\IInitialState;
32+
use OCP\IURLGenerator;
33+
use PHPUnit\Framework\MockObject\MockObject;
3134
use Test\TestCase;
3235

3336
class CalDAVSettingsTest extends TestCase {
3437

35-
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
38+
/** @var IConfig|MockObject */
3639
private $config;
3740

38-
/** @var OCP\AppFramework\Services\IInitialState|\PHPUnit\Framework\MockObject\MockObject */
41+
/** @var IInitialState|MockObject */
3942
private $initialState;
4043

44+
/** @var IURLGenerator|MockObject */
45+
private $urlGenerator;
46+
4147
/** @var CalDAVSettings */
42-
private $settings;
48+
private CalDAVSettings $settings;
4349

4450
protected function setUp(): void {
4551
parent::setUp();
4652

4753
$this->config = $this->createMock(IConfig::class);
4854
$this->initialState = $this->createMock(IInitialState::class);
49-
$this->settings = new CalDAVSettings($this->config, $this->initialState);
55+
$this->urlGenerator = $this->createMock(IURLGenerator::class);
56+
$this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator);
5057
}
5158

5259
public function testGetForm() {
@@ -58,16 +65,22 @@ public function testGetForm() {
5865
['dav', 'sendEventRemindersPush', 'no'],
5966
)
6067
->will($this->onConsecutiveCalls('yes', 'no', 'yes', 'yes'));
68+
$this->urlGenerator
69+
->expects($this->once())
70+
->method('linkToDocs')
71+
->with('user-sync-calendars')
72+
->willReturn('Some docs URL');
6173
$this->initialState->method('provideInitialState')
6274
->withConsecutive(
75+
['userSyncCalendarsDocUrl', 'Some docs URL'],
6376
['sendInvitations', true],
6477
['generateBirthdayCalendar', false],
6578
['sendEventReminders', true],
6679
['sendEventRemindersPush', true],
6780
);
6881
$result = $this->settings->getForm();
6982

70-
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $result);
83+
$this->assertInstanceOf(TemplateResponse::class, $result);
7184
}
7285

7386
public function testGetSection() {

0 commit comments

Comments
 (0)