Completed
Pull Request — master (#10031)
by Blizzz
18:14 queued 01:24
created
lib/private/Files/Search/SearchBinaryOperator.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -25,33 +25,33 @@
 block discarded – undo
25 25
 use OCP\Files\Search\ISearchOperator;
26 26
 
27 27
 class SearchBinaryOperator implements ISearchBinaryOperator {
28
-	/** @var string */
29
-	private $type;
30
-	/** @var ISearchOperator[] */
31
-	private $arguments;
28
+    /** @var string */
29
+    private $type;
30
+    /** @var ISearchOperator[] */
31
+    private $arguments;
32 32
 
33
-	/**
34
-	 * SearchBinaryOperator constructor.
35
-	 *
36
-	 * @param string $type
37
-	 * @param ISearchOperator[] $arguments
38
-	 */
39
-	public function __construct($type, array $arguments) {
40
-		$this->type = $type;
41
-		$this->arguments = $arguments;
42
-	}
33
+    /**
34
+     * SearchBinaryOperator constructor.
35
+     *
36
+     * @param string $type
37
+     * @param ISearchOperator[] $arguments
38
+     */
39
+    public function __construct($type, array $arguments) {
40
+        $this->type = $type;
41
+        $this->arguments = $arguments;
42
+    }
43 43
 
44
-	/**
45
-	 * @return string
46
-	 */
47
-	public function getType() {
48
-		return $this->type;
49
-	}
44
+    /**
45
+     * @return string
46
+     */
47
+    public function getType() {
48
+        return $this->type;
49
+    }
50 50
 
51
-	/**
52
-	 * @return ISearchOperator[]
53
-	 */
54
-	public function getArguments() {
55
-		return $this->arguments;
56
-	}
51
+    /**
52
+     * @return ISearchOperator[]
53
+     */
54
+    public function getArguments() {
55
+        return $this->arguments;
56
+    }
57 57
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/Wrapper/CacheWrapper.php 1 patch
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -34,296 +34,296 @@
 block discarded – undo
34 34
 use OCP\Files\Search\ISearchQuery;
35 35
 
36 36
 class CacheWrapper extends Cache {
37
-	/**
38
-	 * @var \OCP\Files\Cache\ICache
39
-	 */
40
-	protected $cache;
37
+    /**
38
+     * @var \OCP\Files\Cache\ICache
39
+     */
40
+    protected $cache;
41 41
 
42
-	/**
43
-	 * @param \OCP\Files\Cache\ICache $cache
44
-	 */
45
-	public function __construct($cache) {
46
-		$this->cache = $cache;
47
-	}
42
+    /**
43
+     * @param \OCP\Files\Cache\ICache $cache
44
+     */
45
+    public function __construct($cache) {
46
+        $this->cache = $cache;
47
+    }
48 48
 
49
-	protected function getCache() {
50
-		return $this->cache;
51
-	}
49
+    protected function getCache() {
50
+        return $this->cache;
51
+    }
52 52
 
53
-	/**
54
-	 * Make it easy for wrappers to modify every returned cache entry
55
-	 *
56
-	 * @param ICacheEntry $entry
57
-	 * @return ICacheEntry
58
-	 */
59
-	protected function formatCacheEntry($entry) {
60
-		return $entry;
61
-	}
53
+    /**
54
+     * Make it easy for wrappers to modify every returned cache entry
55
+     *
56
+     * @param ICacheEntry $entry
57
+     * @return ICacheEntry
58
+     */
59
+    protected function formatCacheEntry($entry) {
60
+        return $entry;
61
+    }
62 62
 
63
-	/**
64
-	 * get the stored metadata of a file or folder
65
-	 *
66
-	 * @param string|int $file
67
-	 * @return ICacheEntry|false
68
-	 */
69
-	public function get($file) {
70
-		$result = $this->getCache()->get($file);
71
-		if ($result) {
72
-			$result = $this->formatCacheEntry($result);
73
-		}
74
-		return $result;
75
-	}
63
+    /**
64
+     * get the stored metadata of a file or folder
65
+     *
66
+     * @param string|int $file
67
+     * @return ICacheEntry|false
68
+     */
69
+    public function get($file) {
70
+        $result = $this->getCache()->get($file);
71
+        if ($result) {
72
+            $result = $this->formatCacheEntry($result);
73
+        }
74
+        return $result;
75
+    }
76 76
 
77
-	/**
78
-	 * get the metadata of all files stored in $folder
79
-	 *
80
-	 * @param string $folder
81
-	 * @return ICacheEntry[]
82
-	 */
83
-	public function getFolderContents($folder) {
84
-		// can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this
85
-		// and not the wrapped cache
86
-		$fileId = $this->getId($folder);
87
-		return $this->getFolderContentsById($fileId);
88
-	}
77
+    /**
78
+     * get the metadata of all files stored in $folder
79
+     *
80
+     * @param string $folder
81
+     * @return ICacheEntry[]
82
+     */
83
+    public function getFolderContents($folder) {
84
+        // can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this
85
+        // and not the wrapped cache
86
+        $fileId = $this->getId($folder);
87
+        return $this->getFolderContentsById($fileId);
88
+    }
89 89
 
90
-	/**
91
-	 * get the metadata of all files stored in $folder
92
-	 *
93
-	 * @param int $fileId the file id of the folder
94
-	 * @return array
95
-	 */
96
-	public function getFolderContentsById($fileId) {
97
-		$results = $this->getCache()->getFolderContentsById($fileId);
98
-		return array_map(array($this, 'formatCacheEntry'), $results);
99
-	}
90
+    /**
91
+     * get the metadata of all files stored in $folder
92
+     *
93
+     * @param int $fileId the file id of the folder
94
+     * @return array
95
+     */
96
+    public function getFolderContentsById($fileId) {
97
+        $results = $this->getCache()->getFolderContentsById($fileId);
98
+        return array_map(array($this, 'formatCacheEntry'), $results);
99
+    }
100 100
 
101
-	/**
102
-	 * insert or update meta data for a file or folder
103
-	 *
104
-	 * @param string $file
105
-	 * @param array $data
106
-	 *
107
-	 * @return int file id
108
-	 * @throws \RuntimeException
109
-	 */
110
-	public function put($file, array $data) {
111
-		if (($id = $this->getId($file)) > -1) {
112
-			$this->update($id, $data);
113
-			return $id;
114
-		} else {
115
-			return $this->insert($file, $data);
116
-		}
117
-	}
101
+    /**
102
+     * insert or update meta data for a file or folder
103
+     *
104
+     * @param string $file
105
+     * @param array $data
106
+     *
107
+     * @return int file id
108
+     * @throws \RuntimeException
109
+     */
110
+    public function put($file, array $data) {
111
+        if (($id = $this->getId($file)) > -1) {
112
+            $this->update($id, $data);
113
+            return $id;
114
+        } else {
115
+            return $this->insert($file, $data);
116
+        }
117
+    }
118 118
 
119
-	/**
120
-	 * insert meta data for a new file or folder
121
-	 *
122
-	 * @param string $file
123
-	 * @param array $data
124
-	 *
125
-	 * @return int file id
126
-	 * @throws \RuntimeException
127
-	 */
128
-	public function insert($file, array $data) {
129
-		return $this->getCache()->insert($file, $data);
130
-	}
119
+    /**
120
+     * insert meta data for a new file or folder
121
+     *
122
+     * @param string $file
123
+     * @param array $data
124
+     *
125
+     * @return int file id
126
+     * @throws \RuntimeException
127
+     */
128
+    public function insert($file, array $data) {
129
+        return $this->getCache()->insert($file, $data);
130
+    }
131 131
 
132
-	/**
133
-	 * update the metadata in the cache
134
-	 *
135
-	 * @param int $id
136
-	 * @param array $data
137
-	 */
138
-	public function update($id, array $data) {
139
-		$this->getCache()->update($id, $data);
140
-	}
132
+    /**
133
+     * update the metadata in the cache
134
+     *
135
+     * @param int $id
136
+     * @param array $data
137
+     */
138
+    public function update($id, array $data) {
139
+        $this->getCache()->update($id, $data);
140
+    }
141 141
 
142
-	/**
143
-	 * get the file id for a file
144
-	 *
145
-	 * @param string $file
146
-	 * @return int
147
-	 */
148
-	public function getId($file) {
149
-		return $this->getCache()->getId($file);
150
-	}
142
+    /**
143
+     * get the file id for a file
144
+     *
145
+     * @param string $file
146
+     * @return int
147
+     */
148
+    public function getId($file) {
149
+        return $this->getCache()->getId($file);
150
+    }
151 151
 
152
-	/**
153
-	 * get the id of the parent folder of a file
154
-	 *
155
-	 * @param string $file
156
-	 * @return int
157
-	 */
158
-	public function getParentId($file) {
159
-		return $this->getCache()->getParentId($file);
160
-	}
152
+    /**
153
+     * get the id of the parent folder of a file
154
+     *
155
+     * @param string $file
156
+     * @return int
157
+     */
158
+    public function getParentId($file) {
159
+        return $this->getCache()->getParentId($file);
160
+    }
161 161
 
162
-	/**
163
-	 * check if a file is available in the cache
164
-	 *
165
-	 * @param string $file
166
-	 * @return bool
167
-	 */
168
-	public function inCache($file) {
169
-		return $this->getCache()->inCache($file);
170
-	}
162
+    /**
163
+     * check if a file is available in the cache
164
+     *
165
+     * @param string $file
166
+     * @return bool
167
+     */
168
+    public function inCache($file) {
169
+        return $this->getCache()->inCache($file);
170
+    }
171 171
 
172
-	/**
173
-	 * remove a file or folder from the cache
174
-	 *
175
-	 * @param string $file
176
-	 */
177
-	public function remove($file) {
178
-		$this->getCache()->remove($file);
179
-	}
172
+    /**
173
+     * remove a file or folder from the cache
174
+     *
175
+     * @param string $file
176
+     */
177
+    public function remove($file) {
178
+        $this->getCache()->remove($file);
179
+    }
180 180
 
181
-	/**
182
-	 * Move a file or folder in the cache
183
-	 *
184
-	 * @param string $source
185
-	 * @param string $target
186
-	 */
187
-	public function move($source, $target) {
188
-		$this->getCache()->move($source, $target);
189
-	}
181
+    /**
182
+     * Move a file or folder in the cache
183
+     *
184
+     * @param string $source
185
+     * @param string $target
186
+     */
187
+    public function move($source, $target) {
188
+        $this->getCache()->move($source, $target);
189
+    }
190 190
 
191
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
192
-		$this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath);
193
-	}
191
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
192
+        $this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath);
193
+    }
194 194
 
195
-	/**
196
-	 * remove all entries for files that are stored on the storage from the cache
197
-	 */
198
-	public function clear() {
199
-		$this->getCache()->clear();
200
-	}
195
+    /**
196
+     * remove all entries for files that are stored on the storage from the cache
197
+     */
198
+    public function clear() {
199
+        $this->getCache()->clear();
200
+    }
201 201
 
202
-	/**
203
-	 * @param string $file
204
-	 *
205
-	 * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
206
-	 */
207
-	public function getStatus($file) {
208
-		return $this->getCache()->getStatus($file);
209
-	}
202
+    /**
203
+     * @param string $file
204
+     *
205
+     * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
206
+     */
207
+    public function getStatus($file) {
208
+        return $this->getCache()->getStatus($file);
209
+    }
210 210
 
211
-	/**
212
-	 * search for files matching $pattern
213
-	 *
214
-	 * @param string $pattern
215
-	 * @return ICacheEntry[] an array of file data
216
-	 */
217
-	public function search($pattern) {
218
-		$results = $this->getCache()->search($pattern);
219
-		return array_map(array($this, 'formatCacheEntry'), $results);
220
-	}
211
+    /**
212
+     * search for files matching $pattern
213
+     *
214
+     * @param string $pattern
215
+     * @return ICacheEntry[] an array of file data
216
+     */
217
+    public function search($pattern) {
218
+        $results = $this->getCache()->search($pattern);
219
+        return array_map(array($this, 'formatCacheEntry'), $results);
220
+    }
221 221
 
222
-	/**
223
-	 * search for files by mimetype
224
-	 *
225
-	 * @param string $mimetype
226
-	 * @return ICacheEntry[]
227
-	 */
228
-	public function searchByMime($mimetype) {
229
-		$results = $this->getCache()->searchByMime($mimetype);
230
-		return array_map(array($this, 'formatCacheEntry'), $results);
231
-	}
222
+    /**
223
+     * search for files by mimetype
224
+     *
225
+     * @param string $mimetype
226
+     * @return ICacheEntry[]
227
+     */
228
+    public function searchByMime($mimetype) {
229
+        $results = $this->getCache()->searchByMime($mimetype);
230
+        return array_map(array($this, 'formatCacheEntry'), $results);
231
+    }
232 232
 
233
-	public function searchQuery(ISearchQuery $query) {
234
-		$results = $this->getCache()->searchQuery($query);
235
-		return array_map(array($this, 'formatCacheEntry'), $results);
236
-	}
233
+    public function searchQuery(ISearchQuery $query) {
234
+        $results = $this->getCache()->searchQuery($query);
235
+        return array_map(array($this, 'formatCacheEntry'), $results);
236
+    }
237 237
 
238
-	/**
239
-	 * search for files by tag
240
-	 *
241
-	 * @param string|int $tag name or tag id
242
-	 * @param string $userId owner of the tags
243
-	 * @return ICacheEntry[] file data
244
-	 */
245
-	public function searchByTag($tag, $userId) {
246
-		$results = $this->getCache()->searchByTag($tag, $userId);
247
-		return array_map(array($this, 'formatCacheEntry'), $results);
248
-	}
238
+    /**
239
+     * search for files by tag
240
+     *
241
+     * @param string|int $tag name or tag id
242
+     * @param string $userId owner of the tags
243
+     * @return ICacheEntry[] file data
244
+     */
245
+    public function searchByTag($tag, $userId) {
246
+        $results = $this->getCache()->searchByTag($tag, $userId);
247
+        return array_map(array($this, 'formatCacheEntry'), $results);
248
+    }
249 249
 
250
-	/**
251
-	 * update the folder size and the size of all parent folders
252
-	 *
253
-	 * @param string|boolean $path
254
-	 * @param array $data (optional) meta data of the folder
255
-	 */
256
-	public function correctFolderSize($path, $data = null) {
257
-		if ($this->getCache() instanceof Cache) {
258
-			$this->getCache()->correctFolderSize($path, $data);
259
-		}
260
-	}
250
+    /**
251
+     * update the folder size and the size of all parent folders
252
+     *
253
+     * @param string|boolean $path
254
+     * @param array $data (optional) meta data of the folder
255
+     */
256
+    public function correctFolderSize($path, $data = null) {
257
+        if ($this->getCache() instanceof Cache) {
258
+            $this->getCache()->correctFolderSize($path, $data);
259
+        }
260
+    }
261 261
 
262
-	/**
263
-	 * get the size of a folder and set it in the cache
264
-	 *
265
-	 * @param string $path
266
-	 * @param array $entry (optional) meta data of the folder
267
-	 * @return int
268
-	 */
269
-	public function calculateFolderSize($path, $entry = null) {
270
-		if ($this->getCache() instanceof Cache) {
271
-			return $this->getCache()->calculateFolderSize($path, $entry);
272
-		} else {
273
-			return 0;
274
-		}
275
-	}
262
+    /**
263
+     * get the size of a folder and set it in the cache
264
+     *
265
+     * @param string $path
266
+     * @param array $entry (optional) meta data of the folder
267
+     * @return int
268
+     */
269
+    public function calculateFolderSize($path, $entry = null) {
270
+        if ($this->getCache() instanceof Cache) {
271
+            return $this->getCache()->calculateFolderSize($path, $entry);
272
+        } else {
273
+            return 0;
274
+        }
275
+    }
276 276
 
277
-	/**
278
-	 * get all file ids on the files on the storage
279
-	 *
280
-	 * @return int[]
281
-	 */
282
-	public function getAll() {
283
-		return $this->getCache()->getAll();
284
-	}
277
+    /**
278
+     * get all file ids on the files on the storage
279
+     *
280
+     * @return int[]
281
+     */
282
+    public function getAll() {
283
+        return $this->getCache()->getAll();
284
+    }
285 285
 
286
-	/**
287
-	 * find a folder in the cache which has not been fully scanned
288
-	 *
289
-	 * If multiple incomplete folders are in the cache, the one with the highest id will be returned,
290
-	 * use the one with the highest id gives the best result with the background scanner, since that is most
291
-	 * likely the folder where we stopped scanning previously
292
-	 *
293
-	 * @return string|bool the path of the folder or false when no folder matched
294
-	 */
295
-	public function getIncomplete() {
296
-		return $this->getCache()->getIncomplete();
297
-	}
286
+    /**
287
+     * find a folder in the cache which has not been fully scanned
288
+     *
289
+     * If multiple incomplete folders are in the cache, the one with the highest id will be returned,
290
+     * use the one with the highest id gives the best result with the background scanner, since that is most
291
+     * likely the folder where we stopped scanning previously
292
+     *
293
+     * @return string|bool the path of the folder or false when no folder matched
294
+     */
295
+    public function getIncomplete() {
296
+        return $this->getCache()->getIncomplete();
297
+    }
298 298
 
299
-	/**
300
-	 * get the path of a file on this storage by it's id
301
-	 *
302
-	 * @param int $id
303
-	 * @return string|null
304
-	 */
305
-	public function getPathById($id) {
306
-		return $this->getCache()->getPathById($id);
307
-	}
299
+    /**
300
+     * get the path of a file on this storage by it's id
301
+     *
302
+     * @param int $id
303
+     * @return string|null
304
+     */
305
+    public function getPathById($id) {
306
+        return $this->getCache()->getPathById($id);
307
+    }
308 308
 
309
-	/**
310
-	 * Returns the numeric storage id
311
-	 *
312
-	 * @return int
313
-	 */
314
-	public function getNumericStorageId() {
315
-		return $this->getCache()->getNumericStorageId();
316
-	}
309
+    /**
310
+     * Returns the numeric storage id
311
+     *
312
+     * @return int
313
+     */
314
+    public function getNumericStorageId() {
315
+        return $this->getCache()->getNumericStorageId();
316
+    }
317 317
 
318
-	/**
319
-	 * get the storage id of the storage for a file and the internal path of the file
320
-	 * unlike getPathById this does not limit the search to files on this storage and
321
-	 * instead does a global search in the cache table
322
-	 *
323
-	 * @param int $id
324
-	 * @return array first element holding the storage id, second the path
325
-	 */
326
-	static public function getById($id) {
327
-		return parent::getById($id);
328
-	}
318
+    /**
319
+     * get the storage id of the storage for a file and the internal path of the file
320
+     * unlike getPathById this does not limit the search to files on this storage and
321
+     * instead does a global search in the cache table
322
+     *
323
+     * @param int $id
324
+     * @return array first element holding the storage id, second the path
325
+     */
326
+    static public function getById($id) {
327
+        return parent::getById($id);
328
+    }
329 329
 }
Please login to merge, or discard this patch.
lib/private/Lockdown/Filesystem/NullCache.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -27,101 +27,101 @@
 block discarded – undo
27 27
 use OCP\Files\Search\ISearchQuery;
28 28
 
29 29
 class NullCache implements ICache {
30
-	public function getNumericStorageId() {
31
-		return -1;
32
-	}
33
-
34
-	public function get($file) {
35
-		return $file !== '' ? null :
36
-			new CacheEntry([
37
-				'fileid' => -1,
38
-				'parent' => -1,
39
-				'name' => '',
40
-				'path' => '',
41
-				'size' => '0',
42
-				'mtime' => time(),
43
-				'storage_mtime' => time(),
44
-				'etag' => '',
45
-				'mimetype' => FileInfo::MIMETYPE_FOLDER,
46
-				'mimepart' => 'httpd',
47
-				'permissions' => Constants::PERMISSION_READ
48
-			]);
49
-	}
50
-
51
-	public function getFolderContents($folder) {
52
-		return [];
53
-	}
54
-
55
-	public function getFolderContentsById($fileId) {
56
-		return [];
57
-	}
58
-
59
-	public function put($file, array $data) {
60
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
61
-	}
62
-
63
-	public function insert($file, array $data) {
64
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
65
-	}
66
-
67
-	public function update($id, array $data) {
68
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
69
-	}
70
-
71
-	public function getId($file) {
72
-		return -1;
73
-	}
74
-
75
-	public function getParentId($file) {
76
-		return -1;
77
-	}
78
-
79
-	public function inCache($file) {
80
-		return $file === '';
81
-	}
82
-
83
-	public function remove($file) {
84
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
85
-	}
86
-
87
-	public function move($source, $target) {
88
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
89
-	}
90
-
91
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
92
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
93
-	}
94
-
95
-	public function getStatus($file) {
96
-		return ICache::COMPLETE;
97
-	}
98
-
99
-	public function search($pattern) {
100
-		return [];
101
-	}
102
-
103
-	public function searchByMime($mimetype) {
104
-		return [];
105
-	}
106
-
107
-	public function searchQuery(ISearchQuery $query) {
108
-		return [];
109
-	}
110
-
111
-	public function searchByTag($tag, $userId) {
112
-		return [];
113
-	}
114
-
115
-	public function getIncomplete() {
116
-		return [];
117
-	}
118
-
119
-	public function getPathById($id) {
120
-		return '';
121
-	}
122
-
123
-	public function normalize($path) {
124
-		return $path;
125
-	}
30
+    public function getNumericStorageId() {
31
+        return -1;
32
+    }
33
+
34
+    public function get($file) {
35
+        return $file !== '' ? null :
36
+            new CacheEntry([
37
+                'fileid' => -1,
38
+                'parent' => -1,
39
+                'name' => '',
40
+                'path' => '',
41
+                'size' => '0',
42
+                'mtime' => time(),
43
+                'storage_mtime' => time(),
44
+                'etag' => '',
45
+                'mimetype' => FileInfo::MIMETYPE_FOLDER,
46
+                'mimepart' => 'httpd',
47
+                'permissions' => Constants::PERMISSION_READ
48
+            ]);
49
+    }
50
+
51
+    public function getFolderContents($folder) {
52
+        return [];
53
+    }
54
+
55
+    public function getFolderContentsById($fileId) {
56
+        return [];
57
+    }
58
+
59
+    public function put($file, array $data) {
60
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
61
+    }
62
+
63
+    public function insert($file, array $data) {
64
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
65
+    }
66
+
67
+    public function update($id, array $data) {
68
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
69
+    }
70
+
71
+    public function getId($file) {
72
+        return -1;
73
+    }
74
+
75
+    public function getParentId($file) {
76
+        return -1;
77
+    }
78
+
79
+    public function inCache($file) {
80
+        return $file === '';
81
+    }
82
+
83
+    public function remove($file) {
84
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
85
+    }
86
+
87
+    public function move($source, $target) {
88
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
89
+    }
90
+
91
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
92
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
93
+    }
94
+
95
+    public function getStatus($file) {
96
+        return ICache::COMPLETE;
97
+    }
98
+
99
+    public function search($pattern) {
100
+        return [];
101
+    }
102
+
103
+    public function searchByMime($mimetype) {
104
+        return [];
105
+    }
106
+
107
+    public function searchQuery(ISearchQuery $query) {
108
+        return [];
109
+    }
110
+
111
+    public function searchByTag($tag, $userId) {
112
+        return [];
113
+    }
114
+
115
+    public function getIncomplete() {
116
+        return [];
117
+    }
118
+
119
+    public function getPathById($id) {
120
+        return '';
121
+    }
122
+
123
+    public function normalize($path) {
124
+        return $path;
125
+    }
126 126
 
127 127
 }
Please login to merge, or discard this patch.
apps/user_ldap/templates/renewpassword.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php /** @var $l OC_L10N */ ?>
2 2
 <?php
3 3
 script('core', [
4
-	'jquery-showpassword',
4
+    'jquery-showpassword',
5 5
 ]);
6 6
 script('user_ldap', [
7
-	'renewPassword',
7
+    'renewPassword',
8 8
 ]);
9 9
 style('user_ldap', 'renewPassword');
10 10
 \OC_Util::addVendorScript('strengthify/jquery.strengthify');
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 		<div class="warning title">
19 19
 			<?php p($l->t('Please renew your password.')); ?><br>
20 20
 		</div>
21
-		<?php foreach($_['messages'] as $message): ?>
21
+		<?php foreach ($_['messages'] as $message): ?>
22 22
 			<div class="warning">
23 23
 				<?php p($message); ?><br>
24 24
 			</div>
@@ -31,14 +31,14 @@  discard block
 block discarded – undo
31 31
 		<?php endif; ?>
32 32
 		<div id="message" class="hidden">
33 33
 			<img class="float-spinner" alt=""
34
-				src="<?php p(image_path('core', 'loading-dark.gif'));?>">
34
+				src="<?php p(image_path('core', 'loading-dark.gif')); ?>">
35 35
 			<span id="messageText"></span>
36 36
 			<!-- the following div ensures that the spinner is always inside the #message div -->
37 37
 			<div style="clear: both;"></div>
38 38
 		</div>
39 39
 		<p class="grouptop">
40 40
 			<input type="password" id="oldPassword" name="oldPassword"
41
-				placeholder="<?php echo $l->t('Current password');?>"
41
+				placeholder="<?php echo $l->t('Current password'); ?>"
42 42
 				autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/>
43 43
 			<label for="oldPassword" class="infield"><?php p($l->t('Current password')); ?></label>
44 44
 		</p>
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			<input type="checkbox" id="personal-show" name="show" /><label for="personal-show"></label>
48 48
 			<label id="newPassword-label" for="newPassword" class="infield"><?php p($l->t('New password')); ?></label>
49 49
 			<input type="password" id="newPassword" name="newPassword"
50
-				placeholder="<?php echo $l->t('New password');?>"
50
+				placeholder="<?php echo $l->t('New password'); ?>"
51 51
 				data-typetoggle="#personal-show" autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/>
52 52
 		</p>
53 53
 		
Please login to merge, or discard this patch.
lib/private/Repair/RepairInvalidShares.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 
72 72
 		$updatedEntries = $builder->execute();
73 73
 		if ($updatedEntries > 0) {
74
-			$out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
74
+			$out->info('Fixed file share permissions for '.$updatedEntries.' shares');
75 75
 		}
76 76
 	}
77 77
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		}
108 108
 
109 109
 		if ($deletedEntries) {
110
-			$out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
110
+			$out->info('Removed '.$deletedEntries.' shares where the parent did not exist');
111 111
 		}
112 112
 	}
113 113
 
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -33,90 +33,90 @@
 block discarded – undo
33 33
  */
34 34
 class RepairInvalidShares implements IRepairStep {
35 35
 
36
-	const CHUNK_SIZE = 200;
37
-
38
-	/** @var \OCP\IConfig */
39
-	protected $config;
40
-
41
-	/** @var \OCP\IDBConnection */
42
-	protected $connection;
43
-
44
-	/**
45
-	 * @param \OCP\IConfig $config
46
-	 * @param \OCP\IDBConnection $connection
47
-	 */
48
-	public function __construct($config, $connection) {
49
-		$this->connection = $connection;
50
-		$this->config = $config;
51
-	}
52
-
53
-	public function getName() {
54
-		return 'Repair invalid shares';
55
-	}
56
-
57
-	/**
58
-	 * Adjust file share permissions
59
-	 * @suppress SqlInjectionChecker
60
-	 */
61
-	private function adjustFileSharePermissions(IOutput $out) {
62
-		$mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE;
63
-		$builder = $this->connection->getQueryBuilder();
64
-
65
-		$permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask);
66
-		$builder
67
-			->update('share')
68
-			->set('permissions', $permsFunc)
69
-			->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
70
-			->andWhere($builder->expr()->neq('permissions', $permsFunc));
71
-
72
-		$updatedEntries = $builder->execute();
73
-		if ($updatedEntries > 0) {
74
-			$out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
75
-		}
76
-	}
77
-
78
-	/**
79
-	 * Remove shares where the parent share does not exist anymore
80
-	 */
81
-	private function removeSharesNonExistingParent(IOutput $out) {
82
-		$deletedEntries = 0;
83
-
84
-		$query = $this->connection->getQueryBuilder();
85
-		$query->select('s1.parent')
86
-			->from('share', 's1')
87
-			->where($query->expr()->isNotNull('s1.parent'))
88
-				->andWhere($query->expr()->isNull('s2.id'))
89
-			->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))
90
-			->groupBy('s1.parent')
91
-			->setMaxResults(self::CHUNK_SIZE);
92
-
93
-		$deleteQuery = $this->connection->getQueryBuilder();
94
-		$deleteQuery->delete('share')
95
-			->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
96
-
97
-		$deletedInLastChunk = self::CHUNK_SIZE;
98
-		while ($deletedInLastChunk === self::CHUNK_SIZE) {
99
-			$deletedInLastChunk = 0;
100
-			$result = $query->execute();
101
-			while ($row = $result->fetch()) {
102
-				$deletedInLastChunk++;
103
-				$deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])
104
-					->execute();
105
-			}
106
-			$result->closeCursor();
107
-		}
108
-
109
-		if ($deletedEntries) {
110
-			$out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
111
-		}
112
-	}
113
-
114
-	public function run(IOutput $out) {
115
-		$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
116
-		if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
117
-			$this->adjustFileSharePermissions($out);
118
-		}
119
-
120
-		$this->removeSharesNonExistingParent($out);
121
-	}
36
+    const CHUNK_SIZE = 200;
37
+
38
+    /** @var \OCP\IConfig */
39
+    protected $config;
40
+
41
+    /** @var \OCP\IDBConnection */
42
+    protected $connection;
43
+
44
+    /**
45
+     * @param \OCP\IConfig $config
46
+     * @param \OCP\IDBConnection $connection
47
+     */
48
+    public function __construct($config, $connection) {
49
+        $this->connection = $connection;
50
+        $this->config = $config;
51
+    }
52
+
53
+    public function getName() {
54
+        return 'Repair invalid shares';
55
+    }
56
+
57
+    /**
58
+     * Adjust file share permissions
59
+     * @suppress SqlInjectionChecker
60
+     */
61
+    private function adjustFileSharePermissions(IOutput $out) {
62
+        $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE;
63
+        $builder = $this->connection->getQueryBuilder();
64
+
65
+        $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask);
66
+        $builder
67
+            ->update('share')
68
+            ->set('permissions', $permsFunc)
69
+            ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
70
+            ->andWhere($builder->expr()->neq('permissions', $permsFunc));
71
+
72
+        $updatedEntries = $builder->execute();
73
+        if ($updatedEntries > 0) {
74
+            $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
75
+        }
76
+    }
77
+
78
+    /**
79
+     * Remove shares where the parent share does not exist anymore
80
+     */
81
+    private function removeSharesNonExistingParent(IOutput $out) {
82
+        $deletedEntries = 0;
83
+
84
+        $query = $this->connection->getQueryBuilder();
85
+        $query->select('s1.parent')
86
+            ->from('share', 's1')
87
+            ->where($query->expr()->isNotNull('s1.parent'))
88
+                ->andWhere($query->expr()->isNull('s2.id'))
89
+            ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))
90
+            ->groupBy('s1.parent')
91
+            ->setMaxResults(self::CHUNK_SIZE);
92
+
93
+        $deleteQuery = $this->connection->getQueryBuilder();
94
+        $deleteQuery->delete('share')
95
+            ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
96
+
97
+        $deletedInLastChunk = self::CHUNK_SIZE;
98
+        while ($deletedInLastChunk === self::CHUNK_SIZE) {
99
+            $deletedInLastChunk = 0;
100
+            $result = $query->execute();
101
+            while ($row = $result->fetch()) {
102
+                $deletedInLastChunk++;
103
+                $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])
104
+                    ->execute();
105
+            }
106
+            $result->closeCursor();
107
+        }
108
+
109
+        if ($deletedEntries) {
110
+            $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
111
+        }
112
+    }
113
+
114
+    public function run(IOutput $out) {
115
+        $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
116
+        if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
117
+            $this->adjustFileSharePermissions($out);
118
+        }
119
+
120
+        $this->removeSharesNonExistingParent($out);
121
+    }
122 122
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/AddressBook.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -194,6 +194,9 @@
 block discarded – undo
194 194
 		parent::propPatch($propPatch);
195 195
 	}
196 196
 
197
+	/**
198
+	 * @return string
199
+	 */
197 200
 	public function getContactsGroups() {
198 201
 		return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES');
199 202
 	}
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	}
100 100
 
101 101
 	public function getACL() {
102
-		$acl =  [
102
+		$acl = [
103 103
 			[
104 104
 				'privilege' => '{DAV:}read',
105 105
 				'principal' => $this->getOwner(),
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 				'protected' => true,
112 112
 			];
113 113
 		if ($this->getOwner() !== parent::getOwner()) {
114
-			$acl[] =  [
114
+			$acl[] = [
115 115
 					'privilege' => '{DAV:}read',
116 116
 					'principal' => parent::getOwner(),
117 117
 					'protected' => true,
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 
171 171
 	public function delete() {
172 172
 		if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
173
-			$principal = 'principal:' . parent::getOwner();
173
+			$principal = 'principal:'.parent::getOwner();
174 174
 			$shares = $this->carddavBackend->getShares($this->getResourceId());
175 175
 			$shares = array_filter($shares, function($share) use ($principal){
176 176
 				return $share['href'] === $principal;
Please login to merge, or discard this patch.
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -38,179 +38,179 @@
 block discarded – undo
38 38
  */
39 39
 class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
40 40
 
41
-	/**
42
-	 * AddressBook constructor.
43
-	 *
44
-	 * @param BackendInterface $carddavBackend
45
-	 * @param array $addressBookInfo
46
-	 * @param IL10N $l10n
47
-	 */
48
-	public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) {
49
-		parent::__construct($carddavBackend, $addressBookInfo);
50
-
51
-		if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME &&
52
-			$this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) {
53
-			$this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts');
54
-		}
55
-	}
56
-
57
-	/**
58
-	 * Updates the list of shares.
59
-	 *
60
-	 * The first array is a list of people that are to be added to the
61
-	 * addressbook.
62
-	 *
63
-	 * Every element in the add array has the following properties:
64
-	 *   * href - A url. Usually a mailto: address
65
-	 *   * commonName - Usually a first and last name, or false
66
-	 *   * summary - A description of the share, can also be false
67
-	 *   * readOnly - A boolean value
68
-	 *
69
-	 * Every element in the remove array is just the address string.
70
-	 *
71
-	 * @param array $add
72
-	 * @param array $remove
73
-	 * @return void
74
-	 * @throws Forbidden
75
-	 */
76
-	public function updateShares(array $add, array $remove) {
77
-		if ($this->isShared()) {
78
-			throw new Forbidden();
79
-		}
80
-		$this->carddavBackend->updateShares($this, $add, $remove);
81
-	}
82
-
83
-	/**
84
-	 * Returns the list of people whom this addressbook is shared with.
85
-	 *
86
-	 * Every element in this array should have the following properties:
87
-	 *   * href - Often a mailto: address
88
-	 *   * commonName - Optional, for example a first + last name
89
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
90
-	 *   * readOnly - boolean
91
-	 *   * summary - Optional, a description for the share
92
-	 *
93
-	 * @return array
94
-	 */
95
-	public function getShares() {
96
-		if ($this->isShared()) {
97
-			return [];
98
-		}
99
-		return $this->carddavBackend->getShares($this->getResourceId());
100
-	}
101
-
102
-	public function getACL() {
103
-		$acl =  [
104
-			[
105
-				'privilege' => '{DAV:}read',
106
-				'principal' => $this->getOwner(),
107
-				'protected' => true,
108
-			]];
109
-		$acl[] = [
110
-				'privilege' => '{DAV:}write',
111
-				'principal' => $this->getOwner(),
112
-				'protected' => true,
113
-			];
114
-		if ($this->getOwner() !== parent::getOwner()) {
115
-			$acl[] =  [
116
-					'privilege' => '{DAV:}read',
117
-					'principal' => parent::getOwner(),
118
-					'protected' => true,
119
-				];
120
-			if ($this->canWrite()) {
121
-				$acl[] = [
122
-					'privilege' => '{DAV:}write',
123
-					'principal' => parent::getOwner(),
124
-					'protected' => true,
125
-				];
126
-			}
127
-		}
128
-		if ($this->getOwner() === 'principals/system/system') {
129
-			$acl[] = [
130
-					'privilege' => '{DAV:}read',
131
-					'principal' => '{DAV:}authenticated',
132
-					'protected' => true,
133
-			];
134
-		}
135
-
136
-		if ($this->isShared()) {
137
-			return $acl;
138
-		}
139
-
140
-		return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl);
141
-	}
142
-
143
-	public function getChildACL() {
144
-		return $this->getACL();
145
-	}
146
-
147
-	public function getChild($name) {
148
-
149
-		$obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name);
150
-		if (!$obj) {
151
-			throw new NotFound('Card not found');
152
-		}
153
-		$obj['acl'] = $this->getChildACL();
154
-		return new Card($this->carddavBackend, $this->addressBookInfo, $obj);
155
-
156
-	}
157
-
158
-	/**
159
-	 * @return int
160
-	 */
161
-	public function getResourceId() {
162
-		return $this->addressBookInfo['id'];
163
-	}
164
-
165
-	public function getOwner() {
166
-		if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
167
-			return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'];
168
-		}
169
-		return parent::getOwner();
170
-	}
171
-
172
-	public function delete() {
173
-		if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
174
-			$principal = 'principal:' . parent::getOwner();
175
-			$shares = $this->carddavBackend->getShares($this->getResourceId());
176
-			$shares = array_filter($shares, function($share) use ($principal){
177
-				return $share['href'] === $principal;
178
-			});
179
-			if (empty($shares)) {
180
-				throw new Forbidden();
181
-			}
182
-
183
-			$this->carddavBackend->updateShares($this, [], [
184
-				$principal
185
-			]);
186
-			return;
187
-		}
188
-		parent::delete();
189
-	}
190
-
191
-	public function propPatch(PropPatch $propPatch) {
192
-		if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
193
-			throw new Forbidden();
194
-		}
195
-		parent::propPatch($propPatch);
196
-	}
197
-
198
-	public function getContactsGroups() {
199
-		return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES');
200
-	}
201
-
202
-	private function isShared() {
203
-		if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
204
-			return false;
205
-		}
206
-
207
-		return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri'];
208
-	}
209
-
210
-	private function canWrite() {
211
-		if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) {
212
-			return !$this->addressBookInfo['{http://owncloud.org/ns}read-only'];
213
-		}
214
-		return true;
215
-	}
41
+    /**
42
+     * AddressBook constructor.
43
+     *
44
+     * @param BackendInterface $carddavBackend
45
+     * @param array $addressBookInfo
46
+     * @param IL10N $l10n
47
+     */
48
+    public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) {
49
+        parent::__construct($carddavBackend, $addressBookInfo);
50
+
51
+        if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME &&
52
+            $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) {
53
+            $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts');
54
+        }
55
+    }
56
+
57
+    /**
58
+     * Updates the list of shares.
59
+     *
60
+     * The first array is a list of people that are to be added to the
61
+     * addressbook.
62
+     *
63
+     * Every element in the add array has the following properties:
64
+     *   * href - A url. Usually a mailto: address
65
+     *   * commonName - Usually a first and last name, or false
66
+     *   * summary - A description of the share, can also be false
67
+     *   * readOnly - A boolean value
68
+     *
69
+     * Every element in the remove array is just the address string.
70
+     *
71
+     * @param array $add
72
+     * @param array $remove
73
+     * @return void
74
+     * @throws Forbidden
75
+     */
76
+    public function updateShares(array $add, array $remove) {
77
+        if ($this->isShared()) {
78
+            throw new Forbidden();
79
+        }
80
+        $this->carddavBackend->updateShares($this, $add, $remove);
81
+    }
82
+
83
+    /**
84
+     * Returns the list of people whom this addressbook is shared with.
85
+     *
86
+     * Every element in this array should have the following properties:
87
+     *   * href - Often a mailto: address
88
+     *   * commonName - Optional, for example a first + last name
89
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
90
+     *   * readOnly - boolean
91
+     *   * summary - Optional, a description for the share
92
+     *
93
+     * @return array
94
+     */
95
+    public function getShares() {
96
+        if ($this->isShared()) {
97
+            return [];
98
+        }
99
+        return $this->carddavBackend->getShares($this->getResourceId());
100
+    }
101
+
102
+    public function getACL() {
103
+        $acl =  [
104
+            [
105
+                'privilege' => '{DAV:}read',
106
+                'principal' => $this->getOwner(),
107
+                'protected' => true,
108
+            ]];
109
+        $acl[] = [
110
+                'privilege' => '{DAV:}write',
111
+                'principal' => $this->getOwner(),
112
+                'protected' => true,
113
+            ];
114
+        if ($this->getOwner() !== parent::getOwner()) {
115
+            $acl[] =  [
116
+                    'privilege' => '{DAV:}read',
117
+                    'principal' => parent::getOwner(),
118
+                    'protected' => true,
119
+                ];
120
+            if ($this->canWrite()) {
121
+                $acl[] = [
122
+                    'privilege' => '{DAV:}write',
123
+                    'principal' => parent::getOwner(),
124
+                    'protected' => true,
125
+                ];
126
+            }
127
+        }
128
+        if ($this->getOwner() === 'principals/system/system') {
129
+            $acl[] = [
130
+                    'privilege' => '{DAV:}read',
131
+                    'principal' => '{DAV:}authenticated',
132
+                    'protected' => true,
133
+            ];
134
+        }
135
+
136
+        if ($this->isShared()) {
137
+            return $acl;
138
+        }
139
+
140
+        return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl);
141
+    }
142
+
143
+    public function getChildACL() {
144
+        return $this->getACL();
145
+    }
146
+
147
+    public function getChild($name) {
148
+
149
+        $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name);
150
+        if (!$obj) {
151
+            throw new NotFound('Card not found');
152
+        }
153
+        $obj['acl'] = $this->getChildACL();
154
+        return new Card($this->carddavBackend, $this->addressBookInfo, $obj);
155
+
156
+    }
157
+
158
+    /**
159
+     * @return int
160
+     */
161
+    public function getResourceId() {
162
+        return $this->addressBookInfo['id'];
163
+    }
164
+
165
+    public function getOwner() {
166
+        if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
167
+            return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'];
168
+        }
169
+        return parent::getOwner();
170
+    }
171
+
172
+    public function delete() {
173
+        if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
174
+            $principal = 'principal:' . parent::getOwner();
175
+            $shares = $this->carddavBackend->getShares($this->getResourceId());
176
+            $shares = array_filter($shares, function($share) use ($principal){
177
+                return $share['href'] === $principal;
178
+            });
179
+            if (empty($shares)) {
180
+                throw new Forbidden();
181
+            }
182
+
183
+            $this->carddavBackend->updateShares($this, [], [
184
+                $principal
185
+            ]);
186
+            return;
187
+        }
188
+        parent::delete();
189
+    }
190
+
191
+    public function propPatch(PropPatch $propPatch) {
192
+        if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
193
+            throw new Forbidden();
194
+        }
195
+        parent::propPatch($propPatch);
196
+    }
197
+
198
+    public function getContactsGroups() {
199
+        return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES');
200
+    }
201
+
202
+    private function isShared() {
203
+        if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
204
+            return false;
205
+        }
206
+
207
+        return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri'];
208
+    }
209
+
210
+    private function canWrite() {
211
+        if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) {
212
+            return !$this->addressBookInfo['{http://owncloud.org/ns}read-only'];
213
+        }
214
+        return true;
215
+    }
216 216
 }
Please login to merge, or discard this patch.
core/Command/Encryption/DecryptAll.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -38,139 +38,139 @@
 block discarded – undo
38 38
 
39 39
 class DecryptAll extends Command {
40 40
 
41
-	/** @var IManager */
42
-	protected $encryptionManager;
43
-
44
-	/** @var  IAppManager */
45
-	protected $appManager;
46
-
47
-	/** @var IConfig */
48
-	protected $config;
49
-
50
-	/** @var  QuestionHelper */
51
-	protected $questionHelper;
52
-
53
-	/** @var bool */
54
-	protected $wasTrashbinEnabled;
55
-
56
-	/** @var  bool */
57
-	protected $wasMaintenanceModeEnabled;
58
-
59
-	/** @var \OC\Encryption\DecryptAll */
60
-	protected $decryptAll;
61
-
62
-	/**
63
-	 * @param IManager $encryptionManager
64
-	 * @param IAppManager $appManager
65
-	 * @param IConfig $config
66
-	 * @param \OC\Encryption\DecryptAll $decryptAll
67
-	 * @param QuestionHelper $questionHelper
68
-	 */
69
-	public function __construct(
70
-		IManager $encryptionManager,
71
-		IAppManager $appManager,
72
-		IConfig $config,
73
-		\OC\Encryption\DecryptAll $decryptAll,
74
-		QuestionHelper $questionHelper
75
-	) {
76
-		parent::__construct();
77
-
78
-		$this->appManager = $appManager;
79
-		$this->encryptionManager = $encryptionManager;
80
-		$this->config = $config;
81
-		$this->decryptAll = $decryptAll;
82
-		$this->questionHelper = $questionHelper;
83
-	}
84
-
85
-	/**
86
-	 * Set maintenance mode and disable the trashbin app
87
-	 */
88
-	protected function forceMaintenanceAndTrashbin() {
89
-		$this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin');
90
-		$this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
91
-		$this->config->setSystemValue('maintenance', true);
92
-		$this->appManager->disableApp('files_trashbin');
93
-	}
94
-
95
-	/**
96
-	 * Reset the maintenance mode and re-enable the trashbin app
97
-	 */
98
-	protected function resetMaintenanceAndTrashbin() {
99
-		$this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled);
100
-		if ($this->wasTrashbinEnabled) {
101
-			$this->appManager->enableApp('files_trashbin');
102
-		}
103
-	}
104
-
105
-	protected function configure() {
106
-		parent::configure();
107
-
108
-		$this->setName('encryption:decrypt-all');
109
-		$this->setDescription('Disable server-side encryption and decrypt all files');
110
-		$this->setHelp(
111
-			'This will disable server-side encryption and decrypt all files for '
112
-			. 'all users if it is supported by your encryption module. '
113
-			. 'Please make sure that no user access his files during this process!'
114
-		);
115
-		$this->addArgument(
116
-			'user',
117
-			InputArgument::OPTIONAL,
118
-			'user for which you want to decrypt all files (optional)',
119
-			''
120
-		);
121
-	}
122
-
123
-	protected function execute(InputInterface $input, OutputInterface $output) {
124
-
125
-		try {
126
-			if ($this->encryptionManager->isEnabled() === true) {
127
-				$output->write('Disable server side encryption... ');
128
-				$this->config->setAppValue('core', 'encryption_enabled', 'no');
129
-				$output->writeln('done.');
130
-			} else {
131
-				$output->writeln('Server side encryption not enabled. Nothing to do.');
132
-				return;
133
-			}
134
-
135
-			$uid = $input->getArgument('user');
136
-			if ($uid === '') {
137
-				$message = 'your Nextcloud';
138
-			} else {
139
-				$message = "$uid's account";
140
-			}
141
-
142
-			$output->writeln("\n");
143
-			$output->writeln("You are about to start to decrypt all files stored in $message.");
144
-			$output->writeln('It will depend on the encryption module and your setup if this is possible.');
145
-			$output->writeln('Depending on the number and size of your files this can take some time');
146
-			$output->writeln('Please make sure that no user access his files during this process!');
147
-			$output->writeln('');
148
-			$question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false);
149
-			if ($this->questionHelper->ask($input, $output, $question)) {
150
-				$this->forceMaintenanceAndTrashbin();
151
-				$user = $input->getArgument('user');
152
-				$result = $this->decryptAll->decryptAll($input, $output, $user);
153
-				if ($result === false) {
154
-					$output->writeln(' aborted.');
155
-					$output->writeln('Server side encryption remains enabled');
156
-					$this->config->setAppValue('core', 'encryption_enabled', 'yes');
157
-				} else if ($uid !== '') {
158
-					$output->writeln('Server side encryption remains enabled');
159
-					$this->config->setAppValue('core', 'encryption_enabled', 'yes');
160
-				}
161
-				$this->resetMaintenanceAndTrashbin();
162
-			} else {
163
-				$output->write('Enable server side encryption... ');
164
-				$this->config->setAppValue('core', 'encryption_enabled', 'yes');
165
-				$output->writeln('done.');
166
-				$output->writeln('aborted');
167
-			}
168
-		} catch (\Exception $e) {
169
-			// enable server side encryption again if something went wrong
170
-			$this->config->setAppValue('core', 'encryption_enabled', 'yes');
171
-			$this->resetMaintenanceAndTrashbin();
172
-			throw $e;
173
-		}
174
-
175
-	}
41
+    /** @var IManager */
42
+    protected $encryptionManager;
43
+
44
+    /** @var  IAppManager */
45
+    protected $appManager;
46
+
47
+    /** @var IConfig */
48
+    protected $config;
49
+
50
+    /** @var  QuestionHelper */
51
+    protected $questionHelper;
52
+
53
+    /** @var bool */
54
+    protected $wasTrashbinEnabled;
55
+
56
+    /** @var  bool */
57
+    protected $wasMaintenanceModeEnabled;
58
+
59
+    /** @var \OC\Encryption\DecryptAll */
60
+    protected $decryptAll;
61
+
62
+    /**
63
+     * @param IManager $encryptionManager
64
+     * @param IAppManager $appManager
65
+     * @param IConfig $config
66
+     * @param \OC\Encryption\DecryptAll $decryptAll
67
+     * @param QuestionHelper $questionHelper
68
+     */
69
+    public function __construct(
70
+        IManager $encryptionManager,
71
+        IAppManager $appManager,
72
+        IConfig $config,
73
+        \OC\Encryption\DecryptAll $decryptAll,
74
+        QuestionHelper $questionHelper
75
+    ) {
76
+        parent::__construct();
77
+
78
+        $this->appManager = $appManager;
79
+        $this->encryptionManager = $encryptionManager;
80
+        $this->config = $config;
81
+        $this->decryptAll = $decryptAll;
82
+        $this->questionHelper = $questionHelper;
83
+    }
84
+
85
+    /**
86
+     * Set maintenance mode and disable the trashbin app
87
+     */
88
+    protected function forceMaintenanceAndTrashbin() {
89
+        $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin');
90
+        $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
91
+        $this->config->setSystemValue('maintenance', true);
92
+        $this->appManager->disableApp('files_trashbin');
93
+    }
94
+
95
+    /**
96
+     * Reset the maintenance mode and re-enable the trashbin app
97
+     */
98
+    protected function resetMaintenanceAndTrashbin() {
99
+        $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled);
100
+        if ($this->wasTrashbinEnabled) {
101
+            $this->appManager->enableApp('files_trashbin');
102
+        }
103
+    }
104
+
105
+    protected function configure() {
106
+        parent::configure();
107
+
108
+        $this->setName('encryption:decrypt-all');
109
+        $this->setDescription('Disable server-side encryption and decrypt all files');
110
+        $this->setHelp(
111
+            'This will disable server-side encryption and decrypt all files for '
112
+            . 'all users if it is supported by your encryption module. '
113
+            . 'Please make sure that no user access his files during this process!'
114
+        );
115
+        $this->addArgument(
116
+            'user',
117
+            InputArgument::OPTIONAL,
118
+            'user for which you want to decrypt all files (optional)',
119
+            ''
120
+        );
121
+    }
122
+
123
+    protected function execute(InputInterface $input, OutputInterface $output) {
124
+
125
+        try {
126
+            if ($this->encryptionManager->isEnabled() === true) {
127
+                $output->write('Disable server side encryption... ');
128
+                $this->config->setAppValue('core', 'encryption_enabled', 'no');
129
+                $output->writeln('done.');
130
+            } else {
131
+                $output->writeln('Server side encryption not enabled. Nothing to do.');
132
+                return;
133
+            }
134
+
135
+            $uid = $input->getArgument('user');
136
+            if ($uid === '') {
137
+                $message = 'your Nextcloud';
138
+            } else {
139
+                $message = "$uid's account";
140
+            }
141
+
142
+            $output->writeln("\n");
143
+            $output->writeln("You are about to start to decrypt all files stored in $message.");
144
+            $output->writeln('It will depend on the encryption module and your setup if this is possible.');
145
+            $output->writeln('Depending on the number and size of your files this can take some time');
146
+            $output->writeln('Please make sure that no user access his files during this process!');
147
+            $output->writeln('');
148
+            $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false);
149
+            if ($this->questionHelper->ask($input, $output, $question)) {
150
+                $this->forceMaintenanceAndTrashbin();
151
+                $user = $input->getArgument('user');
152
+                $result = $this->decryptAll->decryptAll($input, $output, $user);
153
+                if ($result === false) {
154
+                    $output->writeln(' aborted.');
155
+                    $output->writeln('Server side encryption remains enabled');
156
+                    $this->config->setAppValue('core', 'encryption_enabled', 'yes');
157
+                } else if ($uid !== '') {
158
+                    $output->writeln('Server side encryption remains enabled');
159
+                    $this->config->setAppValue('core', 'encryption_enabled', 'yes');
160
+                }
161
+                $this->resetMaintenanceAndTrashbin();
162
+            } else {
163
+                $output->write('Enable server side encryption... ');
164
+                $this->config->setAppValue('core', 'encryption_enabled', 'yes');
165
+                $output->writeln('done.');
166
+                $output->writeln('aborted');
167
+            }
168
+        } catch (\Exception $e) {
169
+            // enable server side encryption again if something went wrong
170
+            $this->config->setAppValue('core', 'encryption_enabled', 'yes');
171
+            $this->resetMaintenanceAndTrashbin();
172
+            throw $e;
173
+        }
174
+
175
+    }
176 176
 }
Please login to merge, or discard this patch.
lib/private/OCS/Provider.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 			],
55 55
 		];
56 56
 
57
-		if($this->appManager->isEnabledForUser('files_sharing')) {
57
+		if ($this->appManager->isEnabledForUser('files_sharing')) {
58 58
 			$services['SHARING'] = [
59 59
 				'version' => 1,
60 60
 				'endpoints' => [
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 			}
86 86
 		}
87 87
 
88
-		if($this->appManager->isEnabledForUser('activity')) {
88
+		if ($this->appManager->isEnabledForUser('activity')) {
89 89
 			$services['ACTIVITY'] = [
90 90
 				'version' => 1,
91 91
 				'endpoints' => [
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 			];
95 95
 		}
96 96
 
97
-		if($this->appManager->isEnabledForUser('provisioning_api')) {
97
+		if ($this->appManager->isEnabledForUser('provisioning_api')) {
98 98
 			$services['PROVISIONING'] = [
99 99
 				'version' => 1,
100 100
 				'endpoints' => [
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -24,92 +24,92 @@
 block discarded – undo
24 24
 namespace OC\OCS;
25 25
 
26 26
 class Provider extends \OCP\AppFramework\Controller {
27
-	/** @var \OCP\App\IAppManager */
28
-	private $appManager;
27
+    /** @var \OCP\App\IAppManager */
28
+    private $appManager;
29 29
 
30
-	/**
31
-	 * @param string $appName
32
-	 * @param \OCP\IRequest $request
33
-	 * @param \OCP\App\IAppManager $appManager
34
-	 */
35
-	public function __construct($appName,
36
-								\OCP\IRequest $request,
37
-								\OCP\App\IAppManager $appManager) {
38
-		parent::__construct($appName, $request);
39
-		$this->appManager = $appManager;
40
-	}
30
+    /**
31
+     * @param string $appName
32
+     * @param \OCP\IRequest $request
33
+     * @param \OCP\App\IAppManager $appManager
34
+     */
35
+    public function __construct($appName,
36
+                                \OCP\IRequest $request,
37
+                                \OCP\App\IAppManager $appManager) {
38
+        parent::__construct($appName, $request);
39
+        $this->appManager = $appManager;
40
+    }
41 41
 
42
-	/**
43
-	 * @return \OCP\AppFramework\Http\JSONResponse
44
-	 */
45
-	public function buildProviderList() {
46
-		$services = [
47
-			'PRIVATE_DATA' => [
48
-				'version' => 1,
49
-				'endpoints' => [
50
-					'store' => '/ocs/v2.php/privatedata/setattribute',
51
-					'read' => '/ocs/v2.php/privatedata/getattribute',
52
-					'delete' => '/ocs/v2.php/privatedata/deleteattribute',
53
-				],
54
-			],
55
-		];
42
+    /**
43
+     * @return \OCP\AppFramework\Http\JSONResponse
44
+     */
45
+    public function buildProviderList() {
46
+        $services = [
47
+            'PRIVATE_DATA' => [
48
+                'version' => 1,
49
+                'endpoints' => [
50
+                    'store' => '/ocs/v2.php/privatedata/setattribute',
51
+                    'read' => '/ocs/v2.php/privatedata/getattribute',
52
+                    'delete' => '/ocs/v2.php/privatedata/deleteattribute',
53
+                ],
54
+            ],
55
+        ];
56 56
 
57
-		if($this->appManager->isEnabledForUser('files_sharing')) {
58
-			$services['SHARING'] = [
59
-				'version' => 1,
60
-				'endpoints' => [
61
-					'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
62
-				],
63
-			];
64
-			$services['FEDERATED_SHARING'] = [
65
-				'version' => 1,
66
-				'endpoints' => [
67
-					'share' => '/ocs/v2.php/cloud/shares',
68
-					'webdav' => '/public.php/webdav/',
69
-				],
70
-			];
71
-		}
57
+        if($this->appManager->isEnabledForUser('files_sharing')) {
58
+            $services['SHARING'] = [
59
+                'version' => 1,
60
+                'endpoints' => [
61
+                    'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
62
+                ],
63
+            ];
64
+            $services['FEDERATED_SHARING'] = [
65
+                'version' => 1,
66
+                'endpoints' => [
67
+                    'share' => '/ocs/v2.php/cloud/shares',
68
+                    'webdav' => '/public.php/webdav/',
69
+                ],
70
+            ];
71
+        }
72 72
 
73
-		if ($this->appManager->isEnabledForUser('federation')) {
74
-			if (isset($services['FEDERATED_SHARING'])) {
75
-				$services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret';
76
-				$services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system';
77
-				$services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system';
78
-			} else {
79
-				$services['FEDERATED_SHARING'] = [
80
-					'version' => 1,
81
-					'endpoints' => [
82
-						'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
83
-						'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
84
-						'carddav-user' => 'system'
85
-					],
86
-				];
87
-			}
88
-		}
73
+        if ($this->appManager->isEnabledForUser('federation')) {
74
+            if (isset($services['FEDERATED_SHARING'])) {
75
+                $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret';
76
+                $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system';
77
+                $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system';
78
+            } else {
79
+                $services['FEDERATED_SHARING'] = [
80
+                    'version' => 1,
81
+                    'endpoints' => [
82
+                        'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
83
+                        'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
84
+                        'carddav-user' => 'system'
85
+                    ],
86
+                ];
87
+            }
88
+        }
89 89
 
90
-		if($this->appManager->isEnabledForUser('activity')) {
91
-			$services['ACTIVITY'] = [
92
-				'version' => 1,
93
-				'endpoints' => [
94
-					'list' => '/ocs/v2.php/cloud/activity',
95
-				],
96
-			];
97
-		}
90
+        if($this->appManager->isEnabledForUser('activity')) {
91
+            $services['ACTIVITY'] = [
92
+                'version' => 1,
93
+                'endpoints' => [
94
+                    'list' => '/ocs/v2.php/cloud/activity',
95
+                ],
96
+            ];
97
+        }
98 98
 
99
-		if($this->appManager->isEnabledForUser('provisioning_api')) {
100
-			$services['PROVISIONING'] = [
101
-				'version' => 1,
102
-				'endpoints' => [
103
-					'user' => '/ocs/v2.php/cloud/users',
104
-					'groups' => '/ocs/v2.php/cloud/groups',
105
-					'apps' => '/ocs/v2.php/cloud/apps',
106
-				],
107
-			];
108
-		}
99
+        if($this->appManager->isEnabledForUser('provisioning_api')) {
100
+            $services['PROVISIONING'] = [
101
+                'version' => 1,
102
+                'endpoints' => [
103
+                    'user' => '/ocs/v2.php/cloud/users',
104
+                    'groups' => '/ocs/v2.php/cloud/groups',
105
+                    'apps' => '/ocs/v2.php/cloud/apps',
106
+                ],
107
+            ];
108
+        }
109 109
 
110
-		return new \OCP\AppFramework\Http\JSONResponse([
111
-			'version' => 2,
112
-			'services' => $services,
113
-		]);
114
-	}
110
+        return new \OCP\AppFramework\Http\JSONResponse([
111
+            'version' => 2,
112
+            'services' => $services,
113
+        ]);
114
+    }
115 115
 }
Please login to merge, or discard this patch.
apps/dav/lib/DAV/GroupPrincipalBackend.php 2 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -30,172 +30,172 @@
 block discarded – undo
30 30
 
31 31
 class GroupPrincipalBackend implements BackendInterface {
32 32
 
33
-	const PRINCIPAL_PREFIX = 'principals/groups';
34
-
35
-	/** @var IGroupManager */
36
-	private $groupManager;
37
-
38
-	/**
39
-	 * @param IGroupManager $IGroupManager
40
-	 */
41
-	public function __construct(IGroupManager $IGroupManager) {
42
-		$this->groupManager = $IGroupManager;
43
-	}
44
-
45
-	/**
46
-	 * Returns a list of principals based on a prefix.
47
-	 *
48
-	 * This prefix will often contain something like 'principals'. You are only
49
-	 * expected to return principals that are in this base path.
50
-	 *
51
-	 * You are expected to return at least a 'uri' for every user, you can
52
-	 * return any additional properties if you wish so. Common properties are:
53
-	 *   {DAV:}displayname
54
-	 *
55
-	 * @param string $prefixPath
56
-	 * @return string[]
57
-	 */
58
-	public function getPrincipalsByPrefix($prefixPath) {
59
-		$principals = [];
60
-
61
-		if ($prefixPath === self::PRINCIPAL_PREFIX) {
62
-			foreach($this->groupManager->search('') as $user) {
63
-				$principals[] = $this->groupToPrincipal($user);
64
-			}
65
-		}
66
-
67
-		return $principals;
68
-	}
69
-
70
-	/**
71
-	 * Returns a specific principal, specified by it's path.
72
-	 * The returned structure should be the exact same as from
73
-	 * getPrincipalsByPrefix.
74
-	 *
75
-	 * @param string $path
76
-	 * @return array
77
-	 */
78
-	public function getPrincipalByPath($path) {
79
-		$elements = explode('/', $path,  3);
80
-		if ($elements[0] !== 'principals') {
81
-			return null;
82
-		}
83
-		if ($elements[1] !== 'groups') {
84
-			return null;
85
-		}
86
-		$name = urldecode($elements[2]);
87
-		$group = $this->groupManager->get($name);
88
-
89
-		if (!is_null($group)) {
90
-			return $this->groupToPrincipal($group);
91
-		}
92
-
93
-		return null;
94
-	}
95
-
96
-	/**
97
-	 * Returns the list of members for a group-principal
98
-	 *
99
-	 * @param string $principal
100
-	 * @return string[]
101
-	 * @throws Exception
102
-	 */
103
-	public function getGroupMemberSet($principal) {
104
-		$elements = explode('/', $principal);
105
-		if ($elements[0] !== 'principals') {
106
-			return [];
107
-		}
108
-		if ($elements[1] !== 'groups') {
109
-			return [];
110
-		}
111
-		$name = $elements[2];
112
-		$group = $this->groupManager->get($name);
113
-
114
-		if (is_null($group)) {
115
-			return [];
116
-		}
117
-
118
-		return array_map(function($user) {
119
-			return $this->userToPrincipal($user);
120
-		}, $group->getUsers());
121
-	}
122
-
123
-	/**
124
-	 * Returns the list of groups a principal is a member of
125
-	 *
126
-	 * @param string $principal
127
-	 * @return array
128
-	 * @throws Exception
129
-	 */
130
-	public function getGroupMembership($principal) {
131
-		return [];
132
-	}
133
-
134
-	/**
135
-	 * Updates the list of group members for a group principal.
136
-	 *
137
-	 * The principals should be passed as a list of uri's.
138
-	 *
139
-	 * @param string $principal
140
-	 * @param string[] $members
141
-	 * @throws Exception
142
-	 */
143
-	public function setGroupMemberSet($principal, array $members) {
144
-		throw new Exception('Setting members of the group is not supported yet');
145
-	}
146
-
147
-	/**
148
-	 * @param string $path
149
-	 * @param PropPatch $propPatch
150
-	 * @return int
151
-	 */
152
-	function updatePrincipal($path, PropPatch $propPatch) {
153
-		return 0;
154
-	}
155
-
156
-	/**
157
-	 * @param string $prefixPath
158
-	 * @param array $searchProperties
159
-	 * @param string $test
160
-	 * @return array
161
-	 */
162
-	function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
163
-		return [];
164
-	}
165
-
166
-	/**
167
-	 * @param string $uri
168
-	 * @param string $principalPrefix
169
-	 * @return string
170
-	 */
171
-	function findByUri($uri, $principalPrefix) {
172
-		return '';
173
-	}
174
-
175
-	/**
176
-	 * @param IGroup $group
177
-	 * @return array
178
-	 */
179
-	protected function groupToPrincipal($group) {
180
-		$groupId = $group->getGID();
181
-		$principal = [
182
-			'uri' => 'principals/groups/' . urlencode($groupId),
183
-			'{DAV:}displayname' => $groupId,
184
-		];
185
-
186
-		return $principal;
187
-	}
188
-
189
-	/**
190
-	 * @param IUser $user
191
-	 * @return array
192
-	 */
193
-	protected function userToPrincipal($user) {
194
-		$principal = [
195
-			'uri' => 'principals/users/' . $user->getUID(),
196
-			'{DAV:}displayname' => $user->getDisplayName(),
197
-		];
198
-
199
-		return $principal;
200
-	}
33
+    const PRINCIPAL_PREFIX = 'principals/groups';
34
+
35
+    /** @var IGroupManager */
36
+    private $groupManager;
37
+
38
+    /**
39
+     * @param IGroupManager $IGroupManager
40
+     */
41
+    public function __construct(IGroupManager $IGroupManager) {
42
+        $this->groupManager = $IGroupManager;
43
+    }
44
+
45
+    /**
46
+     * Returns a list of principals based on a prefix.
47
+     *
48
+     * This prefix will often contain something like 'principals'. You are only
49
+     * expected to return principals that are in this base path.
50
+     *
51
+     * You are expected to return at least a 'uri' for every user, you can
52
+     * return any additional properties if you wish so. Common properties are:
53
+     *   {DAV:}displayname
54
+     *
55
+     * @param string $prefixPath
56
+     * @return string[]
57
+     */
58
+    public function getPrincipalsByPrefix($prefixPath) {
59
+        $principals = [];
60
+
61
+        if ($prefixPath === self::PRINCIPAL_PREFIX) {
62
+            foreach($this->groupManager->search('') as $user) {
63
+                $principals[] = $this->groupToPrincipal($user);
64
+            }
65
+        }
66
+
67
+        return $principals;
68
+    }
69
+
70
+    /**
71
+     * Returns a specific principal, specified by it's path.
72
+     * The returned structure should be the exact same as from
73
+     * getPrincipalsByPrefix.
74
+     *
75
+     * @param string $path
76
+     * @return array
77
+     */
78
+    public function getPrincipalByPath($path) {
79
+        $elements = explode('/', $path,  3);
80
+        if ($elements[0] !== 'principals') {
81
+            return null;
82
+        }
83
+        if ($elements[1] !== 'groups') {
84
+            return null;
85
+        }
86
+        $name = urldecode($elements[2]);
87
+        $group = $this->groupManager->get($name);
88
+
89
+        if (!is_null($group)) {
90
+            return $this->groupToPrincipal($group);
91
+        }
92
+
93
+        return null;
94
+    }
95
+
96
+    /**
97
+     * Returns the list of members for a group-principal
98
+     *
99
+     * @param string $principal
100
+     * @return string[]
101
+     * @throws Exception
102
+     */
103
+    public function getGroupMemberSet($principal) {
104
+        $elements = explode('/', $principal);
105
+        if ($elements[0] !== 'principals') {
106
+            return [];
107
+        }
108
+        if ($elements[1] !== 'groups') {
109
+            return [];
110
+        }
111
+        $name = $elements[2];
112
+        $group = $this->groupManager->get($name);
113
+
114
+        if (is_null($group)) {
115
+            return [];
116
+        }
117
+
118
+        return array_map(function($user) {
119
+            return $this->userToPrincipal($user);
120
+        }, $group->getUsers());
121
+    }
122
+
123
+    /**
124
+     * Returns the list of groups a principal is a member of
125
+     *
126
+     * @param string $principal
127
+     * @return array
128
+     * @throws Exception
129
+     */
130
+    public function getGroupMembership($principal) {
131
+        return [];
132
+    }
133
+
134
+    /**
135
+     * Updates the list of group members for a group principal.
136
+     *
137
+     * The principals should be passed as a list of uri's.
138
+     *
139
+     * @param string $principal
140
+     * @param string[] $members
141
+     * @throws Exception
142
+     */
143
+    public function setGroupMemberSet($principal, array $members) {
144
+        throw new Exception('Setting members of the group is not supported yet');
145
+    }
146
+
147
+    /**
148
+     * @param string $path
149
+     * @param PropPatch $propPatch
150
+     * @return int
151
+     */
152
+    function updatePrincipal($path, PropPatch $propPatch) {
153
+        return 0;
154
+    }
155
+
156
+    /**
157
+     * @param string $prefixPath
158
+     * @param array $searchProperties
159
+     * @param string $test
160
+     * @return array
161
+     */
162
+    function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
163
+        return [];
164
+    }
165
+
166
+    /**
167
+     * @param string $uri
168
+     * @param string $principalPrefix
169
+     * @return string
170
+     */
171
+    function findByUri($uri, $principalPrefix) {
172
+        return '';
173
+    }
174
+
175
+    /**
176
+     * @param IGroup $group
177
+     * @return array
178
+     */
179
+    protected function groupToPrincipal($group) {
180
+        $groupId = $group->getGID();
181
+        $principal = [
182
+            'uri' => 'principals/groups/' . urlencode($groupId),
183
+            '{DAV:}displayname' => $groupId,
184
+        ];
185
+
186
+        return $principal;
187
+    }
188
+
189
+    /**
190
+     * @param IUser $user
191
+     * @return array
192
+     */
193
+    protected function userToPrincipal($user) {
194
+        $principal = [
195
+            'uri' => 'principals/users/' . $user->getUID(),
196
+            '{DAV:}displayname' => $user->getDisplayName(),
197
+        ];
198
+
199
+        return $principal;
200
+    }
201 201
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		$principals = [];
60 60
 
61 61
 		if ($prefixPath === self::PRINCIPAL_PREFIX) {
62
-			foreach($this->groupManager->search('') as $user) {
62
+			foreach ($this->groupManager->search('') as $user) {
63 63
 				$principals[] = $this->groupToPrincipal($user);
64 64
 			}
65 65
 		}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @return array
77 77
 	 */
78 78
 	public function getPrincipalByPath($path) {
79
-		$elements = explode('/', $path,  3);
79
+		$elements = explode('/', $path, 3);
80 80
 		if ($elements[0] !== 'principals') {
81 81
 			return null;
82 82
 		}
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	protected function groupToPrincipal($group) {
180 180
 		$groupId = $group->getGID();
181 181
 		$principal = [
182
-			'uri' => 'principals/groups/' . urlencode($groupId),
182
+			'uri' => 'principals/groups/'.urlencode($groupId),
183 183
 			'{DAV:}displayname' => $groupId,
184 184
 		];
185 185
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 */
193 193
 	protected function userToPrincipal($user) {
194 194
 		$principal = [
195
-			'uri' => 'principals/users/' . $user->getUID(),
195
+			'uri' => 'principals/users/'.$user->getUID(),
196 196
 			'{DAV:}displayname' => $user->getDisplayName(),
197 197
 		];
198 198
 
Please login to merge, or discard this patch.