Completed
Push — master ( db1408...ac565c )
by Morris
14:12
created
apps/dav/lib/CalDAV/Calendar.php 1 patch
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -38,287 +38,287 @@
 block discarded – undo
38 38
  */
39 39
 class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
40 40
 
41
-	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
42
-		parent::__construct($caldavBackend, $calendarInfo);
43
-
44
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
45
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
46
-		}
47
-		if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
48
-			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
49
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
50
-		}
51
-	}
52
-
53
-	/**
54
-	 * Updates the list of shares.
55
-	 *
56
-	 * The first array is a list of people that are to be added to the
57
-	 * resource.
58
-	 *
59
-	 * Every element in the add array has the following properties:
60
-	 *   * href - A url. Usually a mailto: address
61
-	 *   * commonName - Usually a first and last name, or false
62
-	 *   * summary - A description of the share, can also be false
63
-	 *   * readOnly - A boolean value
64
-	 *
65
-	 * Every element in the remove array is just the address string.
66
-	 *
67
-	 * @param array $add
68
-	 * @param array $remove
69
-	 * @return void
70
-	 * @throws Forbidden
71
-	 */
72
-	public function updateShares(array $add, array $remove) {
73
-		if ($this->isShared()) {
74
-			throw new Forbidden();
75
-		}
76
-		$this->caldavBackend->updateShares($this, $add, $remove);
77
-	}
78
-
79
-	/**
80
-	 * Returns the list of people whom this resource is shared with.
81
-	 *
82
-	 * Every element in this array should have the following properties:
83
-	 *   * href - Often a mailto: address
84
-	 *   * commonName - Optional, for example a first + last name
85
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
86
-	 *   * readOnly - boolean
87
-	 *   * summary - Optional, a description for the share
88
-	 *
89
-	 * @return array
90
-	 */
91
-	public function getShares() {
92
-		if ($this->isShared()) {
93
-			return [];
94
-		}
95
-		return $this->caldavBackend->getShares($this->getResourceId());
96
-	}
97
-
98
-	/**
99
-	 * @return int
100
-	 */
101
-	public function getResourceId() {
102
-		return $this->calendarInfo['id'];
103
-	}
104
-
105
-	/**
106
-	 * @return string
107
-	 */
108
-	public function getPrincipalURI() {
109
-		return $this->calendarInfo['principaluri'];
110
-	}
111
-
112
-	public function getACL() {
113
-		$acl =  [
114
-			[
115
-				'privilege' => '{DAV:}read',
116
-				'principal' => $this->getOwner(),
117
-				'protected' => true,
118
-			]];
119
-		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
120
-			$acl[] = [
121
-				'privilege' => '{DAV:}write',
122
-				'principal' => $this->getOwner(),
123
-				'protected' => true,
124
-			];
125
-		} else {
126
-			$acl[] = [
127
-				'privilege' => '{DAV:}write-properties',
128
-				'principal' => $this->getOwner(),
129
-				'protected' => true,
130
-			];
131
-		}
132
-
133
-		if ($this->getOwner() !== parent::getOwner()) {
134
-			$acl[] =  [
135
-					'privilege' => '{DAV:}read',
136
-					'principal' => parent::getOwner(),
137
-					'protected' => true,
138
-				];
139
-			if ($this->canWrite()) {
140
-				$acl[] = [
141
-					'privilege' => '{DAV:}write',
142
-					'principal' => parent::getOwner(),
143
-					'protected' => true,
144
-				];
145
-			} else {
146
-				$acl[] = [
147
-					'privilege' => '{DAV:}write-properties',
148
-					'principal' => parent::getOwner(),
149
-					'protected' => true,
150
-				];
151
-			}
152
-		}
153
-		if ($this->isPublic()) {
154
-			$acl[] = [
155
-				'privilege' => '{DAV:}read',
156
-				'principal' => 'principals/system/public',
157
-				'protected' => true,
158
-			];
159
-		}
160
-
161
-		$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
162
-
163
-		if (!$this->isShared()) {
164
-			return $acl;
165
-		}
166
-
167
-		$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
168
-		return array_filter($acl, function($rule) use ($allowedPrincipals) {
169
-			return in_array($rule['principal'], $allowedPrincipals);
170
-		});
171
-	}
172
-
173
-	public function getChildACL() {
174
-		return $this->getACL();
175
-	}
176
-
177
-	public function getOwner() {
178
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
179
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
180
-		}
181
-		return parent::getOwner();
182
-	}
183
-
184
-	public function delete() {
185
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
186
-			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
187
-			$principal = 'principal:' . parent::getOwner();
188
-			$shares = $this->caldavBackend->getShares($this->getResourceId());
189
-			$shares = array_filter($shares, function($share) use ($principal){
190
-				return $share['href'] === $principal;
191
-			});
192
-			if (empty($shares)) {
193
-				throw new Forbidden();
194
-			}
195
-
196
-			$this->caldavBackend->updateShares($this, [], [
197
-				'href' => $principal
198
-			]);
199
-			return;
200
-		}
201
-		parent::delete();
202
-	}
203
-
204
-	public function propPatch(PropPatch $propPatch) {
205
-		// parent::propPatch will only update calendars table
206
-		// if calendar is shared, changes have to be made to the properties table
207
-		if (!$this->isShared()) {
208
-			parent::propPatch($propPatch);
209
-		}
210
-	}
211
-
212
-	public function getChild($name) {
213
-
214
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
215
-
216
-		if (!$obj) {
217
-			throw new NotFound('Calendar object not found');
218
-		}
219
-
220
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
221
-			throw new NotFound('Calendar object not found');
222
-		}
223
-
224
-		$obj['acl'] = $this->getChildACL();
225
-
226
-		return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
227
-
228
-	}
229
-
230
-	public function getChildren() {
231
-
232
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
233
-		$children = [];
234
-		foreach ($objs as $obj) {
235
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
236
-				continue;
237
-			}
238
-			$obj['acl'] = $this->getChildACL();
239
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
240
-		}
241
-		return $children;
242
-
243
-	}
244
-
245
-	public function getMultipleChildren(array $paths) {
246
-
247
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
248
-		$children = [];
249
-		foreach ($objs as $obj) {
250
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
251
-				continue;
252
-			}
253
-			$obj['acl'] = $this->getChildACL();
254
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
255
-		}
256
-		return $children;
257
-
258
-	}
259
-
260
-	public function childExists($name) {
261
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
262
-		if (!$obj) {
263
-			return false;
264
-		}
265
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
266
-			return false;
267
-		}
268
-
269
-		return true;
270
-	}
271
-
272
-	public function calendarQuery(array $filters) {
273
-
274
-		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
275
-		if ($this->isShared()) {
276
-			return array_filter($uris, function ($uri) {
277
-				return $this->childExists($uri);
278
-			});
279
-		}
280
-
281
-		return $uris;
282
-	}
283
-
284
-	/**
285
-	 * @param boolean $value
286
-	 * @return string|null
287
-	 */
288
-	public function setPublishStatus($value) {
289
-		$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
290
-		$this->calendarInfo['publicuri'] = $publicUri;
291
-		return $publicUri;
292
-	}
293
-
294
-	/**
295
-	 * @return mixed $value
296
-	 */
297
-	public function getPublishStatus() {
298
-		return $this->caldavBackend->getPublishStatus($this);
299
-	}
300
-
301
-	private function canWrite() {
302
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
303
-			return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
304
-		}
305
-		return true;
306
-	}
307
-
308
-	private function isPublic() {
309
-		return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
310
-	}
311
-
312
-	protected function isShared() {
313
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
314
-			return false;
315
-		}
316
-
317
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
318
-	}
319
-
320
-	public function isSubscription() {
321
-		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
322
-	}
41
+    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
42
+        parent::__construct($caldavBackend, $calendarInfo);
43
+
44
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
45
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
46
+        }
47
+        if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
48
+            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
49
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
50
+        }
51
+    }
52
+
53
+    /**
54
+     * Updates the list of shares.
55
+     *
56
+     * The first array is a list of people that are to be added to the
57
+     * resource.
58
+     *
59
+     * Every element in the add array has the following properties:
60
+     *   * href - A url. Usually a mailto: address
61
+     *   * commonName - Usually a first and last name, or false
62
+     *   * summary - A description of the share, can also be false
63
+     *   * readOnly - A boolean value
64
+     *
65
+     * Every element in the remove array is just the address string.
66
+     *
67
+     * @param array $add
68
+     * @param array $remove
69
+     * @return void
70
+     * @throws Forbidden
71
+     */
72
+    public function updateShares(array $add, array $remove) {
73
+        if ($this->isShared()) {
74
+            throw new Forbidden();
75
+        }
76
+        $this->caldavBackend->updateShares($this, $add, $remove);
77
+    }
78
+
79
+    /**
80
+     * Returns the list of people whom this resource is shared with.
81
+     *
82
+     * Every element in this array should have the following properties:
83
+     *   * href - Often a mailto: address
84
+     *   * commonName - Optional, for example a first + last name
85
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
86
+     *   * readOnly - boolean
87
+     *   * summary - Optional, a description for the share
88
+     *
89
+     * @return array
90
+     */
91
+    public function getShares() {
92
+        if ($this->isShared()) {
93
+            return [];
94
+        }
95
+        return $this->caldavBackend->getShares($this->getResourceId());
96
+    }
97
+
98
+    /**
99
+     * @return int
100
+     */
101
+    public function getResourceId() {
102
+        return $this->calendarInfo['id'];
103
+    }
104
+
105
+    /**
106
+     * @return string
107
+     */
108
+    public function getPrincipalURI() {
109
+        return $this->calendarInfo['principaluri'];
110
+    }
111
+
112
+    public function getACL() {
113
+        $acl =  [
114
+            [
115
+                'privilege' => '{DAV:}read',
116
+                'principal' => $this->getOwner(),
117
+                'protected' => true,
118
+            ]];
119
+        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
120
+            $acl[] = [
121
+                'privilege' => '{DAV:}write',
122
+                'principal' => $this->getOwner(),
123
+                'protected' => true,
124
+            ];
125
+        } else {
126
+            $acl[] = [
127
+                'privilege' => '{DAV:}write-properties',
128
+                'principal' => $this->getOwner(),
129
+                'protected' => true,
130
+            ];
131
+        }
132
+
133
+        if ($this->getOwner() !== parent::getOwner()) {
134
+            $acl[] =  [
135
+                    'privilege' => '{DAV:}read',
136
+                    'principal' => parent::getOwner(),
137
+                    'protected' => true,
138
+                ];
139
+            if ($this->canWrite()) {
140
+                $acl[] = [
141
+                    'privilege' => '{DAV:}write',
142
+                    'principal' => parent::getOwner(),
143
+                    'protected' => true,
144
+                ];
145
+            } else {
146
+                $acl[] = [
147
+                    'privilege' => '{DAV:}write-properties',
148
+                    'principal' => parent::getOwner(),
149
+                    'protected' => true,
150
+                ];
151
+            }
152
+        }
153
+        if ($this->isPublic()) {
154
+            $acl[] = [
155
+                'privilege' => '{DAV:}read',
156
+                'principal' => 'principals/system/public',
157
+                'protected' => true,
158
+            ];
159
+        }
160
+
161
+        $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
162
+
163
+        if (!$this->isShared()) {
164
+            return $acl;
165
+        }
166
+
167
+        $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
168
+        return array_filter($acl, function($rule) use ($allowedPrincipals) {
169
+            return in_array($rule['principal'], $allowedPrincipals);
170
+        });
171
+    }
172
+
173
+    public function getChildACL() {
174
+        return $this->getACL();
175
+    }
176
+
177
+    public function getOwner() {
178
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
179
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
180
+        }
181
+        return parent::getOwner();
182
+    }
183
+
184
+    public function delete() {
185
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
186
+            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
187
+            $principal = 'principal:' . parent::getOwner();
188
+            $shares = $this->caldavBackend->getShares($this->getResourceId());
189
+            $shares = array_filter($shares, function($share) use ($principal){
190
+                return $share['href'] === $principal;
191
+            });
192
+            if (empty($shares)) {
193
+                throw new Forbidden();
194
+            }
195
+
196
+            $this->caldavBackend->updateShares($this, [], [
197
+                'href' => $principal
198
+            ]);
199
+            return;
200
+        }
201
+        parent::delete();
202
+    }
203
+
204
+    public function propPatch(PropPatch $propPatch) {
205
+        // parent::propPatch will only update calendars table
206
+        // if calendar is shared, changes have to be made to the properties table
207
+        if (!$this->isShared()) {
208
+            parent::propPatch($propPatch);
209
+        }
210
+    }
211
+
212
+    public function getChild($name) {
213
+
214
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
215
+
216
+        if (!$obj) {
217
+            throw new NotFound('Calendar object not found');
218
+        }
219
+
220
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
221
+            throw new NotFound('Calendar object not found');
222
+        }
223
+
224
+        $obj['acl'] = $this->getChildACL();
225
+
226
+        return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
227
+
228
+    }
229
+
230
+    public function getChildren() {
231
+
232
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
233
+        $children = [];
234
+        foreach ($objs as $obj) {
235
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
236
+                continue;
237
+            }
238
+            $obj['acl'] = $this->getChildACL();
239
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
240
+        }
241
+        return $children;
242
+
243
+    }
244
+
245
+    public function getMultipleChildren(array $paths) {
246
+
247
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
248
+        $children = [];
249
+        foreach ($objs as $obj) {
250
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
251
+                continue;
252
+            }
253
+            $obj['acl'] = $this->getChildACL();
254
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
255
+        }
256
+        return $children;
257
+
258
+    }
259
+
260
+    public function childExists($name) {
261
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
262
+        if (!$obj) {
263
+            return false;
264
+        }
265
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
266
+            return false;
267
+        }
268
+
269
+        return true;
270
+    }
271
+
272
+    public function calendarQuery(array $filters) {
273
+
274
+        $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
275
+        if ($this->isShared()) {
276
+            return array_filter($uris, function ($uri) {
277
+                return $this->childExists($uri);
278
+            });
279
+        }
280
+
281
+        return $uris;
282
+    }
283
+
284
+    /**
285
+     * @param boolean $value
286
+     * @return string|null
287
+     */
288
+    public function setPublishStatus($value) {
289
+        $publicUri = $this->caldavBackend->setPublishStatus($value, $this);
290
+        $this->calendarInfo['publicuri'] = $publicUri;
291
+        return $publicUri;
292
+    }
293
+
294
+    /**
295
+     * @return mixed $value
296
+     */
297
+    public function getPublishStatus() {
298
+        return $this->caldavBackend->getPublishStatus($this);
299
+    }
300
+
301
+    private function canWrite() {
302
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
303
+            return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
304
+        }
305
+        return true;
306
+    }
307
+
308
+    private function isPublic() {
309
+        return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
310
+    }
311
+
312
+    protected function isShared() {
313
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
314
+            return false;
315
+        }
316
+
317
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
318
+    }
319
+
320
+    public function isSubscription() {
321
+        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
322
+    }
323 323
 
324 324
 }
Please login to merge, or discard this patch.