Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move birthday calendar settings to server component #4402

Closed
wants to merge 3 commits into from
Closed
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
24 changes: 3 additions & 21 deletions src/components/AppNavigation/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
:title="settingsTitle">
<ul class="settings-fieldset-interior">
<SettingsImportSection :is-disabled="loadingCalendars" />
<ActionCheckbox class="settings-fieldset-interior-item"
:checked="birthdayCalendar"
:disabled="isBirthdayCalendarDisabled"
@update:checked="toggleBirthdayEnabled">
{{ $t('calendar', 'Enable birthday calendar') }}
</ActionCheckbox>
<ActionCheckbox class="settings-fieldset-interior-item"
:checked="showTasks"
:disabled="savingTasks"
Expand Down Expand Up @@ -96,12 +90,12 @@
{{ $t('calendar', 'Copy iOS/macOS CalDAV address') }}
</ActionButton>
<ActionLink v-if="hasAppointmentsFeature"
:href="availabilitySettingsUrl"
:href="groupwareSettingsUrl"
target="_blank">
<template #icon>
<OpenInNewIcon :size="20" decorative />
</template>
{{ $t('calendar', 'Personal availability settings') }}
{{ $t('calendar', 'Groupware settings (personal availability & birthday calendar)') }}
</ActionLink>
<ActionButton v-shortkey.propagate="['h']"
@click.prevent.stop="showKeyboardShortcuts"
Expand Down Expand Up @@ -264,23 +258,11 @@ export default {
// TODO: Remove me when Calendar doesn't support server < 23
return parseInt(OC.config.version.split('.')[0]) >= 23
},
availabilitySettingsUrl() {
groupwareSettingsUrl() {
return generateUrl('/settings/user/groupware')
},
},
methods: {
async toggleBirthdayEnabled() {
// change to loading status
this.savingBirthdayCalendar = true
try {
await this.$store.dispatch('toggleBirthdayCalendarEnabled')
this.savingBirthdayCalendar = false
} catch (error) {
console.error(error)
showError(this.$t('calendar', 'New setting was not saved successfully.'))
this.savingBirthdayCalendar = false
}
},
async toggleEventLimitEnabled() {
// change to loading status
this.savingEventLimit = true
Expand Down
11 changes: 0 additions & 11 deletions src/services/caldavService.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,6 @@ const createSubscription = async (displayName, color, source, order) => {
return getCalendarHome().createSubscribedCollection(displayName, color, source, order)
}

/**
* Enables the birthday calendar
*
* @return {Promise<Calendar>}
*/
const enableBirthdayCalendar = async () => {
await getCalendarHome().enableBirthdayCalendar()
return getBirthdayCalendar()
}

/**
* Gets the birthday calendar
*
Expand Down Expand Up @@ -255,7 +245,6 @@ export {
findSchedulingOutbox,
createCalendar,
createSubscription,
enableBirthdayCalendar,
getBirthdayCalendar,
getCurrentUserPrincipal,
principalPropertySearchByDisplaynameOrEmail,
Expand Down
22 changes: 0 additions & 22 deletions src/store/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { enableBirthdayCalendar } from '../services/caldavService.js'
import { mapDavCollectionToCalendar } from '../models/calendar'
import { detectTimezone } from '../services/timezoneDetectionService'
import { setConfig as setCalendarJsConfig } from '@nextcloud/calendar-js'
import { setConfig } from '../services/settings.js'
Expand Down Expand Up @@ -235,26 +233,6 @@ const getters = {

const actions = {

/**
* Updates the user's setting for visibility of birthday calendar
*
* @param {object} vuex The Vuex destructuring object
* @param {object} vuex.getters The Vuex Getters
* @param {Function} vuex.commit The Vuex commit Function
* @param {Function} vuex.dispatch The Vuex dispatch Function
* @return {Promise<void>}
*/
async toggleBirthdayCalendarEnabled({ getters, commit, dispatch }) {
if (getters.hasBirthdayCalendar) {
const calendar = getters.getBirthdayCalendar
await dispatch('deleteCalendar', { calendar })
} else {
const davCalendar = await enableBirthdayCalendar()
const calendar = mapDavCollectionToCalendar(davCalendar)
commit('addCalendar', { calendar })
}
},

/**
* Updates the user's setting for event limit
*
Expand Down
53 changes: 0 additions & 53 deletions tests/javascript/unit/store/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*
*/
import settingsStore from '../../../../src/store/settings.js'
import { enableBirthdayCalendar } from '../../../../src/services/caldavService.js'
import { mapDavCollectionToCalendar } from '../../../../src/models/calendar.js'
import { detectTimezone } from '../../../../src/services/timezoneDetectionService.js'
import { setConfig as setCalendarJsConfig } from '@nextcloud/calendar-js'
Expand All @@ -37,7 +36,6 @@ jest.mock('../../../../src/utils/logger.js')
describe('store/settings test suite', () => {

beforeEach(() => {
enableBirthdayCalendar.mockClear()
mapDavCollectionToCalendar.mockClear()
detectTimezone.mockClear()
setCalendarJsConfig.mockClear()
Expand Down Expand Up @@ -296,57 +294,6 @@ Initial settings:
expect(detectTimezone).toHaveBeenCalledTimes(0)
})

it('should provide an action to toggle the birthday calendar - enabled to disabled', async () => {
expect.assertions(3)

const getters = {
hasBirthdayCalendar: true,
getBirthdayCalendar: {
id: 'contact_birthdays',
},
}
const commit = jest.fn()
const dispatch = jest.fn()

dispatch.mockResolvedValueOnce()

await settingsStore.actions.toggleBirthdayCalendarEnabled({ getters, commit, dispatch })

expect(dispatch).toHaveBeenCalledTimes(1)
expect(dispatch).toHaveBeenNthCalledWith(1, 'deleteCalendar', { calendar: getters.getBirthdayCalendar })
expect(commit).toHaveBeenCalledTimes(0)
})

it('should provide an action to toggle the birthday calendar - disabled to enabled', async () => {
expect.assertions(5)

const getters = {
hasBirthdayCalendar: false,
getBirthdayCalendar: null,
}
const commit = jest.fn()
const dispatch = jest.fn()

const davCalendar = {
davCalendar: true,
}
enableBirthdayCalendar.mockResolvedValueOnce(davCalendar)

const calendar = {
id: 'new-birthday-calendar',
}
mapDavCollectionToCalendar.mockReturnValueOnce(calendar)

await settingsStore.actions.toggleBirthdayCalendarEnabled({ getters, commit, dispatch })

expect(enableBirthdayCalendar).toHaveBeenCalledTimes(1)
expect(mapDavCollectionToCalendar).toHaveBeenCalledTimes(1)
expect(mapDavCollectionToCalendar).toHaveBeenNthCalledWith(1, davCalendar)
expect(commit).toHaveBeenCalledTimes(1)
expect(commit).toHaveBeenNthCalledWith(1, 'addCalendar', { calendar })

})

it('should provide an action to toggle the event limit setting - false to true', async () => {
expect.assertions(4)

Expand Down