Skip to content

Commit

Permalink
feat: Allow shared calendars as appointment conflict calendars
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Nov 12, 2024
1 parent 1dd9614 commit 063e0ac
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
2 changes: 2 additions & 0 deletions lib/Service/CalendarInitialStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 18 additions & 10 deletions src/components/AppointmentConfigModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<label>{{ t('calendar', 'Calendar') }}</label>
<CalendarPicker v-if="calendar !== undefined"
:value="calendar"
:calendars="ownSortedCalendars"
:calendars="availableCalendars"
:show-calendar-on-select="false"
@select-calendar="changeCalendar" />
</div>
Expand All @@ -55,7 +55,7 @@

<div class="appointment-config-modal__form__row appointment-config-modal__form__row--local">
<label>{{ t('calendar', 'Additional calendars to check for conflicts') }}</label>
<CalendarPicker :value="conflictCalendars"
<CalendarPicker :value="selectedConflictCalendars"
:calendars="selectableConflictCalendars"
:multiple="true"
:show-calendar-on-select="false"
Expand Down Expand Up @@ -196,6 +196,7 @@ export default {
isTalkEnabled: 'talkEnabled',
}),
...mapState(useCalendarsStore, ['ownSortedCalendars']),
...mapState(useCalendarsStore, ['sortedCalendars']),
...mapStores(useAppointmentConfigsStore, useCalendarsStore, useSettingsStore),
formTitle() {
if (this.showConfirmation) {
Expand All @@ -216,26 +217,33 @@ export default {
},
calendar() {
if (!this.editing.targetCalendarUri) {
return this.ownSortedCalendars[0]
return this.sortedCalendars[0]
}
const uri = this.editing.targetCalendarUri
const calendar = this.ownSortedCalendars.find(cal => 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,
)
Expand Down
7 changes: 5 additions & 2 deletions src/store/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default defineStore('settings', {
state: () => {
return {
// env
systemVersion: null,
appVersion: null,
firstRun: null,
talkEnabled: false,
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -317,7 +320,7 @@ Initial settings:
- ShowResources: ${showResources}
- PublicCalendars: ${publicCalendars}
`)

this.systemVersion = systemVersion
this.appVersion = appVersion
this.eventLimit = eventLimit
this.firstRun = firstRun
Expand Down
1 change: 1 addition & 0 deletions src/views/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
5 changes: 5 additions & 0 deletions tests/javascript/unit/store/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('store/settings test suite', () => {
const settingsStore = useSettingsStore()

expect(settingsStore.$state).toEqual({
systemVersion: null,
appVersion: null,
firstRun: null,
forceEventAlarmType: false,
Expand Down Expand Up @@ -68,6 +69,7 @@ describe('store/settings test suite', () => {
const settingsStore = useSettingsStore()

const state = {
systemVersion: null,
appVersion: null,
firstRun: null,
talkEnabled: false,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -142,6 +146,7 @@ Initial settings:
- PublicCalendars: null
`)
expect(settingsStore.$state).toEqual({
systemVersion: '1.0.0',
appVersion: '2.1.0',
eventLimit: false,
firstRun: true,
Expand Down
24 changes: 21 additions & 3 deletions tests/php/unit/Service/CalendarInitialStateServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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],
Expand Down Expand Up @@ -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([
Expand All @@ -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],
Expand Down Expand Up @@ -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([
Expand All @@ -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],
Expand Down

0 comments on commit 063e0ac

Please sign in to comment.