SetupManager.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OC\Files;
  23. use OC\Files\Config\MountProviderCollection;
  24. use OC\Files\Mount\MountPoint;
  25. use OC\Files\ObjectStore\HomeObjectStoreStorage;
  26. use OC\Files\Storage\Common;
  27. use OC\Files\Storage\Home;
  28. use OC\Files\Storage\Storage;
  29. use OC\Files\Storage\Wrapper\Availability;
  30. use OC\Files\Storage\Wrapper\Encoding;
  31. use OC\Files\Storage\Wrapper\PermissionsMask;
  32. use OC\Files\Storage\Wrapper\Quota;
  33. use OC\Lockdown\Filesystem\NullStorage;
  34. use OC_App;
  35. use OC_Hook;
  36. use OC_Util;
  37. use OCP\Constants;
  38. use OCP\Diagnostics\IEventLogger;
  39. use OCP\EventDispatcher\IEventDispatcher;
  40. use OCP\Files\Config\ICachedMountInfo;
  41. use OCP\Files\Config\IHomeMountProvider;
  42. use OCP\Files\Config\IMountProvider;
  43. use OCP\Files\Config\IUserMountCache;
  44. use OCP\Files\Events\InvalidateMountCacheEvent;
  45. use OCP\Files\Events\Node\FilesystemTornDownEvent;
  46. use OCP\Files\Mount\IMountManager;
  47. use OCP\Files\Mount\IMountPoint;
  48. use OCP\Files\NotFoundException;
  49. use OCP\Files\Storage\IStorage;
  50. use OCP\Group\Events\UserAddedEvent;
  51. use OCP\Group\Events\UserRemovedEvent;
  52. use OCP\ICache;
  53. use OCP\ICacheFactory;
  54. use OCP\IConfig;
  55. use OCP\IUser;
  56. use OCP\IUserManager;
  57. use OCP\IUserSession;
  58. use OCP\Lockdown\ILockdownManager;
  59. use OCP\Share\Events\ShareCreatedEvent;
  60. use Psr\Log\LoggerInterface;
  61. class SetupManager {
  62. private bool $rootSetup = false;
  63. private IEventLogger $eventLogger;
  64. private MountProviderCollection $mountProviderCollection;
  65. private IMountManager $mountManager;
  66. private IUserManager $userManager;
  67. // List of users for which at least one mount is setup
  68. private array $setupUsers = [];
  69. // List of users for which all mounts are setup
  70. private array $setupUsersComplete = [];
  71. /** @var array<string, string[]> */
  72. private array $setupUserMountProviders = [];
  73. private IEventDispatcher $eventDispatcher;
  74. private IUserMountCache $userMountCache;
  75. private ILockdownManager $lockdownManager;
  76. private IUserSession $userSession;
  77. private ICache $cache;
  78. private LoggerInterface $logger;
  79. private IConfig $config;
  80. private bool $listeningForProviders;
  81. private array $fullSetupRequired = [];
  82. private bool $setupBuiltinWrappersDone = false;
  83. public function __construct(
  84. IEventLogger $eventLogger,
  85. MountProviderCollection $mountProviderCollection,
  86. IMountManager $mountManager,
  87. IUserManager $userManager,
  88. IEventDispatcher $eventDispatcher,
  89. IUserMountCache $userMountCache,
  90. ILockdownManager $lockdownManager,
  91. IUserSession $userSession,
  92. ICacheFactory $cacheFactory,
  93. LoggerInterface $logger,
  94. IConfig $config
  95. ) {
  96. $this->eventLogger = $eventLogger;
  97. $this->mountProviderCollection = $mountProviderCollection;
  98. $this->mountManager = $mountManager;
  99. $this->userManager = $userManager;
  100. $this->eventDispatcher = $eventDispatcher;
  101. $this->userMountCache = $userMountCache;
  102. $this->lockdownManager = $lockdownManager;
  103. $this->logger = $logger;
  104. $this->userSession = $userSession;
  105. $this->cache = $cacheFactory->createDistributed('setupmanager::');
  106. $this->listeningForProviders = false;
  107. $this->config = $config;
  108. $this->setupListeners();
  109. }
  110. private function isSetupStarted(IUser $user): bool {
  111. return in_array($user->getUID(), $this->setupUsers, true);
  112. }
  113. public function isSetupComplete(IUser $user): bool {
  114. return in_array($user->getUID(), $this->setupUsersComplete, true);
  115. }
  116. private function setupBuiltinWrappers() {
  117. if ($this->setupBuiltinWrappersDone) {
  118. return;
  119. }
  120. $this->setupBuiltinWrappersDone = true;
  121. // load all filesystem apps before, so no setup-hook gets lost
  122. OC_App::loadApps(['filesystem']);
  123. $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
  124. Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  125. if ($storage->instanceOfStorage(Common::class)) {
  126. $storage->setMountOptions($mount->getOptions());
  127. }
  128. return $storage;
  129. });
  130. Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  131. if (!$mount->getOption('enable_sharing', true)) {
  132. return new PermissionsMask([
  133. 'storage' => $storage,
  134. 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
  135. ]);
  136. }
  137. return $storage;
  138. });
  139. // install storage availability wrapper, before most other wrappers
  140. Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) {
  141. if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
  142. return new Availability(['storage' => $storage]);
  143. }
  144. return $storage;
  145. });
  146. Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  147. if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
  148. return new Encoding(['storage' => $storage]);
  149. }
  150. return $storage;
  151. });
  152. Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
  153. // set up quota for home storages, even for other users
  154. // which can happen when using sharing
  155. /**
  156. * @var Storage $storage
  157. */
  158. if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) {
  159. if (is_object($storage->getUser())) {
  160. $user = $storage->getUser();
  161. return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
  162. return OC_Util::getUserQuota($user);
  163. }, 'root' => 'files']);
  164. }
  165. }
  166. return $storage;
  167. });
  168. Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
  169. /*
  170. * Do not allow any operations that modify the storage
  171. */
  172. if ($mount->getOption('readonly', false)) {
  173. return new PermissionsMask([
  174. 'storage' => $storage,
  175. 'mask' => Constants::PERMISSION_ALL & ~(
  176. Constants::PERMISSION_UPDATE |
  177. Constants::PERMISSION_CREATE |
  178. Constants::PERMISSION_DELETE
  179. ),
  180. ]);
  181. }
  182. return $storage;
  183. });
  184. Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
  185. }
  186. /**
  187. * Setup the full filesystem for the specified user
  188. */
  189. public function setupForUser(IUser $user): void {
  190. if ($this->isSetupComplete($user)) {
  191. return;
  192. }
  193. $this->setupUsersComplete[] = $user->getUID();
  194. $this->eventLogger->start('fs:setup:user:full', 'Setup full filesystem for user');
  195. if (!isset($this->setupUserMountProviders[$user->getUID()])) {
  196. $this->setupUserMountProviders[$user->getUID()] = [];
  197. }
  198. $previouslySetupProviders = $this->setupUserMountProviders[$user->getUID()];
  199. $this->setupForUserWith($user, function () use ($user) {
  200. $this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
  201. IMountProvider $provider
  202. ) use ($user) {
  203. return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
  204. });
  205. });
  206. $this->afterUserFullySetup($user, $previouslySetupProviders);
  207. $this->eventLogger->end('fs:setup:user:full');
  208. }
  209. /**
  210. * part of the user setup that is run only once per user
  211. */
  212. private function oneTimeUserSetup(IUser $user) {
  213. if ($this->isSetupStarted($user)) {
  214. return;
  215. }
  216. $this->setupUsers[] = $user->getUID();
  217. $this->setupRoot();
  218. $this->eventLogger->start('fs:setup:user:onetime', 'Onetime filesystem for user');
  219. $this->setupBuiltinWrappers();
  220. $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
  221. OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]);
  222. Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
  223. $userDir = '/' . $user->getUID() . '/files';
  224. Filesystem::initInternal($userDir);
  225. if ($this->lockdownManager->canAccessFilesystem()) {
  226. $this->eventLogger->start('fs:setup:user:home', 'Setup home filesystem for user');
  227. // home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers
  228. $homeMount = $this->mountProviderCollection->getHomeMountForUser($user);
  229. $this->mountManager->addMount($homeMount);
  230. if ($homeMount->getStorageRootId() === -1) {
  231. $this->eventLogger->start('fs:setup:user:home:scan', 'Scan home filesystem for user');
  232. $homeMount->getStorage()->mkdir('');
  233. $homeMount->getStorage()->getScanner()->scan('');
  234. $this->eventLogger->end('fs:setup:user:home:scan');
  235. }
  236. $this->eventLogger->end('fs:setup:user:home');
  237. } else {
  238. $this->mountManager->addMount(new MountPoint(
  239. new NullStorage([]),
  240. '/' . $user->getUID()
  241. ));
  242. $this->mountManager->addMount(new MountPoint(
  243. new NullStorage([]),
  244. '/' . $user->getUID() . '/files'
  245. ));
  246. $this->setupUsersComplete[] = $user->getUID();
  247. }
  248. $this->listenForNewMountProviders();
  249. $this->eventLogger->end('fs:setup:user:onetime');
  250. }
  251. /**
  252. * Final housekeeping after a user has been fully setup
  253. */
  254. private function afterUserFullySetup(IUser $user, array $previouslySetupProviders): void {
  255. $this->eventLogger->start('fs:setup:user:full:post', 'Housekeeping after user is setup');
  256. $userRoot = '/' . $user->getUID() . '/';
  257. $mounts = $this->mountManager->getAll();
  258. $mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
  259. return str_starts_with($mount->getMountPoint(), $userRoot);
  260. });
  261. $allProviders = array_map(function (IMountProvider $provider) {
  262. return get_class($provider);
  263. }, $this->mountProviderCollection->getProviders());
  264. $newProviders = array_diff($allProviders, $previouslySetupProviders);
  265. $mounts = array_filter($mounts, function (IMountPoint $mount) use ($previouslySetupProviders) {
  266. return !in_array($mount->getMountProvider(), $previouslySetupProviders);
  267. });
  268. $this->userMountCache->registerMounts($user, $mounts, $newProviders);
  269. $cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
  270. if ($cacheDuration > 0) {
  271. $this->cache->set($user->getUID(), true, $cacheDuration);
  272. $this->fullSetupRequired[$user->getUID()] = false;
  273. }
  274. $this->eventLogger->end('fs:setup:user:full:post');
  275. }
  276. /**
  277. * @param IUser $user
  278. * @param IMountPoint $mounts
  279. * @return void
  280. * @throws \OCP\HintException
  281. * @throws \OC\ServerNotAvailableException
  282. */
  283. private function setupForUserWith(IUser $user, callable $mountCallback): void {
  284. $this->oneTimeUserSetup($user);
  285. if ($this->lockdownManager->canAccessFilesystem()) {
  286. $mountCallback();
  287. }
  288. $this->eventLogger->start('fs:setup:user:post-init-mountpoint', 'post_initMountPoints legacy hook');
  289. \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
  290. $this->eventLogger->end('fs:setup:user:post-init-mountpoint');
  291. $userDir = '/' . $user->getUID() . '/files';
  292. $this->eventLogger->start('fs:setup:user:setup-hook', 'setup legacy hook');
  293. OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
  294. $this->eventLogger->end('fs:setup:user:setup-hook');
  295. }
  296. /**
  297. * Set up the root filesystem
  298. */
  299. public function setupRoot(): void {
  300. //setting up the filesystem twice can only lead to trouble
  301. if ($this->rootSetup) {
  302. return;
  303. }
  304. $this->rootSetup = true;
  305. $this->eventLogger->start('fs:setup:root', 'Setup root filesystem');
  306. $this->setupBuiltinWrappers();
  307. $rootMounts = $this->mountProviderCollection->getRootMounts();
  308. foreach ($rootMounts as $rootMountProvider) {
  309. $this->mountManager->addMount($rootMountProvider);
  310. }
  311. $this->eventLogger->end('fs:setup:root');
  312. }
  313. /**
  314. * Get the user to setup for a path or `null` if the root needs to be setup
  315. *
  316. * @param string $path
  317. * @return IUser|null
  318. */
  319. private function getUserForPath(string $path) {
  320. if (str_starts_with($path, '/__groupfolders')) {
  321. return null;
  322. } elseif (substr_count($path, '/') < 2) {
  323. if ($user = $this->userSession->getUser()) {
  324. return $user;
  325. } else {
  326. return null;
  327. }
  328. } elseif (str_starts_with($path, '/appdata_' . \OC_Util::getInstanceId()) || str_starts_with($path, '/files_external/')) {
  329. return null;
  330. } else {
  331. [, $userId] = explode('/', $path);
  332. }
  333. return $this->userManager->get($userId);
  334. }
  335. /**
  336. * Set up the filesystem for the specified path
  337. */
  338. public function setupForPath(string $path, bool $includeChildren = false): void {
  339. $user = $this->getUserForPath($path);
  340. if (!$user) {
  341. $this->setupRoot();
  342. return;
  343. }
  344. if ($this->isSetupComplete($user)) {
  345. return;
  346. }
  347. if ($this->fullSetupRequired($user)) {
  348. $this->setupForUser($user);
  349. return;
  350. }
  351. // for the user's home folder, and includes children we need everything always
  352. if (rtrim($path) === "/" . $user->getUID() . "/files" && $includeChildren) {
  353. $this->setupForUser($user);
  354. return;
  355. }
  356. if (!isset($this->setupUserMountProviders[$user->getUID()])) {
  357. $this->setupUserMountProviders[$user->getUID()] = [];
  358. }
  359. $setupProviders = &$this->setupUserMountProviders[$user->getUID()];
  360. $currentProviders = [];
  361. try {
  362. $cachedMount = $this->userMountCache->getMountForPath($user, $path);
  363. } catch (NotFoundException $e) {
  364. $this->setupForUser($user);
  365. return;
  366. }
  367. $this->oneTimeUserSetup($user);
  368. $this->eventLogger->start('fs:setup:user:path', "Setup $path filesystem for user");
  369. $this->eventLogger->start('fs:setup:user:path:find', "Find mountpoint for $path");
  370. $mounts = [];
  371. if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
  372. $currentProviders[] = $cachedMount->getMountProvider();
  373. if ($cachedMount->getMountProvider()) {
  374. $setupProviders[] = $cachedMount->getMountProvider();
  375. $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
  376. } else {
  377. $this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
  378. $this->eventLogger->end('fs:setup:user:path:find');
  379. $this->setupForUser($user);
  380. $this->eventLogger->end('fs:setup:user:path');
  381. return;
  382. }
  383. }
  384. if ($includeChildren) {
  385. $subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
  386. $this->eventLogger->end('fs:setup:user:path:find');
  387. $needsFullSetup = array_reduce($subCachedMounts, function (bool $needsFullSetup, ICachedMountInfo $cachedMountInfo) {
  388. return $needsFullSetup || $cachedMountInfo->getMountProvider() === '';
  389. }, false);
  390. if ($needsFullSetup) {
  391. $this->logger->debug("mount has no provider set, performing full setup");
  392. $this->setupForUser($user);
  393. $this->eventLogger->end('fs:setup:user:path');
  394. return;
  395. } else {
  396. foreach ($subCachedMounts as $cachedMount) {
  397. if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
  398. $currentProviders[] = $cachedMount->getMountProvider();
  399. $setupProviders[] = $cachedMount->getMountProvider();
  400. $mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]));
  401. }
  402. }
  403. }
  404. } else {
  405. $this->eventLogger->end('fs:setup:user:path:find');
  406. }
  407. if (count($mounts)) {
  408. $this->userMountCache->registerMounts($user, $mounts, $currentProviders);
  409. $this->setupForUserWith($user, function () use ($mounts) {
  410. array_walk($mounts, [$this->mountManager, 'addMount']);
  411. });
  412. } elseif (!$this->isSetupStarted($user)) {
  413. $this->oneTimeUserSetup($user);
  414. }
  415. $this->eventLogger->end('fs:setup:user:path');
  416. }
  417. private function fullSetupRequired(IUser $user): bool {
  418. // we perform a "cached" setup only after having done the full setup recently
  419. // this is also used to trigger a full setup after handling events that are likely
  420. // to change the available mounts
  421. if (!isset($this->fullSetupRequired[$user->getUID()])) {
  422. $this->fullSetupRequired[$user->getUID()] = !$this->cache->get($user->getUID());
  423. }
  424. return $this->fullSetupRequired[$user->getUID()];
  425. }
  426. /**
  427. * @param string $path
  428. * @param string[] $providers
  429. */
  430. public function setupForProvider(string $path, array $providers): void {
  431. $user = $this->getUserForPath($path);
  432. if (!$user) {
  433. $this->setupRoot();
  434. return;
  435. }
  436. if ($this->isSetupComplete($user)) {
  437. return;
  438. }
  439. if ($this->fullSetupRequired($user)) {
  440. $this->setupForUser($user);
  441. return;
  442. }
  443. $this->eventLogger->start('fs:setup:user:providers', "Setup filesystem for " . implode(', ', $providers));
  444. $this->oneTimeUserSetup($user);
  445. // home providers are always used
  446. $providers = array_filter($providers, function (string $provider) {
  447. return !is_subclass_of($provider, IHomeMountProvider::class);
  448. });
  449. if (in_array('', $providers)) {
  450. $this->setupForUser($user);
  451. return;
  452. }
  453. $setupProviders = $this->setupUserMountProviders[$user->getUID()] ?? [];
  454. $providers = array_diff($providers, $setupProviders);
  455. if (count($providers) === 0) {
  456. if (!$this->isSetupStarted($user)) {
  457. $this->oneTimeUserSetup($user);
  458. }
  459. $this->eventLogger->end('fs:setup:user:providers');
  460. return;
  461. } else {
  462. $this->setupUserMountProviders[$user->getUID()] = array_merge($setupProviders, $providers);
  463. $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, $providers);
  464. }
  465. $this->userMountCache->registerMounts($user, $mounts, $providers);
  466. $this->setupForUserWith($user, function () use ($mounts) {
  467. array_walk($mounts, [$this->mountManager, 'addMount']);
  468. });
  469. $this->eventLogger->end('fs:setup:user:providers');
  470. }
  471. public function tearDown() {
  472. $this->setupUsers = [];
  473. $this->setupUsersComplete = [];
  474. $this->setupUserMountProviders = [];
  475. $this->fullSetupRequired = [];
  476. $this->rootSetup = false;
  477. $this->mountManager->clear();
  478. $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent());
  479. }
  480. /**
  481. * Get mounts from mount providers that are registered after setup
  482. */
  483. private function listenForNewMountProviders() {
  484. if (!$this->listeningForProviders) {
  485. $this->listeningForProviders = true;
  486. $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
  487. IMountProvider $provider
  488. ) {
  489. foreach ($this->setupUsers as $userId) {
  490. $user = $this->userManager->get($userId);
  491. if ($user) {
  492. $mounts = $provider->getMountsForUser($user, Filesystem::getLoader());
  493. array_walk($mounts, [$this->mountManager, 'addMount']);
  494. }
  495. }
  496. });
  497. }
  498. }
  499. private function setupListeners() {
  500. // note that this event handling is intentionally pessimistic
  501. // clearing the cache to often is better than not enough
  502. $this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
  503. $this->cache->remove($event->getUser()->getUID());
  504. });
  505. $this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
  506. $this->cache->remove($event->getUser()->getUID());
  507. });
  508. $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
  509. $this->cache->remove($event->getShare()->getSharedWith());
  510. });
  511. $this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
  512. ) {
  513. if ($user = $event->getUser()) {
  514. $this->cache->remove($user->getUID());
  515. } else {
  516. $this->cache->clear();
  517. }
  518. });
  519. $genericEvents = [
  520. 'OCA\Circles\Events\CreatingCircleEvent',
  521. 'OCA\Circles\Events\DestroyingCircleEvent',
  522. 'OCA\Circles\Events\AddingCircleMemberEvent',
  523. 'OCA\Circles\Events\RemovingCircleMemberEvent',
  524. ];
  525. foreach ($genericEvents as $genericEvent) {
  526. $this->eventDispatcher->addListener($genericEvent, function ($event) {
  527. $this->cache->clear();
  528. });
  529. }
  530. }
  531. }