Completed
Pull Request — master (#6884)
by Georg
17:11 queued 02:16
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/CalendarHome.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -33,96 +33,96 @@
 block discarded – undo
33 33
 
34 34
 class CalendarHome extends \Sabre\CalDAV\CalendarHome {
35 35
 
36
-	/** @var \OCP\IL10N */
37
-	private $l10n;
38
-
39
-	/** @var \OCP\IConfig */
40
-	private $config;
41
-
42
-	public function __construct(BackendInterface $caldavBackend, $principalInfo) {
43
-		parent::__construct($caldavBackend, $principalInfo);
44
-		$this->l10n = \OC::$server->getL10N('dav');
45
-		$this->config = \OC::$server->getConfig();
46
-	}
47
-
48
-	/**
49
-	 * @return BackendInterface
50
-	 */
51
-	public function getCalDAVBackend() {
52
-		return $this->caldavBackend;
53
-	}
54
-
55
-	/**
56
-	 * @inheritdoc
57
-	 */
58
-	function getChildren() {
59
-		$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
60
-		$objects = [];
61
-		foreach ($calendars as $calendar) {
62
-			$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
63
-		}
64
-
65
-		if ($this->caldavBackend instanceof SchedulingSupport) {
66
-			$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
67
-			$objects[] = new Outbox($this->principalInfo['uri']);
68
-		}
69
-
70
-		// We're adding a notifications node, if it's supported by the backend.
71
-		if ($this->caldavBackend instanceof NotificationSupport) {
72
-			$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
73
-		}
74
-
75
-		// If the backend supports subscriptions, we'll add those as well,
76
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
77
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
78
-				$objects[] = new Subscription($this->caldavBackend, $subscription);
79
-			}
80
-		}
81
-
82
-		return $objects;
83
-	}
84
-
85
-	/**
86
-	 * @inheritdoc
87
-	 */
88
-	function getChild($name) {
89
-		// Special nodes
90
-		if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
91
-			return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
92
-		}
93
-		if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
94
-			return new Outbox($this->principalInfo['uri']);
95
-		}
96
-		if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
97
-			return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
98
-		}
99
-
100
-		// Calendars
101
-		foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
102
-			if ($calendar['uri'] === $name) {
103
-				return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
104
-			}
105
-		}
106
-
107
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
108
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
109
-				if ($subscription['uri'] === $name) {
110
-					return new Subscription($this->caldavBackend, $subscription);
111
-				}
112
-			}
113
-
114
-		}
115
-
116
-		throw new NotFound('Node with name \'' . $name . '\' could not be found');
117
-	}
118
-
119
-	/**
120
-	 * @param array $filters
121
-	 * @param integer|null $limit
122
-	 * @param integer|null $offset
123
-	 */
124
-	function calendarSearch(array $filters, $limit=null, $offset=null) {
125
-		$principalUri = $this->principalInfo['uri'];
126
-		return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
127
-	}
36
+    /** @var \OCP\IL10N */
37
+    private $l10n;
38
+
39
+    /** @var \OCP\IConfig */
40
+    private $config;
41
+
42
+    public function __construct(BackendInterface $caldavBackend, $principalInfo) {
43
+        parent::__construct($caldavBackend, $principalInfo);
44
+        $this->l10n = \OC::$server->getL10N('dav');
45
+        $this->config = \OC::$server->getConfig();
46
+    }
47
+
48
+    /**
49
+     * @return BackendInterface
50
+     */
51
+    public function getCalDAVBackend() {
52
+        return $this->caldavBackend;
53
+    }
54
+
55
+    /**
56
+     * @inheritdoc
57
+     */
58
+    function getChildren() {
59
+        $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
60
+        $objects = [];
61
+        foreach ($calendars as $calendar) {
62
+            $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
63
+        }
64
+
65
+        if ($this->caldavBackend instanceof SchedulingSupport) {
66
+            $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
67
+            $objects[] = new Outbox($this->principalInfo['uri']);
68
+        }
69
+
70
+        // We're adding a notifications node, if it's supported by the backend.
71
+        if ($this->caldavBackend instanceof NotificationSupport) {
72
+            $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
73
+        }
74
+
75
+        // If the backend supports subscriptions, we'll add those as well,
76
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
77
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
78
+                $objects[] = new Subscription($this->caldavBackend, $subscription);
79
+            }
80
+        }
81
+
82
+        return $objects;
83
+    }
84
+
85
+    /**
86
+     * @inheritdoc
87
+     */
88
+    function getChild($name) {
89
+        // Special nodes
90
+        if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
91
+            return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
92
+        }
93
+        if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
94
+            return new Outbox($this->principalInfo['uri']);
95
+        }
96
+        if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
97
+            return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
98
+        }
99
+
100
+        // Calendars
101
+        foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
102
+            if ($calendar['uri'] === $name) {
103
+                return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
104
+            }
105
+        }
106
+
107
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
108
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
109
+                if ($subscription['uri'] === $name) {
110
+                    return new Subscription($this->caldavBackend, $subscription);
111
+                }
112
+            }
113
+
114
+        }
115
+
116
+        throw new NotFound('Node with name \'' . $name . '\' could not be found');
117
+    }
118
+
119
+    /**
120
+     * @param array $filters
121
+     * @param integer|null $limit
122
+     * @param integer|null $offset
123
+     */
124
+    function calendarSearch(array $filters, $limit=null, $offset=null) {
125
+        $principalUri = $this->principalInfo['uri'];
126
+        return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
127
+    }
128 128
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/PublicCalendarRoot.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,41 +24,41 @@
 block discarded – undo
24 24
 
25 25
 class PublicCalendarRoot extends Collection {
26 26
 
27
-	/** @var CalDavBackend */
28
-	protected $caldavBackend;
27
+    /** @var CalDavBackend */
28
+    protected $caldavBackend;
29 29
 
30
-	/** @var \OCP\IL10N */
31
-	protected $l10n;
30
+    /** @var \OCP\IL10N */
31
+    protected $l10n;
32 32
 
33
-	/** @var \OCP\IConfig */
34
-	protected $config;
33
+    /** @var \OCP\IConfig */
34
+    protected $config;
35 35
 
36
-	function __construct(CalDavBackend $caldavBackend) {
37
-		$this->caldavBackend = $caldavBackend;
38
-		$this->l10n = \OC::$server->getL10N('dav');
39
-		$this->config = \OC::$server->getConfig();
36
+    function __construct(CalDavBackend $caldavBackend) {
37
+        $this->caldavBackend = $caldavBackend;
38
+        $this->l10n = \OC::$server->getL10N('dav');
39
+        $this->config = \OC::$server->getConfig();
40 40
 
41
-	}
41
+    }
42 42
 
43
-	/**
44
-	 * @inheritdoc
45
-	 */
46
-	function getName() {
47
-		return 'public-calendars';
48
-	}
43
+    /**
44
+     * @inheritdoc
45
+     */
46
+    function getName() {
47
+        return 'public-calendars';
48
+    }
49 49
 
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	function getChild($name) {
54
-		$calendar = $this->caldavBackend->getPublicCalendar($name);
55
-		return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
56
-	}
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    function getChild($name) {
54
+        $calendar = $this->caldavBackend->getPublicCalendar($name);
55
+        return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
56
+    }
57 57
 
58
-	/**
59
-	 * @inheritdoc
60
-	 */
61
-	function getChildren() {
62
-		return [];
63
-	}
58
+    /**
59
+     * @inheritdoc
60
+     */
61
+    function getChildren() {
62
+        return [];
63
+    }
64 64
 }
Please login to merge, or discard this patch.