Example #1
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)
 {
     $principalUri = $this->convertPrincipal($principalUri, true);
     $query = $this->db->getQueryBuilder();
     $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])->from('addressbooks')->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
     $addressBooks = [];
     $result = $query->execute();
     while ($row = $result->fetch()) {
         $addressBooks[$row['id']] = ['id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $this->convertPrincipal($row['principaluri'], false), '{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})";
         if (!isset($addressBooks[$row['id']])) {
             $addressBooks[$row['id']] = ['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 array_values($addressBooks);
 }
Example #2
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)
 {
     $principalUri = $this->convertPrincipal($principalUri, true);
     $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' => $this->convertPrincipal($row['principaluri'], false), '{' . 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 #3
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.uri', '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, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)->execute();
     while ($row = $result->fetch()) {
         $addressBooks[] = ['id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $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', '{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], '{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $row['access'] === self::ACCESS_READ];
     }
     $result->closeCursor();
     return $addressBooks;
 }
Example #4
0
 /**
  * @expectedException \Sabre\DAV\Exception
  * @expectedExceptionMessage Principal not found
  */
 public function testGetGroupMembershipEmpty()
 {
     $this->userManager->expects($this->once())->method('get')->with('foo')->will($this->returnValue(null));
     $this->connector->getGroupMembership('principals/users/foo');
 }