diff --git a/lib/private/Files/Config/MountProviderCollection.php b/lib/private/Files/Config/MountProviderCollection.php index f3252f0fd6..a3c88dd6b4 100644 --- a/lib/private/Files/Config/MountProviderCollection.php +++ b/lib/private/Files/Config/MountProviderCollection.php @@ -57,6 +57,9 @@ class MountProviderCollection implements IMountProviderCollection, Emitter { */ private $mountCache; + /** @var callable[] */ + private $mountFilters = []; + /** * @param \OCP\Files\Storage\IStorageFactory $loader * @param IUserMountCache $mountCache @@ -80,9 +83,10 @@ class MountProviderCollection implements IMountProviderCollection, Emitter { $mounts = array_filter($mounts, function ($result) { return is_array($result); }); - return array_reduce($mounts, function (array $mounts, array $providerMounts) { + $mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) { return array_merge($mounts, $providerMounts); }, array()); + return $this->filterMounts($user, $mounts); } public function addMountForUser(IUser $user, IMountManager $mountManager) { @@ -101,6 +105,7 @@ class MountProviderCollection implements IMountProviderCollection, Emitter { $firstMounts = array_merge($firstMounts, $mounts); } } + $firstMounts = $this->filterMounts($user, $firstMounts); array_walk($firstMounts, [$mountManager, 'addMount']); $lateMounts = []; @@ -111,6 +116,7 @@ class MountProviderCollection implements IMountProviderCollection, Emitter { } } + $lateMounts = $this->filterMounts($user, $lateMounts); array_walk($lateMounts, [$mountManager, 'addMount']); return array_merge($lateMounts, $firstMounts); @@ -146,6 +152,21 @@ class MountProviderCollection implements IMountProviderCollection, Emitter { $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]); } + public function registerMountFilter(callable $filter) { + $this->mountFilters[] = $filter; + } + + private function filterMounts(IUser $user, array $mountPoints) { + return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) { + foreach ($this->mountFilters as $filter) { + if ($filter($mountPoint, $user) === false) { + return false; + } + } + return true; + }); + } + /** * Add a provider for home mount points * diff --git a/lib/public/Files/Config/IMountProviderCollection.php b/lib/public/Files/Config/IMountProviderCollection.php index 93701c326b..a3f96f37aa 100644 --- a/lib/public/Files/Config/IMountProviderCollection.php +++ b/lib/public/Files/Config/IMountProviderCollection.php @@ -56,6 +56,14 @@ interface IMountProviderCollection { */ public function registerProvider(IMountProvider $provider); + /** + * Add a filter for mounts + * + * @param callable $filter (IMountPoint $mountPoint, IUser $user) => boolean + * @since 14.0.0 + */ + public function registerMountFilter(callable $filter); + /** * Add a provider for home mount points *