|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | +namespace OCA\Calendar\Controller; |
| 10 | + |
| 11 | +use OCA\Calendar\Service\ObjectResolverService; |
| 12 | +use OCP\AppFramework\Controller; |
| 13 | +use OCP\AppFramework\Http\Attribute\FrontpageRoute; |
| 14 | +use OCP\AppFramework\Http\Attribute\NoAdminRequired; |
| 15 | +use OCP\AppFramework\Http\Attribute\NoCSRFRequired; |
| 16 | +use OCP\AppFramework\Http\RedirectResponse; |
| 17 | +use OCP\IRequest; |
| 18 | +use OCP\IURLGenerator; |
| 19 | + |
| 20 | +class ObjectController extends Controller { |
| 21 | + |
| 22 | + public function __construct( |
| 23 | + string $appName, |
| 24 | + IRequest $request, |
| 25 | + private ObjectResolverService $objectResolverService, |
| 26 | + private IURLGenerator $urlGenerator, |
| 27 | + private ?string $userId, |
| 28 | + ) { |
| 29 | + parent::__construct($appName, $request); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Resolve a permanent calendar object deep link. |
| 34 | + * |
| 35 | + * @param string $uid The iCalendar UID of the object |
| 36 | + * @param string|null $recurrenceId Unix timestamp of the recurrence instance, or null for 'next' |
| 37 | + */ |
| 38 | + #[NoAdminRequired] |
| 39 | + #[NoCSRFRequired] |
| 40 | + #[FrontpageRoute(verb: 'GET', url: '/object/{uid}', postfix: 'uid')] |
| 41 | + #[FrontpageRoute(verb: 'GET', url: '/object/{uid}/{recurrenceId}', postfix: 'uid.recurrenceId')] |
| 42 | + public function index(string $uid, ?string $recurrenceId = null): RedirectResponse { |
| 43 | + |
| 44 | + $resolved = $this->userId !== null |
| 45 | + ? $this->objectResolverService->findByUid($this->userId, $uid) |
| 46 | + : null; |
| 47 | + |
| 48 | + if ($resolved !== null) { |
| 49 | + $davPath = '/remote.php/dav/calendars/' . $this->userId . '/' . $resolved['calendarUri'] . '/' . $resolved['objectUri']; |
| 50 | + $objectId = base64_encode($davPath); |
| 51 | + |
| 52 | + return new RedirectResponse( |
| 53 | + $this->urlGenerator->linkToRoute('calendar.view.indexdirect.edit.recurrenceId', [ |
| 54 | + 'objectId' => $objectId, |
| 55 | + 'recurrenceId' => $recurrenceId ?? 'next', |
| 56 | + ]) |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + // Object not found (no access or deleted) — redirect to a non-existent object so |
| 61 | + // the frontend error handling displays "Event does not exist" instead of a blank page. |
| 62 | + return new RedirectResponse( |
| 63 | + $this->urlGenerator->linkToRoute('calendar.view.indexdirect.edit.recurrenceId', [ |
| 64 | + 'objectId' => base64_encode("/object-not-found/$uid"), |
| 65 | + 'recurrenceId' => $recurrenceId ?? 'next', |
| 66 | + ]) |
| 67 | + ); |
| 68 | + } |
| 69 | +} |
0 commit comments