Merge pull request #2274 from nextcloud/fix-invites-on-readonly-calendars

Do not add invites into read-only calendars
This commit is contained in:
Lukas Reschke 2016-12-10 12:22:15 +01:00 committed by GitHub
commit 4456fa57e0
2 changed files with 66 additions and 0 deletions

View File

@ -41,6 +41,13 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome {
$this->l10n = \OC::$server->getL10N('dav');
}
/**
* @return BackendInterface
*/
public function getCalDAVBackend() {
return $this->caldavBackend;
}
/**
* @inheritdoc
*/

View File

@ -1,7 +1,9 @@
<?php
/**
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
* @copyright Copyright (c) 2016, Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
@ -22,8 +24,27 @@
*/
namespace OCA\DAV\CalDAV\Schedule;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarHome;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
use Sabre\DAV\Xml\Property\LocalHref;
use Sabre\DAVACL\IPrincipal;
class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
/**
* Initializes the plugin
*
* @param Server $server
* @return void
*/
function initialize(Server $server) {
parent::initialize($server);
$server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
}
/**
* Returns a list of addresses that are associated with a principal.
*
@ -39,4 +60,42 @@ class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
return $result;
}
/**
* Always use the personal calendar as target for scheduled events
*
* @param PropFind $propFind
* @param INode $node
* @return void
*/
function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
if ($node instanceof IPrincipal) {
$propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
$caldavPlugin = $this->server->getPlugin('caldav');
$principalUrl = $node->getPrincipalUrl();
$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
if (!$calendarHomePath) {
return null;
}
/** @var CalendarHome $calendarHome */
$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
'{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
]);
}
$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
if (empty($result)) {
return null;
}
return new LocalHref($result[0]['href']);
});
}
}
}