DefaultCalendarValidator.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\CalDAV;
  8. use Sabre\DAV\Exception as DavException;
  9. class DefaultCalendarValidator {
  10. /**
  11. * Check if a given Calendar node is suitable to be used as the default calendar for scheduling.
  12. *
  13. * @throws DavException If the calendar is not suitable to be used as the default calendar
  14. */
  15. public function validateScheduleDefaultCalendar(Calendar $calendar): void {
  16. // Sanity checks for a calendar that should handle invitations
  17. if ($calendar->isSubscription()
  18. || !$calendar->canWrite()
  19. || $calendar->isShared()
  20. || $calendar->isDeleted()) {
  21. throw new DavException('Calendar is a subscription, not writable, shared or deleted');
  22. }
  23. // Calendar must support VEVENTs
  24. $sCCS = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
  25. $calendarProperties = $calendar->getProperties([$sCCS]);
  26. if (isset($calendarProperties[$sCCS])) {
  27. $supportedComponents = $calendarProperties[$sCCS]->getValue();
  28. } else {
  29. $supportedComponents = ['VJOURNAL', 'VTODO', 'VEVENT'];
  30. }
  31. if (!in_array('VEVENT', $supportedComponents, true)) {
  32. throw new DavException('Calendar does not support VEVENT components');
  33. }
  34. }
  35. }