Skip to content

Commit

Permalink
Merge pull request #2712 from nextcloud/master-2648
Browse files Browse the repository at this point in the history
Fix legacy DAV endpoint
  • Loading branch information
MorrisJobke authored Jan 2, 2017
2 parents 1b8aae8 + db3c918 commit 9e32885
Show file tree
Hide file tree
Showing 13 changed files with 1,827 additions and 41 deletions.
36 changes: 28 additions & 8 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,42 @@ pipeline:
when:
matrix:
TESTS: litmus-v2
caldavtester:
caldavtester-new-endpoint:
image: nextcloudci/litmus-php7.0:litmus-php7.0-4
commands:
- bash tests/travis/install.sh sqlite
- bash apps/dav/tests/travis/caldav/install.sh
- bash apps/dav/tests/travis/caldav/script.sh
- bash apps/dav/tests/travis/caldav/script-new-endpoint.sh
when:
matrix:
TESTS: caldavtester
carddavtester:
TESTS: caldavtester-new-endpoint
caldavtester-old-endpoint:
image: nextcloudci/litmus-php7.0:litmus-php7.0-4
commands:
- bash tests/travis/install.sh sqlite
- bash apps/dav/tests/travis/caldav/install.sh
- bash apps/dav/tests/travis/caldav/script-old-endpoint.sh
when:
matrix:
TESTS: caldavtester-old-endpoint
carddavtester-new-endpoint:
image: nextcloudci/litmus-php7.0:litmus-php7.0-4
commands:
- bash tests/travis/install.sh sqlite
- bash apps/dav/tests/travis/carddav/install.sh
- bash apps/dav/tests/travis/carddav/script-new-endpoint.sh
when:
matrix:
TESTS: carddavtester-new-endpoint
carddavtester-old-endpoint:
image: nextcloudci/litmus-php7.0:litmus-php7.0-4
commands:
- bash tests/travis/install.sh sqlite
- bash apps/dav/tests/travis/carddav/install.sh
- bash apps/dav/tests/travis/carddav/script.sh
- bash apps/dav/tests/travis/carddav/script-old-endpoint.sh
when:
matrix:
TESTS: carddavtester
TESTS: carddavtester-old-endpoint
sqlite-php7.0-samba-native:
image: nextcloudci/samba-native-php7.0:samba-native-php7.0-1
commands:
Expand Down Expand Up @@ -470,8 +488,10 @@ matrix:
- TESTS: syntax-php7.1
- TESTS: litmus-v1
- TESTS: litmus-v2
- TESTS: caldavtester
- TESTS: carddavtester
- TESTS: caldavtester-old-endpoint
- TESTS: caldavtester-new-endpoint
- TESTS: carddavtester-new-endpoint
- TESTS: carddavtester-old-endpoint
- TESTS: object-store
OBJECT_STORE: s3
- TESTS: sqlite-php7.0-samba-native
Expand Down
3 changes: 2 additions & 1 deletion apps/dav/appinfo/v1/caldav.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
$userManager = \OC::$server->getUserManager();
$random = \OC::$server->getSecureRandom();
$dispatcher = \OC::$server->getEventDispatcher();
$calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, $random, $dispatcher);
$calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, $random, $dispatcher, true);

$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);

Expand Down Expand Up @@ -80,6 +80,7 @@
$server->addPlugin(new Sabre\DAV\Browser\Plugin());
}

$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
$server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin());
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin( \OC::$server->getMailer(), \OC::$server->getLogger()));
Expand Down
1 change: 1 addition & 0 deletions apps/dav/appinfo/v1/carddav.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
$server->addPlugin(new Sabre\DAV\Browser\Plugin());
}

$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
$server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
$server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(\OC::$server->getLogger()));
$server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/CalDAV/Activity/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function triggerCalendarActivity($action, array $calendarData, array $
}

$principal = explode('/', $calendarData['principaluri']);
$owner = $principal[2];
$owner = array_pop($principal);

$currentUser = $this->userSession->getUser();
if ($currentUser instanceof IUser) {
Expand Down Expand Up @@ -369,7 +369,7 @@ public function onTouchCalendarObject($action, array $calendarData, array $share
}

$principal = explode('/', $calendarData['principaluri']);
$owner = $principal[2];
$owner = array_pop($principal);

$currentUser = $this->userSession->getUser();
if ($currentUser instanceof IUser) {
Expand Down
32 changes: 19 additions & 13 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
/** @var EventDispatcherInterface */
private $dispatcher;

/** @var bool */
private $legacyEndpoint;

/**
* CalDavBackend constructor.
*
Expand All @@ -139,18 +142,21 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @param IUserManager $userManager
* @param ISecureRandom $random
* @param EventDispatcherInterface $dispatcher
* @param bool $legacyEndpoint
*/
public function __construct(IDBConnection $db,
Principal $principalBackend,
IUserManager $userManager,
ISecureRandom $random,
EventDispatcherInterface $dispatcher) {
EventDispatcherInterface $dispatcher,
$legacyEndpoint = false) {
$this->db = $db;
$this->principalBackend = $principalBackend;
$this->userManager = $userManager;
$this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar');
$this->random = $random;
$this->dispatcher = $dispatcher;
$this->legacyEndpoint = $legacyEndpoint;
}

/**
Expand Down Expand Up @@ -230,12 +236,12 @@ function getCalendarsForUser($principalUri) {
$calendar = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], false),
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
'{' . 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' => $principalUri,
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint),
];

foreach($this->propertyMap as $xmlName=>$dbName) {
Expand Down Expand Up @@ -282,12 +288,12 @@ function getCalendarsForUser($principalUri) {
$calendar = [
'id' => $row['id'],
'uri' => $uri,
'principaluri' => $principalUri,
'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint),
'{' . 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'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ,
];

Expand Down Expand Up @@ -328,7 +334,7 @@ public function getUsersOwnCalendars($principalUri) {
$calendar = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], false),
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
'{' . 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),
Expand Down Expand Up @@ -392,12 +398,12 @@ public function getPublicCalendars() {
$calendar = [
'id' => $row['id'],
'uri' => $row['publicuri'],
'principaluri' => $row['principaluri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
'{' . 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'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ,
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC,
];
Expand Down Expand Up @@ -456,12 +462,12 @@ public function getPublicCalendar($uri) {
$calendar = [
'id' => $row['id'],
'uri' => $row['publicuri'],
'principaluri' => $row['principaluri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
'{' . 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'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ,
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC,
];
Expand Down Expand Up @@ -510,7 +516,7 @@ public function getCalendarByUri($principal, $uri) {
$calendar = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
'{' . 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),
Expand Down Expand Up @@ -554,7 +560,7 @@ public function getCalendarById($calendarId) {
$calendar = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
'{' . 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),
Expand All @@ -581,7 +587,7 @@ public function getCalendarById($calendarId) {
*/
function createCalendar($principalUri, $calendarUri, array $properties) {
$values = [
'principaluri' => $principalUri,
'principaluri' => $this->convertPrincipal($principalUri, true),
'uri' => $calendarUri,
'synctoken' => 1,
'transparent' => 0,
Expand Down
19 changes: 2 additions & 17 deletions apps/dav/lib/Connector/LegacyDAVACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,9 @@
class LegacyDAVACL extends DavAclPlugin {

/**
* Converts the v1 principal `principal/<username>` to the new v2
* `principal/users/<username>` which is required for permission checks
*
* @inheritdoc
*/
function getCurrentUserPrincipal() {
$principalV1 = parent::getCurrentUserPrincipal();
if (is_null($principalV1)) {
return $principalV1;
}
return $this->convertPrincipal($principalV1, true);
}


/**
* @inheritdoc
*/
function getCurrentUserPrincipals() {
public function getCurrentUserPrincipals() {
$principalV2 = $this->getCurrentUserPrincipal();

if (is_null($principalV2)) return [];
Expand All @@ -73,7 +58,7 @@ private function convertPrincipal($principal, $toV2) {
return "principals/$name";
}

function propFind(PropFind $propFind, INode $node) {
public function propFind(PropFind $propFind, INode $node) {
/* Overload current-user-principal */
$propFind->handle('{DAV:}current-user-principal', function () {
if ($url = parent::getCurrentUserPrincipal()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`

# Move the endpoint to the serverinfo file
cp "$SCRIPTPATH/../caldavtest/serverinfo-new-endpoint.xml" "$SCRIPTPATH/../caldavtest/serverinfo.xml"

# start the server
php -S 127.0.0.1:8888 -t "$SCRIPTPATH/../../../../.." &

Expand Down
23 changes: 23 additions & 0 deletions apps/dav/tests/travis/caldav/script-old-endpoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`

# Move the endpoint to the serverinfo file
cp "$SCRIPTPATH/../caldavtest/serverinfo-old-caldav-endpoint.xml" "$SCRIPTPATH/../caldavtest/serverinfo.xml"

# start the server
php -S 127.0.0.1:8888 -t "$SCRIPTPATH/../../../../.." &

sleep 30

# run the tests
cd "$SCRIPTPATH/CalDAVTester"
PYTHONPATH="$SCRIPTPATH/pycalendar/src" python testcaldav.py --print-details-onfail --basedir "$SCRIPTPATH/../caldavtest/" -o cdt.txt \
"CalDAV/current-user-principal.xml" \
"CalDAV/sync-report.xml"

RESULT=$?

tail "$/../../../../../data-autotest/nextcloud.log"

exit $RESULT
Loading

0 comments on commit 9e32885

Please sign in to comment.