diff --git a/apps/calendar/caldav.php b/apps/calendar/caldav.php index b581274398ddb99b1270a18cef06c8faa1493526..db0b35da118f668626afec7a5cb43c080da4d88a 100644 --- a/apps/calendar/caldav.php +++ b/apps/calendar/caldav.php @@ -19,7 +19,7 @@ $caldavBackend = new OC_Connector_Sabre_CalDAV(); // Root nodes $nodes = array( - new Sabre_DAVACL_PrincipalCollection($principalBackend), + new Sabre_CalDAV_Principal_Collection($principalBackend), new Sabre_CalDAV_CalendarRootNode($principalBackend, $caldavBackend), ); diff --git a/apps/contacts/carddav.php b/apps/contacts/carddav.php index df7c858b1a00346b45cf4790b173a5d838f40deb..a2bf492e2062643b00c474123505ddd0651a0fa5 100644 --- a/apps/contacts/carddav.php +++ b/apps/contacts/carddav.php @@ -33,7 +33,7 @@ $carddavBackend = new OC_Connector_Sabre_CardDAV(); // Root nodes $nodes = array( - new Sabre_DAVACL_PrincipalCollection($principalBackend), + new Sabre_CalDAV_Principal_Collection($principalBackend), new Sabre_CardDAV_AddressBookRoot($principalBackend, $carddavBackend), ); diff --git a/lib/connector/sabre/principal.php b/lib/connector/sabre/principal.php index 9c386f85e15f889f249ac117d2d78dfae05129b1..0f3d5feb794fbeeb83dffa15973092986072cc67 100644 --- a/lib/connector/sabre/principal.php +++ b/lib/connector/sabre/principal.php @@ -44,6 +44,7 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { } return true; } + /** * Returns a list of principals based on a prefix. * @@ -57,22 +58,17 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @param string $prefixPath * @return array */ - public function getPrincipalsByPrefix( $prefixPath ){ - $query = OC_DB::prepare('SELECT * FROM *PREFIX*principals'); - $result = $query->execute(); - + public function getPrincipalsByPrefix( $prefixPath ) { $principals = array(); - while($row = $result->fetchRow()){ - // Checking if the principal is in the prefix - list($rowPrefix) = Sabre_DAV_URLUtil::splitPath($row['uri']); - if ($rowPrefix !== $prefixPath) continue; - - $principals[] = array( - 'uri' => $row['uri'], - '{DAV:}displayname' => $row['displayname']?$row['displayname']:basename($row['uri']) - ); - + if ($prefixPath == 'principals') { + foreach(OC_User::getUsers() as $user) { + $user_uri = 'principals/'.$user; + $principals[] = array( + 'uri' => $user_uri, + '{DAV:}displayname' => $user, + ); + } } return $principals; @@ -87,20 +83,16 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @return array */ public function getPrincipalByPath($path) { - $query = OC_DB::prepare('SELECT * FROM *PREFIX*principals WHERE uri=?'); - $result = $query->execute(array($path)); - - $users = array(); + list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($path); - $row = $result->fetchRow(); - if (!$row) return; - - return array( - 'id' => $row['id'], - 'uri' => $row['uri'], - '{DAV:}displayname' => $row['displayname']?$row['displayname']:basename($row['uri']) - ); + if ($prefix == 'principals' && OC_User::userExists($name)) { + return array( + 'uri' => 'principals/'.$name, + '{DAV:}displayname' => $name, + ); + } + return null; } /** @@ -110,17 +102,15 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @return array */ public function getGroupMemberSet($principal) { - $principal = $this->getPrincipalByPath($principal); + // TODO: for now the group principal has only one member, the user itself + list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($principal); + + $principal = $this->getPrincipalByPath($prefix); if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); - $query = OC_DB::prepare('SELECT principals.uri as uri FROM *PREFIX*principalgroups AS groupmembers LEFT JOIN *PREFIX*principals AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?'); - $result = $query->execute(array($principal['id'])); - - $return = array(); - while ($row = $result->fetchRow()){ - $return[] = $row['uri']; - } - return $return; + return array( + $prefix + ); } /** @@ -130,17 +120,24 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @return array */ public function getGroupMembership($principal) { - $principal = $this->getPrincipalByPath($principal); - if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); - - $query = OC_DB::prepare('SELECT principals.uri as uri FROM *PREFIX*principalgroups AS groupmembers LEFT JOIN *PREFIX*principals AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.member_id = ?'); - $result = $query->execute(array($principal['id'])); - - $return = array(); - while ($row = $result->fetchRow()){ - $return[] = $row['uri']; + list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($principal); + + $group_membership = array(); + if ($prefix == 'principals') { + $principal = $this->getPrincipalByPath($principal); + if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); + + // TODO: for now the user principal has only its own groups + return array( + 'principals/'.$name.'/calendar-proxy-read', + 'principals/'.$name.'/calendar-proxy-write', + // The addressbook groups are not supported in Sabre, + // see http://groups.google.com/group/sabredav-discuss/browse_thread/thread/ef2fa9759d55f8c#msg_5720afc11602e753 + //'principals/'.$name.'/addressbook-proxy-read', + //'principals/'.$name.'/addressbook-proxy-write', + ); } - return $return; + return $group_membership; } /** @@ -153,29 +150,6 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { * @return void */ public function setGroupMemberSet($principal, array $members) { - $query = OC_DB::prepare('SELECT id, uri FROM *PREFIX*principals WHERE uri IN (? '.str_repeat(', ?', count($members)).')'); - $result = $query->execute(array_merge(array($principal), $members)); - - $memberIds = array(); - $principalId = null; - - while($row = $$result->fetchRow()) { - if ($row['uri'] == $principal) { - $principalId = $row['id']; - } - else{ - $memberIds[] = $row['id']; - } - } - if (!$principalId) throw new Sabre_DAV_Exception('Principal not found'); - - // Wiping out old members - $query = OC_DB::prepare('DELETE FROM *PREFIX*principalgroups WHERE principal_id = ?'); - $query->execute(array($principalID)); - - $query = OC_DB::prepare('INSERT INTO *PREFIX*principalgroups (principal_id, member_id) VALUES (?, ?);'); - foreach($memberIds as $memberId) { - $query->execute(array($principalId, $memberId)); - } + throw new Sabre_DAV_Exception('Setting members of the group is not supported yet'); } }