Example #1
0
 /**
  * Returns a list of calendars for a principal.
  *
  * Every project is an array with the following keys:
  *  * id, a unique id that will be used by other functions to modify the
  *    calendar. This can be the same as the uri or a database key.
  *  * uri, which the basename of the uri with which the calendar is
  *    accessed.
  *  * principaluri. The owner of the calendar. Almost always the same as
  *    principalUri passed to this method.
  *
  * Furthermore it can contain webdav properties in clark notation. A very
  * common one is '{DAV:}displayname'.
  *
  * Many clients also require:
  * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set
  * For this property, you can just return an instance of
  * Sabre\CalDAV\Property\SupportedCalendarComponentSet.
  *
  * If you return {http://sabredav.org/ns}read-only and set the value to 1,
  * ACL will automatically be put in read-only mode.
  *
  * @param string $principalUri
  * @return array
  */
 function getCalendarsForUser($principalUri)
 {
     $fields = array_values($this->propertyMap);
     $fields[] = 'id';
     $fields[] = 'uri';
     $fields[] = 'synctoken';
     $fields[] = 'components';
     $fields[] = 'principaluri';
     $fields[] = 'transparent';
     // Making fields a comma-delimited list
     $query = $this->db->getQueryBuilder();
     $query->select($fields)->from('calendars')->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)))->orderBy('calendarorder', 'ASC');
     $stmt = $query->execute();
     $calendars = [];
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $components = [];
         if ($row['components']) {
             $components = explode(',', $row['components']);
         }
         $calendar = ['id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $row['principaluri'], '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ? $row['synctoken'] : '0'), '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque')];
         foreach ($this->propertyMap as $xmlName => $dbName) {
             $calendar[$xmlName] = $row[$dbName];
         }
         if (!isset($calendars[$calendar['id']])) {
             $calendars[$calendar['id']] = $calendar;
         }
     }
     $stmt->closeCursor();
     // query for shared calendars
     $principals = $this->principalBackend->getGroupMembership($principalUri);
     $principals[] = $principalUri;
     $fields = array_values($this->propertyMap);
     $fields[] = 'a.id';
     $fields[] = 'a.uri';
     $fields[] = 'a.synctoken';
     $fields[] = 'a.components';
     $fields[] = 'a.principaluri';
     $fields[] = 'a.transparent';
     $query = $this->db->getQueryBuilder();
     $result = $query->select($fields)->from('dav_shares', 's')->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id'))->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri')))->andWhere($query->expr()->eq('s.type', $query->createParameter('type')))->setParameter('type', 'calendar')->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)->execute();
     while ($row = $result->fetch()) {
         list(, $name) = URLUtil::splitPath($row['principaluri']);
         $uri = $row['uri'] . '_shared_by_' . $name;
         $row['displayname'] = $row['displayname'] . "({$name})";
         $components = [];
         if ($row['components']) {
             $components = explode(',', $row['components']);
         }
         $calendar = ['id' => $row['id'], 'uri' => $uri, 'principaluri' => $principalUri, '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ? $row['synctoken'] : '0'), '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri']];
         foreach ($this->propertyMap as $xmlName => $dbName) {
             $calendar[$xmlName] = $row[$dbName];
         }
         if (!isset($calendars[$calendar['id']])) {
             $calendars[$calendar['id']] = $calendar;
         }
     }
     $result->closeCursor();
     return array_values($calendars);
 }
Example #2
0
 public function testFindByUri()
 {
     $fooUser = $this->getMockBuilder('\\OC\\User\\User')->disableOriginalConstructor()->getMock();
     $fooUser->expects($this->exactly(1))->method('getUID')->will($this->returnValue('foo'));
     $this->userManager->expects($this->once())->method('getByEmail')->willReturn([$fooUser]);
     $ret = $this->connector->findByUri('mailto:foo@bar.net', 'principals/users');
     $this->assertSame('principals/users/foo', $ret);
 }
Example #3
0
 private function convertPrincipal($principalUri, $toV2)
 {
     if ($this->principalBackend->getPrincipalPrefix() === 'principals') {
         list(, $name) = URLUtil::splitPath($principalUri);
         if ($toV2 === true) {
             return "principals/users/{$name}";
         }
         return "principals/{$name}";
     }
     return $principalUri;
 }
Example #4
0
 /**
  * Returns the list of people whom this address book is shared with.
  *
  * Every element in this array should have the following properties:
  *   * href - Often a mailto: address
  *   * commonName - Optional, for example a first + last name
  *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
  *   * readOnly - boolean
  *   * summary - Optional, a description for the share
  *
  * @return array
  */
 public function getShares($addressBookId)
 {
     $query = $this->db->getQueryBuilder();
     $result = $query->select(['principaluri', 'access'])->from('dav_shares')->where($query->expr()->eq('resourceid', $query->createNamedParameter($addressBookId)))->andWhere($query->expr()->eq('type', $query->createNamedParameter('addressbook')))->execute();
     $shares = [];
     while ($row = $result->fetch()) {
         $p = $this->principalBackend->getPrincipalByPath($row['principaluri']);
         $shares[] = ['href' => "principal:{$p['uri']}", 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', 'status' => 1, 'readOnly' => $row['access'] === self::ACCESS_READ, '{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}principal' => $p['uri']];
     }
     return $shares;
 }
Example #5
0
 /**
  * Returns the list of people whom this address book is shared with.
  *
  * Every element in this array should have the following properties:
  *   * href - Often a mailto: address
  *   * commonName - Optional, for example a first + last name
  *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
  *   * readOnly - boolean
  *   * summary - Optional, a description for the share
  *
  * @return array
  */
 public function getShares($addressBookUri)
 {
     $query = $this->db->getQueryBuilder();
     $result = $query->select(['principaluri', 'access'])->from('dav_shares')->where($query->expr()->eq('uri', $query->createNamedParameter($addressBookUri)))->andWhere($query->expr()->eq('type', $query->createNamedParameter('addressbook')))->execute();
     $shares = [];
     while ($row = $result->fetch()) {
         $p = $this->principalBackend->getPrincipalByPath($row['principaluri']);
         $shares[] = ['href' => "principal:{$p['uri']}", 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', 'status' => 1, 'readOnly' => $row['access'] === 1];
     }
     return $shares;
 }
Example #6
0
 /**
  * Returns the list of people whom this resource is shared with.
  *
  * Every element in this array should have the following properties:
  *   * href - Often a mailto: address
  *   * commonName - Optional, for example a first + last name
  *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
  *   * readOnly - boolean
  *   * summary - Optional, a description for the share
  *
  * @param int $resourceId
  * @return array
  */
 public function getShares($resourceId)
 {
     $query = $this->db->getQueryBuilder();
     $result = $query->select(['principaluri', 'access'])->from('dav_shares')->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))->execute();
     $shares = [];
     while ($row = $result->fetch()) {
         $p = $this->principalBackend->getPrincipalByPath($row['principaluri']);
         $shares[] = ['href' => "principal:{$row['principaluri']}", 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', 'status' => 1, 'readOnly' => $row['access'] == self::ACCESS_READ, '{http://owncloud.org/ns}principal' => $row['principaluri'], '{http://owncloud.org/ns}group-share' => is_null($p)];
     }
     return $shares;
 }
Example #7
0
 /**
  * Returns the list of address books for a specific user.
  *
  * Every addressbook should have the following properties:
  *   id - an arbitrary unique id
  *   uri - the 'basename' part of the url
  *   principaluri - Same as the passed parameter
  *
  * Any additional clark-notation property may be passed besides this. Some
  * common ones are :
  *   {DAV:}displayname
  *   {urn:ietf:params:xml:ns:carddav}addressbook-description
  *   {http://calendarserver.org/ns/}getctag
  *
  * @param string $principalUri
  * @return array
  */
 function getAddressBooksForUser($principalUri)
 {
     $query = $this->db->getQueryBuilder();
     $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])->from('addressbooks')->where($query->expr()->eq('principaluri', $query->createParameter('principaluri')))->setParameter('principaluri', $principalUri);
     $addressBooks = [];
     $result = $query->execute();
     while ($row = $result->fetch()) {
         $addressBooks[] = ['id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $row['principaluri'], '{DAV:}displayname' => $row['displayname'], '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0'];
     }
     $result->closeCursor();
     // query for shared calendars
     $principals = $this->principalBackend->getGroupMembership($principalUri);
     $principals[] = $principalUri;
     $query = $this->db->getQueryBuilder();
     $result = $query->select(['a.id', 'a.uri', 'a.displayname', 'a.principaluri', 'a.description', 'a.synctoken', 's.access'])->from('dav_shares', 's')->join('s', 'addressbooks', 'a', $query->expr()->eq('s.resourceid', 'a.id'))->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri')))->andWhere($query->expr()->eq('s.type', $query->createParameter('type')))->setParameter('type', 'addressbook')->setParameter('principaluri', $principals, IQueryBuilder::PARAM_STR_ARRAY)->execute();
     while ($row = $result->fetch()) {
         list(, $name) = URLUtil::splitPath($row['principaluri']);
         $uri = $row['uri'] . '_shared_by_' . $name;
         $displayName = $row['displayname'] . "({$name})";
         $addressBooks[] = ['id' => $row['id'], 'uri' => $uri, 'principaluri' => $principalUri, '{DAV:}displayname' => $displayName, '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $row['access'] === self::ACCESS_READ];
     }
     $result->closeCursor();
     return $addressBooks;
 }
Example #8
0
 public function testSearchPrincipals()
 {
     $this->assertSame([], $this->connector->searchPrincipals('principals/users', []));
 }