-
Notifications
You must be signed in to change notification settings - Fork 346
Expand file tree
/
Copy pathCalendarObject.php
More file actions
138 lines (114 loc) · 3.46 KB
/
Copy pathCalendarObject.php
File metadata and controls
138 lines (114 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Deck\DAV;
use OCA\Deck\BadRequestException;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\Stack;
use OCA\Deck\StatusException;
use OCP\AppFramework\Db\DoesNotExistException;
use Sabre\CalDAV\ICalendarObject;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAVACL\IACL;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\InvalidDataException;
class CalendarObject implements ICalendarObject, IACL {
/** @var Calendar */
private $calendar;
/** @var string */
private $name;
/** @var Card|Stack */
private $sourceItem;
/** @var DeckCalendarBackend */
private $backend;
/** @var VCalendar */
private $calendarObject;
public function __construct(Calendar $calendar, string $name, DeckCalendarBackend $backend, $sourceItem) {
$this->calendar = $calendar;
$this->name = $name;
$this->sourceItem = $sourceItem;
$this->backend = $backend;
$this->calendarObject = $this->sourceItem->getCalendarObject();
}
public function getOwner() {
return null;
}
public function getGroup() {
return null;
}
public function getACL() {
$acl = $this->calendar->getACL();
if ($this->sourceItem instanceof Stack) {
return array_values(array_filter($acl, static function (array $entry): bool {
return $entry['privilege'] !== '{DAV:}write-content';
}));
}
return $acl;
}
public function setACL(array $acl) {
throw new Forbidden('Setting ACL is not supported on this node');
}
public function getSupportedPrivilegeSet() {
return null;
}
public function put($data) {
if (!($this->sourceItem instanceof Card)) {
throw new Forbidden('This calendar-object is read-only');
}
// MultipleObjectsReturnedException is intentionally not caught:
// a primary-key lookup returning multiple rows is a data integrity bug
// and should surface as a 500 in the log.
try {
$this->sourceItem = $this->backend->updateCardFromCalendarObject($this->sourceItem, $this->readPutData($data));
} catch (DoesNotExistException $e) {
throw new NotFound($e->getMessage(), 0, $e);
} catch (InvalidDataException $e) {
throw new BadRequest($e->getMessage(), 0, $e);
} catch (BadRequestException $e) {
throw new BadRequest($e->getMessage(), 0, $e);
} catch (StatusException $e) {
throw new Forbidden($e->getMessage(), 0, $e);
}
$this->calendarObject = $this->sourceItem->getCalendarObject();
}
private function readPutData($data): string {
if (is_resource($data)) {
$content = stream_get_contents($data);
if ($content === false) {
throw new BadRequest('Could not read calendar-object data');
}
return $content;
}
return (string)$data;
}
public function get() {
if ($this->sourceItem) {
return $this->calendarObject->serialize();
}
}
public function getContentType() {
return 'text/calendar; charset=utf-8';
}
public function getETag() {
return '"' . md5($this->sourceItem->getLastModified()) . '"';
}
public function getSize() {
return mb_strlen($this->calendarObject->serialize());
}
public function delete() {
throw new Forbidden('Deleting tasks via CalDAV is not supported');
}
public function getName() {
return $this->name;
}
public function setName($name) {
throw new Forbidden('This calendar-object is read-only');
}
public function getLastModified() {
return $this->sourceItem->getLastModified();
}
}