Add the option to filter mounts for a user
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
a22bc0e787
commit
3ad6084891
|
@ -57,6 +57,9 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||||
*/
|
*/
|
||||||
private $mountCache;
|
private $mountCache;
|
||||||
|
|
||||||
|
/** @var callable[] */
|
||||||
|
private $mountFilters = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \OCP\Files\Storage\IStorageFactory $loader
|
* @param \OCP\Files\Storage\IStorageFactory $loader
|
||||||
* @param IUserMountCache $mountCache
|
* @param IUserMountCache $mountCache
|
||||||
|
@ -80,9 +83,10 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||||
$mounts = array_filter($mounts, function ($result) {
|
$mounts = array_filter($mounts, function ($result) {
|
||||||
return is_array($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);
|
return array_merge($mounts, $providerMounts);
|
||||||
}, array());
|
}, array());
|
||||||
|
return $this->filterMounts($user, $mounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addMountForUser(IUser $user, IMountManager $mountManager) {
|
public function addMountForUser(IUser $user, IMountManager $mountManager) {
|
||||||
|
@ -101,6 +105,7 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||||
$firstMounts = array_merge($firstMounts, $mounts);
|
$firstMounts = array_merge($firstMounts, $mounts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$firstMounts = $this->filterMounts($user, $firstMounts);
|
||||||
array_walk($firstMounts, [$mountManager, 'addMount']);
|
array_walk($firstMounts, [$mountManager, 'addMount']);
|
||||||
|
|
||||||
$lateMounts = [];
|
$lateMounts = [];
|
||||||
|
@ -111,6 +116,7 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lateMounts = $this->filterMounts($user, $lateMounts);
|
||||||
array_walk($lateMounts, [$mountManager, 'addMount']);
|
array_walk($lateMounts, [$mountManager, 'addMount']);
|
||||||
|
|
||||||
return array_merge($lateMounts, $firstMounts);
|
return array_merge($lateMounts, $firstMounts);
|
||||||
|
@ -146,6 +152,21 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||||
$this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
|
$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
|
* Add a provider for home mount points
|
||||||
*
|
*
|
||||||
|
|
|
@ -56,6 +56,14 @@ interface IMountProviderCollection {
|
||||||
*/
|
*/
|
||||||
public function registerProvider(IMountProvider $provider);
|
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
|
* Add a provider for home mount points
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue