Completed
Pull Request — master (#6884)
by Georg
13:23
created
apps/dav/appinfo/routes.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@
 block discarded – undo
22 22
  */
23 23
 
24 24
 return [
25
-	'routes' => [
26
-		['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'],
27
-		['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'],
28
-	]
25
+    'routes' => [
26
+        ['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'],
27
+        ['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'],
28
+    ]
29 29
 ];
Please login to merge, or discard this patch.
apps/dav/lib/Controller/BirthdayCalendarController.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -32,50 +32,50 @@
 block discarded – undo
32 32
 
33 33
 class BirthdayCalendarController extends Controller {
34 34
 
35
-	/**
36
-	 * @var IDBConnection
37
-	 */
38
-	protected $db;
35
+    /**
36
+     * @var IDBConnection
37
+     */
38
+    protected $db;
39 39
 
40
-	/**
41
-	 * @var IConfig
42
-	 */
43
-	protected $config;
40
+    /**
41
+     * @var IConfig
42
+     */
43
+    protected $config;
44 44
 
45
-	/**
46
-	 * BirthdayCalendar constructor.
47
-	 *
48
-	 * @param string $appName
49
-	 * @param IRequest $request
50
-	 * @param IDBConnection $db
51
-	 * @param IConfig $config
52
-	 */
53
-	public function __construct($appName, IRequest $request,
54
-								IDBConnection $db, IConfig $config){
55
-		parent::__construct($appName, $request);
56
-		$this->db = $db;
57
-		$this->config = $config;
58
-	}
45
+    /**
46
+     * BirthdayCalendar constructor.
47
+     *
48
+     * @param string $appName
49
+     * @param IRequest $request
50
+     * @param IDBConnection $db
51
+     * @param IConfig $config
52
+     */
53
+    public function __construct($appName, IRequest $request,
54
+                                IDBConnection $db, IConfig $config){
55
+        parent::__construct($appName, $request);
56
+        $this->db = $db;
57
+        $this->config = $config;
58
+    }
59 59
 
60
-	/**
61
-	 * @return Response
62
-	 */
63
-	public function enable() {
64
-		$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes');
60
+    /**
61
+     * @return Response
62
+     */
63
+    public function enable() {
64
+        $this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes');
65 65
 
66
-		// TODO schedule background job to regenerate
66
+        // TODO schedule background job to regenerate
67 67
 
68
-		return new JSONResponse([]);
69
-	}
68
+        return new JSONResponse([]);
69
+    }
70 70
 
71
-	/**
72
-	 * @return Response
73
-	 */
74
-	public function disable() {
75
-		$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no');
71
+    /**
72
+     * @return Response
73
+     */
74
+    public function disable() {
75
+        $this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no');
76 76
 
77
-		// TODO delete all birthday calendars
77
+        // TODO delete all birthday calendars
78 78
 
79
-		return new JSONResponse([]);
80
-	}
79
+        return new JSONResponse([]);
80
+    }
81 81
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 	 * @param IConfig $config
52 52
 	 */
53 53
 	public function __construct($appName, IRequest $request,
54
-								IDBConnection $db, IConfig $config){
54
+								IDBConnection $db, IConfig $config) {
55 55
 		parent::__construct($appName, $request);
56 56
 		$this->db = $db;
57 57
 		$this->config = $config;
Please login to merge, or discard this patch.
apps/dav/lib/Settings/CalDAVSettings.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,41 +29,41 @@
 block discarded – undo
29 29
 
30 30
 class CalDAVSettings implements ISettings {
31 31
 
32
-	/** @var IConfig */
33
-	private $config;
32
+    /** @var IConfig */
33
+    private $config;
34 34
 
35
-	/**
36
-	 * CalDAVSettings constructor.
37
-	 *
38
-	 * @param IConfig $config
39
-	 */
40
-	public function __construct(IConfig $config) {
41
-		$this->config = $config;
42
-	}
35
+    /**
36
+     * CalDAVSettings constructor.
37
+     *
38
+     * @param IConfig $config
39
+     */
40
+    public function __construct(IConfig $config) {
41
+        $this->config = $config;
42
+    }
43 43
 
44
-	/**
45
-	 * @return TemplateResponse
46
-	 */
47
-	public function getForm() {
48
-		$parameters = [
49
-			'send_invitations' => $this->config->getAppValue('dav', 'sendInvitations', 'yes'),
50
-			'generate_birthday_calendar' => $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'),
51
-		];
44
+    /**
45
+     * @return TemplateResponse
46
+     */
47
+    public function getForm() {
48
+        $parameters = [
49
+            'send_invitations' => $this->config->getAppValue('dav', 'sendInvitations', 'yes'),
50
+            'generate_birthday_calendar' => $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'),
51
+        ];
52 52
 
53
-		return new TemplateResponse('dav', 'settings-admin-caldav', $parameters);
54
-	}
53
+        return new TemplateResponse('dav', 'settings-admin-caldav', $parameters);
54
+    }
55 55
 
56
-	/**
57
-	 * @return string
58
-	 */
59
-	public function getSection() {
60
-		return 'additional';
61
-	}
56
+    /**
57
+     * @return string
58
+     */
59
+    public function getSection() {
60
+        return 'additional';
61
+    }
62 62
 
63
-	/**
64
-	 * @return int
65
-	 */
66
-	public function getPriority() {
67
-		return 20;
68
-	}
63
+    /**
64
+     * @return int
65
+     */
66
+    public function getPriority() {
67
+        return 20;
68
+    }
69 69
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Calendar.php 1 patch
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -39,302 +39,302 @@
 block discarded – undo
39 39
  */
40 40
 class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
41 41
 
42
-	/** @var IConfig */
43
-	private $config;
44
-
45
-	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
46
-		parent::__construct($caldavBackend, $calendarInfo);
47
-
48
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
49
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
50
-		}
51
-		if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
52
-			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
53
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
54
-		}
55
-
56
-		$this->config = $config;
57
-	}
58
-
59
-	/**
60
-	 * Updates the list of shares.
61
-	 *
62
-	 * The first array is a list of people that are to be added to the
63
-	 * resource.
64
-	 *
65
-	 * Every element in the add array has the following properties:
66
-	 *   * href - A url. Usually a mailto: address
67
-	 *   * commonName - Usually a first and last name, or false
68
-	 *   * summary - A description of the share, can also be false
69
-	 *   * readOnly - A boolean value
70
-	 *
71
-	 * Every element in the remove array is just the address string.
72
-	 *
73
-	 * @param array $add
74
-	 * @param array $remove
75
-	 * @return void
76
-	 * @throws Forbidden
77
-	 */
78
-	public function updateShares(array $add, array $remove) {
79
-		if ($this->isShared()) {
80
-			throw new Forbidden();
81
-		}
82
-		$this->caldavBackend->updateShares($this, $add, $remove);
83
-	}
84
-
85
-	/**
86
-	 * Returns the list of people whom this resource is shared with.
87
-	 *
88
-	 * Every element in this array should have the following properties:
89
-	 *   * href - Often a mailto: address
90
-	 *   * commonName - Optional, for example a first + last name
91
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
92
-	 *   * readOnly - boolean
93
-	 *   * summary - Optional, a description for the share
94
-	 *
95
-	 * @return array
96
-	 */
97
-	public function getShares() {
98
-		if ($this->isShared()) {
99
-			return [];
100
-		}
101
-		return $this->caldavBackend->getShares($this->getResourceId());
102
-	}
103
-
104
-	/**
105
-	 * @return int
106
-	 */
107
-	public function getResourceId() {
108
-		return $this->calendarInfo['id'];
109
-	}
110
-
111
-	/**
112
-	 * @return string
113
-	 */
114
-	public function getPrincipalURI() {
115
-		return $this->calendarInfo['principaluri'];
116
-	}
117
-
118
-	public function getACL() {
119
-		$acl =  [
120
-			[
121
-				'privilege' => '{DAV:}read',
122
-				'principal' => $this->getOwner(),
123
-				'protected' => true,
124
-			]];
125
-		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
126
-			$acl[] = [
127
-				'privilege' => '{DAV:}write',
128
-				'principal' => $this->getOwner(),
129
-				'protected' => true,
130
-			];
131
-		} else {
132
-			$acl[] = [
133
-				'privilege' => '{DAV:}write-properties',
134
-				'principal' => $this->getOwner(),
135
-				'protected' => true,
136
-			];
137
-		}
138
-
139
-		if ($this->getOwner() !== parent::getOwner()) {
140
-			$acl[] =  [
141
-					'privilege' => '{DAV:}read',
142
-					'principal' => parent::getOwner(),
143
-					'protected' => true,
144
-				];
145
-			if ($this->canWrite()) {
146
-				$acl[] = [
147
-					'privilege' => '{DAV:}write',
148
-					'principal' => parent::getOwner(),
149
-					'protected' => true,
150
-				];
151
-			} else {
152
-				$acl[] = [
153
-					'privilege' => '{DAV:}write-properties',
154
-					'principal' => parent::getOwner(),
155
-					'protected' => true,
156
-				];
157
-			}
158
-		}
159
-		if ($this->isPublic()) {
160
-			$acl[] = [
161
-				'privilege' => '{DAV:}read',
162
-				'principal' => 'principals/system/public',
163
-				'protected' => true,
164
-			];
165
-		}
166
-
167
-		$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
168
-
169
-		if (!$this->isShared()) {
170
-			return $acl;
171
-		}
172
-
173
-		$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
174
-		return array_filter($acl, function($rule) use ($allowedPrincipals) {
175
-			return in_array($rule['principal'], $allowedPrincipals);
176
-		});
177
-	}
178
-
179
-	public function getChildACL() {
180
-		return $this->getACL();
181
-	}
182
-
183
-	public function getOwner() {
184
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
185
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
186
-		}
187
-		return parent::getOwner();
188
-	}
189
-
190
-	public function delete() {
191
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
192
-			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
193
-			$principal = 'principal:' . parent::getOwner();
194
-			$shares = $this->caldavBackend->getShares($this->getResourceId());
195
-			$shares = array_filter($shares, function($share) use ($principal){
196
-				return $share['href'] === $principal;
197
-			});
198
-			if (empty($shares)) {
199
-				throw new Forbidden();
200
-			}
201
-
202
-			$this->caldavBackend->updateShares($this, [], [
203
-				'href' => $principal
204
-			]);
205
-			return;
206
-		}
207
-
208
-		// Remember when a user deleted their birthday calendar
209
-		// in order to not regenerate it on the next contacts change
210
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
211
-			$principalURI = $this->getPrincipalURI();
212
-			$userId = substr($principalURI, 17);
213
-
214
-			$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
215
-		}
216
-
217
-		parent::delete();
218
-	}
219
-
220
-	public function propPatch(PropPatch $propPatch) {
221
-		// parent::propPatch will only update calendars table
222
-		// if calendar is shared, changes have to be made to the properties table
223
-		if (!$this->isShared()) {
224
-			parent::propPatch($propPatch);
225
-		}
226
-	}
227
-
228
-	public function getChild($name) {
229
-
230
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
231
-
232
-		if (!$obj) {
233
-			throw new NotFound('Calendar object not found');
234
-		}
235
-
236
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
237
-			throw new NotFound('Calendar object not found');
238
-		}
239
-
240
-		$obj['acl'] = $this->getChildACL();
241
-
242
-		return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
243
-
244
-	}
245
-
246
-	public function getChildren() {
247
-
248
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
249
-		$children = [];
250
-		foreach ($objs as $obj) {
251
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
252
-				continue;
253
-			}
254
-			$obj['acl'] = $this->getChildACL();
255
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
256
-		}
257
-		return $children;
258
-
259
-	}
260
-
261
-	public function getMultipleChildren(array $paths) {
262
-
263
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
264
-		$children = [];
265
-		foreach ($objs as $obj) {
266
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
267
-				continue;
268
-			}
269
-			$obj['acl'] = $this->getChildACL();
270
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
271
-		}
272
-		return $children;
273
-
274
-	}
275
-
276
-	public function childExists($name) {
277
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
278
-		if (!$obj) {
279
-			return false;
280
-		}
281
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
282
-			return false;
283
-		}
284
-
285
-		return true;
286
-	}
287
-
288
-	public function calendarQuery(array $filters) {
289
-
290
-		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
291
-		if ($this->isShared()) {
292
-			return array_filter($uris, function ($uri) {
293
-				return $this->childExists($uri);
294
-			});
295
-		}
296
-
297
-		return $uris;
298
-	}
299
-
300
-	/**
301
-	 * @param boolean $value
302
-	 * @return string|null
303
-	 */
304
-	public function setPublishStatus($value) {
305
-		$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
306
-		$this->calendarInfo['publicuri'] = $publicUri;
307
-		return $publicUri;
308
-	}
309
-
310
-	/**
311
-	 * @return mixed $value
312
-	 */
313
-	public function getPublishStatus() {
314
-		return $this->caldavBackend->getPublishStatus($this);
315
-	}
316
-
317
-	private function canWrite() {
318
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
319
-			return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
320
-		}
321
-		return true;
322
-	}
323
-
324
-	private function isPublic() {
325
-		return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
326
-	}
327
-
328
-	protected function isShared() {
329
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
330
-			return false;
331
-		}
332
-
333
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
334
-	}
335
-
336
-	public function isSubscription() {
337
-		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
338
-	}
42
+    /** @var IConfig */
43
+    private $config;
44
+
45
+    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
46
+        parent::__construct($caldavBackend, $calendarInfo);
47
+
48
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
49
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
50
+        }
51
+        if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
52
+            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
53
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
54
+        }
55
+
56
+        $this->config = $config;
57
+    }
58
+
59
+    /**
60
+     * Updates the list of shares.
61
+     *
62
+     * The first array is a list of people that are to be added to the
63
+     * resource.
64
+     *
65
+     * Every element in the add array has the following properties:
66
+     *   * href - A url. Usually a mailto: address
67
+     *   * commonName - Usually a first and last name, or false
68
+     *   * summary - A description of the share, can also be false
69
+     *   * readOnly - A boolean value
70
+     *
71
+     * Every element in the remove array is just the address string.
72
+     *
73
+     * @param array $add
74
+     * @param array $remove
75
+     * @return void
76
+     * @throws Forbidden
77
+     */
78
+    public function updateShares(array $add, array $remove) {
79
+        if ($this->isShared()) {
80
+            throw new Forbidden();
81
+        }
82
+        $this->caldavBackend->updateShares($this, $add, $remove);
83
+    }
84
+
85
+    /**
86
+     * Returns the list of people whom this resource is shared with.
87
+     *
88
+     * Every element in this array should have the following properties:
89
+     *   * href - Often a mailto: address
90
+     *   * commonName - Optional, for example a first + last name
91
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
92
+     *   * readOnly - boolean
93
+     *   * summary - Optional, a description for the share
94
+     *
95
+     * @return array
96
+     */
97
+    public function getShares() {
98
+        if ($this->isShared()) {
99
+            return [];
100
+        }
101
+        return $this->caldavBackend->getShares($this->getResourceId());
102
+    }
103
+
104
+    /**
105
+     * @return int
106
+     */
107
+    public function getResourceId() {
108
+        return $this->calendarInfo['id'];
109
+    }
110
+
111
+    /**
112
+     * @return string
113
+     */
114
+    public function getPrincipalURI() {
115
+        return $this->calendarInfo['principaluri'];
116
+    }
117
+
118
+    public function getACL() {
119
+        $acl =  [
120
+            [
121
+                'privilege' => '{DAV:}read',
122
+                'principal' => $this->getOwner(),
123
+                'protected' => true,
124
+            ]];
125
+        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
126
+            $acl[] = [
127
+                'privilege' => '{DAV:}write',
128
+                'principal' => $this->getOwner(),
129
+                'protected' => true,
130
+            ];
131
+        } else {
132
+            $acl[] = [
133
+                'privilege' => '{DAV:}write-properties',
134
+                'principal' => $this->getOwner(),
135
+                'protected' => true,
136
+            ];
137
+        }
138
+
139
+        if ($this->getOwner() !== parent::getOwner()) {
140
+            $acl[] =  [
141
+                    'privilege' => '{DAV:}read',
142
+                    'principal' => parent::getOwner(),
143
+                    'protected' => true,
144
+                ];
145
+            if ($this->canWrite()) {
146
+                $acl[] = [
147
+                    'privilege' => '{DAV:}write',
148
+                    'principal' => parent::getOwner(),
149
+                    'protected' => true,
150
+                ];
151
+            } else {
152
+                $acl[] = [
153
+                    'privilege' => '{DAV:}write-properties',
154
+                    'principal' => parent::getOwner(),
155
+                    'protected' => true,
156
+                ];
157
+            }
158
+        }
159
+        if ($this->isPublic()) {
160
+            $acl[] = [
161
+                'privilege' => '{DAV:}read',
162
+                'principal' => 'principals/system/public',
163
+                'protected' => true,
164
+            ];
165
+        }
166
+
167
+        $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
168
+
169
+        if (!$this->isShared()) {
170
+            return $acl;
171
+        }
172
+
173
+        $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
174
+        return array_filter($acl, function($rule) use ($allowedPrincipals) {
175
+            return in_array($rule['principal'], $allowedPrincipals);
176
+        });
177
+    }
178
+
179
+    public function getChildACL() {
180
+        return $this->getACL();
181
+    }
182
+
183
+    public function getOwner() {
184
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
185
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
186
+        }
187
+        return parent::getOwner();
188
+    }
189
+
190
+    public function delete() {
191
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
192
+            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
193
+            $principal = 'principal:' . parent::getOwner();
194
+            $shares = $this->caldavBackend->getShares($this->getResourceId());
195
+            $shares = array_filter($shares, function($share) use ($principal){
196
+                return $share['href'] === $principal;
197
+            });
198
+            if (empty($shares)) {
199
+                throw new Forbidden();
200
+            }
201
+
202
+            $this->caldavBackend->updateShares($this, [], [
203
+                'href' => $principal
204
+            ]);
205
+            return;
206
+        }
207
+
208
+        // Remember when a user deleted their birthday calendar
209
+        // in order to not regenerate it on the next contacts change
210
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
211
+            $principalURI = $this->getPrincipalURI();
212
+            $userId = substr($principalURI, 17);
213
+
214
+            $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
215
+        }
216
+
217
+        parent::delete();
218
+    }
219
+
220
+    public function propPatch(PropPatch $propPatch) {
221
+        // parent::propPatch will only update calendars table
222
+        // if calendar is shared, changes have to be made to the properties table
223
+        if (!$this->isShared()) {
224
+            parent::propPatch($propPatch);
225
+        }
226
+    }
227
+
228
+    public function getChild($name) {
229
+
230
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
231
+
232
+        if (!$obj) {
233
+            throw new NotFound('Calendar object not found');
234
+        }
235
+
236
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
237
+            throw new NotFound('Calendar object not found');
238
+        }
239
+
240
+        $obj['acl'] = $this->getChildACL();
241
+
242
+        return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
243
+
244
+    }
245
+
246
+    public function getChildren() {
247
+
248
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
249
+        $children = [];
250
+        foreach ($objs as $obj) {
251
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
252
+                continue;
253
+            }
254
+            $obj['acl'] = $this->getChildACL();
255
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
256
+        }
257
+        return $children;
258
+
259
+    }
260
+
261
+    public function getMultipleChildren(array $paths) {
262
+
263
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
264
+        $children = [];
265
+        foreach ($objs as $obj) {
266
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
267
+                continue;
268
+            }
269
+            $obj['acl'] = $this->getChildACL();
270
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
271
+        }
272
+        return $children;
273
+
274
+    }
275
+
276
+    public function childExists($name) {
277
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
278
+        if (!$obj) {
279
+            return false;
280
+        }
281
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
282
+            return false;
283
+        }
284
+
285
+        return true;
286
+    }
287
+
288
+    public function calendarQuery(array $filters) {
289
+
290
+        $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
291
+        if ($this->isShared()) {
292
+            return array_filter($uris, function ($uri) {
293
+                return $this->childExists($uri);
294
+            });
295
+        }
296
+
297
+        return $uris;
298
+    }
299
+
300
+    /**
301
+     * @param boolean $value
302
+     * @return string|null
303
+     */
304
+    public function setPublishStatus($value) {
305
+        $publicUri = $this->caldavBackend->setPublishStatus($value, $this);
306
+        $this->calendarInfo['publicuri'] = $publicUri;
307
+        return $publicUri;
308
+    }
309
+
310
+    /**
311
+     * @return mixed $value
312
+     */
313
+    public function getPublishStatus() {
314
+        return $this->caldavBackend->getPublishStatus($this);
315
+    }
316
+
317
+    private function canWrite() {
318
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
319
+            return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
320
+        }
321
+        return true;
322
+    }
323
+
324
+    private function isPublic() {
325
+        return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
326
+    }
327
+
328
+    protected function isShared() {
329
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
330
+            return false;
331
+        }
332
+
333
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
334
+    }
335
+
336
+    public function isSubscription() {
337
+        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
338
+    }
339 339
 
340 340
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@
 block discarded – undo
104 104
 	 * @param RequestInterface $request
105 105
 	 * @param ResponseInterface $response
106 106
 	 *
107
-	 * @return bool|void
107
+	 * @return null|false
108 108
 	 */
109 109
 	public function httpPost(RequestInterface $request, ResponseInterface $response) {
110 110
 		$node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -37,94 +37,94 @@
 block discarded – undo
37 37
  * @package OCA\DAV\CalDAV\BirthdayCalendar
38 38
  */
39 39
 class EnablePlugin extends ServerPlugin {
40
-	const NS_Nextcloud = 'http://nextcloud.com/ns';
41
-
42
-	/**
43
-	 * @var IConfig
44
-	 */
45
-	protected $config;
46
-
47
-	/**
48
-	 * @var Server
49
-	 */
50
-	protected $server;
51
-
52
-	/**
53
-	 * PublishPlugin constructor.
54
-	 *
55
-	 * @param IConfig $config
56
-	 */
57
-	public function __construct(IConfig $config) {
58
-		$this->config = $config;
59
-	}
60
-
61
-	/**
62
-	 * This method should return a list of server-features.
63
-	 *
64
-	 * This is for example 'versioning' and is added to the DAV: header
65
-	 * in an OPTIONS response.
66
-	 *
67
-	 * @return string[]
68
-	 */
69
-	public function getFeatures() {
70
-		return ['nc-enable-birthday-calendar'];
71
-	}
72
-
73
-	/**
74
-	 * Returns a plugin name.
75
-	 *
76
-	 * Using this name other plugins will be able to access other plugins
77
-	 * using Sabre\DAV\Server::getPlugin
78
-	 *
79
-	 * @return string
80
-	 */
81
-	public function getPluginName()	{
82
-		return 'nc-enable-birthday-calendar';
83
-	}
84
-
85
-	/**
86
-	 * This initializes the plugin.
87
-	 *
88
-	 * This function is called by Sabre\DAV\Server, after
89
-	 * addPlugin is called.
90
-	 *
91
-	 * This method should set up the required event subscriptions.
92
-	 *
93
-	 * @param Server $server
94
-	 */
95
-	public function initialize(Server $server) {
96
-		$this->server = $server;
97
-
98
-		$this->server->on('method:POST', [$this, 'httpPost']);
99
-	}
100
-
101
-	/**
102
-	 * We intercept this to handle POST requests on calendar homes.
103
-	 *
104
-	 * @param RequestInterface $request
105
-	 * @param ResponseInterface $response
106
-	 *
107
-	 * @return bool|void
108
-	 */
109
-	public function httpPost(RequestInterface $request, ResponseInterface $response) {
110
-		$node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
111
-		if (!($node instanceof CalendarHome)) {
112
-			return;
113
-		}
114
-
115
-		$requestBody = $request->getBodyAsString();
116
-		$this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
117
-		if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') {
118
-			return;
119
-		}
120
-
121
-		$principalUri = $node->getOwner();
122
-		$userId = substr($principalUri, 17);
123
-
124
-		$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
125
-
126
-		$this->server->httpResponse->setStatus(204);
127
-
128
-		return false;
129
-	}
40
+    const NS_Nextcloud = 'http://nextcloud.com/ns';
41
+
42
+    /**
43
+     * @var IConfig
44
+     */
45
+    protected $config;
46
+
47
+    /**
48
+     * @var Server
49
+     */
50
+    protected $server;
51
+
52
+    /**
53
+     * PublishPlugin constructor.
54
+     *
55
+     * @param IConfig $config
56
+     */
57
+    public function __construct(IConfig $config) {
58
+        $this->config = $config;
59
+    }
60
+
61
+    /**
62
+     * This method should return a list of server-features.
63
+     *
64
+     * This is for example 'versioning' and is added to the DAV: header
65
+     * in an OPTIONS response.
66
+     *
67
+     * @return string[]
68
+     */
69
+    public function getFeatures() {
70
+        return ['nc-enable-birthday-calendar'];
71
+    }
72
+
73
+    /**
74
+     * Returns a plugin name.
75
+     *
76
+     * Using this name other plugins will be able to access other plugins
77
+     * using Sabre\DAV\Server::getPlugin
78
+     *
79
+     * @return string
80
+     */
81
+    public function getPluginName()	{
82
+        return 'nc-enable-birthday-calendar';
83
+    }
84
+
85
+    /**
86
+     * This initializes the plugin.
87
+     *
88
+     * This function is called by Sabre\DAV\Server, after
89
+     * addPlugin is called.
90
+     *
91
+     * This method should set up the required event subscriptions.
92
+     *
93
+     * @param Server $server
94
+     */
95
+    public function initialize(Server $server) {
96
+        $this->server = $server;
97
+
98
+        $this->server->on('method:POST', [$this, 'httpPost']);
99
+    }
100
+
101
+    /**
102
+     * We intercept this to handle POST requests on calendar homes.
103
+     *
104
+     * @param RequestInterface $request
105
+     * @param ResponseInterface $response
106
+     *
107
+     * @return bool|void
108
+     */
109
+    public function httpPost(RequestInterface $request, ResponseInterface $response) {
110
+        $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
111
+        if (!($node instanceof CalendarHome)) {
112
+            return;
113
+        }
114
+
115
+        $requestBody = $request->getBodyAsString();
116
+        $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
117
+        if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') {
118
+            return;
119
+        }
120
+
121
+        $principalUri = $node->getOwner();
122
+        $userId = substr($principalUri, 17);
123
+
124
+        $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
125
+
126
+        $this->server->httpResponse->setStatus(204);
127
+
128
+        return false;
129
+    }
130 130
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
 	 *
79 79
 	 * @return string
80 80
 	 */
81
-	public function getPluginName()	{
81
+	public function getPluginName() {
82 82
 		return 'nc-enable-birthday-calendar';
83 83
 	}
84 84
 
Please login to merge, or discard this patch.
apps/dav/lib/Command/SyncBirthdayCalendar.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -34,86 +34,86 @@
 block discarded – undo
34 34
 
35 35
 class SyncBirthdayCalendar extends Command {
36 36
 
37
-	/** @var BirthdayService */
38
-	private $birthdayService;
39
-
40
-	/** @var IConfig */
41
-	private $config;
42
-
43
-	/** @var IUserManager */
44
-	private $userManager;
45
-
46
-	/**
47
-	 * @param IUserManager $userManager
48
-	 * @param IConfig $config
49
-	 * @param BirthdayService $birthdayService
50
-	 */
51
-	function __construct(IUserManager $userManager, IConfig $config,
52
-						 BirthdayService $birthdayService) {
53
-		parent::__construct();
54
-		$this->birthdayService = $birthdayService;
55
-		$this->config = $config;
56
-		$this->userManager = $userManager;
57
-	}
58
-
59
-	protected function configure() {
60
-		$this
61
-			->setName('dav:sync-birthday-calendar')
62
-			->setDescription('Synchronizes the birthday calendar')
63
-			->addArgument('user',
64
-				InputArgument::OPTIONAL,
65
-				'User for whom the birthday calendar will be synchronized');
66
-	}
67
-
68
-	/**
69
-	 * @param InputInterface $input
70
-	 * @param OutputInterface $output
71
-	 */
72
-	protected function execute(InputInterface $input, OutputInterface $output) {
73
-		$this->verifyEnabled();
74
-
75
-		$user = $input->getArgument('user');
76
-		if (!is_null($user)) {
77
-			if (!$this->userManager->userExists($user)) {
78
-				throw new \InvalidArgumentException("User <$user> in unknown.");
79
-			}
80
-
81
-			// re-enable the birthday calendar in case it's called directly with a user name
82
-			$isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
83
-			if ($isEnabled !== 'yes') {
84
-				$this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
85
-				$output->writeln("Re-enabling birthday calendar for $user");
86
-			}
87
-
88
-			$output->writeln("Start birthday calendar sync for $user");
89
-			$this->birthdayService->syncUser($user);
90
-			return;
91
-		}
92
-		$output->writeln("Start birthday calendar sync for all users ...");
93
-		$p = new ProgressBar($output);
94
-		$p->start();
95
-		$this->userManager->callForAllUsers(function($user) use ($p)  {
96
-			$p->advance();
97
-
98
-			$userId = $user->getUID();
99
-			$isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
100
-			if ($isEnabled !== 'yes') {
101
-				return;
102
-			}
103
-
104
-			/** @var IUser $user */
105
-			$this->birthdayService->syncUser($user->getUID());
106
-		});
107
-
108
-		$p->finish();
109
-		$output->writeln('');
110
-	}
111
-
112
-	protected function verifyEnabled () {
113
-		$isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
114
-
115
-		if ($isEnabled !== 'yes') {
116
-			throw new \InvalidArgumentException('Birthday calendars are disabled');
117
-		}
118
-	}
37
+    /** @var BirthdayService */
38
+    private $birthdayService;
39
+
40
+    /** @var IConfig */
41
+    private $config;
42
+
43
+    /** @var IUserManager */
44
+    private $userManager;
45
+
46
+    /**
47
+     * @param IUserManager $userManager
48
+     * @param IConfig $config
49
+     * @param BirthdayService $birthdayService
50
+     */
51
+    function __construct(IUserManager $userManager, IConfig $config,
52
+                            BirthdayService $birthdayService) {
53
+        parent::__construct();
54
+        $this->birthdayService = $birthdayService;
55
+        $this->config = $config;
56
+        $this->userManager = $userManager;
57
+    }
58
+
59
+    protected function configure() {
60
+        $this
61
+            ->setName('dav:sync-birthday-calendar')
62
+            ->setDescription('Synchronizes the birthday calendar')
63
+            ->addArgument('user',
64
+                InputArgument::OPTIONAL,
65
+                'User for whom the birthday calendar will be synchronized');
66
+    }
67
+
68
+    /**
69
+     * @param InputInterface $input
70
+     * @param OutputInterface $output
71
+     */
72
+    protected function execute(InputInterface $input, OutputInterface $output) {
73
+        $this->verifyEnabled();
74
+
75
+        $user = $input->getArgument('user');
76
+        if (!is_null($user)) {
77
+            if (!$this->userManager->userExists($user)) {
78
+                throw new \InvalidArgumentException("User <$user> in unknown.");
79
+            }
80
+
81
+            // re-enable the birthday calendar in case it's called directly with a user name
82
+            $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
83
+            if ($isEnabled !== 'yes') {
84
+                $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
85
+                $output->writeln("Re-enabling birthday calendar for $user");
86
+            }
87
+
88
+            $output->writeln("Start birthday calendar sync for $user");
89
+            $this->birthdayService->syncUser($user);
90
+            return;
91
+        }
92
+        $output->writeln("Start birthday calendar sync for all users ...");
93
+        $p = new ProgressBar($output);
94
+        $p->start();
95
+        $this->userManager->callForAllUsers(function($user) use ($p)  {
96
+            $p->advance();
97
+
98
+            $userId = $user->getUID();
99
+            $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
100
+            if ($isEnabled !== 'yes') {
101
+                return;
102
+            }
103
+
104
+            /** @var IUser $user */
105
+            $this->birthdayService->syncUser($user->getUID());
106
+        });
107
+
108
+        $p->finish();
109
+        $output->writeln('');
110
+    }
111
+
112
+    protected function verifyEnabled () {
113
+        $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
114
+
115
+        if ($isEnabled !== 'yes') {
116
+            throw new \InvalidArgumentException('Birthday calendars are disabled');
117
+        }
118
+    }
119 119
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@
 block discarded – undo
109 109
 		$output->writeln('');
110 110
 	}
111 111
 
112
-	protected function verifyEnabled () {
112
+	protected function verifyEnabled() {
113 113
 		$isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
114 114
 
115 115
 		if ($isEnabled !== 'yes') {
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/CalendarHome.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -35,109 +35,109 @@
 block discarded – undo
35 35
 
36 36
 class CalendarHome extends \Sabre\CalDAV\CalendarHome {
37 37
 
38
-	/** @var \OCP\IL10N */
39
-	private $l10n;
40
-
41
-	/** @var \OCP\IConfig */
42
-	private $config;
43
-
44
-	public function __construct(BackendInterface $caldavBackend, $principalInfo) {
45
-		parent::__construct($caldavBackend, $principalInfo);
46
-		$this->l10n = \OC::$server->getL10N('dav');
47
-		$this->config = \OC::$server->getConfig();
48
-	}
49
-
50
-	/**
51
-	 * @return BackendInterface
52
-	 */
53
-	public function getCalDAVBackend() {
54
-		return $this->caldavBackend;
55
-	}
56
-
57
-	/**
58
-	 * @inheritdoc
59
-	 */
60
-	function createExtendedCollection($name, MkCol $mkCol) {
61
-		$reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
62
-
63
-		if (in_array($name, $reservedNames)) {
64
-			throw new MethodNotAllowed('The resource you tried to create has a reserved name');
65
-		}
66
-
67
-		parent::createExtendedCollection($name, $mkCol);
68
-	}
69
-
70
-	/**
71
-	 * @inheritdoc
72
-	 */
73
-	function getChildren() {
74
-		$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
75
-		$objects = [];
76
-		foreach ($calendars as $calendar) {
77
-			$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
78
-		}
79
-
80
-		if ($this->caldavBackend instanceof SchedulingSupport) {
81
-			$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
82
-			$objects[] = new Outbox($this->principalInfo['uri']);
83
-		}
84
-
85
-		// We're adding a notifications node, if it's supported by the backend.
86
-		if ($this->caldavBackend instanceof NotificationSupport) {
87
-			$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
88
-		}
89
-
90
-		// If the backend supports subscriptions, we'll add those as well,
91
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
92
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
93
-				$objects[] = new Subscription($this->caldavBackend, $subscription);
94
-			}
95
-		}
96
-
97
-		return $objects;
98
-	}
99
-
100
-	/**
101
-	 * @inheritdoc
102
-	 */
103
-	function getChild($name) {
104
-		// Special nodes
105
-		if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
106
-			return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
107
-		}
108
-		if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
109
-			return new Outbox($this->principalInfo['uri']);
110
-		}
111
-		if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
112
-			return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
113
-		}
114
-
115
-		// Calendars
116
-		foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
117
-			if ($calendar['uri'] === $name) {
118
-				return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
119
-			}
120
-		}
121
-
122
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
123
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
124
-				if ($subscription['uri'] === $name) {
125
-					return new Subscription($this->caldavBackend, $subscription);
126
-				}
127
-			}
128
-
129
-		}
130
-
131
-		throw new NotFound('Node with name \'' . $name . '\' could not be found');
132
-	}
133
-
134
-	/**
135
-	 * @param array $filters
136
-	 * @param integer|null $limit
137
-	 * @param integer|null $offset
138
-	 */
139
-	function calendarSearch(array $filters, $limit=null, $offset=null) {
140
-		$principalUri = $this->principalInfo['uri'];
141
-		return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
142
-	}
38
+    /** @var \OCP\IL10N */
39
+    private $l10n;
40
+
41
+    /** @var \OCP\IConfig */
42
+    private $config;
43
+
44
+    public function __construct(BackendInterface $caldavBackend, $principalInfo) {
45
+        parent::__construct($caldavBackend, $principalInfo);
46
+        $this->l10n = \OC::$server->getL10N('dav');
47
+        $this->config = \OC::$server->getConfig();
48
+    }
49
+
50
+    /**
51
+     * @return BackendInterface
52
+     */
53
+    public function getCalDAVBackend() {
54
+        return $this->caldavBackend;
55
+    }
56
+
57
+    /**
58
+     * @inheritdoc
59
+     */
60
+    function createExtendedCollection($name, MkCol $mkCol) {
61
+        $reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
62
+
63
+        if (in_array($name, $reservedNames)) {
64
+            throw new MethodNotAllowed('The resource you tried to create has a reserved name');
65
+        }
66
+
67
+        parent::createExtendedCollection($name, $mkCol);
68
+    }
69
+
70
+    /**
71
+     * @inheritdoc
72
+     */
73
+    function getChildren() {
74
+        $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
75
+        $objects = [];
76
+        foreach ($calendars as $calendar) {
77
+            $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
78
+        }
79
+
80
+        if ($this->caldavBackend instanceof SchedulingSupport) {
81
+            $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
82
+            $objects[] = new Outbox($this->principalInfo['uri']);
83
+        }
84
+
85
+        // We're adding a notifications node, if it's supported by the backend.
86
+        if ($this->caldavBackend instanceof NotificationSupport) {
87
+            $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
88
+        }
89
+
90
+        // If the backend supports subscriptions, we'll add those as well,
91
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
92
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
93
+                $objects[] = new Subscription($this->caldavBackend, $subscription);
94
+            }
95
+        }
96
+
97
+        return $objects;
98
+    }
99
+
100
+    /**
101
+     * @inheritdoc
102
+     */
103
+    function getChild($name) {
104
+        // Special nodes
105
+        if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
106
+            return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
107
+        }
108
+        if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
109
+            return new Outbox($this->principalInfo['uri']);
110
+        }
111
+        if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
112
+            return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
113
+        }
114
+
115
+        // Calendars
116
+        foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
117
+            if ($calendar['uri'] === $name) {
118
+                return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
119
+            }
120
+        }
121
+
122
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
123
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
124
+                if ($subscription['uri'] === $name) {
125
+                    return new Subscription($this->caldavBackend, $subscription);
126
+                }
127
+            }
128
+
129
+        }
130
+
131
+        throw new NotFound('Node with name \'' . $name . '\' could not be found');
132
+    }
133
+
134
+    /**
135
+     * @param array $filters
136
+     * @param integer|null $limit
137
+     * @param integer|null $offset
138
+     */
139
+    function calendarSearch(array $filters, $limit=null, $offset=null) {
140
+        $principalUri = $this->principalInfo['uri'];
141
+        return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
142
+    }
143 143
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/PublicCalendarRoot.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -30,49 +30,49 @@
 block discarded – undo
30 30
 
31 31
 class PublicCalendarRoot extends Collection {
32 32
 
33
-	/** @var CalDavBackend */
34
-	protected $caldavBackend;
33
+    /** @var CalDavBackend */
34
+    protected $caldavBackend;
35 35
 
36
-	/** @var \OCP\IL10N */
37
-	protected $l10n;
36
+    /** @var \OCP\IL10N */
37
+    protected $l10n;
38 38
 
39
-	/** @var \OCP\IConfig */
40
-	protected $config;
39
+    /** @var \OCP\IConfig */
40
+    protected $config;
41 41
 
42
-	/**
43
-	 * PublicCalendarRoot constructor.
44
-	 *
45
-	 * @param CalDavBackend $caldavBackend
46
-	 * @param IL10N $l10n
47
-	 * @param IConfig $config
48
-	 */
49
-	function __construct(CalDavBackend $caldavBackend, IL10N $l10n,
50
-						 IConfig $config) {
51
-		$this->caldavBackend = $caldavBackend;
52
-		$this->l10n = $l10n;
53
-		$this->config = $config;
42
+    /**
43
+     * PublicCalendarRoot constructor.
44
+     *
45
+     * @param CalDavBackend $caldavBackend
46
+     * @param IL10N $l10n
47
+     * @param IConfig $config
48
+     */
49
+    function __construct(CalDavBackend $caldavBackend, IL10N $l10n,
50
+                            IConfig $config) {
51
+        $this->caldavBackend = $caldavBackend;
52
+        $this->l10n = $l10n;
53
+        $this->config = $config;
54 54
 
55
-	}
55
+    }
56 56
 
57
-	/**
58
-	 * @inheritdoc
59
-	 */
60
-	function getName() {
61
-		return 'public-calendars';
62
-	}
57
+    /**
58
+     * @inheritdoc
59
+     */
60
+    function getName() {
61
+        return 'public-calendars';
62
+    }
63 63
 
64
-	/**
65
-	 * @inheritdoc
66
-	 */
67
-	function getChild($name) {
68
-		$calendar = $this->caldavBackend->getPublicCalendar($name);
69
-		return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
70
-	}
64
+    /**
65
+     * @inheritdoc
66
+     */
67
+    function getChild($name) {
68
+        $calendar = $this->caldavBackend->getPublicCalendar($name);
69
+        return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
70
+    }
71 71
 
72
-	/**
73
-	 * @inheritdoc
74
-	 */
75
-	function getChildren() {
76
-		return [];
77
-	}
72
+    /**
73
+     * @inheritdoc
74
+     */
75
+    function getChildren() {
76
+        return [];
77
+    }
78 78
 }
Please login to merge, or discard this patch.
apps/dav/lib/RootCollection.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -37,90 +37,90 @@
 block discarded – undo
37 37
 
38 38
 class RootCollection extends SimpleCollection {
39 39
 
40
-	public function __construct() {
41
-		$config = \OC::$server->getConfig();
42
-		$l10n = \OC::$server->getL10N('dav');
43
-		$random = \OC::$server->getSecureRandom();
44
-		$userManager = \OC::$server->getUserManager();
45
-		$groupManager = \OC::$server->getGroupManager();
46
-		$db = \OC::$server->getDatabaseConnection();
47
-		$dispatcher = \OC::$server->getEventDispatcher();
48
-		$userPrincipalBackend = new Principal(
49
-			$userManager,
50
-			$groupManager
51
-		);
52
-		$groupPrincipalBackend = new GroupPrincipalBackend($groupManager);
53
-		// as soon as debug mode is enabled we allow listing of principals
54
-		$disableListing = !$config->getSystemValue('debug', false);
40
+    public function __construct() {
41
+        $config = \OC::$server->getConfig();
42
+        $l10n = \OC::$server->getL10N('dav');
43
+        $random = \OC::$server->getSecureRandom();
44
+        $userManager = \OC::$server->getUserManager();
45
+        $groupManager = \OC::$server->getGroupManager();
46
+        $db = \OC::$server->getDatabaseConnection();
47
+        $dispatcher = \OC::$server->getEventDispatcher();
48
+        $userPrincipalBackend = new Principal(
49
+            $userManager,
50
+            $groupManager
51
+        );
52
+        $groupPrincipalBackend = new GroupPrincipalBackend($groupManager);
53
+        // as soon as debug mode is enabled we allow listing of principals
54
+        $disableListing = !$config->getSystemValue('debug', false);
55 55
 
56
-		// setup the first level of the dav tree
57
-		$userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
58
-		$userPrincipals->disableListing = $disableListing;
59
-		$groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
60
-		$groupPrincipals->disableListing = $disableListing;
61
-		$systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
62
-		$systemPrincipals->disableListing = $disableListing;
63
-		$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
64
-		$filesCollection->disableListing = $disableListing;
65
-		$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $dispatcher);
66
-		$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
67
-		$calendarRoot->disableListing = $disableListing;
68
-		$publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
69
-		$publicCalendarRoot->disableListing = $disableListing;
56
+        // setup the first level of the dav tree
57
+        $userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
58
+        $userPrincipals->disableListing = $disableListing;
59
+        $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
60
+        $groupPrincipals->disableListing = $disableListing;
61
+        $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
62
+        $systemPrincipals->disableListing = $disableListing;
63
+        $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
64
+        $filesCollection->disableListing = $disableListing;
65
+        $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $dispatcher);
66
+        $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
67
+        $calendarRoot->disableListing = $disableListing;
68
+        $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
69
+        $publicCalendarRoot->disableListing = $disableListing;
70 70
 
71
-		$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
72
-			\OC::$server->getSystemTagManager(),
73
-			\OC::$server->getUserSession(),
74
-			$groupManager
75
-		);
76
-		$systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
77
-			\OC::$server->getSystemTagManager(),
78
-			\OC::$server->getSystemTagObjectMapper(),
79
-			\OC::$server->getUserSession(),
80
-			$groupManager,
81
-			\OC::$server->getEventDispatcher()
82
-		);
83
-		$commentsCollection = new Comments\RootCollection(
84
-			\OC::$server->getCommentsManager(),
85
-			$userManager,
86
-			\OC::$server->getUserSession(),
87
-			\OC::$server->getEventDispatcher(),
88
-			\OC::$server->getLogger()
89
-		);
71
+        $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
72
+            \OC::$server->getSystemTagManager(),
73
+            \OC::$server->getUserSession(),
74
+            $groupManager
75
+        );
76
+        $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
77
+            \OC::$server->getSystemTagManager(),
78
+            \OC::$server->getSystemTagObjectMapper(),
79
+            \OC::$server->getUserSession(),
80
+            $groupManager,
81
+            \OC::$server->getEventDispatcher()
82
+        );
83
+        $commentsCollection = new Comments\RootCollection(
84
+            \OC::$server->getCommentsManager(),
85
+            $userManager,
86
+            \OC::$server->getUserSession(),
87
+            \OC::$server->getEventDispatcher(),
88
+            \OC::$server->getLogger()
89
+        );
90 90
 
91
-		$usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
92
-		$usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
93
-		$usersAddressBookRoot->disableListing = $disableListing;
91
+        $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
92
+        $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
93
+        $usersAddressBookRoot->disableListing = $disableListing;
94 94
 
95
-		$systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
96
-		$systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
97
-		$systemAddressBookRoot->disableListing = $disableListing;
95
+        $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
96
+        $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
97
+        $systemAddressBookRoot->disableListing = $disableListing;
98 98
 
99
-		$uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
100
-		$uploadCollection->disableListing = $disableListing;
99
+        $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
100
+        $uploadCollection->disableListing = $disableListing;
101 101
 
102
-		$avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
103
-		$avatarCollection->disableListing = $disableListing;
102
+        $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
103
+        $avatarCollection->disableListing = $disableListing;
104 104
 
105
-		$children = [
106
-				new SimpleCollection('principals', [
107
-						$userPrincipals,
108
-						$groupPrincipals,
109
-						$systemPrincipals]),
110
-				$filesCollection,
111
-				$calendarRoot,
112
-				$publicCalendarRoot,
113
-				new SimpleCollection('addressbooks', [
114
-						$usersAddressBookRoot,
115
-						$systemAddressBookRoot]),
116
-				$systemTagCollection,
117
-				$systemTagRelationsCollection,
118
-				$commentsCollection,
119
-				$uploadCollection,
120
-				$avatarCollection
121
-		];
105
+        $children = [
106
+                new SimpleCollection('principals', [
107
+                        $userPrincipals,
108
+                        $groupPrincipals,
109
+                        $systemPrincipals]),
110
+                $filesCollection,
111
+                $calendarRoot,
112
+                $publicCalendarRoot,
113
+                new SimpleCollection('addressbooks', [
114
+                        $usersAddressBookRoot,
115
+                        $systemAddressBookRoot]),
116
+                $systemTagCollection,
117
+                $systemTagRelationsCollection,
118
+                $commentsCollection,
119
+                $uploadCollection,
120
+                $avatarCollection
121
+        ];
122 122
 
123
-		parent::__construct('root', $children);
124
-	}
123
+        parent::__construct('root', $children);
124
+    }
125 125
 
126 126
 }
Please login to merge, or discard this patch.