Skip to content

Commit

Permalink
Fix missing calendar path for public write on Calendars
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <anna@nextcloud.com>
  • Loading branch information
miaulalala committed Nov 4, 2021
1 parent c6429e6 commit bc68108
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion apps/dav/lib/CalDAV/CalendarImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\Calendar\ICreateFromString;
use OCP\Constants;
use Sabre\DAV\Exception\Conflict;
use function Sabre\Uri\split as uriSplit;

class CalendarImpl implements ICreateFromString {

Expand Down Expand Up @@ -145,11 +146,19 @@ public function createFromString(string $name, string $calendarData): void {
// so set the custom principal here
$plugin->setCurrentPrincipal($this->calendar->getPrincipalURI());

if (empty($this->calendarInfo['uri'])) {
throw new CalendarException('Could not write to calendar as URI parameter is missing');
}

// Build full calendar path
[, $user] = uriSplit($this->calendar->getPrincipalURI());
$fullCalendarFilename = sprintf('calendars/%s/%s/%s', $user, $this->calendarInfo['uri'], $name);

$stream = fopen('php://memory', 'rb+');
fwrite($stream, $calendarData);
rewind($stream);
try {
$server->server->createFile($name, $stream);
$server->server->createFile($fullCalendarFilename, $stream);
} catch (Conflict $e) {
throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e);
} finally {
Expand Down
5 changes: 5 additions & 0 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@
<code>calendarSearch</code>
</UndefinedInterfaceMethod>
</file>
<file src="apps/dav/lib/CalDAV/CalendarImpl.php">
<UndefinedFunction occurrences="1">
<code>uriSplit($this-&gt;calendar-&gt;getPrincipalURI())</code>
</UndefinedFunction>
</file>
<file src="apps/dav/lib/CalDAV/CalendarRoot.php">
<ParamNameMismatch occurrences="1">
<code>$principal</code>
Expand Down

0 comments on commit bc68108

Please sign in to comment.