@@ -61,504 +61,504 @@ |
||
61 | 61 | */ |
62 | 62 | class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage, IDisableEncryptionStorage { |
63 | 63 | |
64 | - /** @var \OCP\Share\IShare */ |
|
65 | - private $superShare; |
|
66 | - |
|
67 | - /** @var \OCP\Share\IShare[] */ |
|
68 | - private $groupedShares; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var \OC\Files\View |
|
72 | - */ |
|
73 | - private $ownerView; |
|
74 | - |
|
75 | - private $initialized = false; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var ICacheEntry |
|
79 | - */ |
|
80 | - private $sourceRootInfo; |
|
81 | - |
|
82 | - /** @var string */ |
|
83 | - private $user; |
|
84 | - |
|
85 | - /** |
|
86 | - * @var \OCP\ILogger |
|
87 | - */ |
|
88 | - private $logger; |
|
89 | - |
|
90 | - /** @var IStorage */ |
|
91 | - private $nonMaskedStorage; |
|
92 | - |
|
93 | - private $options; |
|
94 | - |
|
95 | - /** @var boolean */ |
|
96 | - private $sharingDisabledForUser; |
|
97 | - |
|
98 | - /** @var ?Folder $ownerUserFolder */ |
|
99 | - private $ownerUserFolder = null; |
|
100 | - |
|
101 | - private string $sourcePath = ''; |
|
102 | - |
|
103 | - public function __construct($arguments) { |
|
104 | - $this->ownerView = $arguments['ownerView']; |
|
105 | - $this->logger = \OC::$server->getLogger(); |
|
106 | - |
|
107 | - $this->superShare = $arguments['superShare']; |
|
108 | - $this->groupedShares = $arguments['groupedShares']; |
|
109 | - |
|
110 | - $this->user = $arguments['user']; |
|
111 | - if (isset($arguments['sharingDisabledForUser'])) { |
|
112 | - $this->sharingDisabledForUser = $arguments['sharingDisabledForUser']; |
|
113 | - } else { |
|
114 | - $this->sharingDisabledForUser = false; |
|
115 | - } |
|
116 | - |
|
117 | - parent::__construct([ |
|
118 | - 'storage' => null, |
|
119 | - 'root' => null, |
|
120 | - ]); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @return ICacheEntry |
|
125 | - */ |
|
126 | - private function getSourceRootInfo() { |
|
127 | - if (is_null($this->sourceRootInfo)) { |
|
128 | - if (is_null($this->superShare->getNodeCacheEntry())) { |
|
129 | - $this->init(); |
|
130 | - $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
131 | - } else { |
|
132 | - $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
133 | - } |
|
134 | - } |
|
135 | - return $this->sourceRootInfo; |
|
136 | - } |
|
137 | - |
|
138 | - private function init() { |
|
139 | - if ($this->initialized) { |
|
140 | - return; |
|
141 | - } |
|
142 | - $this->initialized = true; |
|
143 | - try { |
|
144 | - /** @var IRootFolder $rootFolder */ |
|
145 | - $rootFolder = \OC::$server->get(IRootFolder::class); |
|
146 | - $this->ownerUserFolder = $rootFolder->getUserFolder($this->superShare->getShareOwner()); |
|
147 | - $sourceId = $this->superShare->getNodeId(); |
|
148 | - $ownerNodes = $this->ownerUserFolder->getById($sourceId); |
|
149 | - /** @var Node|false $ownerNode */ |
|
150 | - $ownerNode = current($ownerNodes); |
|
151 | - if (!$ownerNode) { |
|
152 | - $this->storage = new FailedStorage(['exception' => new NotFoundException("File by id $sourceId not found")]); |
|
153 | - $this->cache = new FailedCache(); |
|
154 | - $this->rootPath = ''; |
|
155 | - } else { |
|
156 | - $this->nonMaskedStorage = $ownerNode->getStorage(); |
|
157 | - $this->sourcePath = $ownerNode->getPath(); |
|
158 | - $this->rootPath = $ownerNode->getInternalPath(); |
|
159 | - $this->storage = new PermissionsMask([ |
|
160 | - 'storage' => $this->nonMaskedStorage, |
|
161 | - 'mask' => $this->superShare->getPermissions(), |
|
162 | - ]); |
|
163 | - } |
|
164 | - } catch (NotFoundException $e) { |
|
165 | - // original file not accessible or deleted, set FailedStorage |
|
166 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
167 | - $this->cache = new FailedCache(); |
|
168 | - $this->rootPath = ''; |
|
169 | - } catch (NoUserException $e) { |
|
170 | - // sharer user deleted, set FailedStorage |
|
171 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
172 | - $this->cache = new FailedCache(); |
|
173 | - $this->rootPath = ''; |
|
174 | - } catch (\Exception $e) { |
|
175 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
176 | - $this->cache = new FailedCache(); |
|
177 | - $this->rootPath = ''; |
|
178 | - $this->logger->logException($e); |
|
179 | - } |
|
180 | - |
|
181 | - if (!$this->nonMaskedStorage) { |
|
182 | - $this->nonMaskedStorage = $this->storage; |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @inheritdoc |
|
188 | - */ |
|
189 | - public function instanceOfStorage($class): bool { |
|
190 | - if ($class === '\OC\Files\Storage\Common' || $class == Common::class) { |
|
191 | - return true; |
|
192 | - } |
|
193 | - if (in_array($class, [ |
|
194 | - '\OC\Files\Storage\Home', |
|
195 | - '\OC\Files\ObjectStore\HomeObjectStoreStorage', |
|
196 | - '\OCP\Files\IHomeStorage', |
|
197 | - Home::class, |
|
198 | - HomeObjectStoreStorage::class, |
|
199 | - IHomeStorage::class |
|
200 | - ])) { |
|
201 | - return false; |
|
202 | - } |
|
203 | - return parent::instanceOfStorage($class); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public function getShareId() { |
|
210 | - return $this->superShare->getId(); |
|
211 | - } |
|
212 | - |
|
213 | - private function isValid(): bool { |
|
214 | - return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * get id of the mount point |
|
219 | - * |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function getId(): string { |
|
223 | - return 'shared::' . $this->getMountPoint(); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Get the permissions granted for a shared file |
|
228 | - * |
|
229 | - * @param string $target Shared target file path |
|
230 | - * @return int CRUDS permissions granted |
|
231 | - */ |
|
232 | - public function getPermissions($target = ''): int { |
|
233 | - if (!$this->isValid()) { |
|
234 | - return 0; |
|
235 | - } |
|
236 | - $permissions = parent::getPermissions($target) & $this->superShare->getPermissions(); |
|
237 | - |
|
238 | - // part files and the mount point always have delete permissions |
|
239 | - if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
240 | - $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
241 | - } |
|
242 | - |
|
243 | - if ($this->sharingDisabledForUser) { |
|
244 | - $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
245 | - } |
|
246 | - |
|
247 | - return $permissions; |
|
248 | - } |
|
249 | - |
|
250 | - public function isCreatable($path): bool { |
|
251 | - return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
252 | - } |
|
253 | - |
|
254 | - public function isReadable($path): bool { |
|
255 | - if (!$this->isValid()) { |
|
256 | - return false; |
|
257 | - } |
|
258 | - if (!$this->file_exists($path)) { |
|
259 | - return false; |
|
260 | - } |
|
261 | - /** @var IStorage $storage */ |
|
262 | - /** @var string $internalPath */ |
|
263 | - [$storage, $internalPath] = $this->resolvePath($path); |
|
264 | - return $storage->isReadable($internalPath); |
|
265 | - } |
|
266 | - |
|
267 | - public function isUpdatable($path): bool { |
|
268 | - return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
269 | - } |
|
270 | - |
|
271 | - public function isDeletable($path): bool { |
|
272 | - return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
273 | - } |
|
274 | - |
|
275 | - public function isSharable($path): bool { |
|
276 | - if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
277 | - return false; |
|
278 | - } |
|
279 | - return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
280 | - } |
|
281 | - |
|
282 | - public function fopen($path, $mode) { |
|
283 | - $source = $this->getUnjailedPath($path); |
|
284 | - switch ($mode) { |
|
285 | - case 'r+': |
|
286 | - case 'rb+': |
|
287 | - case 'w+': |
|
288 | - case 'wb+': |
|
289 | - case 'x+': |
|
290 | - case 'xb+': |
|
291 | - case 'a+': |
|
292 | - case 'ab+': |
|
293 | - case 'w': |
|
294 | - case 'wb': |
|
295 | - case 'x': |
|
296 | - case 'xb': |
|
297 | - case 'a': |
|
298 | - case 'ab': |
|
299 | - $creatable = $this->isCreatable(dirname($path)); |
|
300 | - $updatable = $this->isUpdatable($path); |
|
301 | - // if neither permissions given, no need to continue |
|
302 | - if (!$creatable && !$updatable) { |
|
303 | - if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
|
304 | - $updatable = $this->isUpdatable(dirname($path)); |
|
305 | - } |
|
306 | - |
|
307 | - if (!$updatable) { |
|
308 | - return false; |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - $exists = $this->file_exists($path); |
|
313 | - // if a file exists, updatable permissions are required |
|
314 | - if ($exists && !$updatable) { |
|
315 | - return false; |
|
316 | - } |
|
317 | - |
|
318 | - // part file is allowed if !$creatable but the final file is $updatable |
|
319 | - if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
320 | - if (!$exists && !$creatable) { |
|
321 | - return false; |
|
322 | - } |
|
323 | - } |
|
324 | - } |
|
325 | - $info = [ |
|
326 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
327 | - 'source' => $source, |
|
328 | - 'mode' => $mode, |
|
329 | - ]; |
|
330 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
331 | - return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * see https://www.php.net/manual/en/function.rename.php |
|
336 | - * |
|
337 | - * @param string $path1 |
|
338 | - * @param string $path2 |
|
339 | - * @return bool |
|
340 | - */ |
|
341 | - public function rename($path1, $path2): bool { |
|
342 | - $this->init(); |
|
343 | - $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
344 | - $targetExists = $this->file_exists($path2); |
|
345 | - $sameFolder = dirname($path1) === dirname($path2); |
|
346 | - |
|
347 | - if ($targetExists || ($sameFolder && !$isPartFile)) { |
|
348 | - if (!$this->isUpdatable('')) { |
|
349 | - return false; |
|
350 | - } |
|
351 | - } else { |
|
352 | - if (!$this->isCreatable('')) { |
|
353 | - return false; |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * return mount point of share, relative to data/user/files |
|
362 | - * |
|
363 | - * @return string |
|
364 | - */ |
|
365 | - public function getMountPoint(): string { |
|
366 | - return $this->superShare->getTarget(); |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * @param string $path |
|
371 | - */ |
|
372 | - public function setMountPoint($path): void { |
|
373 | - $this->superShare->setTarget($path); |
|
374 | - |
|
375 | - foreach ($this->groupedShares as $share) { |
|
376 | - $share->setTarget($path); |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * get the user who shared the file |
|
382 | - * |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public function getSharedFrom(): string { |
|
386 | - return $this->superShare->getShareOwner(); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * @return \OCP\Share\IShare |
|
391 | - */ |
|
392 | - public function getShare(): IShare { |
|
393 | - return $this->superShare; |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * return share type, can be "file" or "folder" |
|
398 | - * |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function getItemType(): string { |
|
402 | - return $this->superShare->getNodeType(); |
|
403 | - } |
|
404 | - |
|
405 | - public function getCache($path = '', $storage = null) { |
|
406 | - if ($this->cache) { |
|
407 | - return $this->cache; |
|
408 | - } |
|
409 | - if (!$storage) { |
|
410 | - $storage = $this; |
|
411 | - } |
|
412 | - $sourceRoot = $this->getSourceRootInfo(); |
|
413 | - if ($this->storage instanceof FailedStorage) { |
|
414 | - return new FailedCache(); |
|
415 | - } |
|
416 | - |
|
417 | - $this->cache = new \OCA\Files_Sharing\Cache( |
|
418 | - $storage, |
|
419 | - $sourceRoot, |
|
420 | - \OC::$server->get(DisplayNameCache::class) |
|
421 | - ); |
|
422 | - return $this->cache; |
|
423 | - } |
|
424 | - |
|
425 | - public function getScanner($path = '', $storage = null) { |
|
426 | - if (!$storage) { |
|
427 | - $storage = $this; |
|
428 | - } |
|
429 | - return new \OCA\Files_Sharing\Scanner($storage); |
|
430 | - } |
|
431 | - |
|
432 | - public function getOwner($path): string { |
|
433 | - return $this->superShare->getShareOwner(); |
|
434 | - } |
|
435 | - |
|
436 | - public function getWatcher($path = '', $storage = null): Watcher { |
|
437 | - $mountManager = \OC::$server->getMountManager(); |
|
438 | - |
|
439 | - // Get node informations |
|
440 | - $node = $this->getShare()->getNodeCacheEntry(); |
|
441 | - if ($node) { |
|
442 | - $mount = $mountManager->findByNumericId($node->getStorageId()); |
|
443 | - // If the share is originating from an external storage |
|
444 | - if (count($mount) > 0 && $mount[0] instanceof ExternalMountPoint) { |
|
445 | - // Propagate original storage scan |
|
446 | - return parent::getWatcher($path, $storage); |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - // cache updating is handled by the share source |
|
451 | - return new NullWatcher(); |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * unshare complete storage, also the grouped shares |
|
456 | - * |
|
457 | - * @return bool |
|
458 | - */ |
|
459 | - public function unshareStorage(): bool { |
|
460 | - foreach ($this->groupedShares as $share) { |
|
461 | - \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
462 | - } |
|
463 | - return true; |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * @param string $path |
|
468 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
469 | - * @param \OCP\Lock\ILockingProvider $provider |
|
470 | - * @throws \OCP\Lock\LockedException |
|
471 | - */ |
|
472 | - public function acquireLock($path, $type, ILockingProvider $provider) { |
|
473 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
474 | - [$targetStorage, $targetInternalPath] = $this->resolvePath($path); |
|
475 | - $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
476 | - // lock the parent folders of the owner when locking the share as recipient |
|
477 | - if ($path === '') { |
|
478 | - $sourcePath = $this->ownerUserFolder->getRelativePath($this->sourcePath); |
|
479 | - $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
480 | - } |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * @param string $path |
|
485 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
486 | - * @param \OCP\Lock\ILockingProvider $provider |
|
487 | - */ |
|
488 | - public function releaseLock($path, $type, ILockingProvider $provider) { |
|
489 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
490 | - [$targetStorage, $targetInternalPath] = $this->resolvePath($path); |
|
491 | - $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
492 | - // unlock the parent folders of the owner when unlocking the share as recipient |
|
493 | - if ($path === '') { |
|
494 | - $sourcePath = $this->ownerUserFolder->getRelativePath($this->sourcePath); |
|
495 | - $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
496 | - } |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * @param string $path |
|
501 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
502 | - * @param \OCP\Lock\ILockingProvider $provider |
|
503 | - */ |
|
504 | - public function changeLock($path, $type, ILockingProvider $provider) { |
|
505 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
506 | - [$targetStorage, $targetInternalPath] = $this->resolvePath($path); |
|
507 | - $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * @return array [ available, last_checked ] |
|
512 | - */ |
|
513 | - public function getAvailability() { |
|
514 | - // shares do not participate in availability logic |
|
515 | - return [ |
|
516 | - 'available' => true, |
|
517 | - 'last_checked' => 0, |
|
518 | - ]; |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * @param bool $available |
|
523 | - */ |
|
524 | - public function setAvailability($available) { |
|
525 | - // shares do not participate in availability logic |
|
526 | - } |
|
527 | - |
|
528 | - public function getSourceStorage() { |
|
529 | - $this->init(); |
|
530 | - return $this->nonMaskedStorage; |
|
531 | - } |
|
532 | - |
|
533 | - public function getWrapperStorage() { |
|
534 | - $this->init(); |
|
535 | - return $this->storage; |
|
536 | - } |
|
537 | - |
|
538 | - public function file_get_contents($path) { |
|
539 | - $info = [ |
|
540 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
541 | - 'source' => $this->getUnjailedPath($path), |
|
542 | - ]; |
|
543 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
544 | - return parent::file_get_contents($path); |
|
545 | - } |
|
546 | - |
|
547 | - public function file_put_contents($path, $data) { |
|
548 | - $info = [ |
|
549 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
550 | - 'source' => $this->getUnjailedPath($path), |
|
551 | - ]; |
|
552 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
553 | - return parent::file_put_contents($path, $data); |
|
554 | - } |
|
555 | - |
|
556 | - public function setMountOptions(array $options) { |
|
557 | - $this->mountOptions = $options; |
|
558 | - } |
|
559 | - |
|
560 | - public function getUnjailedPath($path) { |
|
561 | - $this->init(); |
|
562 | - return parent::getUnjailedPath($path); |
|
563 | - } |
|
64 | + /** @var \OCP\Share\IShare */ |
|
65 | + private $superShare; |
|
66 | + |
|
67 | + /** @var \OCP\Share\IShare[] */ |
|
68 | + private $groupedShares; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var \OC\Files\View |
|
72 | + */ |
|
73 | + private $ownerView; |
|
74 | + |
|
75 | + private $initialized = false; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var ICacheEntry |
|
79 | + */ |
|
80 | + private $sourceRootInfo; |
|
81 | + |
|
82 | + /** @var string */ |
|
83 | + private $user; |
|
84 | + |
|
85 | + /** |
|
86 | + * @var \OCP\ILogger |
|
87 | + */ |
|
88 | + private $logger; |
|
89 | + |
|
90 | + /** @var IStorage */ |
|
91 | + private $nonMaskedStorage; |
|
92 | + |
|
93 | + private $options; |
|
94 | + |
|
95 | + /** @var boolean */ |
|
96 | + private $sharingDisabledForUser; |
|
97 | + |
|
98 | + /** @var ?Folder $ownerUserFolder */ |
|
99 | + private $ownerUserFolder = null; |
|
100 | + |
|
101 | + private string $sourcePath = ''; |
|
102 | + |
|
103 | + public function __construct($arguments) { |
|
104 | + $this->ownerView = $arguments['ownerView']; |
|
105 | + $this->logger = \OC::$server->getLogger(); |
|
106 | + |
|
107 | + $this->superShare = $arguments['superShare']; |
|
108 | + $this->groupedShares = $arguments['groupedShares']; |
|
109 | + |
|
110 | + $this->user = $arguments['user']; |
|
111 | + if (isset($arguments['sharingDisabledForUser'])) { |
|
112 | + $this->sharingDisabledForUser = $arguments['sharingDisabledForUser']; |
|
113 | + } else { |
|
114 | + $this->sharingDisabledForUser = false; |
|
115 | + } |
|
116 | + |
|
117 | + parent::__construct([ |
|
118 | + 'storage' => null, |
|
119 | + 'root' => null, |
|
120 | + ]); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @return ICacheEntry |
|
125 | + */ |
|
126 | + private function getSourceRootInfo() { |
|
127 | + if (is_null($this->sourceRootInfo)) { |
|
128 | + if (is_null($this->superShare->getNodeCacheEntry())) { |
|
129 | + $this->init(); |
|
130 | + $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
131 | + } else { |
|
132 | + $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
133 | + } |
|
134 | + } |
|
135 | + return $this->sourceRootInfo; |
|
136 | + } |
|
137 | + |
|
138 | + private function init() { |
|
139 | + if ($this->initialized) { |
|
140 | + return; |
|
141 | + } |
|
142 | + $this->initialized = true; |
|
143 | + try { |
|
144 | + /** @var IRootFolder $rootFolder */ |
|
145 | + $rootFolder = \OC::$server->get(IRootFolder::class); |
|
146 | + $this->ownerUserFolder = $rootFolder->getUserFolder($this->superShare->getShareOwner()); |
|
147 | + $sourceId = $this->superShare->getNodeId(); |
|
148 | + $ownerNodes = $this->ownerUserFolder->getById($sourceId); |
|
149 | + /** @var Node|false $ownerNode */ |
|
150 | + $ownerNode = current($ownerNodes); |
|
151 | + if (!$ownerNode) { |
|
152 | + $this->storage = new FailedStorage(['exception' => new NotFoundException("File by id $sourceId not found")]); |
|
153 | + $this->cache = new FailedCache(); |
|
154 | + $this->rootPath = ''; |
|
155 | + } else { |
|
156 | + $this->nonMaskedStorage = $ownerNode->getStorage(); |
|
157 | + $this->sourcePath = $ownerNode->getPath(); |
|
158 | + $this->rootPath = $ownerNode->getInternalPath(); |
|
159 | + $this->storage = new PermissionsMask([ |
|
160 | + 'storage' => $this->nonMaskedStorage, |
|
161 | + 'mask' => $this->superShare->getPermissions(), |
|
162 | + ]); |
|
163 | + } |
|
164 | + } catch (NotFoundException $e) { |
|
165 | + // original file not accessible or deleted, set FailedStorage |
|
166 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
167 | + $this->cache = new FailedCache(); |
|
168 | + $this->rootPath = ''; |
|
169 | + } catch (NoUserException $e) { |
|
170 | + // sharer user deleted, set FailedStorage |
|
171 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
172 | + $this->cache = new FailedCache(); |
|
173 | + $this->rootPath = ''; |
|
174 | + } catch (\Exception $e) { |
|
175 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
176 | + $this->cache = new FailedCache(); |
|
177 | + $this->rootPath = ''; |
|
178 | + $this->logger->logException($e); |
|
179 | + } |
|
180 | + |
|
181 | + if (!$this->nonMaskedStorage) { |
|
182 | + $this->nonMaskedStorage = $this->storage; |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @inheritdoc |
|
188 | + */ |
|
189 | + public function instanceOfStorage($class): bool { |
|
190 | + if ($class === '\OC\Files\Storage\Common' || $class == Common::class) { |
|
191 | + return true; |
|
192 | + } |
|
193 | + if (in_array($class, [ |
|
194 | + '\OC\Files\Storage\Home', |
|
195 | + '\OC\Files\ObjectStore\HomeObjectStoreStorage', |
|
196 | + '\OCP\Files\IHomeStorage', |
|
197 | + Home::class, |
|
198 | + HomeObjectStoreStorage::class, |
|
199 | + IHomeStorage::class |
|
200 | + ])) { |
|
201 | + return false; |
|
202 | + } |
|
203 | + return parent::instanceOfStorage($class); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public function getShareId() { |
|
210 | + return $this->superShare->getId(); |
|
211 | + } |
|
212 | + |
|
213 | + private function isValid(): bool { |
|
214 | + return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * get id of the mount point |
|
219 | + * |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function getId(): string { |
|
223 | + return 'shared::' . $this->getMountPoint(); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Get the permissions granted for a shared file |
|
228 | + * |
|
229 | + * @param string $target Shared target file path |
|
230 | + * @return int CRUDS permissions granted |
|
231 | + */ |
|
232 | + public function getPermissions($target = ''): int { |
|
233 | + if (!$this->isValid()) { |
|
234 | + return 0; |
|
235 | + } |
|
236 | + $permissions = parent::getPermissions($target) & $this->superShare->getPermissions(); |
|
237 | + |
|
238 | + // part files and the mount point always have delete permissions |
|
239 | + if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
240 | + $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
241 | + } |
|
242 | + |
|
243 | + if ($this->sharingDisabledForUser) { |
|
244 | + $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
245 | + } |
|
246 | + |
|
247 | + return $permissions; |
|
248 | + } |
|
249 | + |
|
250 | + public function isCreatable($path): bool { |
|
251 | + return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
252 | + } |
|
253 | + |
|
254 | + public function isReadable($path): bool { |
|
255 | + if (!$this->isValid()) { |
|
256 | + return false; |
|
257 | + } |
|
258 | + if (!$this->file_exists($path)) { |
|
259 | + return false; |
|
260 | + } |
|
261 | + /** @var IStorage $storage */ |
|
262 | + /** @var string $internalPath */ |
|
263 | + [$storage, $internalPath] = $this->resolvePath($path); |
|
264 | + return $storage->isReadable($internalPath); |
|
265 | + } |
|
266 | + |
|
267 | + public function isUpdatable($path): bool { |
|
268 | + return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
269 | + } |
|
270 | + |
|
271 | + public function isDeletable($path): bool { |
|
272 | + return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
273 | + } |
|
274 | + |
|
275 | + public function isSharable($path): bool { |
|
276 | + if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
277 | + return false; |
|
278 | + } |
|
279 | + return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
280 | + } |
|
281 | + |
|
282 | + public function fopen($path, $mode) { |
|
283 | + $source = $this->getUnjailedPath($path); |
|
284 | + switch ($mode) { |
|
285 | + case 'r+': |
|
286 | + case 'rb+': |
|
287 | + case 'w+': |
|
288 | + case 'wb+': |
|
289 | + case 'x+': |
|
290 | + case 'xb+': |
|
291 | + case 'a+': |
|
292 | + case 'ab+': |
|
293 | + case 'w': |
|
294 | + case 'wb': |
|
295 | + case 'x': |
|
296 | + case 'xb': |
|
297 | + case 'a': |
|
298 | + case 'ab': |
|
299 | + $creatable = $this->isCreatable(dirname($path)); |
|
300 | + $updatable = $this->isUpdatable($path); |
|
301 | + // if neither permissions given, no need to continue |
|
302 | + if (!$creatable && !$updatable) { |
|
303 | + if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
|
304 | + $updatable = $this->isUpdatable(dirname($path)); |
|
305 | + } |
|
306 | + |
|
307 | + if (!$updatable) { |
|
308 | + return false; |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + $exists = $this->file_exists($path); |
|
313 | + // if a file exists, updatable permissions are required |
|
314 | + if ($exists && !$updatable) { |
|
315 | + return false; |
|
316 | + } |
|
317 | + |
|
318 | + // part file is allowed if !$creatable but the final file is $updatable |
|
319 | + if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
320 | + if (!$exists && !$creatable) { |
|
321 | + return false; |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | + $info = [ |
|
326 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
327 | + 'source' => $source, |
|
328 | + 'mode' => $mode, |
|
329 | + ]; |
|
330 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
331 | + return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * see https://www.php.net/manual/en/function.rename.php |
|
336 | + * |
|
337 | + * @param string $path1 |
|
338 | + * @param string $path2 |
|
339 | + * @return bool |
|
340 | + */ |
|
341 | + public function rename($path1, $path2): bool { |
|
342 | + $this->init(); |
|
343 | + $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
344 | + $targetExists = $this->file_exists($path2); |
|
345 | + $sameFolder = dirname($path1) === dirname($path2); |
|
346 | + |
|
347 | + if ($targetExists || ($sameFolder && !$isPartFile)) { |
|
348 | + if (!$this->isUpdatable('')) { |
|
349 | + return false; |
|
350 | + } |
|
351 | + } else { |
|
352 | + if (!$this->isCreatable('')) { |
|
353 | + return false; |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * return mount point of share, relative to data/user/files |
|
362 | + * |
|
363 | + * @return string |
|
364 | + */ |
|
365 | + public function getMountPoint(): string { |
|
366 | + return $this->superShare->getTarget(); |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * @param string $path |
|
371 | + */ |
|
372 | + public function setMountPoint($path): void { |
|
373 | + $this->superShare->setTarget($path); |
|
374 | + |
|
375 | + foreach ($this->groupedShares as $share) { |
|
376 | + $share->setTarget($path); |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * get the user who shared the file |
|
382 | + * |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public function getSharedFrom(): string { |
|
386 | + return $this->superShare->getShareOwner(); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * @return \OCP\Share\IShare |
|
391 | + */ |
|
392 | + public function getShare(): IShare { |
|
393 | + return $this->superShare; |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * return share type, can be "file" or "folder" |
|
398 | + * |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function getItemType(): string { |
|
402 | + return $this->superShare->getNodeType(); |
|
403 | + } |
|
404 | + |
|
405 | + public function getCache($path = '', $storage = null) { |
|
406 | + if ($this->cache) { |
|
407 | + return $this->cache; |
|
408 | + } |
|
409 | + if (!$storage) { |
|
410 | + $storage = $this; |
|
411 | + } |
|
412 | + $sourceRoot = $this->getSourceRootInfo(); |
|
413 | + if ($this->storage instanceof FailedStorage) { |
|
414 | + return new FailedCache(); |
|
415 | + } |
|
416 | + |
|
417 | + $this->cache = new \OCA\Files_Sharing\Cache( |
|
418 | + $storage, |
|
419 | + $sourceRoot, |
|
420 | + \OC::$server->get(DisplayNameCache::class) |
|
421 | + ); |
|
422 | + return $this->cache; |
|
423 | + } |
|
424 | + |
|
425 | + public function getScanner($path = '', $storage = null) { |
|
426 | + if (!$storage) { |
|
427 | + $storage = $this; |
|
428 | + } |
|
429 | + return new \OCA\Files_Sharing\Scanner($storage); |
|
430 | + } |
|
431 | + |
|
432 | + public function getOwner($path): string { |
|
433 | + return $this->superShare->getShareOwner(); |
|
434 | + } |
|
435 | + |
|
436 | + public function getWatcher($path = '', $storage = null): Watcher { |
|
437 | + $mountManager = \OC::$server->getMountManager(); |
|
438 | + |
|
439 | + // Get node informations |
|
440 | + $node = $this->getShare()->getNodeCacheEntry(); |
|
441 | + if ($node) { |
|
442 | + $mount = $mountManager->findByNumericId($node->getStorageId()); |
|
443 | + // If the share is originating from an external storage |
|
444 | + if (count($mount) > 0 && $mount[0] instanceof ExternalMountPoint) { |
|
445 | + // Propagate original storage scan |
|
446 | + return parent::getWatcher($path, $storage); |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + // cache updating is handled by the share source |
|
451 | + return new NullWatcher(); |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * unshare complete storage, also the grouped shares |
|
456 | + * |
|
457 | + * @return bool |
|
458 | + */ |
|
459 | + public function unshareStorage(): bool { |
|
460 | + foreach ($this->groupedShares as $share) { |
|
461 | + \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
462 | + } |
|
463 | + return true; |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * @param string $path |
|
468 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
469 | + * @param \OCP\Lock\ILockingProvider $provider |
|
470 | + * @throws \OCP\Lock\LockedException |
|
471 | + */ |
|
472 | + public function acquireLock($path, $type, ILockingProvider $provider) { |
|
473 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
474 | + [$targetStorage, $targetInternalPath] = $this->resolvePath($path); |
|
475 | + $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
476 | + // lock the parent folders of the owner when locking the share as recipient |
|
477 | + if ($path === '') { |
|
478 | + $sourcePath = $this->ownerUserFolder->getRelativePath($this->sourcePath); |
|
479 | + $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
480 | + } |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * @param string $path |
|
485 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
486 | + * @param \OCP\Lock\ILockingProvider $provider |
|
487 | + */ |
|
488 | + public function releaseLock($path, $type, ILockingProvider $provider) { |
|
489 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
490 | + [$targetStorage, $targetInternalPath] = $this->resolvePath($path); |
|
491 | + $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
492 | + // unlock the parent folders of the owner when unlocking the share as recipient |
|
493 | + if ($path === '') { |
|
494 | + $sourcePath = $this->ownerUserFolder->getRelativePath($this->sourcePath); |
|
495 | + $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
496 | + } |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * @param string $path |
|
501 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
502 | + * @param \OCP\Lock\ILockingProvider $provider |
|
503 | + */ |
|
504 | + public function changeLock($path, $type, ILockingProvider $provider) { |
|
505 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
506 | + [$targetStorage, $targetInternalPath] = $this->resolvePath($path); |
|
507 | + $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * @return array [ available, last_checked ] |
|
512 | + */ |
|
513 | + public function getAvailability() { |
|
514 | + // shares do not participate in availability logic |
|
515 | + return [ |
|
516 | + 'available' => true, |
|
517 | + 'last_checked' => 0, |
|
518 | + ]; |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * @param bool $available |
|
523 | + */ |
|
524 | + public function setAvailability($available) { |
|
525 | + // shares do not participate in availability logic |
|
526 | + } |
|
527 | + |
|
528 | + public function getSourceStorage() { |
|
529 | + $this->init(); |
|
530 | + return $this->nonMaskedStorage; |
|
531 | + } |
|
532 | + |
|
533 | + public function getWrapperStorage() { |
|
534 | + $this->init(); |
|
535 | + return $this->storage; |
|
536 | + } |
|
537 | + |
|
538 | + public function file_get_contents($path) { |
|
539 | + $info = [ |
|
540 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
541 | + 'source' => $this->getUnjailedPath($path), |
|
542 | + ]; |
|
543 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
544 | + return parent::file_get_contents($path); |
|
545 | + } |
|
546 | + |
|
547 | + public function file_put_contents($path, $data) { |
|
548 | + $info = [ |
|
549 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
550 | + 'source' => $this->getUnjailedPath($path), |
|
551 | + ]; |
|
552 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
553 | + return parent::file_put_contents($path, $data); |
|
554 | + } |
|
555 | + |
|
556 | + public function setMountOptions(array $options) { |
|
557 | + $this->mountOptions = $options; |
|
558 | + } |
|
559 | + |
|
560 | + public function getUnjailedPath($path) { |
|
561 | + $this->init(); |
|
562 | + return parent::getUnjailedPath($path); |
|
563 | + } |
|
564 | 564 | } |
@@ -48,153 +48,153 @@ |
||
48 | 48 | * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead |
49 | 49 | */ |
50 | 50 | class Cache extends CacheJail { |
51 | - /** @var SharedStorage */ |
|
52 | - private $storage; |
|
53 | - private ICacheEntry $sourceRootInfo; |
|
54 | - private bool $rootUnchanged = true; |
|
55 | - private ?string $ownerDisplayName = null; |
|
56 | - private $numericId; |
|
57 | - private DisplayNameCache $displayNameCache; |
|
58 | - |
|
59 | - /** |
|
60 | - * @param SharedStorage $storage |
|
61 | - */ |
|
62 | - public function __construct($storage, ICacheEntry $sourceRootInfo, DisplayNameCache $displayNameCache) { |
|
63 | - $this->storage = $storage; |
|
64 | - $this->sourceRootInfo = $sourceRootInfo; |
|
65 | - $this->numericId = $sourceRootInfo->getStorageId(); |
|
66 | - $this->displayNameCache = $displayNameCache; |
|
67 | - |
|
68 | - parent::__construct( |
|
69 | - null, |
|
70 | - '' |
|
71 | - ); |
|
72 | - } |
|
73 | - |
|
74 | - protected function getRoot() { |
|
75 | - if ($this->root === '') { |
|
76 | - $absoluteRoot = $this->sourceRootInfo->getPath(); |
|
77 | - |
|
78 | - // the sourceRootInfo path is the absolute path of the folder in the "real" storage |
|
79 | - // in the case where a folder is shared from a Jail we need to ensure that the share Jail |
|
80 | - // has it's root set relative to the source Jail |
|
81 | - $currentStorage = $this->storage->getSourceStorage(); |
|
82 | - if ($currentStorage->instanceOfStorage(Jail::class)) { |
|
83 | - /** @var Jail $currentStorage */ |
|
84 | - $absoluteRoot = $currentStorage->getJailedPath($absoluteRoot); |
|
85 | - } |
|
86 | - $this->root = $absoluteRoot; |
|
87 | - } |
|
88 | - return $this->root; |
|
89 | - } |
|
90 | - |
|
91 | - protected function getGetUnjailedRoot() { |
|
92 | - return $this->sourceRootInfo->getPath(); |
|
93 | - } |
|
94 | - |
|
95 | - public function getCache() { |
|
96 | - if (is_null($this->cache)) { |
|
97 | - $sourceStorage = $this->storage->getSourceStorage(); |
|
98 | - if ($sourceStorage) { |
|
99 | - $this->cache = $sourceStorage->getCache(); |
|
100 | - } else { |
|
101 | - // don't set $this->cache here since sourceStorage will be set later |
|
102 | - return new FailedCache(); |
|
103 | - } |
|
104 | - } |
|
105 | - return $this->cache; |
|
106 | - } |
|
107 | - |
|
108 | - public function getNumericStorageId() { |
|
109 | - if (isset($this->numericId)) { |
|
110 | - return $this->numericId; |
|
111 | - } else { |
|
112 | - return false; |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - public function get($file) { |
|
117 | - if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { |
|
118 | - return $this->formatCacheEntry(clone $this->sourceRootInfo, ''); |
|
119 | - } |
|
120 | - return parent::get($file); |
|
121 | - } |
|
122 | - |
|
123 | - public function update($id, array $data) { |
|
124 | - $this->rootUnchanged = false; |
|
125 | - parent::update($id, $data); |
|
126 | - } |
|
127 | - |
|
128 | - public function insert($file, array $data) { |
|
129 | - $this->rootUnchanged = false; |
|
130 | - return parent::insert($file, $data); |
|
131 | - } |
|
132 | - |
|
133 | - public function remove($file) { |
|
134 | - $this->rootUnchanged = false; |
|
135 | - parent::remove($file); |
|
136 | - } |
|
137 | - |
|
138 | - public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
139 | - $this->rootUnchanged = false; |
|
140 | - return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
141 | - } |
|
142 | - |
|
143 | - protected function formatCacheEntry($entry, $path = null) { |
|
144 | - if (is_null($path)) { |
|
145 | - $path = $entry['path'] ?? ''; |
|
146 | - $entry['path'] = $this->getJailedPath($path); |
|
147 | - } else { |
|
148 | - $entry['path'] = $path; |
|
149 | - } |
|
150 | - |
|
151 | - try { |
|
152 | - if (isset($entry['permissions'])) { |
|
153 | - $entry['permissions'] &= $this->storage->getShare()->getPermissions(); |
|
154 | - } else { |
|
155 | - $entry['permissions'] = $this->storage->getPermissions($entry['path']); |
|
156 | - } |
|
157 | - } catch (StorageNotAvailableException $e) { |
|
158 | - // thrown by FailedStorage e.g. when the sharer does not exist anymore |
|
159 | - // (IDE may say the exception is never thrown – false negative) |
|
160 | - $sharePermissions = 0; |
|
161 | - } |
|
162 | - $entry['uid_owner'] = $this->storage->getOwner(''); |
|
163 | - $entry['displayname_owner'] = $this->getOwnerDisplayName(); |
|
164 | - if ($path === '') { |
|
165 | - $entry['is_share_mount_point'] = true; |
|
166 | - } |
|
167 | - return $entry; |
|
168 | - } |
|
169 | - |
|
170 | - private function getOwnerDisplayName() { |
|
171 | - if (!$this->ownerDisplayName) { |
|
172 | - $uid = $this->storage->getOwner(''); |
|
173 | - $this->ownerDisplayName = $this->displayNameCache->getDisplayName($uid); |
|
174 | - } |
|
175 | - return $this->ownerDisplayName; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * remove all entries for files that are stored on the storage from the cache |
|
180 | - */ |
|
181 | - public function clear() { |
|
182 | - // Not a valid action for Shared Cache |
|
183 | - } |
|
184 | - |
|
185 | - public function getQueryFilterForStorage(): ISearchOperator { |
|
186 | - // Do the normal jail behavior for non files |
|
187 | - if ($this->storage->getItemType() !== 'file') { |
|
188 | - return parent::getQueryFilterForStorage(); |
|
189 | - } |
|
190 | - |
|
191 | - // for single file shares we don't need to do the LIKE |
|
192 | - return new SearchBinaryOperator( |
|
193 | - ISearchBinaryOperator::OPERATOR_AND, |
|
194 | - [ |
|
195 | - \OC\Files\Cache\Cache::getQueryFilterForStorage(), |
|
196 | - new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()), |
|
197 | - ] |
|
198 | - ); |
|
199 | - } |
|
51 | + /** @var SharedStorage */ |
|
52 | + private $storage; |
|
53 | + private ICacheEntry $sourceRootInfo; |
|
54 | + private bool $rootUnchanged = true; |
|
55 | + private ?string $ownerDisplayName = null; |
|
56 | + private $numericId; |
|
57 | + private DisplayNameCache $displayNameCache; |
|
58 | + |
|
59 | + /** |
|
60 | + * @param SharedStorage $storage |
|
61 | + */ |
|
62 | + public function __construct($storage, ICacheEntry $sourceRootInfo, DisplayNameCache $displayNameCache) { |
|
63 | + $this->storage = $storage; |
|
64 | + $this->sourceRootInfo = $sourceRootInfo; |
|
65 | + $this->numericId = $sourceRootInfo->getStorageId(); |
|
66 | + $this->displayNameCache = $displayNameCache; |
|
67 | + |
|
68 | + parent::__construct( |
|
69 | + null, |
|
70 | + '' |
|
71 | + ); |
|
72 | + } |
|
73 | + |
|
74 | + protected function getRoot() { |
|
75 | + if ($this->root === '') { |
|
76 | + $absoluteRoot = $this->sourceRootInfo->getPath(); |
|
77 | + |
|
78 | + // the sourceRootInfo path is the absolute path of the folder in the "real" storage |
|
79 | + // in the case where a folder is shared from a Jail we need to ensure that the share Jail |
|
80 | + // has it's root set relative to the source Jail |
|
81 | + $currentStorage = $this->storage->getSourceStorage(); |
|
82 | + if ($currentStorage->instanceOfStorage(Jail::class)) { |
|
83 | + /** @var Jail $currentStorage */ |
|
84 | + $absoluteRoot = $currentStorage->getJailedPath($absoluteRoot); |
|
85 | + } |
|
86 | + $this->root = $absoluteRoot; |
|
87 | + } |
|
88 | + return $this->root; |
|
89 | + } |
|
90 | + |
|
91 | + protected function getGetUnjailedRoot() { |
|
92 | + return $this->sourceRootInfo->getPath(); |
|
93 | + } |
|
94 | + |
|
95 | + public function getCache() { |
|
96 | + if (is_null($this->cache)) { |
|
97 | + $sourceStorage = $this->storage->getSourceStorage(); |
|
98 | + if ($sourceStorage) { |
|
99 | + $this->cache = $sourceStorage->getCache(); |
|
100 | + } else { |
|
101 | + // don't set $this->cache here since sourceStorage will be set later |
|
102 | + return new FailedCache(); |
|
103 | + } |
|
104 | + } |
|
105 | + return $this->cache; |
|
106 | + } |
|
107 | + |
|
108 | + public function getNumericStorageId() { |
|
109 | + if (isset($this->numericId)) { |
|
110 | + return $this->numericId; |
|
111 | + } else { |
|
112 | + return false; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + public function get($file) { |
|
117 | + if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { |
|
118 | + return $this->formatCacheEntry(clone $this->sourceRootInfo, ''); |
|
119 | + } |
|
120 | + return parent::get($file); |
|
121 | + } |
|
122 | + |
|
123 | + public function update($id, array $data) { |
|
124 | + $this->rootUnchanged = false; |
|
125 | + parent::update($id, $data); |
|
126 | + } |
|
127 | + |
|
128 | + public function insert($file, array $data) { |
|
129 | + $this->rootUnchanged = false; |
|
130 | + return parent::insert($file, $data); |
|
131 | + } |
|
132 | + |
|
133 | + public function remove($file) { |
|
134 | + $this->rootUnchanged = false; |
|
135 | + parent::remove($file); |
|
136 | + } |
|
137 | + |
|
138 | + public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
139 | + $this->rootUnchanged = false; |
|
140 | + return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
141 | + } |
|
142 | + |
|
143 | + protected function formatCacheEntry($entry, $path = null) { |
|
144 | + if (is_null($path)) { |
|
145 | + $path = $entry['path'] ?? ''; |
|
146 | + $entry['path'] = $this->getJailedPath($path); |
|
147 | + } else { |
|
148 | + $entry['path'] = $path; |
|
149 | + } |
|
150 | + |
|
151 | + try { |
|
152 | + if (isset($entry['permissions'])) { |
|
153 | + $entry['permissions'] &= $this->storage->getShare()->getPermissions(); |
|
154 | + } else { |
|
155 | + $entry['permissions'] = $this->storage->getPermissions($entry['path']); |
|
156 | + } |
|
157 | + } catch (StorageNotAvailableException $e) { |
|
158 | + // thrown by FailedStorage e.g. when the sharer does not exist anymore |
|
159 | + // (IDE may say the exception is never thrown – false negative) |
|
160 | + $sharePermissions = 0; |
|
161 | + } |
|
162 | + $entry['uid_owner'] = $this->storage->getOwner(''); |
|
163 | + $entry['displayname_owner'] = $this->getOwnerDisplayName(); |
|
164 | + if ($path === '') { |
|
165 | + $entry['is_share_mount_point'] = true; |
|
166 | + } |
|
167 | + return $entry; |
|
168 | + } |
|
169 | + |
|
170 | + private function getOwnerDisplayName() { |
|
171 | + if (!$this->ownerDisplayName) { |
|
172 | + $uid = $this->storage->getOwner(''); |
|
173 | + $this->ownerDisplayName = $this->displayNameCache->getDisplayName($uid); |
|
174 | + } |
|
175 | + return $this->ownerDisplayName; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * remove all entries for files that are stored on the storage from the cache |
|
180 | + */ |
|
181 | + public function clear() { |
|
182 | + // Not a valid action for Shared Cache |
|
183 | + } |
|
184 | + |
|
185 | + public function getQueryFilterForStorage(): ISearchOperator { |
|
186 | + // Do the normal jail behavior for non files |
|
187 | + if ($this->storage->getItemType() !== 'file') { |
|
188 | + return parent::getQueryFilterForStorage(); |
|
189 | + } |
|
190 | + |
|
191 | + // for single file shares we don't need to do the LIKE |
|
192 | + return new SearchBinaryOperator( |
|
193 | + ISearchBinaryOperator::OPERATOR_AND, |
|
194 | + [ |
|
195 | + \OC\Files\Cache\Cache::getQueryFilterForStorage(), |
|
196 | + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()), |
|
197 | + ] |
|
198 | + ); |
|
199 | + } |
|
200 | 200 | } |
@@ -73,154 +73,154 @@ |
||
73 | 73 | use Symfony\Component\EventDispatcher\GenericEvent; |
74 | 74 | |
75 | 75 | class Application extends App implements IBootstrap { |
76 | - public const APP_ID = 'files_sharing'; |
|
77 | - |
|
78 | - public function __construct(array $urlParams = []) { |
|
79 | - parent::__construct(self::APP_ID, $urlParams); |
|
80 | - } |
|
81 | - |
|
82 | - public function register(IRegistrationContext $context): void { |
|
83 | - $context->registerService(ExternalMountProvider::class, function (ContainerInterface $c) { |
|
84 | - return new ExternalMountProvider( |
|
85 | - $c->get(IDBConnection::class), |
|
86 | - function () use ($c) { |
|
87 | - return $c->get(Manager::class); |
|
88 | - }, |
|
89 | - $c->get(ICloudIdManager::class) |
|
90 | - ); |
|
91 | - }); |
|
92 | - |
|
93 | - /** |
|
94 | - * Middleware |
|
95 | - */ |
|
96 | - $context->registerMiddleWare(SharingCheckMiddleware::class); |
|
97 | - $context->registerMiddleWare(OCSShareAPIMiddleware::class); |
|
98 | - $context->registerMiddleWare(ShareInfoMiddleware::class); |
|
99 | - |
|
100 | - $context->registerCapability(Capabilities::class); |
|
101 | - |
|
102 | - $context->registerNotifierService(Notifier::class); |
|
103 | - $context->registerEventListener(UserChangedEvent::class, DisplayNameCache::class); |
|
104 | - } |
|
105 | - |
|
106 | - public function boot(IBootContext $context): void { |
|
107 | - $context->injectFn([$this, 'registerMountProviders']); |
|
108 | - $context->injectFn([$this, 'registerEventsScripts']); |
|
109 | - $context->injectFn([$this, 'setupSharingMenus']); |
|
110 | - |
|
111 | - Helper::registerHooks(); |
|
112 | - |
|
113 | - Share::registerBackend('file', File::class); |
|
114 | - Share::registerBackend('folder', Folder::class, 'file'); |
|
115 | - |
|
116 | - /** |
|
117 | - * Always add main sharing script |
|
118 | - */ |
|
119 | - Util::addScript(self::APP_ID, 'main'); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider) { |
|
124 | - $mountProviderCollection->registerProvider($mountProvider); |
|
125 | - $mountProviderCollection->registerProvider($externalMountProvider); |
|
126 | - } |
|
127 | - |
|
128 | - public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) { |
|
129 | - // sidebar and files scripts |
|
130 | - $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
131 | - $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); |
|
132 | - $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
|
133 | - $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); |
|
134 | - $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { |
|
135 | - \OCP\Util::addScript('files_sharing', 'collaboration'); |
|
136 | - }); |
|
137 | - $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); |
|
138 | - $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); |
|
139 | - |
|
140 | - // notifications api to accept incoming user shares |
|
141 | - $oldDispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { |
|
142 | - /** @var Listener $listener */ |
|
143 | - $listener = $this->getContainer()->query(Listener::class); |
|
144 | - $listener->shareNotification($event); |
|
145 | - }); |
|
146 | - $oldDispatcher->addListener(IGroup::class . '::postAddUser', function (GenericEvent $event) { |
|
147 | - /** @var Listener $listener */ |
|
148 | - $listener = $this->getContainer()->query(Listener::class); |
|
149 | - $listener->userAddedToGroup($event); |
|
150 | - }); |
|
151 | - } |
|
152 | - |
|
153 | - public function setupSharingMenus(IManager $shareManager, IFactory $l10nFactory, IUserSession $userSession) { |
|
154 | - if (!$shareManager->shareApiEnabled() || !class_exists('\OCA\Files\App')) { |
|
155 | - return; |
|
156 | - } |
|
157 | - |
|
158 | - $navigationManager = \OCA\Files\App::getNavigationManager(); |
|
159 | - // show_Quick_Access stored as string |
|
160 | - $navigationManager->add(function () use ($shareManager, $l10nFactory, $userSession) { |
|
161 | - $l = $l10nFactory->get('files_sharing'); |
|
162 | - $user = $userSession->getUser(); |
|
163 | - $userId = $user ? $user->getUID() : null; |
|
164 | - |
|
165 | - $sharingSublistArray = []; |
|
166 | - |
|
167 | - if ($shareManager->sharingDisabledForUser($userId) === false) { |
|
168 | - $sharingSublistArray[] = [ |
|
169 | - 'id' => 'sharingout', |
|
170 | - 'appname' => 'files_sharing', |
|
171 | - 'script' => 'list.php', |
|
172 | - 'order' => 16, |
|
173 | - 'name' => $l->t('Shared with others'), |
|
174 | - ]; |
|
175 | - } |
|
176 | - |
|
177 | - $sharingSublistArray[] = [ |
|
178 | - 'id' => 'sharingin', |
|
179 | - 'appname' => 'files_sharing', |
|
180 | - 'script' => 'list.php', |
|
181 | - 'order' => 15, |
|
182 | - 'name' => $l->t('Shared with you'), |
|
183 | - ]; |
|
184 | - |
|
185 | - if ($shareManager->sharingDisabledForUser($userId) === false) { |
|
186 | - // Check if sharing by link is enabled |
|
187 | - if ($shareManager->shareApiAllowLinks()) { |
|
188 | - $sharingSublistArray[] = [ |
|
189 | - 'id' => 'sharinglinks', |
|
190 | - 'appname' => 'files_sharing', |
|
191 | - 'script' => 'list.php', |
|
192 | - 'order' => 17, |
|
193 | - 'name' => $l->t('Shared by link'), |
|
194 | - ]; |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - $sharingSublistArray[] = [ |
|
199 | - 'id' => 'deletedshares', |
|
200 | - 'appname' => 'files_sharing', |
|
201 | - 'script' => 'list.php', |
|
202 | - 'order' => 19, |
|
203 | - 'name' => $l->t('Deleted shares'), |
|
204 | - ]; |
|
205 | - |
|
206 | - $sharingSublistArray[] = [ |
|
207 | - 'id' => 'pendingshares', |
|
208 | - 'appname' => 'files_sharing', |
|
209 | - 'script' => 'list.php', |
|
210 | - 'order' => 19, |
|
211 | - 'name' => $l->t('Pending shares'), |
|
212 | - ]; |
|
213 | - |
|
214 | - return [ |
|
215 | - 'id' => 'shareoverview', |
|
216 | - 'appname' => 'files_sharing', |
|
217 | - 'script' => 'list.php', |
|
218 | - 'order' => 18, |
|
219 | - 'name' => $l->t('Shares'), |
|
220 | - 'classes' => 'collapsible', |
|
221 | - 'sublist' => $sharingSublistArray, |
|
222 | - 'expandedState' => 'show_sharing_menu' |
|
223 | - ]; |
|
224 | - }); |
|
225 | - } |
|
76 | + public const APP_ID = 'files_sharing'; |
|
77 | + |
|
78 | + public function __construct(array $urlParams = []) { |
|
79 | + parent::__construct(self::APP_ID, $urlParams); |
|
80 | + } |
|
81 | + |
|
82 | + public function register(IRegistrationContext $context): void { |
|
83 | + $context->registerService(ExternalMountProvider::class, function (ContainerInterface $c) { |
|
84 | + return new ExternalMountProvider( |
|
85 | + $c->get(IDBConnection::class), |
|
86 | + function () use ($c) { |
|
87 | + return $c->get(Manager::class); |
|
88 | + }, |
|
89 | + $c->get(ICloudIdManager::class) |
|
90 | + ); |
|
91 | + }); |
|
92 | + |
|
93 | + /** |
|
94 | + * Middleware |
|
95 | + */ |
|
96 | + $context->registerMiddleWare(SharingCheckMiddleware::class); |
|
97 | + $context->registerMiddleWare(OCSShareAPIMiddleware::class); |
|
98 | + $context->registerMiddleWare(ShareInfoMiddleware::class); |
|
99 | + |
|
100 | + $context->registerCapability(Capabilities::class); |
|
101 | + |
|
102 | + $context->registerNotifierService(Notifier::class); |
|
103 | + $context->registerEventListener(UserChangedEvent::class, DisplayNameCache::class); |
|
104 | + } |
|
105 | + |
|
106 | + public function boot(IBootContext $context): void { |
|
107 | + $context->injectFn([$this, 'registerMountProviders']); |
|
108 | + $context->injectFn([$this, 'registerEventsScripts']); |
|
109 | + $context->injectFn([$this, 'setupSharingMenus']); |
|
110 | + |
|
111 | + Helper::registerHooks(); |
|
112 | + |
|
113 | + Share::registerBackend('file', File::class); |
|
114 | + Share::registerBackend('folder', Folder::class, 'file'); |
|
115 | + |
|
116 | + /** |
|
117 | + * Always add main sharing script |
|
118 | + */ |
|
119 | + Util::addScript(self::APP_ID, 'main'); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider) { |
|
124 | + $mountProviderCollection->registerProvider($mountProvider); |
|
125 | + $mountProviderCollection->registerProvider($externalMountProvider); |
|
126 | + } |
|
127 | + |
|
128 | + public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) { |
|
129 | + // sidebar and files scripts |
|
130 | + $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
131 | + $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); |
|
132 | + $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
|
133 | + $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); |
|
134 | + $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { |
|
135 | + \OCP\Util::addScript('files_sharing', 'collaboration'); |
|
136 | + }); |
|
137 | + $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); |
|
138 | + $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); |
|
139 | + |
|
140 | + // notifications api to accept incoming user shares |
|
141 | + $oldDispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) { |
|
142 | + /** @var Listener $listener */ |
|
143 | + $listener = $this->getContainer()->query(Listener::class); |
|
144 | + $listener->shareNotification($event); |
|
145 | + }); |
|
146 | + $oldDispatcher->addListener(IGroup::class . '::postAddUser', function (GenericEvent $event) { |
|
147 | + /** @var Listener $listener */ |
|
148 | + $listener = $this->getContainer()->query(Listener::class); |
|
149 | + $listener->userAddedToGroup($event); |
|
150 | + }); |
|
151 | + } |
|
152 | + |
|
153 | + public function setupSharingMenus(IManager $shareManager, IFactory $l10nFactory, IUserSession $userSession) { |
|
154 | + if (!$shareManager->shareApiEnabled() || !class_exists('\OCA\Files\App')) { |
|
155 | + return; |
|
156 | + } |
|
157 | + |
|
158 | + $navigationManager = \OCA\Files\App::getNavigationManager(); |
|
159 | + // show_Quick_Access stored as string |
|
160 | + $navigationManager->add(function () use ($shareManager, $l10nFactory, $userSession) { |
|
161 | + $l = $l10nFactory->get('files_sharing'); |
|
162 | + $user = $userSession->getUser(); |
|
163 | + $userId = $user ? $user->getUID() : null; |
|
164 | + |
|
165 | + $sharingSublistArray = []; |
|
166 | + |
|
167 | + if ($shareManager->sharingDisabledForUser($userId) === false) { |
|
168 | + $sharingSublistArray[] = [ |
|
169 | + 'id' => 'sharingout', |
|
170 | + 'appname' => 'files_sharing', |
|
171 | + 'script' => 'list.php', |
|
172 | + 'order' => 16, |
|
173 | + 'name' => $l->t('Shared with others'), |
|
174 | + ]; |
|
175 | + } |
|
176 | + |
|
177 | + $sharingSublistArray[] = [ |
|
178 | + 'id' => 'sharingin', |
|
179 | + 'appname' => 'files_sharing', |
|
180 | + 'script' => 'list.php', |
|
181 | + 'order' => 15, |
|
182 | + 'name' => $l->t('Shared with you'), |
|
183 | + ]; |
|
184 | + |
|
185 | + if ($shareManager->sharingDisabledForUser($userId) === false) { |
|
186 | + // Check if sharing by link is enabled |
|
187 | + if ($shareManager->shareApiAllowLinks()) { |
|
188 | + $sharingSublistArray[] = [ |
|
189 | + 'id' => 'sharinglinks', |
|
190 | + 'appname' => 'files_sharing', |
|
191 | + 'script' => 'list.php', |
|
192 | + 'order' => 17, |
|
193 | + 'name' => $l->t('Shared by link'), |
|
194 | + ]; |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + $sharingSublistArray[] = [ |
|
199 | + 'id' => 'deletedshares', |
|
200 | + 'appname' => 'files_sharing', |
|
201 | + 'script' => 'list.php', |
|
202 | + 'order' => 19, |
|
203 | + 'name' => $l->t('Deleted shares'), |
|
204 | + ]; |
|
205 | + |
|
206 | + $sharingSublistArray[] = [ |
|
207 | + 'id' => 'pendingshares', |
|
208 | + 'appname' => 'files_sharing', |
|
209 | + 'script' => 'list.php', |
|
210 | + 'order' => 19, |
|
211 | + 'name' => $l->t('Pending shares'), |
|
212 | + ]; |
|
213 | + |
|
214 | + return [ |
|
215 | + 'id' => 'shareoverview', |
|
216 | + 'appname' => 'files_sharing', |
|
217 | + 'script' => 'list.php', |
|
218 | + 'order' => 18, |
|
219 | + 'name' => $l->t('Shares'), |
|
220 | + 'classes' => 'collapsible', |
|
221 | + 'sublist' => $sharingSublistArray, |
|
222 | + 'expandedState' => 'show_sharing_menu' |
|
223 | + ]; |
|
224 | + }); |
|
225 | + } |
|
226 | 226 | } |
@@ -38,40 +38,40 @@ |
||
38 | 38 | * outdated. |
39 | 39 | */ |
40 | 40 | class DisplayNameCache implements IEventListener { |
41 | - private ICache $internalCache; |
|
42 | - private IUserManager $userManager; |
|
41 | + private ICache $internalCache; |
|
42 | + private IUserManager $userManager; |
|
43 | 43 | |
44 | - public function __construct(ICacheFactory $cacheFactory, IUserManager $userManager) { |
|
45 | - $this->internalCache = $cacheFactory->createDistributed('displayNameMappingCache'); |
|
46 | - $this->userManager = $userManager; |
|
47 | - } |
|
44 | + public function __construct(ICacheFactory $cacheFactory, IUserManager $userManager) { |
|
45 | + $this->internalCache = $cacheFactory->createDistributed('displayNameMappingCache'); |
|
46 | + $this->userManager = $userManager; |
|
47 | + } |
|
48 | 48 | |
49 | - public function getDisplayName(string $userId) { |
|
50 | - $displayName = $this->internalCache->get($userId); |
|
51 | - if ($displayName) { |
|
52 | - return $displayName; |
|
53 | - } |
|
49 | + public function getDisplayName(string $userId) { |
|
50 | + $displayName = $this->internalCache->get($userId); |
|
51 | + if ($displayName) { |
|
52 | + return $displayName; |
|
53 | + } |
|
54 | 54 | |
55 | - $user = $this->userManager->get($userId); |
|
56 | - if ($user) { |
|
57 | - $displayName = $user->getDisplayName(); |
|
58 | - } else { |
|
59 | - $displayName = $userId; |
|
60 | - } |
|
61 | - $this->internalCache->set($userId, $displayName, 60 * 10); // 10 minutes |
|
55 | + $user = $this->userManager->get($userId); |
|
56 | + if ($user) { |
|
57 | + $displayName = $user->getDisplayName(); |
|
58 | + } else { |
|
59 | + $displayName = $userId; |
|
60 | + } |
|
61 | + $this->internalCache->set($userId, $displayName, 60 * 10); // 10 minutes |
|
62 | 62 | |
63 | - return $displayName; |
|
64 | - } |
|
63 | + return $displayName; |
|
64 | + } |
|
65 | 65 | |
66 | - public function clear(): void { |
|
67 | - $this->internalCache->clear(); |
|
68 | - } |
|
66 | + public function clear(): void { |
|
67 | + $this->internalCache->clear(); |
|
68 | + } |
|
69 | 69 | |
70 | - public function handle(Event $event): void { |
|
71 | - if ($event instanceof UserChangedEvent && $event->getFeature() === 'displayName') { |
|
72 | - $userId = $event->getUser()->getUID(); |
|
73 | - $newDisplayName = $event->getValue(); |
|
74 | - $this->internalCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes |
|
75 | - } |
|
76 | - } |
|
70 | + public function handle(Event $event): void { |
|
71 | + if ($event instanceof UserChangedEvent && $event->getFeature() === 'displayName') { |
|
72 | + $userId = $event->getUser()->getUID(); |
|
73 | + $newDisplayName = $event->getValue(); |
|
74 | + $this->internalCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes |
|
75 | + } |
|
76 | + } |
|
77 | 77 | } |