-
Notifications
You must be signed in to change notification settings - Fork 304
fix: add event link #8123
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
base: main
Are you sure you want to change the base?
fix: add event link #8123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OCA\Calendar\Controller; | ||
|
|
||
| use OCA\Calendar\Service\CalendarInitialStateService; | ||
| use OCP\AppFramework\Controller; | ||
| use OCP\AppFramework\Http\RedirectResponse; | ||
| use OCP\AppFramework\Http\Response; | ||
| use OCP\AppFramework\Http\TemplateResponse; | ||
| use OCP\Calendar\IManager; | ||
| use OCP\IRequest; | ||
| use OCP\IURLGenerator; | ||
|
|
||
| /** | ||
| * Controller for permanent event deep links. | ||
| * | ||
| * Routes like /apps/calendar/event/{uid} and /apps/calendar/event/{uid}/{recurrenceId} | ||
| * resolve the UID to the appropriate calendar object and redirect to the standard | ||
| * edit route | ||
| */ | ||
| class EventController extends Controller { | ||
|
|
||
| public function __construct( | ||
| string $appName, | ||
| IRequest $request, | ||
| private CalendarInitialStateService $calendarInitialStateService, | ||
| private IManager $calendarManager, | ||
| private IURLGenerator $urlGenerator, | ||
| private ?string $userId, | ||
|
SebastianKrupinski marked this conversation as resolved.
|
||
| ) { | ||
| parent::__construct($appName, $request); | ||
| } | ||
|
|
||
| /** | ||
| * Resolve a permanent event deep link. | ||
| * | ||
| * Searches all calendars for an event with the given UID and redirects | ||
| * to the standard edit route. Falls back to serving the SPA if the | ||
| * event cannot be resolved server-side. | ||
| * | ||
| * @NoAdminRequired | ||
| * @NoCSRFRequired | ||
|
Comment on lines
+47
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the new route attributes |
||
| * | ||
| * @param string $uid The iCalendar UID of the event | ||
| * @param string|null $recurrenceId Unix timestamp of the recurrence instance, or null for 'next' | ||
| * @return Response | ||
| */ | ||
| public function index(string $uid, ?string $recurrenceId = null): Response { | ||
| if ($this->userId === null) { | ||
| $this->calendarInitialStateService->run(); | ||
| return new TemplateResponse($this->appName, 'main'); | ||
| } | ||
|
Comment on lines
+55
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
|
|
||
| $principalUri = "principals/users/{$this->userId}"; | ||
| $calendars = $this->calendarManager->getCalendarsForPrincipal($principalUri); | ||
|
|
||
| foreach ($calendars as $calendar) { | ||
| if (method_exists($calendar, 'isDeleted') && $calendar->isDeleted()) { | ||
| continue; | ||
| } | ||
|
|
||
| $results = $calendar->search('', [], ['uid' => $uid], 1); | ||
| if (!empty($results)) { | ||
| $result = $results[0]; | ||
| $objectUri = $result['uri']; | ||
| $calendarUri = $calendar->getUri(); | ||
|
|
||
| $davPath = '/remote.php/dav/calendars/' . $this->userId . '/' . $calendarUri . '/' . $objectUri; | ||
| $objectId = base64_encode($davPath); | ||
|
|
||
| $editRecurrenceId = $recurrenceId ?? 'next'; | ||
|
|
||
| return new RedirectResponse( | ||
| $this->urlGenerator->linkToRoute('calendar.view.indexdirect.edit.recurrenceId', [ | ||
| 'objectId' => $objectId, | ||
| 'recurrenceId' => $editRecurrenceId, | ||
| ]) | ||
| ); | ||
| } | ||
|
Comment on lines
+63
to
+85
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be maybe moved to a service, so it can be reused by #8048
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be helpful indeed 😊 |
||
| } | ||
|
|
||
| // Event not found (no access or deleted) — redirect to a non-existent object so | ||
| // the SPA's error handling displays "Event does not exist" instead of a blank page. | ||
| return new RedirectResponse( | ||
| $this->urlGenerator->linkToRoute('calendar.view.indexdirect.edit.recurrenceId', [ | ||
| 'objectId' => base64_encode("/event-not-found/$uid"), | ||
| 'recurrenceId' => $recurrenceId ?? 'next', | ||
| ]) | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.