Skip to content

Commit 25fe2fa

Browse files
committed
Revert 'Revert "send invitations for shared calendars"'
This is basically the original commit, but with the addition that CalDavBackend::getCalendarObjectByUID() also takes object in writable shared calendars in to account and adjusts their uri s.t. the Sabre library can find the returned object uri in the user's calendar collection.
1 parent d078380 commit 25fe2fa

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,18 +2146,44 @@ public function searchPrincipalUri(string $principalUri,
21462146
* @return string|null
21472147
*/
21482148
public function getCalendarObjectByUID($principalUri, $uid) {
2149+
// query for shared writable calendars
2150+
$principals = $this->principalBackend->getGroupMembership($principalUri, true);
2151+
$principals = array_merge($principals, $this->principalBackend->getCircleMembership($principalUri));
2152+
21492153
$query = $this->db->getQueryBuilder();
2150-
$query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi')
2154+
$query
2155+
->selectAlias('c.id', 'calendarid')
2156+
->selectAlias('c.principaluri', 'principaluri')
2157+
->selectAlias('c.uri', 'calendaruri')
2158+
->selectAlias('co.uri', 'objecturi')
2159+
->selectAlias('ds.access', 'access')
21512160
->from('calendarobjects', 'co')
21522161
->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id'))
2153-
->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri)))
2154-
->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid)))
2155-
->andWhere($query->expr()->isNull('co.deleted_at'));
2162+
->leftJoin('co', 'dav_shares', 'ds', $query->expr()->eq('co.calendarid', 'ds.resourceid'))
2163+
->where($query->expr()->eq('co.uid', $query->createNamedParameter($uid)))
2164+
->andWhere($query->expr()->isNull('co.deleted_at'))
2165+
->andWhere($query->expr()->orX(
2166+
$query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri)),
2167+
$query->expr()->andX(
2168+
$query->expr()->in('ds.principaluri', $query->createParameter('shareprincipal')),
2169+
$query->expr()->eq('ds.type', $query->createParameter('type')),
2170+
$query->expr()->eq('ds.access', $query->createParameter('access')),
2171+
)
2172+
))
2173+
->setParameter('access', Backend::ACCESS_READ_WRITE)
2174+
->setParameter('type', 'calendar')
2175+
->setParameter('shareprincipal', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
21562176
$stmt = $query->executeQuery();
21572177
$row = $stmt->fetch();
21582178
$stmt->closeCursor();
21592179
if ($row) {
2160-
return $row['calendaruri'] . '/' . $row['objecturi'];
2180+
if ($row['principaluri'] != $principalUri) {
2181+
[, $name] = Uri\split($row['principaluri']);
2182+
$calendarUri = $row['calendaruri'] . '_shared_by_' . $name;
2183+
} else {
2184+
$calendarUri = $row['calendaruri'];
2185+
}
2186+
return $calendarUri . '/' . $row['objecturi'];
21612187
}
21622188

21632189
return null;

apps/dav/lib/CalDAV/Schedule/Plugin.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,53 @@ public function calendarObjectChange(RequestInterface $request, ResponseInterfac
162162
$this->pathOfCalendarObjectChange = $request->getPath();
163163
}
164164

165-
parent::calendarObjectChange($request, $response, $vCal, $calendarPath, $modified, $isNew);
165+
//parent::calendarObjectChange($request, $response, $vCal, $calendarPath, $modified, $isNew);
166+
167+
if (!$this->scheduleReply($this->server->httpRequest)) {
168+
return;
169+
}
170+
171+
$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
172+
173+
// Original code in parent class:
174+
//
175+
// $addresses = $this->getAddressesForPrincipal(
176+
// $calendarNode->getOwner()
177+
// );
178+
179+
// Allow also writable shared calendars:
180+
$addresses = $this->getAddressesForPrincipal(
181+
$calendarNode->getPrincipalURI()
182+
);
183+
184+
if (!$isNew) {
185+
$node = $this->server->tree->getNodeForPath($request->getPath());
186+
$oldObj = Reader::read($node->get());
187+
} else {
188+
$oldObj = null;
189+
}
190+
191+
$this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
192+
193+
if ($oldObj) {
194+
// Destroy circular references so PHP will GC the object.
195+
$oldObj->destroy();
196+
}
197+
}
198+
199+
/**
200+
* This method checks the 'Schedule-Reply' header
201+
* and returns false if it's 'F', otherwise true.
202+
*
203+
* Copied from Sabre/DAV's Schedule plugin, because it's
204+
* private for whatever reason
205+
*
206+
* @param RequestInterface $request
207+
* @return bool
208+
*/
209+
private function scheduleReply(RequestInterface $request) {
210+
$scheduleReply = $request->getHeader('Schedule-Reply');
211+
return $scheduleReply !== 'F';
166212
}
167213

168214
/**

0 commit comments

Comments
 (0)