summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-07-10 16:49:26 +0200
committerRobin Appelman <robin@icewind.nl>2018-07-10 16:49:26 +0200
commit3ad6084891b88b3b7ef784bbf297b0a57b282d77 (patch)
tree51d058322483a40f6f57e759ab1c19ed43dd7c99 /lib
parenta22bc0e78758a86000b1023c93e554ebca696493 (diff)
downloadnextcloud-server-3ad6084891b88b3b7ef784bbf297b0a57b282d77.tar.gz
nextcloud-server-3ad6084891b88b3b7ef784bbf297b0a57b282d77.zip
Add the option to filter mounts for a user
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Config/MountProviderCollection.php23
-rw-r--r--lib/public/Files/Config/IMountProviderCollection.php8
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/private/Files/Config/MountProviderCollection.php b/lib/private/Files/Config/MountProviderCollection.php
index f3252f0fd65..a3c88dd6b4b 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 93701c326b2..a3f96f37aa6 100644
--- a/lib/public/Files/Config/IMountProviderCollection.php
+++ b/lib/public/Files/Config/IMountProviderCollection.php
@@ -57,6 +57,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
*
* @param \OCP\Files\Config\IHomeMountProvider $provider