@@ -23,11 +23,11 @@ |
||
23 | 23 | |
24 | 24 | class PublicCalendarObject extends CalendarObject { |
25 | 25 | |
26 | - /** |
|
27 | - * public calendars are always shared |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - protected function isShared() { |
|
31 | - return true; |
|
32 | - } |
|
26 | + /** |
|
27 | + * public calendars are always shared |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + protected function isShared() { |
|
31 | + return true; |
|
32 | + } |
|
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -32,68 +32,68 @@ |
||
32 | 32 | |
33 | 33 | class CalendarObject extends \Sabre\CalDAV\CalendarObject { |
34 | 34 | |
35 | - /** |
|
36 | - * @inheritdoc |
|
37 | - */ |
|
38 | - function get() { |
|
39 | - $data = parent::get(); |
|
40 | - if ($this->isShared() && $this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) { |
|
41 | - return $this->createConfidentialObject($data); |
|
42 | - } |
|
43 | - return $data; |
|
44 | - } |
|
35 | + /** |
|
36 | + * @inheritdoc |
|
37 | + */ |
|
38 | + function get() { |
|
39 | + $data = parent::get(); |
|
40 | + if ($this->isShared() && $this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) { |
|
41 | + return $this->createConfidentialObject($data); |
|
42 | + } |
|
43 | + return $data; |
|
44 | + } |
|
45 | 45 | |
46 | - protected function isShared() { |
|
47 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
48 | - return false; |
|
49 | - } |
|
46 | + protected function isShared() { |
|
47 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
52 | - } |
|
51 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $calData |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - private static function createConfidentialObject($calData) { |
|
54 | + /** |
|
55 | + * @param string $calData |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + private static function createConfidentialObject($calData) { |
|
59 | 59 | |
60 | - $vObject = Reader::read($calData); |
|
60 | + $vObject = Reader::read($calData); |
|
61 | 61 | |
62 | - /** @var Component $vElement */ |
|
63 | - $vElement = null; |
|
64 | - if(isset($vObject->VEVENT)) { |
|
65 | - $vElement = $vObject->VEVENT; |
|
66 | - } |
|
67 | - if(isset($vObject->VJOURNAL)) { |
|
68 | - $vElement = $vObject->VJOURNAL; |
|
69 | - } |
|
70 | - if(isset($vObject->VTODO)) { |
|
71 | - $vElement = $vObject->VTODO; |
|
72 | - } |
|
73 | - if(!is_null($vElement)) { |
|
74 | - foreach ($vElement->children() as &$property) { |
|
75 | - /** @var Property $property */ |
|
76 | - switch($property->name) { |
|
77 | - case 'CREATED': |
|
78 | - case 'DTSTART': |
|
79 | - case 'RRULE': |
|
80 | - case 'DURATION': |
|
81 | - case 'DTEND': |
|
82 | - case 'CLASS': |
|
83 | - case 'UID': |
|
84 | - break; |
|
85 | - case 'SUMMARY': |
|
86 | - $property->setValue('Busy'); |
|
87 | - break; |
|
88 | - default: |
|
89 | - $vElement->__unset($property->name); |
|
90 | - unset($property); |
|
91 | - break; |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
62 | + /** @var Component $vElement */ |
|
63 | + $vElement = null; |
|
64 | + if(isset($vObject->VEVENT)) { |
|
65 | + $vElement = $vObject->VEVENT; |
|
66 | + } |
|
67 | + if(isset($vObject->VJOURNAL)) { |
|
68 | + $vElement = $vObject->VJOURNAL; |
|
69 | + } |
|
70 | + if(isset($vObject->VTODO)) { |
|
71 | + $vElement = $vObject->VTODO; |
|
72 | + } |
|
73 | + if(!is_null($vElement)) { |
|
74 | + foreach ($vElement->children() as &$property) { |
|
75 | + /** @var Property $property */ |
|
76 | + switch($property->name) { |
|
77 | + case 'CREATED': |
|
78 | + case 'DTSTART': |
|
79 | + case 'RRULE': |
|
80 | + case 'DURATION': |
|
81 | + case 'DTEND': |
|
82 | + case 'CLASS': |
|
83 | + case 'UID': |
|
84 | + break; |
|
85 | + case 'SUMMARY': |
|
86 | + $property->setValue('Busy'); |
|
87 | + break; |
|
88 | + default: |
|
89 | + $vElement->__unset($property->name); |
|
90 | + unset($property); |
|
91 | + break; |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - return $vObject->serialize(); |
|
97 | - } |
|
96 | + return $vObject->serialize(); |
|
97 | + } |
|
98 | 98 | |
99 | 99 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | |
25 | 25 | class PublicCalendarRoot extends Collection { |
26 | 26 | |
27 | - /** @var CalDavBackend */ |
|
28 | - protected $caldavBackend; |
|
29 | - |
|
30 | - /** @var \OCP\IL10N */ |
|
31 | - protected $l10n; |
|
32 | - |
|
33 | - function __construct(CalDavBackend $caldavBackend) { |
|
34 | - $this->caldavBackend = $caldavBackend; |
|
35 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @inheritdoc |
|
40 | - */ |
|
41 | - function getName() { |
|
42 | - return 'public-calendars'; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @inheritdoc |
|
47 | - */ |
|
48 | - function getChild($name) { |
|
49 | - $calendar = $this->caldavBackend->getPublicCalendar($name); |
|
50 | - return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @inheritdoc |
|
55 | - */ |
|
56 | - function getChildren() { |
|
57 | - return []; |
|
58 | - } |
|
27 | + /** @var CalDavBackend */ |
|
28 | + protected $caldavBackend; |
|
29 | + |
|
30 | + /** @var \OCP\IL10N */ |
|
31 | + protected $l10n; |
|
32 | + |
|
33 | + function __construct(CalDavBackend $caldavBackend) { |
|
34 | + $this->caldavBackend = $caldavBackend; |
|
35 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @inheritdoc |
|
40 | + */ |
|
41 | + function getName() { |
|
42 | + return 'public-calendars'; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @inheritdoc |
|
47 | + */ |
|
48 | + function getChild($name) { |
|
49 | + $calendar = $this->caldavBackend->getPublicCalendar($name); |
|
50 | + return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @inheritdoc |
|
55 | + */ |
|
56 | + function getChildren() { |
|
57 | + return []; |
|
58 | + } |
|
59 | 59 | } |
@@ -25,63 +25,63 @@ |
||
25 | 25 | |
26 | 26 | class PublicCalendar extends Calendar { |
27 | 27 | |
28 | - /** |
|
29 | - * @param string $name |
|
30 | - * @throws NotFound |
|
31 | - * @return PublicCalendarObject |
|
32 | - */ |
|
33 | - public function getChild($name) { |
|
34 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
28 | + /** |
|
29 | + * @param string $name |
|
30 | + * @throws NotFound |
|
31 | + * @return PublicCalendarObject |
|
32 | + */ |
|
33 | + public function getChild($name) { |
|
34 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
35 | 35 | |
36 | - if (!$obj) { |
|
37 | - throw new NotFound('Calendar object not found'); |
|
38 | - } |
|
39 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
40 | - throw new NotFound('Calendar object not found'); |
|
41 | - } |
|
42 | - $obj['acl'] = $this->getChildACL(); |
|
36 | + if (!$obj) { |
|
37 | + throw new NotFound('Calendar object not found'); |
|
38 | + } |
|
39 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
40 | + throw new NotFound('Calendar object not found'); |
|
41 | + } |
|
42 | + $obj['acl'] = $this->getChildACL(); |
|
43 | 43 | |
44 | - return new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
45 | - } |
|
44 | + return new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return PublicCalendarObject[] |
|
49 | - */ |
|
50 | - public function getChildren() { |
|
51 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
52 | - $children = []; |
|
53 | - foreach ($objs as $obj) { |
|
54 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
55 | - continue; |
|
56 | - } |
|
57 | - $obj['acl'] = $this->getChildACL(); |
|
58 | - $children[] = new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
59 | - } |
|
60 | - return $children; |
|
61 | - } |
|
47 | + /** |
|
48 | + * @return PublicCalendarObject[] |
|
49 | + */ |
|
50 | + public function getChildren() { |
|
51 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
52 | + $children = []; |
|
53 | + foreach ($objs as $obj) { |
|
54 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
55 | + continue; |
|
56 | + } |
|
57 | + $obj['acl'] = $this->getChildACL(); |
|
58 | + $children[] = new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
59 | + } |
|
60 | + return $children; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param string[] $paths |
|
65 | - * @return PublicCalendarObject[] |
|
66 | - */ |
|
67 | - public function getMultipleChildren(array $paths) { |
|
68 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
69 | - $children = []; |
|
70 | - foreach ($objs as $obj) { |
|
71 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
72 | - continue; |
|
73 | - } |
|
74 | - $obj['acl'] = $this->getChildACL(); |
|
75 | - $children[] = new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
76 | - } |
|
77 | - return $children; |
|
78 | - } |
|
63 | + /** |
|
64 | + * @param string[] $paths |
|
65 | + * @return PublicCalendarObject[] |
|
66 | + */ |
|
67 | + public function getMultipleChildren(array $paths) { |
|
68 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
69 | + $children = []; |
|
70 | + foreach ($objs as $obj) { |
|
71 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
72 | + continue; |
|
73 | + } |
|
74 | + $obj['acl'] = $this->getChildACL(); |
|
75 | + $children[] = new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
76 | + } |
|
77 | + return $children; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * public calendars are always shared |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - protected function isShared() { |
|
85 | - return true; |
|
86 | - } |
|
80 | + /** |
|
81 | + * public calendars are always shared |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + protected function isShared() { |
|
85 | + return true; |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | \ No newline at end of file |
@@ -32,266 +32,266 @@ |
||
32 | 32 | |
33 | 33 | class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { |
34 | 34 | |
35 | - public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { |
|
36 | - parent::__construct($caldavBackend, $calendarInfo); |
|
37 | - |
|
38 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
39 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
40 | - } |
|
41 | - if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
42 | - $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
43 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Updates the list of shares. |
|
49 | - * |
|
50 | - * The first array is a list of people that are to be added to the |
|
51 | - * resource. |
|
52 | - * |
|
53 | - * Every element in the add array has the following properties: |
|
54 | - * * href - A url. Usually a mailto: address |
|
55 | - * * commonName - Usually a first and last name, or false |
|
56 | - * * summary - A description of the share, can also be false |
|
57 | - * * readOnly - A boolean value |
|
58 | - * |
|
59 | - * Every element in the remove array is just the address string. |
|
60 | - * |
|
61 | - * @param array $add |
|
62 | - * @param array $remove |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - function updateShares(array $add, array $remove) { |
|
66 | - /** @var CalDavBackend $calDavBackend */ |
|
67 | - $calDavBackend = $this->caldavBackend; |
|
68 | - $calDavBackend->updateShares($this, $add, $remove); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns the list of people whom this resource is shared with. |
|
73 | - * |
|
74 | - * Every element in this array should have the following properties: |
|
75 | - * * href - Often a mailto: address |
|
76 | - * * commonName - Optional, for example a first + last name |
|
77 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
78 | - * * readOnly - boolean |
|
79 | - * * summary - Optional, a description for the share |
|
80 | - * |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - function getShares() { |
|
84 | - /** @var CalDavBackend $calDavBackend */ |
|
85 | - $calDavBackend = $this->caldavBackend; |
|
86 | - return $calDavBackend->getShares($this->getResourceId()); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return int |
|
91 | - */ |
|
92 | - public function getResourceId() { |
|
93 | - return $this->calendarInfo['id']; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function getPrincipalURI() { |
|
100 | - return $this->calendarInfo['principaluri']; |
|
101 | - } |
|
102 | - |
|
103 | - function getACL() { |
|
104 | - $acl = [ |
|
105 | - [ |
|
106 | - 'privilege' => '{DAV:}read', |
|
107 | - 'principal' => $this->getOwner(), |
|
108 | - 'protected' => true, |
|
109 | - ]]; |
|
110 | - if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
111 | - $acl[] = [ |
|
112 | - 'privilege' => '{DAV:}write', |
|
113 | - 'principal' => $this->getOwner(), |
|
114 | - 'protected' => true, |
|
115 | - ]; |
|
116 | - } |
|
117 | - if ($this->getOwner() !== parent::getOwner()) { |
|
118 | - $acl[] = [ |
|
119 | - 'privilege' => '{DAV:}read', |
|
120 | - 'principal' => parent::getOwner(), |
|
121 | - 'protected' => true, |
|
122 | - ]; |
|
123 | - if ($this->canWrite()) { |
|
124 | - $acl[] = [ |
|
125 | - 'privilege' => '{DAV:}write', |
|
126 | - 'principal' => parent::getOwner(), |
|
127 | - 'protected' => true, |
|
128 | - ]; |
|
129 | - } |
|
130 | - } |
|
131 | - if ($this->isPublic()) { |
|
132 | - $acl[] = [ |
|
133 | - 'privilege' => '{DAV:}read', |
|
134 | - 'principal' => 'principals/system/public', |
|
135 | - 'protected' => true, |
|
136 | - ]; |
|
137 | - } |
|
138 | - |
|
139 | - /** @var CalDavBackend $calDavBackend */ |
|
140 | - $calDavBackend = $this->caldavBackend; |
|
141 | - return $calDavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
142 | - } |
|
143 | - |
|
144 | - function getChildACL() { |
|
145 | - return $this->getACL(); |
|
146 | - } |
|
147 | - |
|
148 | - function getOwner() { |
|
149 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
150 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
151 | - } |
|
152 | - return parent::getOwner(); |
|
153 | - } |
|
154 | - |
|
155 | - function delete() { |
|
156 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
157 | - $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
158 | - $principal = 'principal:' . parent::getOwner(); |
|
159 | - $shares = $this->getShares(); |
|
160 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
161 | - return $share['href'] === $principal; |
|
162 | - }); |
|
163 | - if (empty($shares)) { |
|
164 | - throw new Forbidden(); |
|
165 | - } |
|
166 | - |
|
167 | - /** @var CalDavBackend $calDavBackend */ |
|
168 | - $calDavBackend = $this->caldavBackend; |
|
169 | - $calDavBackend->updateShares($this, [], [ |
|
170 | - 'href' => $principal |
|
171 | - ]); |
|
172 | - return; |
|
173 | - } |
|
174 | - parent::delete(); |
|
175 | - } |
|
176 | - |
|
177 | - function propPatch(PropPatch $propPatch) { |
|
178 | - // parent::propPatch will only update calendars table |
|
179 | - // if calendar is shared, changes have to be made to the properties table |
|
180 | - if (!$this->isShared()) { |
|
181 | - parent::propPatch($propPatch); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - function getChild($name) { |
|
186 | - |
|
187 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
188 | - |
|
189 | - if (!$obj) { |
|
190 | - throw new NotFound('Calendar object not found'); |
|
191 | - } |
|
192 | - |
|
193 | - if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
194 | - throw new NotFound('Calendar object not found'); |
|
195 | - } |
|
196 | - |
|
197 | - $obj['acl'] = $this->getChildACL(); |
|
198 | - |
|
199 | - return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
200 | - |
|
201 | - } |
|
202 | - |
|
203 | - function getChildren() { |
|
204 | - |
|
205 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
206 | - $children = []; |
|
207 | - foreach ($objs as $obj) { |
|
208 | - if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
209 | - continue; |
|
210 | - } |
|
211 | - $obj['acl'] = $this->getChildACL(); |
|
212 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
213 | - } |
|
214 | - return $children; |
|
215 | - |
|
216 | - } |
|
217 | - |
|
218 | - function getMultipleChildren(array $paths) { |
|
219 | - |
|
220 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
221 | - $children = []; |
|
222 | - foreach ($objs as $obj) { |
|
223 | - if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
224 | - continue; |
|
225 | - } |
|
226 | - $obj['acl'] = $this->getChildACL(); |
|
227 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
228 | - } |
|
229 | - return $children; |
|
230 | - |
|
231 | - } |
|
232 | - |
|
233 | - function childExists($name) { |
|
234 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
235 | - if (!$obj) { |
|
236 | - return false; |
|
237 | - } |
|
238 | - if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
239 | - return false; |
|
240 | - } |
|
241 | - |
|
242 | - return true; |
|
243 | - } |
|
244 | - |
|
245 | - function calendarQuery(array $filters) { |
|
246 | - |
|
247 | - $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
248 | - if ($this->isShared()) { |
|
249 | - return array_filter($uris, function ($uri) { |
|
250 | - return $this->childExists($uri); |
|
251 | - }); |
|
252 | - } |
|
253 | - |
|
254 | - return $uris; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @param boolean $value |
|
259 | - * @return string|null |
|
260 | - */ |
|
261 | - function setPublishStatus($value) { |
|
262 | - $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
263 | - $this->calendarInfo['publicuri'] = $publicUri; |
|
264 | - return $publicUri; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @return mixed $value |
|
269 | - */ |
|
270 | - function getPublishStatus() { |
|
271 | - return $this->caldavBackend->getPublishStatus($this); |
|
272 | - } |
|
273 | - |
|
274 | - private function canWrite() { |
|
275 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
276 | - return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
277 | - } |
|
278 | - return true; |
|
279 | - } |
|
280 | - |
|
281 | - private function isPublic() { |
|
282 | - return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
283 | - } |
|
284 | - |
|
285 | - protected function isShared() { |
|
286 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
287 | - return false; |
|
288 | - } |
|
289 | - |
|
290 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
291 | - } |
|
292 | - |
|
293 | - public function isSubscription() { |
|
294 | - return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
295 | - } |
|
35 | + public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { |
|
36 | + parent::__construct($caldavBackend, $calendarInfo); |
|
37 | + |
|
38 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
39 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
40 | + } |
|
41 | + if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
42 | + $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
43 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Updates the list of shares. |
|
49 | + * |
|
50 | + * The first array is a list of people that are to be added to the |
|
51 | + * resource. |
|
52 | + * |
|
53 | + * Every element in the add array has the following properties: |
|
54 | + * * href - A url. Usually a mailto: address |
|
55 | + * * commonName - Usually a first and last name, or false |
|
56 | + * * summary - A description of the share, can also be false |
|
57 | + * * readOnly - A boolean value |
|
58 | + * |
|
59 | + * Every element in the remove array is just the address string. |
|
60 | + * |
|
61 | + * @param array $add |
|
62 | + * @param array $remove |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + function updateShares(array $add, array $remove) { |
|
66 | + /** @var CalDavBackend $calDavBackend */ |
|
67 | + $calDavBackend = $this->caldavBackend; |
|
68 | + $calDavBackend->updateShares($this, $add, $remove); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns the list of people whom this resource is shared with. |
|
73 | + * |
|
74 | + * Every element in this array should have the following properties: |
|
75 | + * * href - Often a mailto: address |
|
76 | + * * commonName - Optional, for example a first + last name |
|
77 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
78 | + * * readOnly - boolean |
|
79 | + * * summary - Optional, a description for the share |
|
80 | + * |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + function getShares() { |
|
84 | + /** @var CalDavBackend $calDavBackend */ |
|
85 | + $calDavBackend = $this->caldavBackend; |
|
86 | + return $calDavBackend->getShares($this->getResourceId()); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return int |
|
91 | + */ |
|
92 | + public function getResourceId() { |
|
93 | + return $this->calendarInfo['id']; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function getPrincipalURI() { |
|
100 | + return $this->calendarInfo['principaluri']; |
|
101 | + } |
|
102 | + |
|
103 | + function getACL() { |
|
104 | + $acl = [ |
|
105 | + [ |
|
106 | + 'privilege' => '{DAV:}read', |
|
107 | + 'principal' => $this->getOwner(), |
|
108 | + 'protected' => true, |
|
109 | + ]]; |
|
110 | + if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
111 | + $acl[] = [ |
|
112 | + 'privilege' => '{DAV:}write', |
|
113 | + 'principal' => $this->getOwner(), |
|
114 | + 'protected' => true, |
|
115 | + ]; |
|
116 | + } |
|
117 | + if ($this->getOwner() !== parent::getOwner()) { |
|
118 | + $acl[] = [ |
|
119 | + 'privilege' => '{DAV:}read', |
|
120 | + 'principal' => parent::getOwner(), |
|
121 | + 'protected' => true, |
|
122 | + ]; |
|
123 | + if ($this->canWrite()) { |
|
124 | + $acl[] = [ |
|
125 | + 'privilege' => '{DAV:}write', |
|
126 | + 'principal' => parent::getOwner(), |
|
127 | + 'protected' => true, |
|
128 | + ]; |
|
129 | + } |
|
130 | + } |
|
131 | + if ($this->isPublic()) { |
|
132 | + $acl[] = [ |
|
133 | + 'privilege' => '{DAV:}read', |
|
134 | + 'principal' => 'principals/system/public', |
|
135 | + 'protected' => true, |
|
136 | + ]; |
|
137 | + } |
|
138 | + |
|
139 | + /** @var CalDavBackend $calDavBackend */ |
|
140 | + $calDavBackend = $this->caldavBackend; |
|
141 | + return $calDavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
142 | + } |
|
143 | + |
|
144 | + function getChildACL() { |
|
145 | + return $this->getACL(); |
|
146 | + } |
|
147 | + |
|
148 | + function getOwner() { |
|
149 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
150 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
151 | + } |
|
152 | + return parent::getOwner(); |
|
153 | + } |
|
154 | + |
|
155 | + function delete() { |
|
156 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
157 | + $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
158 | + $principal = 'principal:' . parent::getOwner(); |
|
159 | + $shares = $this->getShares(); |
|
160 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
161 | + return $share['href'] === $principal; |
|
162 | + }); |
|
163 | + if (empty($shares)) { |
|
164 | + throw new Forbidden(); |
|
165 | + } |
|
166 | + |
|
167 | + /** @var CalDavBackend $calDavBackend */ |
|
168 | + $calDavBackend = $this->caldavBackend; |
|
169 | + $calDavBackend->updateShares($this, [], [ |
|
170 | + 'href' => $principal |
|
171 | + ]); |
|
172 | + return; |
|
173 | + } |
|
174 | + parent::delete(); |
|
175 | + } |
|
176 | + |
|
177 | + function propPatch(PropPatch $propPatch) { |
|
178 | + // parent::propPatch will only update calendars table |
|
179 | + // if calendar is shared, changes have to be made to the properties table |
|
180 | + if (!$this->isShared()) { |
|
181 | + parent::propPatch($propPatch); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + function getChild($name) { |
|
186 | + |
|
187 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
188 | + |
|
189 | + if (!$obj) { |
|
190 | + throw new NotFound('Calendar object not found'); |
|
191 | + } |
|
192 | + |
|
193 | + if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
194 | + throw new NotFound('Calendar object not found'); |
|
195 | + } |
|
196 | + |
|
197 | + $obj['acl'] = $this->getChildACL(); |
|
198 | + |
|
199 | + return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + function getChildren() { |
|
204 | + |
|
205 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
206 | + $children = []; |
|
207 | + foreach ($objs as $obj) { |
|
208 | + if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
209 | + continue; |
|
210 | + } |
|
211 | + $obj['acl'] = $this->getChildACL(); |
|
212 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
213 | + } |
|
214 | + return $children; |
|
215 | + |
|
216 | + } |
|
217 | + |
|
218 | + function getMultipleChildren(array $paths) { |
|
219 | + |
|
220 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
221 | + $children = []; |
|
222 | + foreach ($objs as $obj) { |
|
223 | + if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
224 | + continue; |
|
225 | + } |
|
226 | + $obj['acl'] = $this->getChildACL(); |
|
227 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
228 | + } |
|
229 | + return $children; |
|
230 | + |
|
231 | + } |
|
232 | + |
|
233 | + function childExists($name) { |
|
234 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
235 | + if (!$obj) { |
|
236 | + return false; |
|
237 | + } |
|
238 | + if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
239 | + return false; |
|
240 | + } |
|
241 | + |
|
242 | + return true; |
|
243 | + } |
|
244 | + |
|
245 | + function calendarQuery(array $filters) { |
|
246 | + |
|
247 | + $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
248 | + if ($this->isShared()) { |
|
249 | + return array_filter($uris, function ($uri) { |
|
250 | + return $this->childExists($uri); |
|
251 | + }); |
|
252 | + } |
|
253 | + |
|
254 | + return $uris; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @param boolean $value |
|
259 | + * @return string|null |
|
260 | + */ |
|
261 | + function setPublishStatus($value) { |
|
262 | + $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
263 | + $this->calendarInfo['publicuri'] = $publicUri; |
|
264 | + return $publicUri; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @return mixed $value |
|
269 | + */ |
|
270 | + function getPublishStatus() { |
|
271 | + return $this->caldavBackend->getPublishStatus($this); |
|
272 | + } |
|
273 | + |
|
274 | + private function canWrite() { |
|
275 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
276 | + return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
277 | + } |
|
278 | + return true; |
|
279 | + } |
|
280 | + |
|
281 | + private function isPublic() { |
|
282 | + return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
283 | + } |
|
284 | + |
|
285 | + protected function isShared() { |
|
286 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
287 | + return false; |
|
288 | + } |
|
289 | + |
|
290 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
291 | + } |
|
292 | + |
|
293 | + public function isSubscription() { |
|
294 | + return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
295 | + } |
|
296 | 296 | |
297 | 297 | } |