1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* @copyright 2018 Georg Ehrke <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @author Georg Ehrke <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @license GNU AGPL version 3 or any later version |
9
|
|
|
* |
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
13
|
|
|
* License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
namespace OCA\DAV\CalDAV; |
25
|
|
|
|
26
|
|
|
use Sabre\CalDAV\Backend\BackendInterface; |
27
|
|
|
use Sabre\DAV\Exception\MethodNotAllowed; |
28
|
|
|
use Sabre\DAV\Exception\NotFound; |
29
|
|
|
use Sabre\DAV\PropPatch; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class CachedSubscription |
33
|
|
|
* |
34
|
|
|
* @package OCA\DAV\CalDAV |
35
|
|
|
* @property BackendInterface|CalDavBackend $caldavBackend |
36
|
|
|
*/ |
37
|
|
|
class CachedSubscription extends \Sabre\CalDAV\Calendar { |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getPrincipalURI():string { |
43
|
|
|
return $this->calendarInfo['principaluri']; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
public function getACL():array { |
50
|
|
|
return [ |
51
|
|
|
[ |
52
|
|
|
'privilege' => '{DAV:}read', |
53
|
|
|
'principal' => $this->getOwner(), |
54
|
|
|
'protected' => true, |
55
|
|
|
], |
56
|
|
|
[ |
57
|
|
|
'privilege' => '{DAV:}read', |
58
|
|
|
'principal' => $this->getOwner() . '/calendar-proxy-write', |
59
|
|
|
'protected' => true, |
60
|
|
|
], |
61
|
|
|
[ |
62
|
|
|
'privilege' => '{DAV:}read', |
63
|
|
|
'principal' => $this->getOwner() . '/calendar-proxy-read', |
64
|
|
|
'protected' => true, |
65
|
|
|
], |
66
|
|
|
[ |
67
|
|
|
'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', |
68
|
|
|
'principal' => '{DAV:}authenticated', |
69
|
|
|
'protected' => true, |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
public function getChildACL():array { |
78
|
|
|
return [ |
79
|
|
|
[ |
80
|
|
|
'privilege' => '{DAV:}read', |
81
|
|
|
'principal' => $this->getOwner(), |
82
|
|
|
'protected' => true, |
83
|
|
|
], |
84
|
|
|
|
85
|
|
|
[ |
86
|
|
|
'privilege' => '{DAV:}read', |
87
|
|
|
'principal' => $this->getOwner() . '/calendar-proxy-write', |
88
|
|
|
'protected' => true, |
89
|
|
|
], |
90
|
|
|
[ |
91
|
|
|
'privilege' => '{DAV:}read', |
92
|
|
|
'principal' => $this->getOwner() . '/calendar-proxy-read', |
93
|
|
|
'protected' => true, |
94
|
|
|
], |
95
|
|
|
|
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return null|string |
101
|
|
|
*/ |
102
|
|
|
public function getOwner() { |
103
|
|
|
if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
104
|
|
|
return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
105
|
|
|
} |
106
|
|
|
return parent::getOwner(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* |
111
|
|
|
*/ |
112
|
|
|
public function delete() { |
113
|
|
|
$this->caldavBackend->deleteSubscription($this->calendarInfo['id']); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param PropPatch $propPatch |
118
|
|
|
*/ |
119
|
|
|
public function propPatch(PropPatch $propPatch) { |
120
|
|
|
$this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $name |
125
|
|
|
* @return CalendarObject|\Sabre\CalDAV\ICalendarObject |
126
|
|
|
* @throws NotFound |
127
|
|
|
*/ |
128
|
|
|
public function getChild($name) { |
129
|
|
|
$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
|
|
|
130
|
|
|
if (!$obj) { |
131
|
|
|
throw new NotFound('Calendar object not found'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$obj['acl'] = $this->getChildACL(); |
135
|
|
|
return new CachedSubscriptionObject ($this->caldavBackend, $this->calendarInfo, $obj); |
136
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
public function getChildren():array { |
143
|
|
|
$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
|
|
|
144
|
|
|
|
145
|
|
|
$children = []; |
146
|
|
|
foreach($objs as $obj) { |
147
|
|
|
$children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
return $children; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param array $paths |
155
|
|
|
* @return array |
156
|
|
|
*/ |
157
|
|
|
public function getMultipleChildren(array $paths):array { |
158
|
|
|
$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
|
|
|
159
|
|
|
|
160
|
|
|
$children = []; |
161
|
|
|
foreach($objs as $obj) { |
162
|
|
|
$children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $children; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param string $name |
170
|
|
|
* @param null $calendarData |
|
|
|
|
171
|
|
|
* @return null|string|void |
172
|
|
|
* @throws MethodNotAllowed |
173
|
|
|
*/ |
174
|
|
|
public function createFile($name, $calendarData = null) { |
175
|
|
|
throw new MethodNotAllowed('Creating objects in cached subscription is not allowed'); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string $name |
180
|
|
|
* @return bool |
181
|
|
|
*/ |
182
|
|
|
public function childExists($name):bool { |
183
|
|
|
$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
|
|
|
184
|
|
|
if (!$obj) { |
185
|
|
|
return false; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return true; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param array $filters |
193
|
|
|
* @return array |
194
|
|
|
*/ |
195
|
|
|
public function calendarQuery(array $filters):array { |
196
|
|
|
return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
|
|
|
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|