From 063e0acb7868ed58bf87da58e671acefa637e543 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Tue, 8 Oct 2024 17:16:24 -0400 Subject: [PATCH] feat: Allow shared calendars as appointment conflict calendars Signed-off-by: SebastianKrupinski --- lib/Service/CalendarInitialStateService.php | 2 ++ src/components/AppointmentConfigModal.vue | 28 ++++++++++++------- src/store/settings.js | 7 +++-- src/views/Calendar.vue | 1 + tests/javascript/unit/store/settings.test.js | 5 ++++ .../CalendarInitialStateServiceTest.php | 24 ++++++++++++++-- 6 files changed, 52 insertions(+), 15 deletions(-) diff --git a/lib/Service/CalendarInitialStateService.php b/lib/Service/CalendarInitialStateService.php index 861ca2028..54eaa173d 100644 --- a/lib/Service/CalendarInitialStateService.php +++ b/lib/Service/CalendarInitialStateService.php @@ -38,6 +38,7 @@ public function run(): void { $defaultDefaultReminder = $this->config->getAppValue($this->appName, 'defaultReminder', 'none'); $defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes'); + $systemVersion = $this->config->getSystemValue('version', '1.0.0'); $appVersion = $this->config->getAppValue($this->appName, 'installed_version', ''); $eventLimit = $this->config->getUserValue($this->userId, $this->appName, 'eventLimit', $defaultEventLimit) === 'yes'; $firstRun = $this->config->getUserValue($this->userId, $this->appName, 'firstRun', 'yes') === 'yes'; @@ -69,6 +70,7 @@ public function run(): void { // if circles is not installed, we use 0.0.0 $isCircleVersionCompatible = $this->compareVersion->isCompatible($circleVersion ? $circleVersion : '0.0.0', '22'); + $this->initialStateService->provideInitialState('system_version', $systemVersion); $this->initialStateService->provideInitialState('app_version', $appVersion); $this->initialStateService->provideInitialState('event_limit', $eventLimit); $this->initialStateService->provideInitialState('first_run', $firstRun); diff --git a/src/components/AppointmentConfigModal.vue b/src/components/AppointmentConfigModal.vue index b76055ac2..51397b887 100644 --- a/src/components/AppointmentConfigModal.vue +++ b/src/components/AppointmentConfigModal.vue @@ -38,7 +38,7 @@ @@ -55,7 +55,7 @@
- this.calendarUrlToUri(cal.url) === uri) - return calendar || this.ownSortedCalendars[0] + const calendar = this.sortedCalendars.find(cal => this.calendarUrlToUri(cal.url) === uri) + return calendar || this.sortedCalendars[0] + }, + // TODO: Can be removed after NC version 30 support is dropped + availableCalendars() { + if (parseInt(this.settingsStore.systemVersion) >= 31) { + return this.sortedCalendars + } + return this.ownSortedCalendars }, selectableConflictCalendars() { // The target calendar is always a conflict calendar, remove it from additional conflict calendars - return this.ownSortedCalendars.filter(calendar => calendar.url !== this.calendar.url) + return this.availableCalendars.filter(calendar => calendar.url !== this.calendar.url) }, - conflictCalendars() { + selectedConflictCalendars() { const freebusyUris = this.editing.calendarFreeBusyUris ?? [] return freebusyUris.map(uri => { - return this.ownSortedCalendars.find(cal => this.calendarUrlToUri(cal.url) === uri) - }) + return this.availableCalendars.find(cal => this.calendarUrlToUri(cal.url) === uri) + }).filter(calendar => calendar !== undefined) }, defaultConfig() { return AppointmentConfig.createDefault( - this.calendarUrlToUri(this.ownSortedCalendars[0].url), + this.calendarUrlToUri(this.sortedCalendars[0].url), this.calendarsStore.scheduleInbox, this.settingsStore.getResolvedTimezone, ) diff --git a/src/store/settings.js b/src/store/settings.js index e959ca2e0..f72e407a8 100644 --- a/src/store/settings.js +++ b/src/store/settings.js @@ -20,6 +20,7 @@ export default defineStore('settings', { state: () => { return { // env + systemVersion: null, appVersion: null, firstRun: null, talkEnabled: false, @@ -274,6 +275,7 @@ export default defineStore('settings', { * Initialize settings * * @param {object} data The destructuring object + * @param {string} data.systemVersion The version of the Nextcloud * @param {string} data.appVersion The version of the Nextcloud app * @param {boolean} data.eventLimit Whether or not to limit number of visible events in grid view * @param {boolean} data.firstRun Whether or not this is the first run @@ -294,9 +296,10 @@ export default defineStore('settings', { * @param {boolean} data.showResources Show or hide the resources tab * @param {string} data.publicCalendars */ - loadSettingsFromServer({ appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, defaultReminder, talkEnabled, tasksEnabled, timezone, hideEventExport, forceEventAlarmType, disableAppointments, canSubscribeLink, attachmentsFolder, showResources, publicCalendars }) { + loadSettingsFromServer({ systemVersion, appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showWeekends, skipPopover, slotDuration, defaultReminder, talkEnabled, tasksEnabled, timezone, hideEventExport, forceEventAlarmType, disableAppointments, canSubscribeLink, attachmentsFolder, showResources, publicCalendars }) { logInfo(` Initial settings: + - SystemVersion: ${systemVersion} - AppVersion: ${appVersion} - EventLimit: ${eventLimit} - FirstRun: ${firstRun} @@ -317,7 +320,7 @@ Initial settings: - ShowResources: ${showResources} - PublicCalendars: ${publicCalendars} `) - + this.systemVersion = systemVersion this.appVersion = appVersion this.eventLimit = eventLimit this.firstRun = firstRun diff --git a/src/views/Calendar.vue b/src/views/Calendar.vue index c84a7cde5..135288b3f 100644 --- a/src/views/Calendar.vue +++ b/src/views/Calendar.vue @@ -267,6 +267,7 @@ export default { }, async beforeMount() { this.settingsStore.loadSettingsFromServer({ + systemVersion: loadState('calendar', 'system_version'), appVersion: loadState('calendar', 'app_version'), eventLimit: loadState('calendar', 'event_limit'), firstRun: loadState('calendar', 'first_run'), diff --git a/tests/javascript/unit/store/settings.test.js b/tests/javascript/unit/store/settings.test.js index 4e685306c..8df0ada87 100644 --- a/tests/javascript/unit/store/settings.test.js +++ b/tests/javascript/unit/store/settings.test.js @@ -40,6 +40,7 @@ describe('store/settings test suite', () => { const settingsStore = useSettingsStore() expect(settingsStore.$state).toEqual({ + systemVersion: null, appVersion: null, firstRun: null, forceEventAlarmType: false, @@ -68,6 +69,7 @@ describe('store/settings test suite', () => { const settingsStore = useSettingsStore() const state = { + systemVersion: null, appVersion: null, firstRun: null, talkEnabled: false, @@ -94,6 +96,7 @@ describe('store/settings test suite', () => { settingsStore.$state = state const settings = { + systemVersion: '1.0.0', appVersion: '2.1.0', eventLimit: false, firstRun: true, @@ -121,6 +124,7 @@ describe('store/settings test suite', () => { expect(logInfo).toHaveBeenCalledTimes(1) expect(logInfo).toHaveBeenNthCalledWith(1, ` Initial settings: + - SystemVersion: 1.0.0 - AppVersion: 2.1.0 - EventLimit: false - FirstRun: true @@ -142,6 +146,7 @@ Initial settings: - PublicCalendars: null `) expect(settingsStore.$state).toEqual({ + systemVersion: '1.0.0', appVersion: '2.1.0', eventLimit: false, firstRun: true, diff --git a/tests/php/unit/Service/CalendarInitialStateServiceTest.php b/tests/php/unit/Service/CalendarInitialStateServiceTest.php index 2689d292d..23602e36f 100755 --- a/tests/php/unit/Service/CalendarInitialStateServiceTest.php +++ b/tests/php/unit/Service/CalendarInitialStateServiceTest.php @@ -97,6 +97,11 @@ public function testRun(): void { ['user123', 'calendar', 'defaultReminder', 'defaultDefaultReminder', '00:10:00'], ['user123', 'calendar', 'showTasks', 'defaultShowTasks', '00:15:00'], ]); + $this->config->expects(self::exactly(1)) + ->method('getSystemValue') + ->willReturnMap([ + ['version', '1.0.0', '1.0.0'], + ]); $this->appManager->expects(self::exactly(3)) ->method('isEnabledForUser') ->willReturnMap([ @@ -114,9 +119,10 @@ public function testRun(): void { ->method('getAllAppointmentConfigurations') ->with($this->userId) ->willReturn([new AppointmentConfig()]); - $this->initialStateService->expects(self::exactly(23)) + $this->initialStateService->expects(self::exactly(24)) ->method('provideInitialState') ->withConsecutive( + ['system_version', '1.0.0'], ['app_version', '1.0.0'], ['event_limit', true], ['first_run', true], @@ -190,6 +196,11 @@ public function testRunAnonymously(): void { [null, 'calendar', 'defaultReminder', 'defaultDefaultReminder', '00:10:00'], [null, 'calendar', 'showTasks', 'defaultShowTasks', '00:15:00'], ]); + $this->config->expects(self::exactly(1)) + ->method('getSystemValue') + ->willReturnMap([ + ['version', '1.0.0', '1.0.0'], + ]); $this->appManager->expects(self::exactly(3)) ->method('isEnabledForUser') ->willReturnMap([ @@ -203,9 +214,10 @@ public function testRunAnonymously(): void { ['spreed', true, '12.0.0'], ['circles', true, '22.0.0'], ]); - $this->initialStateService->expects(self::exactly(22)) + $this->initialStateService->expects(self::exactly(23)) ->method('provideInitialState') ->withConsecutive( + ['system_version', '1.0.0'], ['app_version', '1.0.0'], ['event_limit', true], ['first_run', true], @@ -284,6 +296,11 @@ public function testIndexViewFix(string $savedView, string $expectedView): void ['user123', 'calendar', 'defaultReminder', 'defaultDefaultReminder', '00:10:00'], ['user123', 'calendar', 'showTasks', 'defaultShowTasks', '00:15:00'], ]); + $this->config->expects(self::exactly(1)) + ->method('getSystemValue') + ->willReturnMap([ + ['version', '1.0.0', '1.0.0'], + ]); $this->appManager->expects(self::exactly(3)) ->method('isEnabledForUser') ->willReturnMap([ @@ -301,9 +318,10 @@ public function testIndexViewFix(string $savedView, string $expectedView): void ->method('getAllAppointmentConfigurations') ->with($this->userId) ->willReturn([new AppointmentConfig()]); - $this->initialStateService->expects(self::exactly(23)) + $this->initialStateService->expects(self::exactly(24)) ->method('provideInitialState') ->withConsecutive( + ['system_version', '1.0.0'], ['app_version', '1.0.0'], ['event_limit', true], ['first_run', true],