diff options
Diffstat (limited to 'apps/dav/src/service')
-rw-r--r-- | apps/dav/src/service/CalendarService.js | 87 | ||||
-rw-r--r-- | apps/dav/src/service/ExampleEventService.js | 43 | ||||
-rw-r--r-- | apps/dav/src/service/PreferenceService.js | 34 | ||||
-rw-r--r-- | apps/dav/src/service/logger.js | 12 |
4 files changed, 176 insertions, 0 deletions
diff --git a/apps/dav/src/service/CalendarService.js b/apps/dav/src/service/CalendarService.js new file mode 100644 index 00000000000..93b36b8e74f --- /dev/null +++ b/apps/dav/src/service/CalendarService.js @@ -0,0 +1,87 @@ +/** + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { getClient } from '../dav/client.js' +import logger from './logger.js' +import { parseXML } from 'webdav' + +import { + slotsToVavailability, + vavailabilityToSlots, +} from '@nextcloud/calendar-availability-vue' + +/** + * + */ +export function getEmptySlots() { + return { + MO: [], + TU: [], + WE: [], + TH: [], + FR: [], + SA: [], + SU: [], + } +} + +/** + * + */ +export async function findScheduleInboxAvailability() { + const client = getClient('calendars') + + const response = await client.customRequest('inbox', { + method: 'PROPFIND', + data: `<?xml version="1.0"?> + <x0:propfind xmlns:x0="DAV:"> + <x0:prop> + <x1:calendar-availability xmlns:x1="urn:ietf:params:xml:ns:caldav"/> + </x0:prop> + </x0:propfind>`, + }) + + const xml = await parseXML(await response.text()) + + if (!xml) { + return undefined + } + + const availability = xml?.multistatus?.response[0]?.propstat?.prop['calendar-availability'] + if (!availability) { + return undefined + } + + return vavailabilityToSlots(availability) +} + +/** + * @param {any} slots - + * @param {any} timezoneId - + */ +export async function saveScheduleInboxAvailability(slots, timezoneId) { + const all = [...Object.keys(slots).flatMap(dayId => slots[dayId].map(slot => ({ + ...slot, + day: dayId, + })))] + + const vavailability = slotsToVavailability(all, timezoneId) + + logger.debug('New availability ical created', { + vavailability, + }) + + const client = getClient('calendars') + await client.customRequest('inbox', { + method: 'PROPPATCH', + data: `<?xml version="1.0"?> + <x0:propertyupdate xmlns:x0="DAV:"> + <x0:set> + <x0:prop> + <x1:calendar-availability xmlns:x1="urn:ietf:params:xml:ns:caldav">${vavailability}</x1:calendar-availability> + </x0:prop> + </x0:set> + </x0:propertyupdate>`, + }) +} diff --git a/apps/dav/src/service/ExampleEventService.js b/apps/dav/src/service/ExampleEventService.js new file mode 100644 index 00000000000..a39e3641bd9 --- /dev/null +++ b/apps/dav/src/service/ExampleEventService.js @@ -0,0 +1,43 @@ +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { generateUrl } from '@nextcloud/router' +import axios from '@nextcloud/axios' + +/** + * Configure the creation of example events on a user's first login. + * + * @param {boolean} enable Whether to enable or disable the feature. + * @return {Promise<void>} + */ +export async function setCreateExampleEvent(enable) { + const url = generateUrl('/apps/dav/api/exampleEvent/enable') + await axios.post(url, { + enable, + }) +} + +/** + * Upload a custom example event. + * + * @param {string} ics The ICS data of the event. + * @return {Promise<void>} + */ +export async function uploadExampleEvent(ics) { + const url = generateUrl('/apps/dav/api/exampleEvent/event') + await axios.post(url, { + ics, + }) +} + +/** + * Delete a previously uploaded custom example event. + * + * @return {Promise<void>} + */ +export async function deleteExampleEvent() { + const url = generateUrl('/apps/dav/api/exampleEvent/event') + await axios.delete(url) +} diff --git a/apps/dav/src/service/PreferenceService.js b/apps/dav/src/service/PreferenceService.js new file mode 100644 index 00000000000..39b2c067c61 --- /dev/null +++ b/apps/dav/src/service/PreferenceService.js @@ -0,0 +1,34 @@ +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import axios from '@nextcloud/axios' +import { generateOcsUrl } from '@nextcloud/router' + +/** + * Enable user status automation based on availability + */ +export async function enableUserStatusAutomation() { + return await axios.post( + generateOcsUrl('/apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { + appId: 'dav', + configKey: 'user_status_automation', + }), + { + configValue: 'yes', + }, + ) +} + +/** + * Disable user status automation based on availability + */ +export async function disableUserStatusAutomation() { + return await axios.delete( + generateOcsUrl('/apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { + appId: 'dav', + configKey: 'user_status_automation', + }), + ) +} diff --git a/apps/dav/src/service/logger.js b/apps/dav/src/service/logger.js new file mode 100644 index 00000000000..cb7f1a95103 --- /dev/null +++ b/apps/dav/src/service/logger.js @@ -0,0 +1,12 @@ +/** + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { getLoggerBuilder } from '@nextcloud/logger' + +const logger = getLoggerBuilder() + .setApp('dav') + .detectUser() + .build() + +export default logger |