Completed
Pull Request — master (#9609)
by Georg
15:55
created
apps/dav/appinfo/v1/caldav.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,19 +34,19 @@  discard block
 block discarded – undo
34 34
 use OCA\DAV\Connector\Sabre\Principal;
35 35
 
36 36
 $authBackend = new Auth(
37
-	\OC::$server->getSession(),
38
-	\OC::$server->getUserSession(),
39
-	\OC::$server->getRequest(),
40
-	\OC::$server->getTwoFactorAuthManager(),
41
-	\OC::$server->getBruteForceThrottler(),
42
-	'principals/'
37
+    \OC::$server->getSession(),
38
+    \OC::$server->getUserSession(),
39
+    \OC::$server->getRequest(),
40
+    \OC::$server->getTwoFactorAuthManager(),
41
+    \OC::$server->getBruteForceThrottler(),
42
+    'principals/'
43 43
 );
44 44
 $principalBackend = new Principal(
45
-	\OC::$server->getUserManager(),
46
-	\OC::$server->getGroupManager(),
47
-	\OC::$server->getShareManager(),
48
-	\OC::$server->getUserSession(),
49
-	'principals/'
45
+    \OC::$server->getUserManager(),
46
+    \OC::$server->getGroupManager(),
47
+    \OC::$server->getShareManager(),
48
+    \OC::$server->getUserSession(),
49
+    'principals/'
50 50
 );
51 51
 $db = \OC::$server->getDatabaseConnection();
52 52
 $userManager = \OC::$server->getUserManager();
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 $addressBookRoot->disableListing = !$debugging; // Disable listing
67 67
 
68 68
 $nodes = array(
69
-	$principalCollection,
70
-	$addressBookRoot,
69
+    $principalCollection,
70
+    $addressBookRoot,
71 71
 );
72 72
 
73 73
 // Fire up server
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
 $server->addPlugin(new LegacyDAVACL());
85 85
 if ($debugging) {
86
-	$server->addPlugin(new Sabre\DAV\Browser\Plugin());
86
+    $server->addPlugin(new Sabre\DAV\Browser\Plugin());
87 87
 }
88 88
 
89 89
 $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin($principalBackend));
92 92
 
93 93
 if ($sendInvitations) {
94
-	$server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
94
+    $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
95 95
 }
96 96
 $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));
97 97
 
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Principal.php 2 patches
Indentation   +347 added lines, -347 removed lines patch added patch discarded remove patch
@@ -42,352 +42,352 @@
 block discarded – undo
42 42
 
43 43
 class Principal implements BackendInterface {
44 44
 
45
-	/** @var IUserManager */
46
-	private $userManager;
47
-
48
-	/** @var IGroupManager */
49
-	private $groupManager;
50
-
51
-	/** @var IShareManager */
52
-	private $shareManager;
53
-
54
-	/** @var IUserSession */
55
-	private $userSession;
56
-
57
-	/** @var string */
58
-	private $principalPrefix;
59
-
60
-	/** @var string */
61
-	private $groupPrincipalPrefix;
62
-
63
-	/** @var bool */
64
-	private $hasGroups;
65
-
66
-	/**
67
-	 * @param IUserManager $userManager
68
-	 * @param IGroupManager $groupManager
69
-	 * @param IShareManager $shareManager
70
-	 * @param IUserSession $userSession
71
-	 * @param string $principalPrefix
72
-	 * @param string $groupPrincipalPrefix
73
-	 */
74
-	public function __construct(IUserManager $userManager,
75
-								IGroupManager $groupManager,
76
-								IShareManager $shareManager,
77
-								IUserSession $userSession,
78
-								$principalPrefix = 'principals/users/',
79
-								$groupPrincipalPrefix = 'principals/groups/') {
80
-		$this->userManager = $userManager;
81
-		$this->groupManager = $groupManager;
82
-		$this->shareManager = $shareManager;
83
-		$this->userSession = $userSession;
84
-		$this->principalPrefix = trim($principalPrefix, '/');
85
-		$this->groupPrincipalPrefix = trim($groupPrincipalPrefix, '/');
86
-		$this->hasGroups = ($principalPrefix === 'principals/users/');
87
-	}
88
-
89
-	/**
90
-	 * Returns a list of principals based on a prefix.
91
-	 *
92
-	 * This prefix will often contain something like 'principals'. You are only
93
-	 * expected to return principals that are in this base path.
94
-	 *
95
-	 * You are expected to return at least a 'uri' for every user, you can
96
-	 * return any additional properties if you wish so. Common properties are:
97
-	 *   {DAV:}displayname
98
-	 *
99
-	 * @param string $prefixPath
100
-	 * @return string[]
101
-	 */
102
-	public function getPrincipalsByPrefix($prefixPath) {
103
-		$principals = [];
104
-
105
-		if ($prefixPath === $this->principalPrefix) {
106
-			foreach($this->userManager->search('') as $user) {
107
-				$principals[] = $this->userToPrincipal($user);
108
-			}
109
-		}
110
-
111
-		return $principals;
112
-	}
113
-
114
-	/**
115
-	 * Returns a specific principal, specified by it's path.
116
-	 * The returned structure should be the exact same as from
117
-	 * getPrincipalsByPrefix.
118
-	 *
119
-	 * @param string $path
120
-	 * @return array
121
-	 */
122
-	public function getPrincipalByPath($path) {
123
-		list($prefix, $name) = \Sabre\Uri\split($path);
124
-
125
-		if ($prefix === $this->principalPrefix) {
126
-			$user = $this->userManager->get($name);
127
-
128
-			if ($user !== null) {
129
-				return $this->userToPrincipal($user);
130
-			}
131
-		} elseif ($prefix === $this->groupPrincipalPrefix) {
132
-			$group = $this->groupManager->get($name);
133
-
134
-			if ($group !== null) {
135
-				return $this->groupToPrincipal($group);
136
-			}
137
-		}
138
-
139
-		return null;
140
-	}
141
-
142
-	/**
143
-	 * Returns the list of members for a group-principal
144
-	 *
145
-	 * @param string $principal
146
-	 * @return string[]
147
-	 * @throws Exception
148
-	 */
149
-	public function getGroupMemberSet($principal) {
150
-		$principal = $this->getPrincipalByPath($principal);
151
-		if (!$principal) {
152
-			throw new Exception('Principal not found');
153
-		}
154
-
155
-		list($prefix, $gid) = \Sabre\Uri\split($principal['uri']);
156
-		if ($prefix !== $this->groupPrincipalPrefix) {
157
-			throw new Exception('Requested members for principal that\'s not a group');
158
-		}
159
-
160
-		$group = $this->groupManager->get($gid);
161
-		$users = $group->getUsers();
162
-		$members = [];
163
-		foreach($users as $user) {
164
-			$members[] = $this->userToPrincipal($user)['uri'];
165
-		}
166
-
167
-		return $members;
168
-	}
169
-
170
-	/**
171
-	 * Returns the list of groups a principal is a member of
172
-	 *
173
-	 * @param string $principal
174
-	 * @param bool $needGroups
175
-	 * @return array
176
-	 * @throws Exception
177
-	 */
178
-	public function getGroupMembership($principal, $needGroups = false) {
179
-		list($prefix, $name) = \Sabre\Uri\split($principal);
180
-
181
-		if ($prefix === $this->principalPrefix) {
182
-			$user = $this->userManager->get($name);
183
-			if (!$user) {
184
-				throw new Exception('Principal not found');
185
-			}
186
-
187
-			if ($this->hasGroups || $needGroups) {
188
-				$groups = $this->groupManager->getUserGroups($user);
189
-				$groups = array_map(function($group) {
190
-					/** @var IGroup $group */
191
-					return 'principals/groups/' . urlencode($group->getGID());
192
-				}, $groups);
193
-
194
-				return $groups;
195
-			}
196
-		}
197
-		return [];
198
-	}
199
-
200
-	/**
201
-	 * Updates the list of group members for a group principal.
202
-	 *
203
-	 * The principals should be passed as a list of uri's.
204
-	 *
205
-	 * @param string $principal
206
-	 * @param string[] $members
207
-	 * @throws Exception
208
-	 */
209
-	public function setGroupMemberSet($principal, array $members) {
210
-		throw new Exception('Setting members of the group is not supported yet');
211
-	}
212
-
213
-	/**
214
-	 * @param string $path
215
-	 * @param PropPatch $propPatch
216
-	 * @return int
217
-	 */
218
-	function updatePrincipal($path, PropPatch $propPatch) {
219
-		return 0;
220
-	}
221
-
222
-	/**
223
-	 * Search user principals
224
-	 *
225
-	 * @param array $searchProperties
226
-	 * @param string $test
227
-	 * @return array
228
-	 */
229
-	protected function searchUserPrincipals(array $searchProperties, $test = 'allof') {
230
-		$results = [];
231
-
232
-		// If sharing is disabled, return the empty array
233
-		if (!$this->shareManager->shareApiEnabled()) {
234
-			return [];
235
-		}
236
-
237
-		// If sharing is restricted to group members only,
238
-		// return only members that have groups in common
239
-		$restrictGroups = false;
240
-		if ($this->shareManager->shareWithGroupMembersOnly()) {
241
-			$user = $this->userSession->getUser();
242
-			if (!$user) {
243
-				return [];
244
-			}
245
-
246
-			$restrictGroups = $this->groupManager->getUserGroupIds($user);
247
-		}
248
-
249
-		foreach ($searchProperties as $prop => $value) {
250
-			switch ($prop) {
251
-				case '{http://sabredav.org/ns}email-address':
252
-					$users = $this->userManager->getByEmail($value);
253
-
254
-					$results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) {
255
-						// is sharing restricted to groups only?
256
-						if ($restrictGroups !== false) {
257
-							$userGroups = $this->groupManager->getUserGroupIds($user);
258
-							if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
259
-								return $carry;
260
-							}
261
-						}
262
-
263
-						$carry[] = $this->principalPrefix . '/' . $user->getUID();
264
-						return $carry;
265
-					}, []);
266
-					break;
267
-
268
-				default:
269
-					$results[] = [];
270
-					break;
271
-			}
272
-		}
273
-
274
-		// results is an array of arrays, so this is not the first search result
275
-		// but the results of the first searchProperty
276
-		if (count($results) === 1) {
277
-			return $results[0];
278
-		}
279
-
280
-		switch ($test) {
281
-			case 'anyof':
282
-				return array_unique(array_merge(...$results));
283
-
284
-			case 'allof':
285
-			default:
286
-				return array_intersect(...$results);
287
-		}
288
-	}
289
-
290
-	/**
291
-	 * @param string $prefixPath
292
-	 * @param array $searchProperties
293
-	 * @param string $test
294
-	 * @return array
295
-	 */
296
-	function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
297
-		if (count($searchProperties) === 0) {
298
-			return [];
299
-		}
300
-
301
-		switch ($prefixPath) {
302
-			case 'principals/users':
303
-				return $this->searchUserPrincipals($searchProperties, $test);
304
-
305
-			default:
306
-				return [];
307
-		}
308
-	}
309
-
310
-	/**
311
-	 * @param string $uri
312
-	 * @param string $principalPrefix
313
-	 * @return string
314
-	 */
315
-	function findByUri($uri, $principalPrefix) {
316
-		// If sharing is disabled, return null as in user not found
317
-		if (!$this->shareManager->shareApiEnabled()) {
318
-			return null;
319
-		}
320
-
321
-		// If sharing is restricted to group members only,
322
-		// return only members that have groups in common
323
-		$restrictGroups = false;
324
-		if ($this->shareManager->shareWithGroupMembersOnly()) {
325
-			$user = $this->userSession->getUser();
326
-			if (!$user) {
327
-				return null;
328
-			}
329
-
330
-			$restrictGroups = $this->groupManager->getUserGroupIds($user);
331
-		}
332
-
333
-		if (strpos($uri, 'mailto:') === 0) {
334
-			if ($principalPrefix === 'principals/users') {
335
-				$users = $this->userManager->getByEmail(substr($uri, 7));
336
-				if (count($users) !== 1) {
337
-					return null;
338
-				}
339
-				$user = $users[0];
340
-
341
-				if ($restrictGroups !== false) {
342
-					$userGroups = $this->groupManager->getUserGroupIds($user);
343
-					if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
344
-						return null;
345
-					}
346
-				}
347
-
348
-				return $this->principalPrefix . '/' . $user->getUID();
349
-			}
350
-		}
351
-
352
-		return null;
353
-	}
354
-
355
-	/**
356
-	 * @param IUser $user
357
-	 * @return array
358
-	 */
359
-	protected function userToPrincipal(IUser $user) {
360
-		$userId = $user->getUID();
361
-		$displayName = $user->getDisplayName();
362
-		$principal = [
363
-				'uri' => $this->principalPrefix . '/' . $userId,
364
-				'{DAV:}displayname' => is_null($displayName) ? $userId : $displayName,
365
-		];
366
-
367
-		$email = $user->getEMailAddress();
368
-		if (!empty($email)) {
369
-			$principal['{http://sabredav.org/ns}email-address'] = $email;
370
-		}
371
-
372
-		return $principal;
373
-	}
374
-
375
-	/**
376
-	 * @param IGroup $group
377
-	 * @return array
378
-	 */
379
-	protected function groupToPrincipal(IGroup $group) {
380
-		$groupId = $group->getGID();
381
-		$displayName = $group->getDisplayName();
382
-
383
-		return [
384
-			'uri' => $this->groupPrincipalPrefix . '/' . $groupId,
385
-			'{DAV:}displayname' => is_null($displayName) ? $groupId : $displayName,
386
-		];
387
-	}
388
-
389
-	public function getPrincipalPrefix() {
390
-		return $this->principalPrefix;
391
-	}
45
+    /** @var IUserManager */
46
+    private $userManager;
47
+
48
+    /** @var IGroupManager */
49
+    private $groupManager;
50
+
51
+    /** @var IShareManager */
52
+    private $shareManager;
53
+
54
+    /** @var IUserSession */
55
+    private $userSession;
56
+
57
+    /** @var string */
58
+    private $principalPrefix;
59
+
60
+    /** @var string */
61
+    private $groupPrincipalPrefix;
62
+
63
+    /** @var bool */
64
+    private $hasGroups;
65
+
66
+    /**
67
+     * @param IUserManager $userManager
68
+     * @param IGroupManager $groupManager
69
+     * @param IShareManager $shareManager
70
+     * @param IUserSession $userSession
71
+     * @param string $principalPrefix
72
+     * @param string $groupPrincipalPrefix
73
+     */
74
+    public function __construct(IUserManager $userManager,
75
+                                IGroupManager $groupManager,
76
+                                IShareManager $shareManager,
77
+                                IUserSession $userSession,
78
+                                $principalPrefix = 'principals/users/',
79
+                                $groupPrincipalPrefix = 'principals/groups/') {
80
+        $this->userManager = $userManager;
81
+        $this->groupManager = $groupManager;
82
+        $this->shareManager = $shareManager;
83
+        $this->userSession = $userSession;
84
+        $this->principalPrefix = trim($principalPrefix, '/');
85
+        $this->groupPrincipalPrefix = trim($groupPrincipalPrefix, '/');
86
+        $this->hasGroups = ($principalPrefix === 'principals/users/');
87
+    }
88
+
89
+    /**
90
+     * Returns a list of principals based on a prefix.
91
+     *
92
+     * This prefix will often contain something like 'principals'. You are only
93
+     * expected to return principals that are in this base path.
94
+     *
95
+     * You are expected to return at least a 'uri' for every user, you can
96
+     * return any additional properties if you wish so. Common properties are:
97
+     *   {DAV:}displayname
98
+     *
99
+     * @param string $prefixPath
100
+     * @return string[]
101
+     */
102
+    public function getPrincipalsByPrefix($prefixPath) {
103
+        $principals = [];
104
+
105
+        if ($prefixPath === $this->principalPrefix) {
106
+            foreach($this->userManager->search('') as $user) {
107
+                $principals[] = $this->userToPrincipal($user);
108
+            }
109
+        }
110
+
111
+        return $principals;
112
+    }
113
+
114
+    /**
115
+     * Returns a specific principal, specified by it's path.
116
+     * The returned structure should be the exact same as from
117
+     * getPrincipalsByPrefix.
118
+     *
119
+     * @param string $path
120
+     * @return array
121
+     */
122
+    public function getPrincipalByPath($path) {
123
+        list($prefix, $name) = \Sabre\Uri\split($path);
124
+
125
+        if ($prefix === $this->principalPrefix) {
126
+            $user = $this->userManager->get($name);
127
+
128
+            if ($user !== null) {
129
+                return $this->userToPrincipal($user);
130
+            }
131
+        } elseif ($prefix === $this->groupPrincipalPrefix) {
132
+            $group = $this->groupManager->get($name);
133
+
134
+            if ($group !== null) {
135
+                return $this->groupToPrincipal($group);
136
+            }
137
+        }
138
+
139
+        return null;
140
+    }
141
+
142
+    /**
143
+     * Returns the list of members for a group-principal
144
+     *
145
+     * @param string $principal
146
+     * @return string[]
147
+     * @throws Exception
148
+     */
149
+    public function getGroupMemberSet($principal) {
150
+        $principal = $this->getPrincipalByPath($principal);
151
+        if (!$principal) {
152
+            throw new Exception('Principal not found');
153
+        }
154
+
155
+        list($prefix, $gid) = \Sabre\Uri\split($principal['uri']);
156
+        if ($prefix !== $this->groupPrincipalPrefix) {
157
+            throw new Exception('Requested members for principal that\'s not a group');
158
+        }
159
+
160
+        $group = $this->groupManager->get($gid);
161
+        $users = $group->getUsers();
162
+        $members = [];
163
+        foreach($users as $user) {
164
+            $members[] = $this->userToPrincipal($user)['uri'];
165
+        }
166
+
167
+        return $members;
168
+    }
169
+
170
+    /**
171
+     * Returns the list of groups a principal is a member of
172
+     *
173
+     * @param string $principal
174
+     * @param bool $needGroups
175
+     * @return array
176
+     * @throws Exception
177
+     */
178
+    public function getGroupMembership($principal, $needGroups = false) {
179
+        list($prefix, $name) = \Sabre\Uri\split($principal);
180
+
181
+        if ($prefix === $this->principalPrefix) {
182
+            $user = $this->userManager->get($name);
183
+            if (!$user) {
184
+                throw new Exception('Principal not found');
185
+            }
186
+
187
+            if ($this->hasGroups || $needGroups) {
188
+                $groups = $this->groupManager->getUserGroups($user);
189
+                $groups = array_map(function($group) {
190
+                    /** @var IGroup $group */
191
+                    return 'principals/groups/' . urlencode($group->getGID());
192
+                }, $groups);
193
+
194
+                return $groups;
195
+            }
196
+        }
197
+        return [];
198
+    }
199
+
200
+    /**
201
+     * Updates the list of group members for a group principal.
202
+     *
203
+     * The principals should be passed as a list of uri's.
204
+     *
205
+     * @param string $principal
206
+     * @param string[] $members
207
+     * @throws Exception
208
+     */
209
+    public function setGroupMemberSet($principal, array $members) {
210
+        throw new Exception('Setting members of the group is not supported yet');
211
+    }
212
+
213
+    /**
214
+     * @param string $path
215
+     * @param PropPatch $propPatch
216
+     * @return int
217
+     */
218
+    function updatePrincipal($path, PropPatch $propPatch) {
219
+        return 0;
220
+    }
221
+
222
+    /**
223
+     * Search user principals
224
+     *
225
+     * @param array $searchProperties
226
+     * @param string $test
227
+     * @return array
228
+     */
229
+    protected function searchUserPrincipals(array $searchProperties, $test = 'allof') {
230
+        $results = [];
231
+
232
+        // If sharing is disabled, return the empty array
233
+        if (!$this->shareManager->shareApiEnabled()) {
234
+            return [];
235
+        }
236
+
237
+        // If sharing is restricted to group members only,
238
+        // return only members that have groups in common
239
+        $restrictGroups = false;
240
+        if ($this->shareManager->shareWithGroupMembersOnly()) {
241
+            $user = $this->userSession->getUser();
242
+            if (!$user) {
243
+                return [];
244
+            }
245
+
246
+            $restrictGroups = $this->groupManager->getUserGroupIds($user);
247
+        }
248
+
249
+        foreach ($searchProperties as $prop => $value) {
250
+            switch ($prop) {
251
+                case '{http://sabredav.org/ns}email-address':
252
+                    $users = $this->userManager->getByEmail($value);
253
+
254
+                    $results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) {
255
+                        // is sharing restricted to groups only?
256
+                        if ($restrictGroups !== false) {
257
+                            $userGroups = $this->groupManager->getUserGroupIds($user);
258
+                            if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
259
+                                return $carry;
260
+                            }
261
+                        }
262
+
263
+                        $carry[] = $this->principalPrefix . '/' . $user->getUID();
264
+                        return $carry;
265
+                    }, []);
266
+                    break;
267
+
268
+                default:
269
+                    $results[] = [];
270
+                    break;
271
+            }
272
+        }
273
+
274
+        // results is an array of arrays, so this is not the first search result
275
+        // but the results of the first searchProperty
276
+        if (count($results) === 1) {
277
+            return $results[0];
278
+        }
279
+
280
+        switch ($test) {
281
+            case 'anyof':
282
+                return array_unique(array_merge(...$results));
283
+
284
+            case 'allof':
285
+            default:
286
+                return array_intersect(...$results);
287
+        }
288
+    }
289
+
290
+    /**
291
+     * @param string $prefixPath
292
+     * @param array $searchProperties
293
+     * @param string $test
294
+     * @return array
295
+     */
296
+    function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
297
+        if (count($searchProperties) === 0) {
298
+            return [];
299
+        }
300
+
301
+        switch ($prefixPath) {
302
+            case 'principals/users':
303
+                return $this->searchUserPrincipals($searchProperties, $test);
304
+
305
+            default:
306
+                return [];
307
+        }
308
+    }
309
+
310
+    /**
311
+     * @param string $uri
312
+     * @param string $principalPrefix
313
+     * @return string
314
+     */
315
+    function findByUri($uri, $principalPrefix) {
316
+        // If sharing is disabled, return null as in user not found
317
+        if (!$this->shareManager->shareApiEnabled()) {
318
+            return null;
319
+        }
320
+
321
+        // If sharing is restricted to group members only,
322
+        // return only members that have groups in common
323
+        $restrictGroups = false;
324
+        if ($this->shareManager->shareWithGroupMembersOnly()) {
325
+            $user = $this->userSession->getUser();
326
+            if (!$user) {
327
+                return null;
328
+            }
329
+
330
+            $restrictGroups = $this->groupManager->getUserGroupIds($user);
331
+        }
332
+
333
+        if (strpos($uri, 'mailto:') === 0) {
334
+            if ($principalPrefix === 'principals/users') {
335
+                $users = $this->userManager->getByEmail(substr($uri, 7));
336
+                if (count($users) !== 1) {
337
+                    return null;
338
+                }
339
+                $user = $users[0];
340
+
341
+                if ($restrictGroups !== false) {
342
+                    $userGroups = $this->groupManager->getUserGroupIds($user);
343
+                    if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
344
+                        return null;
345
+                    }
346
+                }
347
+
348
+                return $this->principalPrefix . '/' . $user->getUID();
349
+            }
350
+        }
351
+
352
+        return null;
353
+    }
354
+
355
+    /**
356
+     * @param IUser $user
357
+     * @return array
358
+     */
359
+    protected function userToPrincipal(IUser $user) {
360
+        $userId = $user->getUID();
361
+        $displayName = $user->getDisplayName();
362
+        $principal = [
363
+                'uri' => $this->principalPrefix . '/' . $userId,
364
+                '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName,
365
+        ];
366
+
367
+        $email = $user->getEMailAddress();
368
+        if (!empty($email)) {
369
+            $principal['{http://sabredav.org/ns}email-address'] = $email;
370
+        }
371
+
372
+        return $principal;
373
+    }
374
+
375
+    /**
376
+     * @param IGroup $group
377
+     * @return array
378
+     */
379
+    protected function groupToPrincipal(IGroup $group) {
380
+        $groupId = $group->getGID();
381
+        $displayName = $group->getDisplayName();
382
+
383
+        return [
384
+            'uri' => $this->groupPrincipalPrefix . '/' . $groupId,
385
+            '{DAV:}displayname' => is_null($displayName) ? $groupId : $displayName,
386
+        ];
387
+    }
388
+
389
+    public function getPrincipalPrefix() {
390
+        return $this->principalPrefix;
391
+    }
392 392
 
393 393
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		$principals = [];
104 104
 
105 105
 		if ($prefixPath === $this->principalPrefix) {
106
-			foreach($this->userManager->search('') as $user) {
106
+			foreach ($this->userManager->search('') as $user) {
107 107
 				$principals[] = $this->userToPrincipal($user);
108 108
 			}
109 109
 		}
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		$group = $this->groupManager->get($gid);
161 161
 		$users = $group->getUsers();
162 162
 		$members = [];
163
-		foreach($users as $user) {
163
+		foreach ($users as $user) {
164 164
 			$members[] = $this->userToPrincipal($user)['uri'];
165 165
 		}
166 166
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 				$groups = $this->groupManager->getUserGroups($user);
189 189
 				$groups = array_map(function($group) {
190 190
 					/** @var IGroup $group */
191
-					return 'principals/groups/' . urlencode($group->getGID());
191
+					return 'principals/groups/'.urlencode($group->getGID());
192 192
 				}, $groups);
193 193
 
194 194
 				return $groups;
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 							}
261 261
 						}
262 262
 
263
-						$carry[] = $this->principalPrefix . '/' . $user->getUID();
263
+						$carry[] = $this->principalPrefix.'/'.$user->getUID();
264 264
 						return $carry;
265 265
 					}, []);
266 266
 					break;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 					}
346 346
 				}
347 347
 
348
-				return $this->principalPrefix . '/' . $user->getUID();
348
+				return $this->principalPrefix.'/'.$user->getUID();
349 349
 			}
350 350
 		}
351 351
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 		$userId = $user->getUID();
361 361
 		$displayName = $user->getDisplayName();
362 362
 		$principal = [
363
-				'uri' => $this->principalPrefix . '/' . $userId,
363
+				'uri' => $this->principalPrefix.'/'.$userId,
364 364
 				'{DAV:}displayname' => is_null($displayName) ? $userId : $displayName,
365 365
 		];
366 366
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 		$displayName = $group->getDisplayName();
382 382
 
383 383
 		return [
384
-			'uri' => $this->groupPrincipalPrefix . '/' . $groupId,
384
+			'uri' => $this->groupPrincipalPrefix.'/'.$groupId,
385 385
 			'{DAV:}displayname' => is_null($displayName) ? $groupId : $displayName,
386 386
 		];
387 387
 	}
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Calendar.php 1 patch
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -42,306 +42,306 @@
 block discarded – undo
42 42
  */
43 43
 class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
44 44
 
45
-	/** @var IConfig */
46
-	private $config;
47
-
48
-	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
49
-		parent::__construct($caldavBackend, $calendarInfo);
50
-
51
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
52
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
53
-		}
54
-		if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
55
-			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
56
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
57
-		}
58
-
59
-		$this->config = $config;
60
-	}
61
-
62
-	/**
63
-	 * Updates the list of shares.
64
-	 *
65
-	 * The first array is a list of people that are to be added to the
66
-	 * resource.
67
-	 *
68
-	 * Every element in the add array has the following properties:
69
-	 *   * href - A url. Usually a mailto: address
70
-	 *   * commonName - Usually a first and last name, or false
71
-	 *   * summary - A description of the share, can also be false
72
-	 *   * readOnly - A boolean value
73
-	 *
74
-	 * Every element in the remove array is just the address string.
75
-	 *
76
-	 * @param array $add
77
-	 * @param array $remove
78
-	 * @return void
79
-	 * @throws Forbidden
80
-	 */
81
-	public function updateShares(array $add, array $remove) {
82
-		if ($this->isShared()) {
83
-			throw new Forbidden();
84
-		}
85
-		$this->caldavBackend->updateShares($this, $add, $remove);
86
-	}
87
-
88
-	/**
89
-	 * Returns the list of people whom this resource is shared with.
90
-	 *
91
-	 * Every element in this array should have the following properties:
92
-	 *   * href - Often a mailto: address
93
-	 *   * commonName - Optional, for example a first + last name
94
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
95
-	 *   * readOnly - boolean
96
-	 *   * summary - Optional, a description for the share
97
-	 *
98
-	 * @return array
99
-	 */
100
-	public function getShares() {
101
-		if ($this->isShared()) {
102
-			return [];
103
-		}
104
-		return $this->caldavBackend->getShares($this->getResourceId());
105
-	}
106
-
107
-	public function getAllShares() {
108
-		return $this->caldavBackend->getShares($this->getResourceId());
109
-	}
110
-
111
-	/**
112
-	 * @return int
113
-	 */
114
-	public function getResourceId() {
115
-		return $this->calendarInfo['id'];
116
-	}
117
-
118
-	/**
119
-	 * @return string
120
-	 */
121
-	public function getPrincipalURI() {
122
-		return $this->calendarInfo['principaluri'];
123
-	}
124
-
125
-	public function getACL() {
126
-		$acl =  [
127
-			[
128
-				'privilege' => '{DAV:}read',
129
-				'principal' => $this->getOwner(),
130
-				'protected' => true,
131
-			]];
132
-		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
133
-			$acl[] = [
134
-				'privilege' => '{DAV:}write',
135
-				'principal' => $this->getOwner(),
136
-				'protected' => true,
137
-			];
138
-		} else {
139
-			$acl[] = [
140
-				'privilege' => '{DAV:}write-properties',
141
-				'principal' => $this->getOwner(),
142
-				'protected' => true,
143
-			];
144
-		}
145
-
146
-		if ($this->getOwner() !== parent::getOwner()) {
147
-			$acl[] =  [
148
-					'privilege' => '{DAV:}read',
149
-					'principal' => parent::getOwner(),
150
-					'protected' => true,
151
-				];
152
-			if ($this->canWrite()) {
153
-				$acl[] = [
154
-					'privilege' => '{DAV:}write',
155
-					'principal' => parent::getOwner(),
156
-					'protected' => true,
157
-				];
158
-			} else {
159
-				$acl[] = [
160
-					'privilege' => '{DAV:}write-properties',
161
-					'principal' => parent::getOwner(),
162
-					'protected' => true,
163
-				];
164
-			}
165
-		}
166
-		if ($this->isPublic()) {
167
-			$acl[] = [
168
-				'privilege' => '{DAV:}read',
169
-				'principal' => 'principals/system/public',
170
-				'protected' => true,
171
-			];
172
-		}
173
-
174
-		$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
175
-
176
-		if (!$this->isShared()) {
177
-			return $acl;
178
-		}
179
-
180
-		$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
181
-		return array_filter($acl, function($rule) use ($allowedPrincipals) {
182
-			return in_array($rule['principal'], $allowedPrincipals);
183
-		});
184
-	}
185
-
186
-	public function getChildACL() {
187
-		return $this->getACL();
188
-	}
189
-
190
-	public function getOwner() {
191
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
192
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
193
-		}
194
-		return parent::getOwner();
195
-	}
196
-
197
-	public function delete() {
198
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
199
-			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
200
-			$principal = 'principal:' . parent::getOwner();
201
-			$shares = $this->caldavBackend->getShares($this->getResourceId());
202
-			$shares = array_filter($shares, function($share) use ($principal){
203
-				return $share['href'] === $principal;
204
-			});
205
-			if (empty($shares)) {
206
-				throw new Forbidden();
207
-			}
208
-
209
-			$this->caldavBackend->updateShares($this, [], [
210
-				'href' => $principal
211
-			]);
212
-			return;
213
-		}
214
-
215
-		// Remember when a user deleted their birthday calendar
216
-		// in order to not regenerate it on the next contacts change
217
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
218
-			$principalURI = $this->getPrincipalURI();
219
-			$userId = substr($principalURI, 17);
220
-
221
-			$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
222
-		}
223
-
224
-		parent::delete();
225
-	}
226
-
227
-	public function propPatch(PropPatch $propPatch) {
228
-		// parent::propPatch will only update calendars table
229
-		// if calendar is shared, changes have to be made to the properties table
230
-		if (!$this->isShared()) {
231
-			parent::propPatch($propPatch);
232
-		}
233
-	}
234
-
235
-	public function getChild($name) {
236
-
237
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
238
-
239
-		if (!$obj) {
240
-			throw new NotFound('Calendar object not found');
241
-		}
242
-
243
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
244
-			throw new NotFound('Calendar object not found');
245
-		}
246
-
247
-		$obj['acl'] = $this->getChildACL();
248
-
249
-		return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
250
-
251
-	}
252
-
253
-	public function getChildren() {
254
-
255
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
256
-		$children = [];
257
-		foreach ($objs as $obj) {
258
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
259
-				continue;
260
-			}
261
-			$obj['acl'] = $this->getChildACL();
262
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
263
-		}
264
-		return $children;
265
-
266
-	}
267
-
268
-	public function getMultipleChildren(array $paths) {
269
-
270
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
271
-		$children = [];
272
-		foreach ($objs as $obj) {
273
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
274
-				continue;
275
-			}
276
-			$obj['acl'] = $this->getChildACL();
277
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
278
-		}
279
-		return $children;
280
-
281
-	}
282
-
283
-	public function childExists($name) {
284
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
285
-		if (!$obj) {
286
-			return false;
287
-		}
288
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
289
-			return false;
290
-		}
291
-
292
-		return true;
293
-	}
294
-
295
-	public function calendarQuery(array $filters) {
296
-
297
-		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
298
-		if ($this->isShared()) {
299
-			return array_filter($uris, function ($uri) {
300
-				return $this->childExists($uri);
301
-			});
302
-		}
303
-
304
-		return $uris;
305
-	}
306
-
307
-	/**
308
-	 * @param boolean $value
309
-	 * @return string|null
310
-	 */
311
-	public function setPublishStatus($value) {
312
-		$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
313
-		$this->calendarInfo['publicuri'] = $publicUri;
314
-		return $publicUri;
315
-	}
316
-
317
-	/**
318
-	 * @return mixed $value
319
-	 */
320
-	public function getPublishStatus() {
321
-		return $this->caldavBackend->getPublishStatus($this);
322
-	}
323
-
324
-	private function canWrite() {
325
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
326
-			return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
327
-		}
328
-		return true;
329
-	}
330
-
331
-	private function isPublic() {
332
-		return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
333
-	}
334
-
335
-	protected function isShared() {
336
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
337
-			return false;
338
-		}
339
-
340
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
341
-	}
342
-
343
-	public function isSubscription() {
344
-		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
345
-	}
45
+    /** @var IConfig */
46
+    private $config;
47
+
48
+    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
49
+        parent::__construct($caldavBackend, $calendarInfo);
50
+
51
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
52
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
53
+        }
54
+        if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
55
+            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
56
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
57
+        }
58
+
59
+        $this->config = $config;
60
+    }
61
+
62
+    /**
63
+     * Updates the list of shares.
64
+     *
65
+     * The first array is a list of people that are to be added to the
66
+     * resource.
67
+     *
68
+     * Every element in the add array has the following properties:
69
+     *   * href - A url. Usually a mailto: address
70
+     *   * commonName - Usually a first and last name, or false
71
+     *   * summary - A description of the share, can also be false
72
+     *   * readOnly - A boolean value
73
+     *
74
+     * Every element in the remove array is just the address string.
75
+     *
76
+     * @param array $add
77
+     * @param array $remove
78
+     * @return void
79
+     * @throws Forbidden
80
+     */
81
+    public function updateShares(array $add, array $remove) {
82
+        if ($this->isShared()) {
83
+            throw new Forbidden();
84
+        }
85
+        $this->caldavBackend->updateShares($this, $add, $remove);
86
+    }
87
+
88
+    /**
89
+     * Returns the list of people whom this resource is shared with.
90
+     *
91
+     * Every element in this array should have the following properties:
92
+     *   * href - Often a mailto: address
93
+     *   * commonName - Optional, for example a first + last name
94
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
95
+     *   * readOnly - boolean
96
+     *   * summary - Optional, a description for the share
97
+     *
98
+     * @return array
99
+     */
100
+    public function getShares() {
101
+        if ($this->isShared()) {
102
+            return [];
103
+        }
104
+        return $this->caldavBackend->getShares($this->getResourceId());
105
+    }
106
+
107
+    public function getAllShares() {
108
+        return $this->caldavBackend->getShares($this->getResourceId());
109
+    }
110
+
111
+    /**
112
+     * @return int
113
+     */
114
+    public function getResourceId() {
115
+        return $this->calendarInfo['id'];
116
+    }
117
+
118
+    /**
119
+     * @return string
120
+     */
121
+    public function getPrincipalURI() {
122
+        return $this->calendarInfo['principaluri'];
123
+    }
124
+
125
+    public function getACL() {
126
+        $acl =  [
127
+            [
128
+                'privilege' => '{DAV:}read',
129
+                'principal' => $this->getOwner(),
130
+                'protected' => true,
131
+            ]];
132
+        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
133
+            $acl[] = [
134
+                'privilege' => '{DAV:}write',
135
+                'principal' => $this->getOwner(),
136
+                'protected' => true,
137
+            ];
138
+        } else {
139
+            $acl[] = [
140
+                'privilege' => '{DAV:}write-properties',
141
+                'principal' => $this->getOwner(),
142
+                'protected' => true,
143
+            ];
144
+        }
145
+
146
+        if ($this->getOwner() !== parent::getOwner()) {
147
+            $acl[] =  [
148
+                    'privilege' => '{DAV:}read',
149
+                    'principal' => parent::getOwner(),
150
+                    'protected' => true,
151
+                ];
152
+            if ($this->canWrite()) {
153
+                $acl[] = [
154
+                    'privilege' => '{DAV:}write',
155
+                    'principal' => parent::getOwner(),
156
+                    'protected' => true,
157
+                ];
158
+            } else {
159
+                $acl[] = [
160
+                    'privilege' => '{DAV:}write-properties',
161
+                    'principal' => parent::getOwner(),
162
+                    'protected' => true,
163
+                ];
164
+            }
165
+        }
166
+        if ($this->isPublic()) {
167
+            $acl[] = [
168
+                'privilege' => '{DAV:}read',
169
+                'principal' => 'principals/system/public',
170
+                'protected' => true,
171
+            ];
172
+        }
173
+
174
+        $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
175
+
176
+        if (!$this->isShared()) {
177
+            return $acl;
178
+        }
179
+
180
+        $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
181
+        return array_filter($acl, function($rule) use ($allowedPrincipals) {
182
+            return in_array($rule['principal'], $allowedPrincipals);
183
+        });
184
+    }
185
+
186
+    public function getChildACL() {
187
+        return $this->getACL();
188
+    }
189
+
190
+    public function getOwner() {
191
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
192
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
193
+        }
194
+        return parent::getOwner();
195
+    }
196
+
197
+    public function delete() {
198
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
199
+            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
200
+            $principal = 'principal:' . parent::getOwner();
201
+            $shares = $this->caldavBackend->getShares($this->getResourceId());
202
+            $shares = array_filter($shares, function($share) use ($principal){
203
+                return $share['href'] === $principal;
204
+            });
205
+            if (empty($shares)) {
206
+                throw new Forbidden();
207
+            }
208
+
209
+            $this->caldavBackend->updateShares($this, [], [
210
+                'href' => $principal
211
+            ]);
212
+            return;
213
+        }
214
+
215
+        // Remember when a user deleted their birthday calendar
216
+        // in order to not regenerate it on the next contacts change
217
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
218
+            $principalURI = $this->getPrincipalURI();
219
+            $userId = substr($principalURI, 17);
220
+
221
+            $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
222
+        }
223
+
224
+        parent::delete();
225
+    }
226
+
227
+    public function propPatch(PropPatch $propPatch) {
228
+        // parent::propPatch will only update calendars table
229
+        // if calendar is shared, changes have to be made to the properties table
230
+        if (!$this->isShared()) {
231
+            parent::propPatch($propPatch);
232
+        }
233
+    }
234
+
235
+    public function getChild($name) {
236
+
237
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
238
+
239
+        if (!$obj) {
240
+            throw new NotFound('Calendar object not found');
241
+        }
242
+
243
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
244
+            throw new NotFound('Calendar object not found');
245
+        }
246
+
247
+        $obj['acl'] = $this->getChildACL();
248
+
249
+        return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
250
+
251
+    }
252
+
253
+    public function getChildren() {
254
+
255
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
256
+        $children = [];
257
+        foreach ($objs as $obj) {
258
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
259
+                continue;
260
+            }
261
+            $obj['acl'] = $this->getChildACL();
262
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
263
+        }
264
+        return $children;
265
+
266
+    }
267
+
268
+    public function getMultipleChildren(array $paths) {
269
+
270
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
271
+        $children = [];
272
+        foreach ($objs as $obj) {
273
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
274
+                continue;
275
+            }
276
+            $obj['acl'] = $this->getChildACL();
277
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
278
+        }
279
+        return $children;
280
+
281
+    }
282
+
283
+    public function childExists($name) {
284
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
285
+        if (!$obj) {
286
+            return false;
287
+        }
288
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
289
+            return false;
290
+        }
291
+
292
+        return true;
293
+    }
294
+
295
+    public function calendarQuery(array $filters) {
296
+
297
+        $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
298
+        if ($this->isShared()) {
299
+            return array_filter($uris, function ($uri) {
300
+                return $this->childExists($uri);
301
+            });
302
+        }
303
+
304
+        return $uris;
305
+    }
306
+
307
+    /**
308
+     * @param boolean $value
309
+     * @return string|null
310
+     */
311
+    public function setPublishStatus($value) {
312
+        $publicUri = $this->caldavBackend->setPublishStatus($value, $this);
313
+        $this->calendarInfo['publicuri'] = $publicUri;
314
+        return $publicUri;
315
+    }
316
+
317
+    /**
318
+     * @return mixed $value
319
+     */
320
+    public function getPublishStatus() {
321
+        return $this->caldavBackend->getPublishStatus($this);
322
+    }
323
+
324
+    private function canWrite() {
325
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
326
+            return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
327
+        }
328
+        return true;
329
+    }
330
+
331
+    private function isPublic() {
332
+        return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
333
+    }
334
+
335
+    protected function isShared() {
336
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
337
+            return false;
338
+        }
339
+
340
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
341
+    }
342
+
343
+    public function isSubscription() {
344
+        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
345
+    }
346 346
 
347 347
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Schedule/Plugin.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -39,160 +39,160 @@
 block discarded – undo
39 39
 
40 40
 class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
41 41
 
42
-	/** @var Principal */
43
-	protected $principalBackend;
44
-
45
-	/**
46
-	 * Plugin constructor.
47
-	 *
48
-	 * @param Principal $principalBackend
49
-	 */
50
-	public function __construct(Principal $principalBackend) {
51
-		$this->principalBackend = $principalBackend;
52
-	}
53
-
54
-	/**
55
-	 * Initializes the plugin
56
-	 *
57
-	 * @param Server $server
58
-	 * @return void
59
-	 */
60
-	function initialize(Server $server) {
61
-		parent::initialize($server);
62
-		$server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
63
-	}
64
-
65
-	/**
66
-	 * Returns a list of addresses that are associated with a principal.
67
-	 *
68
-	 * @param string $principal
69
-	 * @return array
70
-	 */
71
-	protected function getAddressesForPrincipal($principal) {
72
-		$result = parent::getAddressesForPrincipal($principal);
73
-
74
-		if ($result === null) {
75
-			$result = [];
76
-		}
77
-
78
-		return $result;
79
-	}
80
-
81
-	/**
82
-	 * This method is triggered whenever there was a calendar object gets
83
-	 * created or updated.
84
-	 *
85
-	 * @param RequestInterface $request HTTP request
86
-	 * @param ResponseInterface $response HTTP Response
87
-	 * @param VCalendar $vCal Parsed iCalendar object
88
-	 * @param mixed $calendarPath Path to calendar collection
89
-	 * @param mixed $modified The iCalendar object has been touched.
90
-	 * @param mixed $isNew Whether this was a new item or we're updating one
91
-	 * @return void
92
-	 */
93
-	function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
94
-
95
-		if (!$this->scheduleReply($this->server->httpRequest)) {
96
-			return;
97
-		}
98
-
99
-		/** @var \OCA\DAV\CalDAV\Calendar $calendarNode */
100
-		$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
101
-
102
-		$addresses = [];
103
-		$addresses[] = $this->getAddressesForPrincipal(
104
-			$calendarNode->getOwner()
105
-		);
106
-
107
-		// get writable calendar shares
108
-		$shares = $calendarNode->getAllShares();
109
-		foreach($shares as $share) {
110
-			if ($share['readOnly']) {
111
-				continue;
112
-			}
113
-
114
-			if (strpos($share['{http://owncloud.org/ns}principal'], 'principals/users/') === 0) {
115
-				$addresses[] = $this->getAddressesForPrincipal($share['{http://owncloud.org/ns}principal']);
116
-			} elseif (strpos($share['{http://owncloud.org/ns}principal'], 'principals/groups/') === 0) {
117
-				try {
118
-					$members = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
119
-					foreach ($members as $member) {
120
-						$addresses[] = $this->getAddressesForPrincipal($member);
121
-					}
122
-				} catch(\Sabre\Dav\Exception $ex) {
123
-					continue;
124
-				}
125
-			}
126
-		}
127
-
128
-		$addresses = array_merge(...$addresses);
129
-
130
-		if (!$isNew) {
131
-			$node = $this->server->tree->getNodeForPath($request->getPath());
132
-			$oldObj = Reader::read($node->get());
133
-		} else {
134
-			$oldObj = null;
135
-		}
136
-
137
-		$this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
138
-
139
-		if ($oldObj) {
140
-			// Destroy circular references so PHP will GC the object.
141
-			$oldObj->destroy();
142
-		}
143
-
144
-	}
145
-
146
-	/**
147
-	 * Always use the personal calendar as target for scheduled events
148
-	 *
149
-	 * @param PropFind $propFind
150
-	 * @param INode $node
151
-	 * @return void
152
-	 */
153
-	function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
154
-		if ($node instanceof IPrincipal) {
155
-			$propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
156
-				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
157
-				$caldavPlugin = $this->server->getPlugin('caldav');
158
-				$principalUrl = $node->getPrincipalUrl();
159
-
160
-				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
161
-
162
-				if (!$calendarHomePath) {
163
-					return null;
164
-				}
165
-
166
-				/** @var CalendarHome $calendarHome */
167
-				$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
168
-				if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
169
-					$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
170
-						'{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
171
-					]);
172
-				}
173
-
174
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
175
-				if (empty($result)) {
176
-					return null;
177
-				}
178
-
179
-				return new LocalHref($result[0]['href']);
180
-			});
181
-		}
182
-	}
183
-
184
-	/**
185
-	 * This method checks the 'Schedule-Reply' header
186
-	 * and returns false if it's 'F', otherwise true.
187
-	 *
188
-	 * Copied from Sabre/DAV's Schedule plugin, because it's
189
-	 * private for whatever reason
190
-	 *
191
-	 * @param RequestInterface $request
192
-	 * @return bool
193
-	 */
194
-	private function scheduleReply(RequestInterface $request) {
195
-		$scheduleReply = $request->getHeader('Schedule-Reply');
196
-		return $scheduleReply !== 'F';
197
-	}
42
+    /** @var Principal */
43
+    protected $principalBackend;
44
+
45
+    /**
46
+     * Plugin constructor.
47
+     *
48
+     * @param Principal $principalBackend
49
+     */
50
+    public function __construct(Principal $principalBackend) {
51
+        $this->principalBackend = $principalBackend;
52
+    }
53
+
54
+    /**
55
+     * Initializes the plugin
56
+     *
57
+     * @param Server $server
58
+     * @return void
59
+     */
60
+    function initialize(Server $server) {
61
+        parent::initialize($server);
62
+        $server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
63
+    }
64
+
65
+    /**
66
+     * Returns a list of addresses that are associated with a principal.
67
+     *
68
+     * @param string $principal
69
+     * @return array
70
+     */
71
+    protected function getAddressesForPrincipal($principal) {
72
+        $result = parent::getAddressesForPrincipal($principal);
73
+
74
+        if ($result === null) {
75
+            $result = [];
76
+        }
77
+
78
+        return $result;
79
+    }
80
+
81
+    /**
82
+     * This method is triggered whenever there was a calendar object gets
83
+     * created or updated.
84
+     *
85
+     * @param RequestInterface $request HTTP request
86
+     * @param ResponseInterface $response HTTP Response
87
+     * @param VCalendar $vCal Parsed iCalendar object
88
+     * @param mixed $calendarPath Path to calendar collection
89
+     * @param mixed $modified The iCalendar object has been touched.
90
+     * @param mixed $isNew Whether this was a new item or we're updating one
91
+     * @return void
92
+     */
93
+    function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
94
+
95
+        if (!$this->scheduleReply($this->server->httpRequest)) {
96
+            return;
97
+        }
98
+
99
+        /** @var \OCA\DAV\CalDAV\Calendar $calendarNode */
100
+        $calendarNode = $this->server->tree->getNodeForPath($calendarPath);
101
+
102
+        $addresses = [];
103
+        $addresses[] = $this->getAddressesForPrincipal(
104
+            $calendarNode->getOwner()
105
+        );
106
+
107
+        // get writable calendar shares
108
+        $shares = $calendarNode->getAllShares();
109
+        foreach($shares as $share) {
110
+            if ($share['readOnly']) {
111
+                continue;
112
+            }
113
+
114
+            if (strpos($share['{http://owncloud.org/ns}principal'], 'principals/users/') === 0) {
115
+                $addresses[] = $this->getAddressesForPrincipal($share['{http://owncloud.org/ns}principal']);
116
+            } elseif (strpos($share['{http://owncloud.org/ns}principal'], 'principals/groups/') === 0) {
117
+                try {
118
+                    $members = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
119
+                    foreach ($members as $member) {
120
+                        $addresses[] = $this->getAddressesForPrincipal($member);
121
+                    }
122
+                } catch(\Sabre\Dav\Exception $ex) {
123
+                    continue;
124
+                }
125
+            }
126
+        }
127
+
128
+        $addresses = array_merge(...$addresses);
129
+
130
+        if (!$isNew) {
131
+            $node = $this->server->tree->getNodeForPath($request->getPath());
132
+            $oldObj = Reader::read($node->get());
133
+        } else {
134
+            $oldObj = null;
135
+        }
136
+
137
+        $this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
138
+
139
+        if ($oldObj) {
140
+            // Destroy circular references so PHP will GC the object.
141
+            $oldObj->destroy();
142
+        }
143
+
144
+    }
145
+
146
+    /**
147
+     * Always use the personal calendar as target for scheduled events
148
+     *
149
+     * @param PropFind $propFind
150
+     * @param INode $node
151
+     * @return void
152
+     */
153
+    function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
154
+        if ($node instanceof IPrincipal) {
155
+            $propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
156
+                /** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
157
+                $caldavPlugin = $this->server->getPlugin('caldav');
158
+                $principalUrl = $node->getPrincipalUrl();
159
+
160
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
161
+
162
+                if (!$calendarHomePath) {
163
+                    return null;
164
+                }
165
+
166
+                /** @var CalendarHome $calendarHome */
167
+                $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
168
+                if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
169
+                    $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
170
+                        '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
171
+                    ]);
172
+                }
173
+
174
+                $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
175
+                if (empty($result)) {
176
+                    return null;
177
+                }
178
+
179
+                return new LocalHref($result[0]['href']);
180
+            });
181
+        }
182
+    }
183
+
184
+    /**
185
+     * This method checks the 'Schedule-Reply' header
186
+     * and returns false if it's 'F', otherwise true.
187
+     *
188
+     * Copied from Sabre/DAV's Schedule plugin, because it's
189
+     * private for whatever reason
190
+     *
191
+     * @param RequestInterface $request
192
+     * @return bool
193
+     */
194
+    private function scheduleReply(RequestInterface $request) {
195
+        $scheduleReply = $request->getHeader('Schedule-Reply');
196
+        return $scheduleReply !== 'F';
197
+    }
198 198
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 
107 107
 		// get writable calendar shares
108 108
 		$shares = $calendarNode->getAllShares();
109
-		foreach($shares as $share) {
109
+		foreach ($shares as $share) {
110 110
 			if ($share['readOnly']) {
111 111
 				continue;
112 112
 			}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 					foreach ($members as $member) {
120 120
 						$addresses[] = $this->getAddressesForPrincipal($member);
121 121
 					}
122
-				} catch(\Sabre\Dav\Exception $ex) {
122
+				} catch (\Sabre\Dav\Exception $ex) {
123 123
 					continue;
124 124
 				}
125 125
 			}
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
154 154
 		if ($node instanceof IPrincipal) {
155
-			$propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
155
+			$propFind->handle('{'.self::NS_CALDAV.'}schedule-default-calendar-URL', function() use ($node) {
156 156
 				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
157 157
 				$caldavPlugin = $this->server->getPlugin('caldav');
158 158
 				$principalUrl = $node->getPrincipalUrl();
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 					]);
172 172
 				}
173 173
 
174
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
174
+				$result = $this->server->getPropertiesForPath($calendarHomePath.'/'.CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
175 175
 				if (empty($result)) {
176 176
 					return null;
177 177
 				}
Please login to merge, or discard this patch.
apps/dav/lib/Server.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -64,220 +64,220 @@
 block discarded – undo
64 64
 
65 65
 class Server {
66 66
 
67
-	/** @var IRequest */
68
-	private $request;
67
+    /** @var IRequest */
68
+    private $request;
69 69
 
70
-	/** @var  string */
71
-	private $baseUri;
70
+    /** @var  string */
71
+    private $baseUri;
72 72
 
73
-	/** @var Connector\Sabre\Server  */
74
-	private $server;
73
+    /** @var Connector\Sabre\Server  */
74
+    private $server;
75 75
 
76
-	public function __construct(IRequest $request, $baseUri) {
77
-		$this->request = $request;
78
-		$this->baseUri = $baseUri;
79
-		$logger = \OC::$server->getLogger();
80
-		$dispatcher = \OC::$server->getEventDispatcher();
81
-		$sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes';
76
+    public function __construct(IRequest $request, $baseUri) {
77
+        $this->request = $request;
78
+        $this->baseUri = $baseUri;
79
+        $logger = \OC::$server->getLogger();
80
+        $dispatcher = \OC::$server->getEventDispatcher();
81
+        $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes';
82 82
 
83
-		$root = new RootCollection();
84
-		$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
83
+        $root = new RootCollection();
84
+        $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
85 85
 
86
-		// Add maintenance plugin
87
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
86
+        // Add maintenance plugin
87
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
88 88
 
89
-		// Backends
90
-		$authBackend = new Auth(
91
-			\OC::$server->getSession(),
92
-			\OC::$server->getUserSession(),
93
-			\OC::$server->getRequest(),
94
-			\OC::$server->getTwoFactorAuthManager(),
95
-			\OC::$server->getBruteForceThrottler()
96
-		);
89
+        // Backends
90
+        $authBackend = new Auth(
91
+            \OC::$server->getSession(),
92
+            \OC::$server->getUserSession(),
93
+            \OC::$server->getRequest(),
94
+            \OC::$server->getTwoFactorAuthManager(),
95
+            \OC::$server->getBruteForceThrottler()
96
+        );
97 97
 
98
-		// Set URL explicitly due to reverse-proxy situations
99
-		$this->server->httpRequest->setUrl($this->request->getRequestUri());
100
-		$this->server->setBaseUri($this->baseUri);
98
+        // Set URL explicitly due to reverse-proxy situations
99
+        $this->server->httpRequest->setUrl($this->request->getRequestUri());
100
+        $this->server->setBaseUri($this->baseUri);
101 101
 
102
-		$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
103
-		$authPlugin = new Plugin();
104
-		$authPlugin->addBackend(new PublicAuth());
105
-		$this->server->addPlugin($authPlugin);
102
+        $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
103
+        $authPlugin = new Plugin();
104
+        $authPlugin->addBackend(new PublicAuth());
105
+        $this->server->addPlugin($authPlugin);
106 106
 
107
-		// allow setup of additional auth backends
108
-		$event = new SabrePluginEvent($this->server);
109
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
107
+        // allow setup of additional auth backends
108
+        $event = new SabrePluginEvent($this->server);
109
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
110 110
 
111
-		$bearerAuthBackend = new BearerAuth(
112
-			\OC::$server->getUserSession(),
113
-			\OC::$server->getSession(),
114
-			\OC::$server->getRequest()
115
-		);
116
-		$authPlugin->addBackend($bearerAuthBackend);
117
-		// because we are throwing exceptions this plugin has to be the last one
118
-		$authPlugin->addBackend($authBackend);
111
+        $bearerAuthBackend = new BearerAuth(
112
+            \OC::$server->getUserSession(),
113
+            \OC::$server->getSession(),
114
+            \OC::$server->getRequest()
115
+        );
116
+        $authPlugin->addBackend($bearerAuthBackend);
117
+        // because we are throwing exceptions this plugin has to be the last one
118
+        $authPlugin->addBackend($authBackend);
119 119
 
120
-		// debugging
121
-		if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
122
-			$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
123
-		} else {
124
-			$this->server->addPlugin(new DummyGetResponsePlugin());
125
-		}
120
+        // debugging
121
+        if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
122
+            $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
123
+        } else {
124
+            $this->server->addPlugin(new DummyGetResponsePlugin());
125
+        }
126 126
 
127
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
128
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
129
-		$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
127
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
128
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
129
+        $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
130 130
 
131
-		// acl
132
-		$acl = new DavAclPlugin();
133
-		$acl->principalCollectionSet = [
134
-			'principals/users', 'principals/groups'
135
-		];
136
-		$acl->defaultUsernamePath = 'principals/users';
137
-		$this->server->addPlugin($acl);
131
+        // acl
132
+        $acl = new DavAclPlugin();
133
+        $acl->principalCollectionSet = [
134
+            'principals/users', 'principals/groups'
135
+        ];
136
+        $acl->defaultUsernamePath = 'principals/users';
137
+        $this->server->addPlugin($acl);
138 138
 
139
-		// calendar plugins
140
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
141
-		$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
142
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->query(\OCA\DAV\Connector\Sabre\Principal::class)));
143
-		if ($sendInvitations) {
144
-			$this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
145
-		}
146
-		$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
147
-		$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
148
-		$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
149
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
150
-			\OC::$server->getConfig(),
151
-			\OC::$server->getURLGenerator()
152
-		));
139
+        // calendar plugins
140
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
141
+        $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
142
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->query(\OCA\DAV\Connector\Sabre\Principal::class)));
143
+        if ($sendInvitations) {
144
+            $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
145
+        }
146
+        $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
147
+        $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
148
+        $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
149
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
150
+            \OC::$server->getConfig(),
151
+            \OC::$server->getURLGenerator()
152
+        ));
153 153
 
154
-		// addressbook plugins
155
-		$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
156
-		$this->server->addPlugin(new VCFExportPlugin());
157
-		$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
154
+        // addressbook plugins
155
+        $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
156
+        $this->server->addPlugin(new VCFExportPlugin());
157
+        $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
158 158
 
159
-		// system tags plugins
160
-		$this->server->addPlugin(new SystemTagPlugin(
161
-			\OC::$server->getSystemTagManager(),
162
-			\OC::$server->getGroupManager(),
163
-			\OC::$server->getUserSession()
164
-		));
159
+        // system tags plugins
160
+        $this->server->addPlugin(new SystemTagPlugin(
161
+            \OC::$server->getSystemTagManager(),
162
+            \OC::$server->getGroupManager(),
163
+            \OC::$server->getUserSession()
164
+        ));
165 165
 
166
-		// comments plugin
167
-		$this->server->addPlugin(new CommentsPlugin(
168
-			\OC::$server->getCommentsManager(),
169
-			\OC::$server->getUserSession()
170
-		));
166
+        // comments plugin
167
+        $this->server->addPlugin(new CommentsPlugin(
168
+            \OC::$server->getCommentsManager(),
169
+            \OC::$server->getUserSession()
170
+        ));
171 171
 
172
-		$this->server->addPlugin(new CopyEtagHeaderPlugin());
173
-		$this->server->addPlugin(new ChunkingPlugin());
172
+        $this->server->addPlugin(new CopyEtagHeaderPlugin());
173
+        $this->server->addPlugin(new ChunkingPlugin());
174 174
 
175
-		// allow setup of additional plugins
176
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
175
+        // allow setup of additional plugins
176
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
177 177
 
178
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
179
-		// we do not provide locking we emulate it using a fake locking plugin.
180
-		if($request->isUserAgent([
181
-			'/WebDAVFS/',
182
-			'/OneNote/',
183
-			'/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
184
-		])) {
185
-			$this->server->addPlugin(new FakeLockerPlugin());
186
-		}
178
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
179
+        // we do not provide locking we emulate it using a fake locking plugin.
180
+        if($request->isUserAgent([
181
+            '/WebDAVFS/',
182
+            '/OneNote/',
183
+            '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
184
+        ])) {
185
+            $this->server->addPlugin(new FakeLockerPlugin());
186
+        }
187 187
 
188
-		if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
189
-			$this->server->addPlugin(new BrowserErrorPagePlugin());
190
-		}
188
+        if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
189
+            $this->server->addPlugin(new BrowserErrorPagePlugin());
190
+        }
191 191
 
192
-		// wait with registering these until auth is handled and the filesystem is setup
193
-		$this->server->on('beforeMethod', function () use ($root) {
194
-			// custom properties plugin must be the last one
195
-			$userSession = \OC::$server->getUserSession();
196
-			$user = $userSession->getUser();
197
-			if ($user !== null) {
198
-				$view = \OC\Files\Filesystem::getView();
199
-				$this->server->addPlugin(
200
-					new FilesPlugin(
201
-						$this->server->tree,
202
-						\OC::$server->getConfig(),
203
-						$this->request,
204
-						\OC::$server->getPreviewManager(),
205
-						false,
206
-						!\OC::$server->getConfig()->getSystemValue('debug', false)
207
-					)
208
-				);
192
+        // wait with registering these until auth is handled and the filesystem is setup
193
+        $this->server->on('beforeMethod', function () use ($root) {
194
+            // custom properties plugin must be the last one
195
+            $userSession = \OC::$server->getUserSession();
196
+            $user = $userSession->getUser();
197
+            if ($user !== null) {
198
+                $view = \OC\Files\Filesystem::getView();
199
+                $this->server->addPlugin(
200
+                    new FilesPlugin(
201
+                        $this->server->tree,
202
+                        \OC::$server->getConfig(),
203
+                        $this->request,
204
+                        \OC::$server->getPreviewManager(),
205
+                        false,
206
+                        !\OC::$server->getConfig()->getSystemValue('debug', false)
207
+                    )
208
+                );
209 209
 
210
-				$this->server->addPlugin(
211
-					new \Sabre\DAV\PropertyStorage\Plugin(
212
-						new CustomPropertiesBackend(
213
-							$this->server->tree,
214
-							\OC::$server->getDatabaseConnection(),
215
-							\OC::$server->getUserSession()->getUser()
216
-						)
217
-					)
218
-				);
219
-				if ($view !== null) {
220
-					$this->server->addPlugin(
221
-						new QuotaPlugin($view, false));
222
-				}
223
-				$this->server->addPlugin(
224
-					new TagsPlugin(
225
-						$this->server->tree, \OC::$server->getTagManager()
226
-					)
227
-				);
228
-				// TODO: switch to LazyUserFolder
229
-				$userFolder = \OC::$server->getUserFolder();
230
-				$this->server->addPlugin(new SharesPlugin(
231
-					$this->server->tree,
232
-					$userSession,
233
-					$userFolder,
234
-					\OC::$server->getShareManager()
235
-				));
236
-				$this->server->addPlugin(new CommentPropertiesPlugin(
237
-					\OC::$server->getCommentsManager(),
238
-					$userSession
239
-				));
240
-				$this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
241
-				if ($view !== null) {
242
-					$this->server->addPlugin(new FilesReportPlugin(
243
-						$this->server->tree,
244
-						$view,
245
-						\OC::$server->getSystemTagManager(),
246
-						\OC::$server->getSystemTagObjectMapper(),
247
-						\OC::$server->getTagManager(),
248
-						$userSession,
249
-						\OC::$server->getGroupManager(),
250
-						$userFolder
251
-					));
252
-					$this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend(
253
-						$this->server->tree,
254
-						$user,
255
-						\OC::$server->getRootFolder(),
256
-						\OC::$server->getShareManager(),
257
-						$view
258
-					)));
259
-				}
260
-				$this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
261
-					\OC::$server->getConfig(),
262
-					\OC::$server->query(BirthdayService::class)
263
-				));
264
-			}
210
+                $this->server->addPlugin(
211
+                    new \Sabre\DAV\PropertyStorage\Plugin(
212
+                        new CustomPropertiesBackend(
213
+                            $this->server->tree,
214
+                            \OC::$server->getDatabaseConnection(),
215
+                            \OC::$server->getUserSession()->getUser()
216
+                        )
217
+                    )
218
+                );
219
+                if ($view !== null) {
220
+                    $this->server->addPlugin(
221
+                        new QuotaPlugin($view, false));
222
+                }
223
+                $this->server->addPlugin(
224
+                    new TagsPlugin(
225
+                        $this->server->tree, \OC::$server->getTagManager()
226
+                    )
227
+                );
228
+                // TODO: switch to LazyUserFolder
229
+                $userFolder = \OC::$server->getUserFolder();
230
+                $this->server->addPlugin(new SharesPlugin(
231
+                    $this->server->tree,
232
+                    $userSession,
233
+                    $userFolder,
234
+                    \OC::$server->getShareManager()
235
+                ));
236
+                $this->server->addPlugin(new CommentPropertiesPlugin(
237
+                    \OC::$server->getCommentsManager(),
238
+                    $userSession
239
+                ));
240
+                $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
241
+                if ($view !== null) {
242
+                    $this->server->addPlugin(new FilesReportPlugin(
243
+                        $this->server->tree,
244
+                        $view,
245
+                        \OC::$server->getSystemTagManager(),
246
+                        \OC::$server->getSystemTagObjectMapper(),
247
+                        \OC::$server->getTagManager(),
248
+                        $userSession,
249
+                        \OC::$server->getGroupManager(),
250
+                        $userFolder
251
+                    ));
252
+                    $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend(
253
+                        $this->server->tree,
254
+                        $user,
255
+                        \OC::$server->getRootFolder(),
256
+                        \OC::$server->getShareManager(),
257
+                        $view
258
+                    )));
259
+                }
260
+                $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
261
+                    \OC::$server->getConfig(),
262
+                    \OC::$server->query(BirthdayService::class)
263
+                ));
264
+            }
265 265
 
266
-			// register plugins from apps
267
-			$pluginManager = new PluginManager(
268
-				\OC::$server,
269
-				\OC::$server->getAppManager()
270
-			);
271
-			foreach ($pluginManager->getAppPlugins() as $appPlugin) {
272
-				$this->server->addPlugin($appPlugin);
273
-			}
274
-			foreach ($pluginManager->getAppCollections() as $appCollection) {
275
-				$root->addChild($appCollection);
276
-			}
277
-		});
278
-	}
266
+            // register plugins from apps
267
+            $pluginManager = new PluginManager(
268
+                \OC::$server,
269
+                \OC::$server->getAppManager()
270
+            );
271
+            foreach ($pluginManager->getAppPlugins() as $appPlugin) {
272
+                $this->server->addPlugin($appPlugin);
273
+            }
274
+            foreach ($pluginManager->getAppCollections() as $appCollection) {
275
+                $root->addChild($appCollection);
276
+            }
277
+        });
278
+    }
279 279
 
280
-	public function exec() {
281
-		$this->server->exec();
282
-	}
280
+    public function exec() {
281
+        $this->server->exec();
282
+    }
283 283
 }
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/Backend.php 1 patch
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -32,208 +32,208 @@
 block discarded – undo
32 32
 
33 33
 class Backend {
34 34
 
35
-	/** @var IDBConnection */
36
-	private $db;
37
-	/** @var IUserManager */
38
-	private $userManager;
39
-	/** @var IGroupManager */
40
-	private $groupManager;
41
-	/** @var Principal */
42
-	private $principalBackend;
43
-	/** @var string */
44
-	private $resourceType;
45
-
46
-	const ACCESS_OWNER = 1;
47
-	const ACCESS_READ_WRITE = 2;
48
-	const ACCESS_READ = 3;
49
-
50
-	/**
51
-	 * @param IDBConnection $db
52
-	 * @param IUserManager $userManager
53
-	 * @param IGroupManager $groupManager
54
-	 * @param Principal $principalBackend
55
-	 * @param string $resourceType
56
-	 */
57
-	public function __construct(IDBConnection $db, IUserManager $userManager, IGroupManager $groupManager, Principal $principalBackend, $resourceType) {
58
-		$this->db = $db;
59
-		$this->userManager = $userManager;
60
-		$this->groupManager = $groupManager;
61
-		$this->principalBackend = $principalBackend;
62
-		$this->resourceType = $resourceType;
63
-	}
64
-
65
-	/**
66
-	 * @param IShareable $shareable
67
-	 * @param string[] $add
68
-	 * @param string[] $remove
69
-	 */
70
-	public function updateShares($shareable, $add, $remove) {
71
-		foreach($add as $element) {
72
-			$this->shareWith($shareable, $element);
73
-		}
74
-		foreach($remove as $element) {
75
-			$this->unshare($shareable, $element);
76
-		}
77
-	}
78
-
79
-	/**
80
-	 * @param IShareable $shareable
81
-	 * @param string $element
82
-	 */
83
-	private function shareWith($shareable, $element) {
84
-		$user = $element['href'];
85
-		$parts = explode(':', $user, 2);
86
-		if ($parts[0] !== 'principal') {
87
-			return;
88
-		}
89
-
90
-		// don't share with owner
91
-		if ($shareable->getOwner() === $parts[1]) {
92
-			return;
93
-		}
94
-
95
-		$principal = explode('/', $parts[1], 3);
96
-		if (count($principal) !== 3 || $principal[0] !== 'principals' || !in_array($principal[1], ['users', 'groups'], true)) {
97
-			// Invalid principal
98
-			return;
99
-		}
100
-
101
-		if (($principal[1] === 'users' && !$this->userManager->userExists($principal[2])) ||
102
-			($principal[1] === 'groups' && !$this->groupManager->groupExists($principal[2]))) {
103
-			// User or group does not exist
104
-			return;
105
-		}
106
-
107
-		// remove the share if it already exists
108
-		$this->unshare($shareable, $element['href']);
109
-		$access = self::ACCESS_READ;
110
-		if (isset($element['readOnly'])) {
111
-			$access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE;
112
-		}
113
-
114
-		$query = $this->db->getQueryBuilder();
115
-		$query->insert('dav_shares')
116
-			->values([
117
-				'principaluri' => $query->createNamedParameter($parts[1]),
118
-				'type' => $query->createNamedParameter($this->resourceType),
119
-				'access' => $query->createNamedParameter($access),
120
-				'resourceid' => $query->createNamedParameter($shareable->getResourceId())
121
-			]);
122
-		$query->execute();
123
-	}
124
-
125
-	/**
126
-	 * @param $resourceId
127
-	 */
128
-	public function deleteAllShares($resourceId) {
129
-		$query = $this->db->getQueryBuilder();
130
-		$query->delete('dav_shares')
131
-			->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
132
-			->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
133
-			->execute();
134
-	}
135
-
136
-	public function deleteAllSharesByUser($principaluri) {
137
-		$query = $this->db->getQueryBuilder();
138
-		$query->delete('dav_shares')
139
-			->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri)))
140
-			->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
141
-			->execute();
142
-	}
143
-
144
-	/**
145
-	 * @param IShareable $shareable
146
-	 * @param string $element
147
-	 */
148
-	private function unshare($shareable, $element) {
149
-		$parts = explode(':', $element, 2);
150
-		if ($parts[0] !== 'principal') {
151
-			return;
152
-		}
153
-
154
-		// don't share with owner
155
-		if ($shareable->getOwner() === $parts[1]) {
156
-			return;
157
-		}
158
-
159
-		$query = $this->db->getQueryBuilder();
160
-		$query->delete('dav_shares')
161
-			->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId())))
162
-			->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
163
-			->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1])))
164
-		;
165
-		$query->execute();
166
-	}
167
-
168
-	/**
169
-	 * Returns the list of people whom this resource is shared with.
170
-	 *
171
-	 * Every element in this array should have the following properties:
172
-	 *   * href - Often a mailto: address
173
-	 *   * commonName - Optional, for example a first + last name
174
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
175
-	 *   * readOnly - boolean
176
-	 *   * summary - Optional, a description for the share
177
-	 *
178
-	 * @param int $resourceId
179
-	 * @return array
180
-	 */
181
-	public function getShares($resourceId) {
182
-		$query = $this->db->getQueryBuilder();
183
-		$result = $query->select(['principaluri', 'access'])
184
-			->from('dav_shares')
185
-			->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
186
-			->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
187
-			->execute();
188
-
189
-		$shares = [];
190
-		while($row = $result->fetch()) {
191
-			$p = $this->principalBackend->getPrincipalByPath($row['principaluri']);
192
-			$shares[]= [
193
-				'href' => "principal:${row['principaluri']}",
194
-				'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '',
195
-				'status' => 1,
196
-				'readOnly' => (int) $row['access'] === self::ACCESS_READ,
197
-				'{http://owncloud.org/ns}principal' => $row['principaluri'],
198
-				'{http://owncloud.org/ns}group-share' => is_null($p)
199
-			];
200
-		}
201
-
202
-		return $shares;
203
-	}
204
-
205
-	/**
206
-	 * For shared resources the sharee is set in the ACL of the resource
207
-	 *
208
-	 * @param int $resourceId
209
-	 * @param array $acl
210
-	 * @return array
211
-	 */
212
-	public function  applyShareAcl($resourceId, $acl) {
213
-
214
-		$shares = $this->getShares($resourceId);
215
-		foreach ($shares as $share) {
216
-			$acl[] = [
217
-				'privilege' => '{DAV:}read',
218
-				'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
219
-				'protected' => true,
220
-			];
221
-			if (!$share['readOnly']) {
222
-				$acl[] = [
223
-					'privilege' => '{DAV:}write',
224
-					'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
225
-					'protected' => true,
226
-				];
227
-			} else if ($this->resourceType === 'calendar') {
228
-				// Allow changing the properties of read only calendars,
229
-				// so users can change the visibility.
230
-				$acl[] = [
231
-					'privilege' => '{DAV:}write-properties',
232
-					'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
233
-					'protected' => true,
234
-				];
235
-			}
236
-		}
237
-		return $acl;
238
-	}
35
+    /** @var IDBConnection */
36
+    private $db;
37
+    /** @var IUserManager */
38
+    private $userManager;
39
+    /** @var IGroupManager */
40
+    private $groupManager;
41
+    /** @var Principal */
42
+    private $principalBackend;
43
+    /** @var string */
44
+    private $resourceType;
45
+
46
+    const ACCESS_OWNER = 1;
47
+    const ACCESS_READ_WRITE = 2;
48
+    const ACCESS_READ = 3;
49
+
50
+    /**
51
+     * @param IDBConnection $db
52
+     * @param IUserManager $userManager
53
+     * @param IGroupManager $groupManager
54
+     * @param Principal $principalBackend
55
+     * @param string $resourceType
56
+     */
57
+    public function __construct(IDBConnection $db, IUserManager $userManager, IGroupManager $groupManager, Principal $principalBackend, $resourceType) {
58
+        $this->db = $db;
59
+        $this->userManager = $userManager;
60
+        $this->groupManager = $groupManager;
61
+        $this->principalBackend = $principalBackend;
62
+        $this->resourceType = $resourceType;
63
+    }
64
+
65
+    /**
66
+     * @param IShareable $shareable
67
+     * @param string[] $add
68
+     * @param string[] $remove
69
+     */
70
+    public function updateShares($shareable, $add, $remove) {
71
+        foreach($add as $element) {
72
+            $this->shareWith($shareable, $element);
73
+        }
74
+        foreach($remove as $element) {
75
+            $this->unshare($shareable, $element);
76
+        }
77
+    }
78
+
79
+    /**
80
+     * @param IShareable $shareable
81
+     * @param string $element
82
+     */
83
+    private function shareWith($shareable, $element) {
84
+        $user = $element['href'];
85
+        $parts = explode(':', $user, 2);
86
+        if ($parts[0] !== 'principal') {
87
+            return;
88
+        }
89
+
90
+        // don't share with owner
91
+        if ($shareable->getOwner() === $parts[1]) {
92
+            return;
93
+        }
94
+
95
+        $principal = explode('/', $parts[1], 3);
96
+        if (count($principal) !== 3 || $principal[0] !== 'principals' || !in_array($principal[1], ['users', 'groups'], true)) {
97
+            // Invalid principal
98
+            return;
99
+        }
100
+
101
+        if (($principal[1] === 'users' && !$this->userManager->userExists($principal[2])) ||
102
+            ($principal[1] === 'groups' && !$this->groupManager->groupExists($principal[2]))) {
103
+            // User or group does not exist
104
+            return;
105
+        }
106
+
107
+        // remove the share if it already exists
108
+        $this->unshare($shareable, $element['href']);
109
+        $access = self::ACCESS_READ;
110
+        if (isset($element['readOnly'])) {
111
+            $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE;
112
+        }
113
+
114
+        $query = $this->db->getQueryBuilder();
115
+        $query->insert('dav_shares')
116
+            ->values([
117
+                'principaluri' => $query->createNamedParameter($parts[1]),
118
+                'type' => $query->createNamedParameter($this->resourceType),
119
+                'access' => $query->createNamedParameter($access),
120
+                'resourceid' => $query->createNamedParameter($shareable->getResourceId())
121
+            ]);
122
+        $query->execute();
123
+    }
124
+
125
+    /**
126
+     * @param $resourceId
127
+     */
128
+    public function deleteAllShares($resourceId) {
129
+        $query = $this->db->getQueryBuilder();
130
+        $query->delete('dav_shares')
131
+            ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
132
+            ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
133
+            ->execute();
134
+    }
135
+
136
+    public function deleteAllSharesByUser($principaluri) {
137
+        $query = $this->db->getQueryBuilder();
138
+        $query->delete('dav_shares')
139
+            ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri)))
140
+            ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
141
+            ->execute();
142
+    }
143
+
144
+    /**
145
+     * @param IShareable $shareable
146
+     * @param string $element
147
+     */
148
+    private function unshare($shareable, $element) {
149
+        $parts = explode(':', $element, 2);
150
+        if ($parts[0] !== 'principal') {
151
+            return;
152
+        }
153
+
154
+        // don't share with owner
155
+        if ($shareable->getOwner() === $parts[1]) {
156
+            return;
157
+        }
158
+
159
+        $query = $this->db->getQueryBuilder();
160
+        $query->delete('dav_shares')
161
+            ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId())))
162
+            ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
163
+            ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1])))
164
+        ;
165
+        $query->execute();
166
+    }
167
+
168
+    /**
169
+     * Returns the list of people whom this resource is shared with.
170
+     *
171
+     * Every element in this array should have the following properties:
172
+     *   * href - Often a mailto: address
173
+     *   * commonName - Optional, for example a first + last name
174
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
175
+     *   * readOnly - boolean
176
+     *   * summary - Optional, a description for the share
177
+     *
178
+     * @param int $resourceId
179
+     * @return array
180
+     */
181
+    public function getShares($resourceId) {
182
+        $query = $this->db->getQueryBuilder();
183
+        $result = $query->select(['principaluri', 'access'])
184
+            ->from('dav_shares')
185
+            ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
186
+            ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
187
+            ->execute();
188
+
189
+        $shares = [];
190
+        while($row = $result->fetch()) {
191
+            $p = $this->principalBackend->getPrincipalByPath($row['principaluri']);
192
+            $shares[]= [
193
+                'href' => "principal:${row['principaluri']}",
194
+                'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '',
195
+                'status' => 1,
196
+                'readOnly' => (int) $row['access'] === self::ACCESS_READ,
197
+                '{http://owncloud.org/ns}principal' => $row['principaluri'],
198
+                '{http://owncloud.org/ns}group-share' => is_null($p)
199
+            ];
200
+        }
201
+
202
+        return $shares;
203
+    }
204
+
205
+    /**
206
+     * For shared resources the sharee is set in the ACL of the resource
207
+     *
208
+     * @param int $resourceId
209
+     * @param array $acl
210
+     * @return array
211
+     */
212
+    public function  applyShareAcl($resourceId, $acl) {
213
+
214
+        $shares = $this->getShares($resourceId);
215
+        foreach ($shares as $share) {
216
+            $acl[] = [
217
+                'privilege' => '{DAV:}read',
218
+                'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
219
+                'protected' => true,
220
+            ];
221
+            if (!$share['readOnly']) {
222
+                $acl[] = [
223
+                    'privilege' => '{DAV:}write',
224
+                    'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
225
+                    'protected' => true,
226
+                ];
227
+            } else if ($this->resourceType === 'calendar') {
228
+                // Allow changing the properties of read only calendars,
229
+                // so users can change the visibility.
230
+                $acl[] = [
231
+                    'privilege' => '{DAV:}write-properties',
232
+                    'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
233
+                    'protected' => true,
234
+                ];
235
+            }
236
+        }
237
+        return $acl;
238
+    }
239 239
 }
Please login to merge, or discard this patch.