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
10 changes: 7 additions & 3 deletions lib/CalDAV/Backend/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ public function getCalendarsForUser($principalUri)
$calendar['share-access'] = (int) $row['access'];
// 1 = owner, 2 = readonly, 3 = readwrite
if ($row['access'] > 1) {
// We need to find more information about the original owner.
//$stmt2 = $this->pdo->prepare('SELECT principaluri FROM ' . $this->calendarInstancesTableName . ' WHERE access = 1 AND id = ?');
//$stmt2->execute([$row['id']]);
$ownerStmt = $this->pdo->prepare("SELECT principaluri FROM {$this->calendarInstancesTableName} WHERE access = 1 AND calendarid = ?");
$ownerStmt->execute([$row['calendarid']]);

$ownerRow = $ownerStmt->fetch(\PDO::FETCH_ASSOC);
if ($ownerRow && is_array($ownerRow) && array_key_exists('principaluri', $ownerRow)) {
$calendar['owner-principal'] = $ownerRow['principaluri'];
}

// read-only is for backwards compatibility. Might go away in
// the future.
Expand Down
16 changes: 16 additions & 0 deletions lib/CalDAV/Principal/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ public function getACL()
'protected' => true,
];

/**
* Members of shared calendars needs to be able to read information about the owner.
*
* The Principal has no knowledge about the calendars and therefore it is not
* possible to limit the access to members of a shared calendar
* in DAVACL/Plugin.php getCurrentUserPrivilegeSet.
*
* As workaround all authenticated users are getting the read privilege for other users.
*/

$acl[] = [
'privilege' => '{DAV:}read',
'principal' => '{DAV:}authenticated',
'protected' => true,
];

return $acl;
}
}
12 changes: 12 additions & 0 deletions lib/CalDAV/SharedCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,16 @@ public function getChildACL()

return $acl;
}

/**
* Returns the 'original owner principal' for this shared resource.
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getOwnerPrincipal()
{
return isset($this->calendarInfo['owner-principal']) ? $this->calendarInfo['owner-principal'] : $this->getOwner();
}
}
10 changes: 9 additions & 1 deletion lib/CalDAV/SharingPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function initialize(DAV\Server $server)
$this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}share'] = \Sabre\CalDAV\Xml\Request\Share::class;
$this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}invite-reply'] = \Sabre\CalDAV\Xml\Request\InviteReply::class;

$this->server->on('propFind', [$this, 'propFindEarly']);
$this->server->on('propFind', [$this, 'propFindEarly'], 10);
$this->server->on('propFind', [$this, 'propFindLate'], 150);
$this->server->on('propPatch', [$this, 'propPatch'], 40);
$this->server->on('method:POST', [$this, 'httpPost']);
Expand All @@ -106,6 +106,14 @@ public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node)
$node->getInvites()
);
});

// Needs to be called before ACL
$propFind->handle('{DAV:}owner', function () use ($node) {
$shareAccess = $node->getShareAccess();
if ($shareAccess > 1) {
return new \Sabre\DAV\Xml\Property\Href($node->getOwnerPrincipal() . '/');
}
});
}
}

Expand Down
9 changes: 9 additions & 0 deletions lib/DAV/Sharing/ISharedNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@ public function updateInvites(array $sharees);
* @return \Sabre\DAV\Xml\Element\Sharee[]
*/
public function getInvites();

/**
* Returns the 'original owner principal' for this shared resource.
*
* This must be a url to a principal, or null if there's no owner
*
* @return string|null
*/
public function getOwnerPrincipal();
}