Skip to content

Commit

Permalink
TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
susnux committed Jan 13, 2023
1 parent 5bad308 commit 47909b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
21 changes: 15 additions & 6 deletions apps/dav/lib/CalDAV/AppCalendar/AppCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public function __construct(string $appId, ICalendar $calendar, string $principa
$this->calendar = $calendar;
}

/**
* Return permissions supported by the backend calendar
* @return int Permissions based on \OCP\Constants
*/
public function getPermissions(): int {
// Make sure to only promote write support if the backend implement the correct interface
if ($this->calendar instanceof ICreateFromString) return $this->calendar->getPermissions();
return Constants::PERMISSION_READ;
}

public function getOwner(): ?string {
return $this->principal;
}
Expand All @@ -46,8 +56,7 @@ public function getACL(): array {
'protected' => true,
]
];
if ($this->calendar instanceof ICreateFromString &&
$this->calendar->getPermissions() & Constants::PERMISSION_CREATE) {
if ($this->getPermissions() & Constants::PERMISSION_CREATE) {
$acl[] = [
'privilege' => '{DAV:}write',
'principal' => $this->getOwner(),
Expand All @@ -72,7 +81,7 @@ public function getLastModified(): ?int {
}

public function delete(): void {
// No delete method in OCP\Calendar\ICalendar
// No method for deleting a calendar in OCP\Calendar\ICalendar
throw new Forbidden('Deleting an entry is not implemented');
}

Expand All @@ -92,7 +101,7 @@ public function getProperties($properties) {
return [
'{DAV:}displayname' => $this->calendar->getDisplayName() ?: $this->calendar->getKey(),
'{http://apple.com/ns/ical/}calendar-color' => '#' . ($this->calendar->getDisplayColor() ?: '0082c9'),
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VEVENT', 'VTODO']),
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VEVENT', 'VJOURNAL', 'VTODO']),
];
}

Expand Down Expand Up @@ -136,7 +145,7 @@ public function getChild($name) {
$children = $this->calendar->search(substr($name, 0, $pos === false ? null : $pos), ['UID'], [], 1);

if (count($children) > 0) {
return new CalendarObject($this, $children[0]);
return new CalendarObject($this, $this->calendar, $children[0]);
}

throw new NotFound('Node not found');
Expand All @@ -147,7 +156,7 @@ public function getChild($name) {
*/
public function getChildren(): array {
$children = array_map(function ($calendar) {
return new CalendarObject($this, $calendar);
return new CalendarObject($this, $this->calendar, $calendar);
}, $this->calendar->search(''));

return $children;
Expand Down
20 changes: 18 additions & 2 deletions apps/dav/lib/CalDAV/AppCalendar/CalendarObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace OCA\DAV\CalDAV\AppCalendar;

use OCP\Calendar\ICalendar;
use OCP\Calendar\ICreateFromString;
use OCP\Constants;
use Sabre\CalDAV\ICalendarObject;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
Expand All @@ -12,10 +15,12 @@
class CalendarObject implements ICalendarObject, IACL {
private VCalendar $vobject;
private AppCalendar $calendar;
private ICalendar $backend;

public function __construct(AppCalendar $calendar, array $sourceItem) {
public function __construct(AppCalendar $calendar, ICalendar $backend, array $sourceItem) {
$this->calendar = $calendar;
$this->vobject = new VCalendar($sourceItem);
$this->backend = $backend;
}

public function getOwner() {
Expand Down Expand Up @@ -65,7 +70,18 @@ public function getSize() {
}

public function delete(): void {
throw new Forbidden('This calendar-object is read-only');
if ($this->calendar->getPermissions() & Constants::PERMISSION_DELETE) {
/** @var \Sabre\VObject\Component */
$vcomponent = $this->vobject->getBaseComponent();
$vcomponent->STATUS = 'CANCELLED';
$vcomponent->SEQUENCE = isset($vcomponent->SEQUENCE) ? ((int)$vcomponent->SEQUENCE) + 1 : 1;
if ($vcomponent->name == 'VEVENT') $vcomponent->METHOD = 'CANCEL';
/** @var ICreateFromString */
$backend = &$this->backend;
$backend->createFromString((string)$vcomponent->UID . '.ics', $vcomponent->serialize());
} else {
throw new Forbidden('This calendar-object is read-only');
}
}

public function getName(): string {
Expand Down

0 comments on commit 47909b0

Please sign in to comment.