Skip to content

Commit

Permalink
feat: add webhook compatible object creation event for calendar objects
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Ly <[email protected]>
  • Loading branch information
edward-ly committed Feb 28, 2025
1 parent 7ef9ffa commit 82477b8
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\DAV\Events\SubscriptionDeletedEvent;
use OCA\DAV\Events\SubscriptionUpdatedEvent;
use OCP\AppFramework\Db\TTransactional;
use OCA\Calendar\Events\CalendarObjectCreatedEvent as PublicCalendarObjectCreatedEvent;
use OCP\Calendar\Exceptions\CalendarException;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -1318,6 +1319,7 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
$shares = $this->getShares($calendarId);

$this->dispatcher->dispatchTyped(new CalendarObjectCreatedEvent($calendarId, $calendarRow, $shares, $objectRow));
$this->dispatcher->dispatchTyped(new PublicCalendarObjectCreatedEvent($calendarId, $calendarRow, $shares, $objectRow));

Check failure on line 1322 in apps/dav/lib/CalDAV/CalDavBackend.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedClass

apps/dav/lib/CalDAV/CalDavBackend.php:1322:42: UndefinedClass: Class, interface or enum named OCA\Calendar\Events\CalendarObjectCreatedEvent does not exist (see https://psalm.dev/019)
} else {
$subscriptionRow = $this->getSubscriptionById($calendarId);

Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
'OCP\\Broadcast\\Events\\IBroadcastEvent' => $baseDir . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
'OCP\\Cache\\CappedMemoryCache' => $baseDir . '/lib/public/Cache/CappedMemoryCache.php',
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => $baseDir . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\Events\\AbstractCalendarObjectEvent' => $baseDir . '/lib/public/Calendar/Events/AbstractCalendarObjectEvent.php',
'OCP\\Calendar\\Events\\CalendarObjectCreatedEvent' => $baseDir . '/lib/public/Calendar/Events/CalendarObjectCreatedEvent.php',
'OCP\\Calendar\\Exceptions\\CalendarException' => $baseDir . '/lib/public/Calendar/Exceptions/CalendarException.php',
'OCP\\Calendar\\IAvailabilityResult' => $baseDir . '/lib/public/Calendar/IAvailabilityResult.php',
'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Broadcast\\Events\\IBroadcastEvent' => __DIR__ . '/../../..' . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
'OCP\\Cache\\CappedMemoryCache' => __DIR__ . '/../../..' . '/lib/public/Cache/CappedMemoryCache.php',
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\Events\\AbstractCalendarObjectEvent' => __DIR__ . '/../../..' . '/lib/public/Calendar/Events/AbstractCalendarObjectEvent.php',
'OCP\\Calendar\\Events\\CalendarObjectCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Calendar/Events/CalendarObjectCreatedEvent.php',
'OCP\\Calendar\\Exceptions\\CalendarException' => __DIR__ . '/../../..' . '/lib/public/Calendar/Exceptions/CalendarException.php',
'OCP\\Calendar\\IAvailabilityResult' => __DIR__ . '/../../..' . '/lib/public/Calendar/IAvailabilityResult.php',
'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php',
Expand Down
79 changes: 79 additions & 0 deletions lib/public/Calendar/Events/AbstractCalendarObjectEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Calendar\Events;

use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IWebhookCompatibleEvent;

/**
* @since 32.0.0
*/
abstract class AbstractCalendarObjectEvent extends Event implements IWebhookCompatibleEvent {

/**
* @param int $calendarId
* @param array $calendarData
* @param array $shares
* @param array $objectData
* @since 32.0.0
*/
public function __construct(
private int $calendarId,
private array $calendarData,
private array $shares,
private array $objectData,
) {
parent::__construct();
}

/**
* @return int
* @since 32.0.0
*/
public function getCalendarId(): int {
return $this->calendarId;
}

/**
* @return array
* @since 32.0.0
*/
public function getCalendarData(): array {
return $this->calendarData;
}

/**
* @return array
* @since 32.0.0
*/
public function getShares(): array {
return $this->shares;
}

/**
* @return array
* @since 32.0.0
*/
public function getObjectData(): array {
return $this->objectData;
}

/**
* @return array
* @since 32.0.0
*/
public function getWebhookSerializable(): array {
return [
'calendarId' => $this->getCalendarId(),
'calendarData' => $this->getCalendarData(),
'shares' => $this->getShares(),
'objectData' => $this->getObjectData(),
];
}
}
15 changes: 15 additions & 0 deletions lib/public/Calendar/Events/CalendarObjectCreatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Calendar\Events;

/**
* @since 32.0.0
*/
class CalendarObjectCreatedEvent extends AbstractCalendarObjectEvent {
}

0 comments on commit 82477b8

Please sign in to comment.