Passed
Push — master ( a52ed8...d87248 )
by Christoph
11:23 queued 12s
created
apps/dav/lib/CalDAV/Calendar.php 1 patch
Indentation   +374 added lines, -374 removed lines patch added patch discarded remove patch
@@ -48,378 +48,378 @@
 block discarded – undo
48 48
  */
49 49
 class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable {
50 50
 
51
-	/** @var IConfig */
52
-	private $config;
53
-
54
-	/** @var IL10N */
55
-	protected $l10n;
56
-
57
-	/** @var bool */
58
-	private $useTrashbin = true;
59
-
60
-	/**
61
-	 * Calendar constructor.
62
-	 *
63
-	 * @param BackendInterface $caldavBackend
64
-	 * @param $calendarInfo
65
-	 * @param IL10N $l10n
66
-	 * @param IConfig $config
67
-	 */
68
-	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
69
-		// Convert deletion date to ISO8601 string
70
-		if (isset($calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT])) {
71
-			$calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT] = (new DateTimeImmutable())
72
-				->setTimestamp($calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT])
73
-				->format(DateTimeInterface::ATOM);
74
-		}
75
-
76
-		parent::__construct($caldavBackend, $calendarInfo);
77
-
78
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
79
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
80
-		}
81
-		if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
82
-			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
83
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
84
-		}
85
-
86
-		$this->config = $config;
87
-		$this->l10n = $l10n;
88
-	}
89
-
90
-	/**
91
-	 * Updates the list of shares.
92
-	 *
93
-	 * The first array is a list of people that are to be added to the
94
-	 * resource.
95
-	 *
96
-	 * Every element in the add array has the following properties:
97
-	 *   * href - A url. Usually a mailto: address
98
-	 *   * commonName - Usually a first and last name, or false
99
-	 *   * summary - A description of the share, can also be false
100
-	 *   * readOnly - A boolean value
101
-	 *
102
-	 * Every element in the remove array is just the address string.
103
-	 *
104
-	 * @param array $add
105
-	 * @param array $remove
106
-	 * @return void
107
-	 * @throws Forbidden
108
-	 */
109
-	public function updateShares(array $add, array $remove) {
110
-		if ($this->isShared()) {
111
-			throw new Forbidden();
112
-		}
113
-		$this->caldavBackend->updateShares($this, $add, $remove);
114
-	}
115
-
116
-	/**
117
-	 * Returns the list of people whom this resource is shared with.
118
-	 *
119
-	 * Every element in this array should have the following properties:
120
-	 *   * href - Often a mailto: address
121
-	 *   * commonName - Optional, for example a first + last name
122
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
123
-	 *   * readOnly - boolean
124
-	 *   * summary - Optional, a description for the share
125
-	 *
126
-	 * @return array
127
-	 */
128
-	public function getShares() {
129
-		if ($this->isShared()) {
130
-			return [];
131
-		}
132
-		return $this->caldavBackend->getShares($this->getResourceId());
133
-	}
134
-
135
-	/**
136
-	 * @return int
137
-	 */
138
-	public function getResourceId() {
139
-		return $this->calendarInfo['id'];
140
-	}
141
-
142
-	/**
143
-	 * @return string
144
-	 */
145
-	public function getPrincipalURI() {
146
-		return $this->calendarInfo['principaluri'];
147
-	}
148
-
149
-	/**
150
-	 * @return array
151
-	 */
152
-	public function getACL() {
153
-		$acl = [
154
-			[
155
-				'privilege' => '{DAV:}read',
156
-				'principal' => $this->getOwner(),
157
-				'protected' => true,
158
-			],
159
-			[
160
-				'privilege' => '{DAV:}read',
161
-				'principal' => $this->getOwner() . '/calendar-proxy-write',
162
-				'protected' => true,
163
-			],
164
-			[
165
-				'privilege' => '{DAV:}read',
166
-				'principal' => $this->getOwner() . '/calendar-proxy-read',
167
-				'protected' => true,
168
-			],
169
-		];
170
-
171
-		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
172
-			$acl[] = [
173
-				'privilege' => '{DAV:}write',
174
-				'principal' => $this->getOwner(),
175
-				'protected' => true,
176
-			];
177
-			$acl[] = [
178
-				'privilege' => '{DAV:}write',
179
-				'principal' => $this->getOwner() . '/calendar-proxy-write',
180
-				'protected' => true,
181
-			];
182
-		} else {
183
-			$acl[] = [
184
-				'privilege' => '{DAV:}write-properties',
185
-				'principal' => $this->getOwner(),
186
-				'protected' => true,
187
-			];
188
-			$acl[] = [
189
-				'privilege' => '{DAV:}write-properties',
190
-				'principal' => $this->getOwner() . '/calendar-proxy-write',
191
-				'protected' => true,
192
-			];
193
-		}
194
-
195
-		$acl[] = [
196
-			'privilege' => '{DAV:}write-properties',
197
-			'principal' => $this->getOwner() . '/calendar-proxy-read',
198
-			'protected' => true,
199
-		];
200
-
201
-		if (!$this->isShared()) {
202
-			return $acl;
203
-		}
204
-
205
-		if ($this->getOwner() !== parent::getOwner()) {
206
-			$acl[] = [
207
-				'privilege' => '{DAV:}read',
208
-				'principal' => parent::getOwner(),
209
-				'protected' => true,
210
-			];
211
-			if ($this->canWrite()) {
212
-				$acl[] = [
213
-					'privilege' => '{DAV:}write',
214
-					'principal' => parent::getOwner(),
215
-					'protected' => true,
216
-				];
217
-			} else {
218
-				$acl[] = [
219
-					'privilege' => '{DAV:}write-properties',
220
-					'principal' => parent::getOwner(),
221
-					'protected' => true,
222
-				];
223
-			}
224
-		}
225
-		if ($this->isPublic()) {
226
-			$acl[] = [
227
-				'privilege' => '{DAV:}read',
228
-				'principal' => 'principals/system/public',
229
-				'protected' => true,
230
-			];
231
-		}
232
-
233
-		$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
234
-		$allowedPrincipals = [
235
-			$this->getOwner(),
236
-			$this->getOwner(). '/calendar-proxy-read',
237
-			$this->getOwner(). '/calendar-proxy-write',
238
-			parent::getOwner(),
239
-			'principals/system/public'
240
-		];
241
-		return array_filter($acl, function ($rule) use ($allowedPrincipals) {
242
-			return \in_array($rule['principal'], $allowedPrincipals, true);
243
-		});
244
-	}
245
-
246
-	public function getChildACL() {
247
-		return $this->getACL();
248
-	}
249
-
250
-	public function getOwner() {
251
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
252
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
253
-		}
254
-		return parent::getOwner();
255
-	}
256
-
257
-	public function delete() {
258
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
259
-			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
260
-			$principal = 'principal:' . parent::getOwner();
261
-			$shares = $this->caldavBackend->getShares($this->getResourceId());
262
-			$shares = array_filter($shares, function ($share) use ($principal) {
263
-				return $share['href'] === $principal;
264
-			});
265
-			if (empty($shares)) {
266
-				throw new Forbidden();
267
-			}
268
-
269
-			$this->caldavBackend->updateShares($this, [], [
270
-				$principal
271
-			]);
272
-			return;
273
-		}
274
-
275
-		// Remember when a user deleted their birthday calendar
276
-		// in order to not regenerate it on the next contacts change
277
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
278
-			$principalURI = $this->getPrincipalURI();
279
-			$userId = substr($principalURI, 17);
280
-
281
-			$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
282
-		}
283
-
284
-		$this->caldavBackend->deleteCalendar(
285
-			$this->calendarInfo['id'],
286
-			!$this->useTrashbin
287
-		);
288
-	}
289
-
290
-	public function propPatch(PropPatch $propPatch) {
291
-		// parent::propPatch will only update calendars table
292
-		// if calendar is shared, changes have to be made to the properties table
293
-		if (!$this->isShared()) {
294
-			parent::propPatch($propPatch);
295
-		}
296
-	}
297
-
298
-	public function getChild($name) {
299
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
300
-
301
-		if (!$obj) {
302
-			throw new NotFound('Calendar object not found');
303
-		}
304
-
305
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
306
-			throw new NotFound('Calendar object not found');
307
-		}
308
-
309
-		$obj['acl'] = $this->getChildACL();
310
-
311
-		return new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
312
-	}
313
-
314
-	public function getChildren() {
315
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
316
-		$children = [];
317
-		foreach ($objs as $obj) {
318
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
319
-				continue;
320
-			}
321
-			$obj['acl'] = $this->getChildACL();
322
-			$children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
323
-		}
324
-		return $children;
325
-	}
326
-
327
-	public function getMultipleChildren(array $paths) {
328
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
329
-		$children = [];
330
-		foreach ($objs as $obj) {
331
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
332
-				continue;
333
-			}
334
-			$obj['acl'] = $this->getChildACL();
335
-			$children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
336
-		}
337
-		return $children;
338
-	}
339
-
340
-	public function childExists($name) {
341
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
342
-		if (!$obj) {
343
-			return false;
344
-		}
345
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
346
-			return false;
347
-		}
348
-
349
-		return true;
350
-	}
351
-
352
-	public function calendarQuery(array $filters) {
353
-		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
354
-		if ($this->isShared()) {
355
-			return array_filter($uris, function ($uri) {
356
-				return $this->childExists($uri);
357
-			});
358
-		}
359
-
360
-		return $uris;
361
-	}
362
-
363
-	/**
364
-	 * @param boolean $value
365
-	 * @return string|null
366
-	 */
367
-	public function setPublishStatus($value) {
368
-		$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
369
-		$this->calendarInfo['publicuri'] = $publicUri;
370
-		return $publicUri;
371
-	}
372
-
373
-	/**
374
-	 * @return mixed $value
375
-	 */
376
-	public function getPublishStatus() {
377
-		return $this->caldavBackend->getPublishStatus($this);
378
-	}
379
-
380
-	public function canWrite() {
381
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
382
-			return false;
383
-		}
384
-
385
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
386
-			return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
387
-		}
388
-		return true;
389
-	}
390
-
391
-	private function isPublic() {
392
-		return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
393
-	}
394
-
395
-	protected function isShared() {
396
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
397
-			return false;
398
-		}
399
-
400
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
401
-	}
402
-
403
-	public function isSubscription() {
404
-		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
405
-	}
406
-
407
-	/**
408
-	 * @inheritDoc
409
-	 */
410
-	public function getChanges($syncToken, $syncLevel, $limit = null) {
411
-		if (!$syncToken && $limit) {
412
-			throw new UnsupportedLimitOnInitialSyncException();
413
-		}
414
-
415
-		return parent::getChanges($syncToken, $syncLevel, $limit);
416
-	}
417
-
418
-	public function restore(): void {
419
-		$this->caldavBackend->restoreCalendar((int) $this->calendarInfo['id']);
420
-	}
421
-
422
-	public function disableTrashbin(): void {
423
-		$this->useTrashbin = false;
424
-	}
51
+    /** @var IConfig */
52
+    private $config;
53
+
54
+    /** @var IL10N */
55
+    protected $l10n;
56
+
57
+    /** @var bool */
58
+    private $useTrashbin = true;
59
+
60
+    /**
61
+     * Calendar constructor.
62
+     *
63
+     * @param BackendInterface $caldavBackend
64
+     * @param $calendarInfo
65
+     * @param IL10N $l10n
66
+     * @param IConfig $config
67
+     */
68
+    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
69
+        // Convert deletion date to ISO8601 string
70
+        if (isset($calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT])) {
71
+            $calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT] = (new DateTimeImmutable())
72
+                ->setTimestamp($calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT])
73
+                ->format(DateTimeInterface::ATOM);
74
+        }
75
+
76
+        parent::__construct($caldavBackend, $calendarInfo);
77
+
78
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
79
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
80
+        }
81
+        if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
82
+            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
83
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
84
+        }
85
+
86
+        $this->config = $config;
87
+        $this->l10n = $l10n;
88
+    }
89
+
90
+    /**
91
+     * Updates the list of shares.
92
+     *
93
+     * The first array is a list of people that are to be added to the
94
+     * resource.
95
+     *
96
+     * Every element in the add array has the following properties:
97
+     *   * href - A url. Usually a mailto: address
98
+     *   * commonName - Usually a first and last name, or false
99
+     *   * summary - A description of the share, can also be false
100
+     *   * readOnly - A boolean value
101
+     *
102
+     * Every element in the remove array is just the address string.
103
+     *
104
+     * @param array $add
105
+     * @param array $remove
106
+     * @return void
107
+     * @throws Forbidden
108
+     */
109
+    public function updateShares(array $add, array $remove) {
110
+        if ($this->isShared()) {
111
+            throw new Forbidden();
112
+        }
113
+        $this->caldavBackend->updateShares($this, $add, $remove);
114
+    }
115
+
116
+    /**
117
+     * Returns the list of people whom this resource is shared with.
118
+     *
119
+     * Every element in this array should have the following properties:
120
+     *   * href - Often a mailto: address
121
+     *   * commonName - Optional, for example a first + last name
122
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
123
+     *   * readOnly - boolean
124
+     *   * summary - Optional, a description for the share
125
+     *
126
+     * @return array
127
+     */
128
+    public function getShares() {
129
+        if ($this->isShared()) {
130
+            return [];
131
+        }
132
+        return $this->caldavBackend->getShares($this->getResourceId());
133
+    }
134
+
135
+    /**
136
+     * @return int
137
+     */
138
+    public function getResourceId() {
139
+        return $this->calendarInfo['id'];
140
+    }
141
+
142
+    /**
143
+     * @return string
144
+     */
145
+    public function getPrincipalURI() {
146
+        return $this->calendarInfo['principaluri'];
147
+    }
148
+
149
+    /**
150
+     * @return array
151
+     */
152
+    public function getACL() {
153
+        $acl = [
154
+            [
155
+                'privilege' => '{DAV:}read',
156
+                'principal' => $this->getOwner(),
157
+                'protected' => true,
158
+            ],
159
+            [
160
+                'privilege' => '{DAV:}read',
161
+                'principal' => $this->getOwner() . '/calendar-proxy-write',
162
+                'protected' => true,
163
+            ],
164
+            [
165
+                'privilege' => '{DAV:}read',
166
+                'principal' => $this->getOwner() . '/calendar-proxy-read',
167
+                'protected' => true,
168
+            ],
169
+        ];
170
+
171
+        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
172
+            $acl[] = [
173
+                'privilege' => '{DAV:}write',
174
+                'principal' => $this->getOwner(),
175
+                'protected' => true,
176
+            ];
177
+            $acl[] = [
178
+                'privilege' => '{DAV:}write',
179
+                'principal' => $this->getOwner() . '/calendar-proxy-write',
180
+                'protected' => true,
181
+            ];
182
+        } else {
183
+            $acl[] = [
184
+                'privilege' => '{DAV:}write-properties',
185
+                'principal' => $this->getOwner(),
186
+                'protected' => true,
187
+            ];
188
+            $acl[] = [
189
+                'privilege' => '{DAV:}write-properties',
190
+                'principal' => $this->getOwner() . '/calendar-proxy-write',
191
+                'protected' => true,
192
+            ];
193
+        }
194
+
195
+        $acl[] = [
196
+            'privilege' => '{DAV:}write-properties',
197
+            'principal' => $this->getOwner() . '/calendar-proxy-read',
198
+            'protected' => true,
199
+        ];
200
+
201
+        if (!$this->isShared()) {
202
+            return $acl;
203
+        }
204
+
205
+        if ($this->getOwner() !== parent::getOwner()) {
206
+            $acl[] = [
207
+                'privilege' => '{DAV:}read',
208
+                'principal' => parent::getOwner(),
209
+                'protected' => true,
210
+            ];
211
+            if ($this->canWrite()) {
212
+                $acl[] = [
213
+                    'privilege' => '{DAV:}write',
214
+                    'principal' => parent::getOwner(),
215
+                    'protected' => true,
216
+                ];
217
+            } else {
218
+                $acl[] = [
219
+                    'privilege' => '{DAV:}write-properties',
220
+                    'principal' => parent::getOwner(),
221
+                    'protected' => true,
222
+                ];
223
+            }
224
+        }
225
+        if ($this->isPublic()) {
226
+            $acl[] = [
227
+                'privilege' => '{DAV:}read',
228
+                'principal' => 'principals/system/public',
229
+                'protected' => true,
230
+            ];
231
+        }
232
+
233
+        $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
234
+        $allowedPrincipals = [
235
+            $this->getOwner(),
236
+            $this->getOwner(). '/calendar-proxy-read',
237
+            $this->getOwner(). '/calendar-proxy-write',
238
+            parent::getOwner(),
239
+            'principals/system/public'
240
+        ];
241
+        return array_filter($acl, function ($rule) use ($allowedPrincipals) {
242
+            return \in_array($rule['principal'], $allowedPrincipals, true);
243
+        });
244
+    }
245
+
246
+    public function getChildACL() {
247
+        return $this->getACL();
248
+    }
249
+
250
+    public function getOwner() {
251
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
252
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
253
+        }
254
+        return parent::getOwner();
255
+    }
256
+
257
+    public function delete() {
258
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
259
+            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
260
+            $principal = 'principal:' . parent::getOwner();
261
+            $shares = $this->caldavBackend->getShares($this->getResourceId());
262
+            $shares = array_filter($shares, function ($share) use ($principal) {
263
+                return $share['href'] === $principal;
264
+            });
265
+            if (empty($shares)) {
266
+                throw new Forbidden();
267
+            }
268
+
269
+            $this->caldavBackend->updateShares($this, [], [
270
+                $principal
271
+            ]);
272
+            return;
273
+        }
274
+
275
+        // Remember when a user deleted their birthday calendar
276
+        // in order to not regenerate it on the next contacts change
277
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
278
+            $principalURI = $this->getPrincipalURI();
279
+            $userId = substr($principalURI, 17);
280
+
281
+            $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
282
+        }
283
+
284
+        $this->caldavBackend->deleteCalendar(
285
+            $this->calendarInfo['id'],
286
+            !$this->useTrashbin
287
+        );
288
+    }
289
+
290
+    public function propPatch(PropPatch $propPatch) {
291
+        // parent::propPatch will only update calendars table
292
+        // if calendar is shared, changes have to be made to the properties table
293
+        if (!$this->isShared()) {
294
+            parent::propPatch($propPatch);
295
+        }
296
+    }
297
+
298
+    public function getChild($name) {
299
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
300
+
301
+        if (!$obj) {
302
+            throw new NotFound('Calendar object not found');
303
+        }
304
+
305
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
306
+            throw new NotFound('Calendar object not found');
307
+        }
308
+
309
+        $obj['acl'] = $this->getChildACL();
310
+
311
+        return new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
312
+    }
313
+
314
+    public function getChildren() {
315
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
316
+        $children = [];
317
+        foreach ($objs as $obj) {
318
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
319
+                continue;
320
+            }
321
+            $obj['acl'] = $this->getChildACL();
322
+            $children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
323
+        }
324
+        return $children;
325
+    }
326
+
327
+    public function getMultipleChildren(array $paths) {
328
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
329
+        $children = [];
330
+        foreach ($objs as $obj) {
331
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
332
+                continue;
333
+            }
334
+            $obj['acl'] = $this->getChildACL();
335
+            $children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
336
+        }
337
+        return $children;
338
+    }
339
+
340
+    public function childExists($name) {
341
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
342
+        if (!$obj) {
343
+            return false;
344
+        }
345
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
346
+            return false;
347
+        }
348
+
349
+        return true;
350
+    }
351
+
352
+    public function calendarQuery(array $filters) {
353
+        $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
354
+        if ($this->isShared()) {
355
+            return array_filter($uris, function ($uri) {
356
+                return $this->childExists($uri);
357
+            });
358
+        }
359
+
360
+        return $uris;
361
+    }
362
+
363
+    /**
364
+     * @param boolean $value
365
+     * @return string|null
366
+     */
367
+    public function setPublishStatus($value) {
368
+        $publicUri = $this->caldavBackend->setPublishStatus($value, $this);
369
+        $this->calendarInfo['publicuri'] = $publicUri;
370
+        return $publicUri;
371
+    }
372
+
373
+    /**
374
+     * @return mixed $value
375
+     */
376
+    public function getPublishStatus() {
377
+        return $this->caldavBackend->getPublishStatus($this);
378
+    }
379
+
380
+    public function canWrite() {
381
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
382
+            return false;
383
+        }
384
+
385
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
386
+            return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
387
+        }
388
+        return true;
389
+    }
390
+
391
+    private function isPublic() {
392
+        return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
393
+    }
394
+
395
+    protected function isShared() {
396
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
397
+            return false;
398
+        }
399
+
400
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
401
+    }
402
+
403
+    public function isSubscription() {
404
+        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
405
+    }
406
+
407
+    /**
408
+     * @inheritDoc
409
+     */
410
+    public function getChanges($syncToken, $syncLevel, $limit = null) {
411
+        if (!$syncToken && $limit) {
412
+            throw new UnsupportedLimitOnInitialSyncException();
413
+        }
414
+
415
+        return parent::getChanges($syncToken, $syncLevel, $limit);
416
+    }
417
+
418
+    public function restore(): void {
419
+        $this->caldavBackend->restoreCalendar((int) $this->calendarInfo['id']);
420
+    }
421
+
422
+    public function disableTrashbin(): void {
423
+        $this->useTrashbin = false;
424
+    }
425 425
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Trashbin/Plugin.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -42,92 +42,92 @@
 block discarded – undo
42 42
 use function implode;
43 43
 
44 44
 class Plugin extends ServerPlugin {
45
-	public const PROPERTY_DELETED_AT = '{http://nextcloud.com/ns}deleted-at';
46
-	public const PROPERTY_CALENDAR_URI = '{http://nextcloud.com/ns}calendar-uri';
47
-	public const PROPERTY_RETENTION_DURATION = '{http://nextcloud.com/ns}trash-bin-retention-duration';
48
-
49
-	/** @var bool */
50
-	private $disableTrashbin;
51
-
52
-	/** @var RetentionService */
53
-	private $retentionService;
54
-
55
-	/** @var Server */
56
-	private $server;
57
-
58
-	public function __construct(IRequest $request,
59
-								RetentionService $retentionService) {
60
-		$this->disableTrashbin = $request->getHeader('X-NC-CalDAV-No-Trashbin') === '1';
61
-		$this->retentionService = $retentionService;
62
-	}
63
-
64
-	public function initialize(Server $server): void {
65
-		$this->server = $server;
66
-		$server->on('beforeMethod:*', [$this, 'beforeMethod']);
67
-		$server->on('propFind', Closure::fromCallable([$this, 'propFind']));
68
-	}
69
-
70
-	public function beforeMethod(RequestInterface $request, ResponseInterface $response): void {
71
-		if (!$this->disableTrashbin) {
72
-			return;
73
-		}
74
-
75
-		$path = $request->getPath();
76
-		$pathParts = explode('/', ltrim($path, '/'));
77
-		if (\count($pathParts) < 3) {
78
-			// We are looking for a path like calendars/username/calendarname
79
-			return;
80
-		}
81
-
82
-		// $calendarPath will look like calendars/username/calendarname
83
-		$calendarPath = implode(
84
-			'/',
85
-			array_slice($pathParts, 0, 3)
86
-		);
87
-		try {
88
-			$calendar = $this->server->tree->getNodeForPath($calendarPath);
89
-			if (!($calendar instanceof Calendar)) {
90
-				// This is odd
91
-				return;
92
-			}
93
-
94
-			/** @var Calendar $calendar */
95
-			$calendar->disableTrashbin();
96
-		} catch (NotFound $ex) {
97
-			return;
98
-		}
99
-	}
100
-
101
-	private function propFind(
102
-		PropFind $propFind,
103
-		INode $node): void {
104
-		if ($node instanceof DeletedCalendarObject) {
105
-			$propFind->handle(self::PROPERTY_DELETED_AT, function () use ($node) {
106
-				$ts = $node->getDeletedAt();
107
-				if ($ts === null) {
108
-					return null;
109
-				}
110
-
111
-				return (new DateTimeImmutable())
112
-					->setTimestamp($ts)
113
-					->format(DateTimeInterface::ATOM);
114
-			});
115
-			$propFind->handle(self::PROPERTY_CALENDAR_URI, function () use ($node) {
116
-				return $node->getCalendarUri();
117
-			});
118
-		}
119
-		if ($node instanceof TrashbinHome) {
120
-			$propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) {
121
-				return $this->retentionService->getDuration();
122
-			});
123
-		}
124
-	}
125
-
126
-	public function getFeatures(): array {
127
-		return ['nc-calendar-trashbin'];
128
-	}
129
-
130
-	public function getPluginName(): string {
131
-		return 'nc-calendar-trashbin';
132
-	}
45
+    public const PROPERTY_DELETED_AT = '{http://nextcloud.com/ns}deleted-at';
46
+    public const PROPERTY_CALENDAR_URI = '{http://nextcloud.com/ns}calendar-uri';
47
+    public const PROPERTY_RETENTION_DURATION = '{http://nextcloud.com/ns}trash-bin-retention-duration';
48
+
49
+    /** @var bool */
50
+    private $disableTrashbin;
51
+
52
+    /** @var RetentionService */
53
+    private $retentionService;
54
+
55
+    /** @var Server */
56
+    private $server;
57
+
58
+    public function __construct(IRequest $request,
59
+                                RetentionService $retentionService) {
60
+        $this->disableTrashbin = $request->getHeader('X-NC-CalDAV-No-Trashbin') === '1';
61
+        $this->retentionService = $retentionService;
62
+    }
63
+
64
+    public function initialize(Server $server): void {
65
+        $this->server = $server;
66
+        $server->on('beforeMethod:*', [$this, 'beforeMethod']);
67
+        $server->on('propFind', Closure::fromCallable([$this, 'propFind']));
68
+    }
69
+
70
+    public function beforeMethod(RequestInterface $request, ResponseInterface $response): void {
71
+        if (!$this->disableTrashbin) {
72
+            return;
73
+        }
74
+
75
+        $path = $request->getPath();
76
+        $pathParts = explode('/', ltrim($path, '/'));
77
+        if (\count($pathParts) < 3) {
78
+            // We are looking for a path like calendars/username/calendarname
79
+            return;
80
+        }
81
+
82
+        // $calendarPath will look like calendars/username/calendarname
83
+        $calendarPath = implode(
84
+            '/',
85
+            array_slice($pathParts, 0, 3)
86
+        );
87
+        try {
88
+            $calendar = $this->server->tree->getNodeForPath($calendarPath);
89
+            if (!($calendar instanceof Calendar)) {
90
+                // This is odd
91
+                return;
92
+            }
93
+
94
+            /** @var Calendar $calendar */
95
+            $calendar->disableTrashbin();
96
+        } catch (NotFound $ex) {
97
+            return;
98
+        }
99
+    }
100
+
101
+    private function propFind(
102
+        PropFind $propFind,
103
+        INode $node): void {
104
+        if ($node instanceof DeletedCalendarObject) {
105
+            $propFind->handle(self::PROPERTY_DELETED_AT, function () use ($node) {
106
+                $ts = $node->getDeletedAt();
107
+                if ($ts === null) {
108
+                    return null;
109
+                }
110
+
111
+                return (new DateTimeImmutable())
112
+                    ->setTimestamp($ts)
113
+                    ->format(DateTimeInterface::ATOM);
114
+            });
115
+            $propFind->handle(self::PROPERTY_CALENDAR_URI, function () use ($node) {
116
+                return $node->getCalendarUri();
117
+            });
118
+        }
119
+        if ($node instanceof TrashbinHome) {
120
+            $propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) {
121
+                return $this->retentionService->getDuration();
122
+            });
123
+        }
124
+    }
125
+
126
+    public function getFeatures(): array {
127
+        return ['nc-calendar-trashbin'];
128
+    }
129
+
130
+    public function getPluginName(): string {
131
+        return 'nc-calendar-trashbin';
132
+    }
133 133
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		PropFind $propFind,
103 103
 		INode $node): void {
104 104
 		if ($node instanceof DeletedCalendarObject) {
105
-			$propFind->handle(self::PROPERTY_DELETED_AT, function () use ($node) {
105
+			$propFind->handle(self::PROPERTY_DELETED_AT, function() use ($node) {
106 106
 				$ts = $node->getDeletedAt();
107 107
 				if ($ts === null) {
108 108
 					return null;
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 					->setTimestamp($ts)
113 113
 					->format(DateTimeInterface::ATOM);
114 114
 			});
115
-			$propFind->handle(self::PROPERTY_CALENDAR_URI, function () use ($node) {
115
+			$propFind->handle(self::PROPERTY_CALENDAR_URI, function() use ($node) {
116 116
 				return $node->getCalendarUri();
117 117
 			});
118 118
 		}
119 119
 		if ($node instanceof TrashbinHome) {
120
-			$propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) {
120
+			$propFind->handle(self::PROPERTY_RETENTION_DURATION, function() use ($node) {
121 121
 				return $this->retentionService->getDuration();
122 122
 			});
123 123
 		}
Please login to merge, or discard this patch.