Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
['name' => 'view#index', 'url' => '/new/{isAllDay}/{dtStart}/{dtEnd}', 'verb' => 'GET', 'postfix' => 'direct.new.timerange'],
['name' => 'view#index', 'url' => '/edit/{objectId}', 'verb' => 'GET', 'postfix' => 'direct.edit'],
['name' => 'view#index', 'url' => '/edit/{objectId}/{recurrenceId}', 'verb' => 'GET', 'postfix' => 'direct.edit.recurrenceId'],
// Events
['name' => 'event#index', 'url' => '/event/{uid}', 'verb' => 'GET', 'postfix' => 'event.uid'],
['name' => 'event#index', 'url' => '/event/{uid}/{recurrenceId}', 'verb' => 'GET', 'postfix' => 'event.uid.recurrenceId'],
Comment on lines +17 to +19
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this a generic route "/object/{uid}" or something like that, this way this can be used for both Events and Tasks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can we use the new route attributes instead of the routes file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never worked with tasks, would they also use the same logic to resolve/ redirect ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, VTODO (tasks) are identical for the most part to a VEVENT, they have a UID and a RECURRANCE-ID, the main differences are VTODO does not have a DTEND it uses a DUE and DURATION.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I'll update it then

['name' => 'view#index', 'url' => '/{view}/{timeRange}', 'verb' => 'GET', 'requirements' => ['view' => 'timeGridDay|timeGridWeek|dayGridMonth|multiMonthYear|listMonth'], 'postfix' => 'view.timerange'],
['name' => 'view#index', 'url' => '/{view}/{timeRange}/new/{mode}/{isAllDay}/{dtStart}/{dtEnd}', 'verb' => 'GET', 'requirements' => ['view' => 'timeGridDay|timeGridWeek|dayGridMonth|multiMonthYear|listMonth'], 'postfix' => 'view.timerange.new'],
['name' => 'view#index', 'url' => '/{view}/{timeRange}/edit/{mode}/{objectId}/{recurrenceId}', 'verb' => 'GET', 'requirements' => ['view' => 'timeGridDay|timeGridWeek|dayGridMonth|multiMonthYear|listMonth'], 'postfix' => 'view.timerange.edit'],
Expand Down
97 changes: 97 additions & 0 deletions lib/Controller/EventController.php
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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a userSession

) {
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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',
])
);
}
}
44 changes: 43 additions & 1 deletion src/mixins/EditorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { showError } from '@nextcloud/dialogs'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { mapState, mapStores } from 'pinia'
import { getRFCProperties } from '../models/rfcProps.js'
import { containsRoomUrl } from '../services/talkService.ts'
Expand Down Expand Up @@ -367,6 +368,28 @@ export default {

return this.calendarObject.dav.url + '?export'
},
/**
* Returns the permanent deep link URL for this event, or null if the event is new
*
* @return {string|null}
*/
eventLink() {
if (!this.calendarObject) {
return null
}

const uid = this.calendarObject.uid
if (!uid) {
return null
}

const recurrenceId = this.$route?.params?.recurrenceId
if (recurrenceId && recurrenceId !== 'next') {
return window.location.origin + generateUrl('/apps/calendar/event/{uid}/{recurrenceId}', { uid, recurrenceId })
}

return window.location.origin + generateUrl('/apps/calendar/event/{uid}', { uid })
},
/**
* Returns whether or not this is a new event
*
Expand Down Expand Up @@ -645,6 +668,25 @@ export default {
await this.calendarObjectInstanceStore.duplicateCalendarObjectInstance()
},

/**
* Copies the permanent event deep link to the clipboard
*
* @return {Promise<void>}
*/
async copyEventLink() {
if (!this.eventLink) {
return
}

try {
await navigator.clipboard.writeText(this.eventLink)
showSuccess(t('calendar', 'Event link copied to clipboard'))
} catch (error) {
logger.error('Failed to copy event link to clipboard', { error })
showError(t('calendar', 'Failed to copy event link'))
}
},

/**
* Deletes a calendar-object
*
Expand Down
4 changes: 2 additions & 2 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ const router = createRouter({
},
{
path: '/edit/:object',
redirect: () => `/${getInitialView()}/now/edit/${getPreferredEditorRoute()}/:object/next`,
redirect: (to) => `/${getInitialView()}/now/edit/${getPreferredEditorRoute()}/${to.params.object}/next`,
},
{
path: '/edit/:object/:recurrenceId',
redirect: () => `/${getInitialView()}/now/edit/${getPreferredEditorRoute()}/:object/:recurrenceId`,
redirect: (to) => `/${getInitialView()}/now/edit/${getPreferredEditorRoute()}/${to.params.object}/${to.params.recurrenceId}`,
},
/**
* This is the main route that contains the current view and viewed day
Expand Down
8 changes: 8 additions & 0 deletions src/views/EditFull.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
@saveThisAndAllFuture="prepareAccessForAttachments(true)" />
<div class="app-full__actions__inner" :class="[{ 'app-full__actions__inner__readonly': isReadOnly }]">
<NcActions>
<NcActionButton v-if="eventLink && !isNew" @click="copyEventLink()">
<template #icon>
<ContentCopy :size="20" decorative />
</template>
{{ $t('calendar', 'Copy link') }}
</NcActionButton>
<NcActionLink v-if="!hideEventExport && hasDownloadURL && !isNew" :href="downloadURL">
<template #icon>
<Download :size="20" decorative />
Expand Down Expand Up @@ -349,6 +355,7 @@ import {
import { mapState, mapStores } from 'pinia'
import CalendarBlank from 'vue-material-design-icons/CalendarBlank.vue'
import Close from 'vue-material-design-icons/Close.vue'
import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
import ContentDuplicate from 'vue-material-design-icons/ContentDuplicate.vue'
import HelpCircleIcon from 'vue-material-design-icons/HelpCircleOutline.vue'
import Delete from 'vue-material-design-icons/TrashCanOutline.vue'
Expand Down Expand Up @@ -404,6 +411,7 @@ export default {
Delete,
Download,
ContentDuplicate,
ContentCopy,
InvitationResponseButtons,
AttachmentsList,
CalendarPickerHeader,
Expand Down
8 changes: 8 additions & 0 deletions src/views/EditSimple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
</template>
</NcPopover>
<Actions v-if="!isLoading && !isError && !isNew" :forceMenu="true">
<ActionButton v-if="eventLink" @click="copyEventLink()">
<template #icon>
<ContentCopy :size="20" decorative />
</template>
{{ $t('calendar', 'Copy link') }}
</ActionButton>
<ActionLink
v-if="!hideEventExport && hasDownloadURL"
:href="downloadURL">
Expand Down Expand Up @@ -277,6 +283,7 @@ import { mapState, mapStores } from 'pinia'
import Bell from 'vue-material-design-icons/BellOutline.vue'
import CalendarBlank from 'vue-material-design-icons/CalendarBlankOutline.vue'
import Close from 'vue-material-design-icons/Close.vue'
import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
import ContentDuplicate from 'vue-material-design-icons/ContentDuplicate.vue'
import HelpCircleIcon from 'vue-material-design-icons/HelpCircleOutline.vue'
import EditIcon from 'vue-material-design-icons/PencilOutline.vue'
Expand Down Expand Up @@ -319,6 +326,7 @@ export default {
Close,
Download,
ContentDuplicate,
ContentCopy,
Delete,
InvitationResponseButtons,
CalendarPickerHeader,
Expand Down
Loading