Merge pull request #4229 from nextcloud/stable11-dont-list-on-public-calendar-endpoint

[stable11] Don't list on public calendar endpoints
This commit is contained in:
Morris Jobke 2017-04-06 00:55:36 -05:00 committed by GitHub
commit b2c87ae63f
4 changed files with 61 additions and 17 deletions

View File

@ -21,7 +21,6 @@
namespace OCA\DAV\CalDAV;
use Sabre\DAV\Collection;
use Sabre\DAV\Exception\NotFound;
class PublicCalendarRoot extends Collection {
@ -48,6 +47,7 @@ class PublicCalendarRoot extends Collection {
*/
function getChild($name) {
$calendar = $this->caldavBackend->getPublicCalendar($name);
$calendar['{http://owncloud.org/ns}owner-principal'] = '';
return new Calendar($this->caldavBackend, $calendar, $this->l10n);
}
@ -55,13 +55,6 @@ class PublicCalendarRoot extends Collection {
* @inheritdoc
*/
function getChildren() {
$calendars = $this->caldavBackend->getPublicCalendars();
$children = [];
foreach ($calendars as $calendar) {
// TODO: maybe implement a new class PublicCalendar ???
$children[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
}
return $children;
return [];
}
}

View File

@ -21,7 +21,7 @@ use Test\TestCase;
*/
class PublicCalendarRootTest extends TestCase {
const UNIT_TEST_USER = 'principals/users/caldav-unit-test';
const UNIT_TEST_USER = '';
/** @var CalDavBackend */
private $backend;
/** @var PublicCalendarRoot */
@ -92,13 +92,8 @@ class PublicCalendarRootTest extends TestCase {
public function testGetChildren() {
$this->createPublicCalendar();
$publicCalendars = $this->backend->getPublicCalendars();
$calendarResults = $this->publicCalendarRoot->getChildren();
$this->assertEquals(1, count($calendarResults));
$this->assertEquals(new Calendar($this->backend, $publicCalendars[0], $this->l10n), $calendarResults[0]);
$this->assertSame([], $calendarResults);
}
/**

View File

@ -89,7 +89,7 @@ class CalDavContext implements \Behat\Behat\Context\Context {
'auth' => [
$user,
$password,
]
],
]
);
$this->response = $this->client->send($request);
@ -184,4 +184,51 @@ class CalDavContext implements \Behat\Behat\Context\Context {
$this->response = $this->client->send($request);
}
/**
* @Then :user publicly shares the calendar named :name
*
* @param string $user
* @param string $name
*/
public function publiclySharesTheCalendarNamed($user, $name) {
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$user.'/'.$name;
$password = ($user === 'admin') ? 'admin' : '123456';
$request = $this->client->createRequest(
'POST',
$davUrl,
[
'body' => '<cs:publish-calendar xmlns:cs="http://calendarserver.org/ns/"/>',
'auth' => [
$user,
$password,
],
'headers' => [
'Content-Type' => 'application/xml; charset=UTF-8',
],
]
);
$this->response = $this->client->send($request);
}
/**
* @Then There should be :amount calendars in the response body
*
* @param string $amount
*/
public function t($amount) {
$jsonEncoded = json_encode($this->responseXml);
$arrayElement = json_decode($jsonEncoded, true);
$actual = count($arrayElement['value']) - 1;
if($actual !== (int)$amount) {
throw new InvalidArgumentException(
sprintf(
'Expected %s got %s',
$amount,
$actual
)
);
}
}
}

View File

@ -50,3 +50,12 @@ Feature: caldav
Then The CalDAV HTTP status code should be "201"
And "admin" requests calendar "admin/MyCalendar" on the endpoint "/remote.php/dav/calendars/"
Then The CalDAV HTTP status code should be "207"
Scenario: Propfind on public calendar endpoint without calendars
When "admin" creates a calendar named "MyCalendar"
Then The CalDAV HTTP status code should be "201"
And "admin" publicly shares the calendar named "MyCalendar"
Then The CalDAV HTTP status code should be "202"
When "admin" requests calendar "/" on the endpoint "/remote.php/dav/public-calendars"
Then The CalDAV HTTP status code should be "207"
Then There should be "0" calendars in the response body