Skip to content

fix: access shared and delegated trashbin objects#60648

Open
hamza221 wants to merge 1 commit into
masterfrom
fix/caldav/trashbin-shared
Open

fix: access shared and delegated trashbin objects#60648
hamza221 wants to merge 1 commit into
masterfrom
fix/caldav/trashbin-shared

Conversation

@hamza221
Copy link
Copy Markdown
Contributor

@hamza221 hamza221 commented May 21, 2026

Assisted-by: claude:Opus 4.7 (1M context)

Summary

  • Allow frontend to list ( potentially permanently delete or restore) shared and delegator's accessible deleted calendar objects
  • Ensure that every object is showed only once with most permissive access example:
    • Bob shares (readonly) calendar1 to Alice
    • Bob shares (write) to Jhon
    • Jhon delegates account to Alice
    • Bob deletes 'example event'
    • Jane sees one 'example event' in her trashbin
    • Jane can restore or permanently delete 'example event'

Checklist

AI (if applicable)

  • The content of this PR was partly generated using AI

Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>

Assisted-by: claude:Opus 4.7 (1M context)
@hamza221 hamza221 added bug 3. to review Waiting for reviews feature: caldav Related to CalDAV internals labels May 21, 2026
@hamza221 hamza221 added this to the Nextcloud 35 milestone May 21, 2026
@hamza221
Copy link
Copy Markdown
Contributor Author

/backport to stable34

@hamza221
Copy link
Copy Markdown
Contributor Author

/backport to stable33

@hamza221
Copy link
Copy Markdown
Contributor Author

/backport to stable32

@hamza221 hamza221 marked this pull request as ready for review May 21, 2026 19:52
@hamza221 hamza221 self-assigned this May 21, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands the CalDAV trashbin to surface deleted calendar objects that are accessible via calendar sharing and via calendar proxy delegation, and adds permission enforcement so only sufficiently privileged sharees/proxies can restore or permanently delete entries.

Changes:

  • Extend deleted-object listing/lookup in CalDavBackend to include owned + shared calendars and proxy delegators, and to compute an effective access level per entry.
  • Update trashbin collection/object nodes to use the new backend lookup and to restrict restore/permanent delete for read-only access paths.
  • Refactor deleted-object row building into a shared helper (rowToDeletedCalendarObject) and add helpers for principal resolution and shared-calendar filtering.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
apps/dav/lib/CalDAV/Trashbin/DeletedCalendarObjectsCollection.php Switches child lookup to a principal-aware deleted-object lookup and simplifies calendarQuery() mapping.
apps/dav/lib/CalDAV/Trashbin/DeletedCalendarObject.php Adds access checks for restore/permanent delete and adapts ACL generation based on effective access.
apps/dav/lib/CalDAV/CalDavBackend.php Adds shared/proxy-aware deleted-object listing and single-object lookup, with effective-access and principal resolution helpers.
Comments suppressed due to low confidence (1)

apps/dav/lib/CalDAV/CalDavBackend.php:2683

  • New trashbin behavior (shared calendars + proxy delegation + access overlay selection) is complex and currently untested. Since apps/dav has extensive CalDavBackend unit coverage, please add tests that cover: (1) deduping the same deleted object across multiple accessible paths while keeping the most permissive access, and (2) proxy-read vs proxy-write vs direct share permissions for restore/permanent delete.
	public function getDeletedCalendarObjectByIdForPrincipal(int $id, string $principalUri): ?array {
		// Visit every accessible path (self + delegators) and keep the most
		// permissive row, so canModify() doesn't get a read-only view when a
		// write path also exists.
		$candidates = [];
		$row = $this->findDeletedCalendarObjectForPrincipal($id, $principalUri, null);
		if ($row !== null) {
			$candidates[$id] = $row;
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1204 to +1212
$result = $this->collectDeletedCalendarObjectsForPrincipal($principalUri, null);
foreach ($this->getProxyDelegators($principalUri) as $delegator => $hasProxyWrite) {
$overlay = $hasProxyWrite ? Backend::ACCESS_READ_WRITE : Backend::ACCESS_READ;
$result = array_merge($result, $this->collectDeletedCalendarObjectsForPrincipal($delegator, $overlay));
}
return $result;
}

/**
Comment on lines +1213 to +1220
* Run the owned + shared trashbin queries for $principalUri and merge into $result.
*
* @param string $principalUri principal whose calendars to scan.
* @param array $result accumulator keyed by calendar object id; merged in-place.
* @param int|null $proxyOverlay if non-null, the entries are being collected on
* behalf of a different accessor via calendar-proxy; the value caps the
* effective share access for that accessor (READ_WRITE for proxy-write,
* READ for proxy-read). null means $principalUri is the accessor itself.
->from('calendarobjects', 'co')
->join('co', 'calendars', 'c', $query->expr()->eq('c.id', 'co.calendarid', IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('co.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
->andWhere($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri)))
->from('calendarobjects', 'co')
->join('co', 'calendars', 'c', $select->expr()->eq('c.id', 'co.calendarid', IQueryBuilder::PARAM_INT))
->andWhere($select->expr()->eq('co.id', $select->createNamedParameter($id, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
->andWhere($select->expr()->isNotNull('co.deleted_at'))
@hamza221 hamza221 added 2. developing Work in progress and removed 3. to review Waiting for reviews labels May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress backport-request bug feature: caldav Related to CalDAV internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants