Skip to content
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

Shared calendar invitations #36756

Closed
Closed
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
55 changes: 46 additions & 9 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2171,21 +2171,58 @@ public function searchPrincipalUri(string $principalUri,
* @return string|null
*/
public function getCalendarObjectByUID($principalUri, $uid) {
// query for shared writable calendars
$principals = $this->principalBackend->getGroupMembership($principalUri, true);
$principals = array_merge($principals, $this->principalBackend->getCircleMembership($principalUri));

$query = $this->db->getQueryBuilder();
$query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi')
$query
->selectAlias('c.id', 'calendarid')
->selectAlias('c.principaluri', 'principaluri')
->selectAlias('c.uri', 'calendaruri')
->selectAlias('co.uri', 'objecturi')
->selectAlias('ds.access', 'access')
->selectAlias('ds.principaluri', 'shareprincipal')
->from('calendarobjects', 'co')
->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id'))
->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri)))
->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid)))
->andWhere($query->expr()->isNull('co.deleted_at'));
->leftJoin('co', 'dav_shares', 'ds', $query->expr()->eq('co.calendarid', 'ds.resourceid'))
->where($query->expr()->eq('co.uid', $query->createNamedParameter($uid)))
->andWhere($query->expr()->isNull('co.deleted_at'))
->andWhere($query->expr()->orX(
$query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri)),
$query->expr()->andX(
$query->expr()->in('ds.principaluri', $query->createParameter('shareprincipal')),
$query->expr()->eq('ds.type', $query->createParameter('type')),
$query->expr()->eq('ds.access', $query->createParameter('access')),
)
))
->setParameter('access', Backend::ACCESS_READ_WRITE)
->setParameter('type', 'calendar')
->setParameter('shareprincipal', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
$stmt = $query->executeQuery();
$row = $stmt->fetch();
$stmt->closeCursor();
if ($row) {
return $row['calendaruri'] . '/' . $row['objecturi'];
$calendarObjectUri = null;
while ($row = $stmt->fetch()) {
if ($row['principaluri'] != $principalUri && !empty($row['shareprincipal']) && $row['access'] == Backend::ACCESS_READ_WRITE) {
/**
* This seeems to be a false positive: we have "use Sabre\Uri" and Uri\split() IS defined.
*
* @psalm-suppress UndefinedFunction
*/
[, $name] = Uri\split($row['principaluri']);
$calendarUri = $row['calendaruri'] . '_shared_by_' . $name;
} elseif (!empty($calendarObjectUri)) {
// There could be multiple entries for the UID if the share
// permissions have been changed "in between". In this case we
// prefer the shared calendar object.
continue;
} else {
$calendarUri = $row['calendaruri'];
}
$calendarObjectUri = $calendarUri . '/' . $row['objecturi'];
}
$stmt->closeCursor();

return null;
return $calendarObjectUri;
}

public function getCalendarObjectById(string $principalUri, int $id): ?array {
Expand Down
58 changes: 57 additions & 1 deletion apps/dav/lib/CalDAV/Schedule/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,63 @@ public function calendarObjectChange(RequestInterface $request, ResponseInterfac
$this->pathOfCalendarObjectChange = $request->getPath();
}

parent::calendarObjectChange($request, $response, $vCal, $calendarPath, $modified, $isNew);
//parent::calendarObjectChange($request, $response, $vCal, $calendarPath, $modified, $isNew);

if (!$this->scheduleReply($this->server->httpRequest)) {
return;
}

/** @var Calendar $calendarNode */
$calendarNode = $this->server->tree->getNodeForPath($calendarPath);

// Original code in parent class:
//
// $addresses = $this->getAddressesForPrincipal(
// $calendarNode->getOwner()
// );

// Allow also writable shared calendars:
$addresses = $this->getAddressesForPrincipal(
$calendarNode->getPrincipalURI()
);

/** @var VCalendar $oldObj */
if (!$isNew) {
/** @var \Sabre\CalDAV\CalendarObject $node */
$node = $this->server->tree->getNodeForPath($request->getPath());
$oldObj = Reader::read($node->get());
} else {
$oldObj = null;
}

/**
* Sabre has several issues with faulty argument type specifications
* in its doc-block comments. Passing null is ok here.
*
* @psalm-suppress PossiblyNullArgument
* @psalm-suppress ArgumentTypeCoercion
*/
$this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);

if ($oldObj) {
// Destroy circular references so PHP will GC the object.
$oldObj->destroy();
}
}

/**
* This method checks the 'Schedule-Reply' header
* and returns false if it's 'F', otherwise true.
*
* Copied from Sabre/DAV's Schedule plugin, because it's
* private for whatever reason
*
* @param RequestInterface $request
* @return bool
*/
private function scheduleReply(RequestInterface $request) {
$scheduleReply = $request->getHeader('Schedule-Reply');
return $scheduleReply !== 'F';
}

/**
Expand Down