Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/private/Files/Config/MountProviderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
*/
private $mountCache;

/** @var callable[] */
private $mountFilters = [];

/**
* @param \OCP\Files\Storage\IStorageFactory $loader
* @param IUserMountCache $mountCache
Expand All @@ -80,9 +83,10 @@ public function getMountsForUser(IUser $user) {
$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) {
Expand All @@ -101,6 +105,7 @@ public function addMountForUser(IUser $user, IMountManager $mountManager) {
$firstMounts = array_merge($firstMounts, $mounts);
}
}
$firstMounts = $this->filterMounts($user, $firstMounts);
array_walk($firstMounts, [$mountManager, 'addMount']);

$lateMounts = [];
Expand All @@ -111,6 +116,7 @@ public function addMountForUser(IUser $user, IMountManager $mountManager) {
}
}

$lateMounts = $this->filterMounts($user, $lateMounts);
array_walk($lateMounts, [$mountManager, 'addMount']);

return array_merge($lateMounts, $firstMounts);
Expand Down Expand Up @@ -146,6 +152,21 @@ public function registerProvider(IMountProvider $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
*
Expand Down
8 changes: 8 additions & 0 deletions lib/public/Files/Config/IMountProviderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public function getHomeMountForUser(IUser $user);
*/
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
*
Expand Down