diff options
author | Joas Schilling <coding@schilljs.com> | 2016-11-15 17:01:40 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-12-09 09:34:25 +0100 |
commit | 474720ff1c7fb996b0537a6d786e0fb930c786b0 (patch) | |
tree | 92e0ac8fea767ce4143fddc7588a25dac4d1271f /apps/dav/lib | |
parent | 60e4299bcbf441a45605ae3a8f7cb74afd00301d (diff) | |
download | nextcloud-server-474720ff1c7fb996b0537a6d786e0fb930c786b0.tar.gz nextcloud-server-474720ff1c7fb996b0537a6d786e0fb930c786b0.zip |
Overwrite the schedule target calendar with the personal one and create it if missing
Otherwise this leads to problems like events being added to the birthday calendar,
if that one is the first calendar which was created for the user. See:
https://github.com/nextcloud/server/pull/2274
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/CalDAV/CalendarHome.php | 7 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/Schedule/Plugin.php | 59 |
2 files changed, 66 insertions, 0 deletions
diff --git a/apps/dav/lib/CalDAV/CalendarHome.php b/apps/dav/lib/CalDAV/CalendarHome.php index f84b0c863c6..7320754e6df 100644 --- a/apps/dav/lib/CalDAV/CalendarHome.php +++ b/apps/dav/lib/CalDAV/CalendarHome.php @@ -42,6 +42,13 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome { } /** + * @return BackendInterface + */ + public function getCalDAVBackend() { + return $this->caldavBackend; + } + + /** * @inheritdoc */ function getChildren() { diff --git a/apps/dav/lib/CalDAV/Schedule/Plugin.php b/apps/dav/lib/CalDAV/Schedule/Plugin.php index ad55a2756b0..34df666637c 100644 --- a/apps/dav/lib/CalDAV/Schedule/Plugin.php +++ b/apps/dav/lib/CalDAV/Schedule/Plugin.php @@ -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,9 +24,28 @@ */ 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. * * @param string $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']); + }); + } + } } |