Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b2755b8fc2 |
@@ -60,6 +60,7 @@ return array(
|
||||
'OCA\\Files_Sharing\\Listener\\BeforeZipCreatedListener' => $baseDir . '/../lib/Listener/BeforeZipCreatedListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\RegisterMountProviderListener' => $baseDir . '/../lib/Listener/RegisterMountProviderListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\ShareInteractionListener' => $baseDir . '/../lib/Listener/ShareInteractionListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\UserAddedToGroupListener' => $baseDir . '/../lib/Listener/UserAddedToGroupListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\UserShareAcceptanceListener' => $baseDir . '/../lib/Listener/UserShareAcceptanceListener.php',
|
||||
|
||||
@@ -75,6 +75,7 @@ class ComposerStaticInitFiles_Sharing
|
||||
'OCA\\Files_Sharing\\Listener\\BeforeZipCreatedListener' => __DIR__ . '/..' . '/../lib/Listener/BeforeZipCreatedListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\RegisterMountProviderListener' => __DIR__ . '/..' . '/../lib/Listener/RegisterMountProviderListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\ShareInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/ShareInteractionListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\UserAddedToGroupListener' => __DIR__ . '/..' . '/../lib/Listener/UserAddedToGroupListener.php',
|
||||
'OCA\\Files_Sharing\\Listener\\UserShareAcceptanceListener' => __DIR__ . '/..' . '/../lib/Listener/UserShareAcceptanceListener.php',
|
||||
|
||||
@@ -19,13 +19,13 @@ use OCA\Files_Sharing\Listener\BeforeDirectFileDownloadListener;
|
||||
use OCA\Files_Sharing\Listener\BeforeZipCreatedListener;
|
||||
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
|
||||
use OCA\Files_Sharing\Listener\LoadSidebarListener;
|
||||
use OCA\Files_Sharing\Listener\RegisterMountProviderListener;
|
||||
use OCA\Files_Sharing\Listener\ShareInteractionListener;
|
||||
use OCA\Files_Sharing\Listener\UserAddedToGroupListener;
|
||||
use OCA\Files_Sharing\Listener\UserShareAcceptanceListener;
|
||||
use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware;
|
||||
use OCA\Files_Sharing\Middleware\ShareInfoMiddleware;
|
||||
use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
|
||||
use OCA\Files_Sharing\MountProvider;
|
||||
use OCA\Files_Sharing\Notification\Listener;
|
||||
use OCA\Files_Sharing\Notification\Notifier;
|
||||
use OCA\Files_Sharing\ShareBackend\File;
|
||||
@@ -37,9 +37,9 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Federation\ICloudIdManager;
|
||||
use OCP\Files\Config\IMountProviderCollection;
|
||||
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
|
||||
use OCP\Files\Events\BeforeZipCreatedEvent;
|
||||
use OCP\Files\Events\RegisterMountProviderEvent;
|
||||
use OCP\Group\Events\GroupChangedEvent;
|
||||
use OCP\Group\Events\GroupDeletedEvent;
|
||||
use OCP\Group\Events\UserAddedEvent;
|
||||
@@ -95,10 +95,11 @@ class Application extends App implements IBootstrap {
|
||||
// Handle download events for view only checks
|
||||
$context->registerEventListener(BeforeZipCreatedEvent::class, BeforeZipCreatedListener::class);
|
||||
$context->registerEventListener(BeforeDirectFileDownloadEvent::class, BeforeDirectFileDownloadListener::class);
|
||||
|
||||
$context->registerEventListener(RegisterMountProviderEvent::class, RegisterMountProviderListener::class);
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
$context->injectFn([$this, 'registerMountProviders']);
|
||||
$context->injectFn([$this, 'registerEventsScripts']);
|
||||
|
||||
Helper::registerHooks();
|
||||
@@ -107,12 +108,6 @@ class Application extends App implements IBootstrap {
|
||||
Share::registerBackend('folder', Folder::class, 'file');
|
||||
}
|
||||
|
||||
|
||||
public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider): void {
|
||||
$mountProviderCollection->registerProvider($mountProvider);
|
||||
$mountProviderCollection->registerProvider($externalMountProvider);
|
||||
}
|
||||
|
||||
public function registerEventsScripts(IEventDispatcher $dispatcher): void {
|
||||
$dispatcher->addListener(ResourcesLoadAdditionalScriptsEvent::class, function () {
|
||||
\OCP\Util::addScript('files_sharing', 'collaboration');
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Sharing\Listener;
|
||||
|
||||
use OCA\Files_Sharing\External\MountProvider as ExternalMountProvider;
|
||||
use OCA\Files_Sharing\MountProvider;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\Files\Events\RegisterMountProviderEvent;
|
||||
|
||||
/** @template-implements IEventListener<RegisterMountProviderEvent> */
|
||||
class RegisterMountProviderListener implements IEventListener {
|
||||
|
||||
public function __construct(
|
||||
private MountProvider $mountProvider,
|
||||
private ExternalMountProvider $externalMountProvider,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!($event instanceof RegisterMountProviderEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mountProviderCollection = $event->getProviderCollection();
|
||||
$mountProviderCollection->registerProvider($this->mountProvider);
|
||||
$mountProviderCollection->registerProvider($this->externalMountProvider);
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,6 @@ namespace OCA\Files_Sharing\Tests;
|
||||
use OC\Files\Filesystem;
|
||||
use OC\User\DisplayNameCache;
|
||||
use OCA\Files_Sharing\AppInfo\Application;
|
||||
use OCA\Files_Sharing\External\MountProvider as ExternalMountProvider;
|
||||
use OCA\Files_Sharing\MountProvider;
|
||||
use OCP\Files\Config\IMountProviderCollection;
|
||||
use OCP\Share\IShare;
|
||||
use Test\Traits\MountProviderTrait;
|
||||
|
||||
@@ -54,11 +51,6 @@ abstract class TestCase extends \Test\TestCase {
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
$app = new Application();
|
||||
$app->registerMountProviders(
|
||||
\OC::$server->get(IMountProviderCollection::class),
|
||||
\OC::$server->get(MountProvider::class),
|
||||
\OC::$server->get(ExternalMountProvider::class),
|
||||
);
|
||||
|
||||
// reset backend
|
||||
\OC_User::clearBackends();
|
||||
|
||||
@@ -370,6 +370,7 @@ return array(
|
||||
'OCP\\Files\\Events\\Node\\NodeRenamedEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeRenamedEvent.php',
|
||||
'OCP\\Files\\Events\\Node\\NodeTouchedEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeTouchedEvent.php',
|
||||
'OCP\\Files\\Events\\Node\\NodeWrittenEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeWrittenEvent.php',
|
||||
'OCP\\Files\\Events\\RegisterMountProviderEvent' => $baseDir . '/lib/public/Files/Events/RegisterMountProviderEvent.php',
|
||||
'OCP\\Files\\File' => $baseDir . '/lib/public/Files/File.php',
|
||||
'OCP\\Files\\FileInfo' => $baseDir . '/lib/public/Files/FileInfo.php',
|
||||
'OCP\\Files\\FileNameTooLongException' => $baseDir . '/lib/public/Files/FileNameTooLongException.php',
|
||||
|
||||
@@ -403,6 +403,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
||||
'OCP\\Files\\Events\\Node\\NodeRenamedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeRenamedEvent.php',
|
||||
'OCP\\Files\\Events\\Node\\NodeTouchedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeTouchedEvent.php',
|
||||
'OCP\\Files\\Events\\Node\\NodeWrittenEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeWrittenEvent.php',
|
||||
'OCP\\Files\\Events\\RegisterMountProviderEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/RegisterMountProviderEvent.php',
|
||||
'OCP\\Files\\File' => __DIR__ . '/../../..' . '/lib/public/Files/File.php',
|
||||
'OCP\\Files\\FileInfo' => __DIR__ . '/../../..' . '/lib/public/Files/FileInfo.php',
|
||||
'OCP\\Files\\FileNameTooLongException' => __DIR__ . '/../../..' . '/lib/public/Files/FileNameTooLongException.php',
|
||||
|
||||
@@ -10,11 +10,13 @@ namespace OC\Files\Config;
|
||||
use OC\Hooks\Emitter;
|
||||
use OC\Hooks\EmitterTrait;
|
||||
use OCP\Diagnostics\IEventLogger;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\Config\IHomeMountProvider;
|
||||
use OCP\Files\Config\IMountProvider;
|
||||
use OCP\Files\Config\IMountProviderCollection;
|
||||
use OCP\Files\Config\IRootMountProvider;
|
||||
use OCP\Files\Config\IUserMountCache;
|
||||
use OCP\Files\Events\RegisterMountProviderEvent;
|
||||
use OCP\Files\Mount\IMountManager;
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
use OCP\Files\Storage\IStorageFactory;
|
||||
@@ -23,46 +25,30 @@ use OCP\IUser;
|
||||
class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||
use EmitterTrait;
|
||||
|
||||
/**
|
||||
* @var \OCP\Files\Config\IHomeMountProvider[]
|
||||
*/
|
||||
private $homeProviders = [];
|
||||
/** @var \OCP\Files\Config\IHomeMountProvider[] */
|
||||
private array $homeProviders = [];
|
||||
|
||||
/**
|
||||
* @var \OCP\Files\Config\IMountProvider[]
|
||||
*/
|
||||
private $providers = [];
|
||||
/** @var \OCP\Files\Config\IMountProvider[] */
|
||||
private array $providers = [];
|
||||
|
||||
/** @var \OCP\Files\Config\IRootMountProvider[] */
|
||||
private $rootProviders = [];
|
||||
|
||||
/**
|
||||
* @var \OCP\Files\Storage\IStorageFactory
|
||||
*/
|
||||
private $loader;
|
||||
|
||||
/**
|
||||
* @var \OCP\Files\Config\IUserMountCache
|
||||
*/
|
||||
private $mountCache;
|
||||
private array $rootProviders = [];
|
||||
|
||||
/** @var callable[] */
|
||||
private $mountFilters = [];
|
||||
private array $mountFilters = [];
|
||||
|
||||
private IEventLogger $eventLogger;
|
||||
private bool $registerEventEmitted = false;
|
||||
|
||||
/**
|
||||
* @param \OCP\Files\Storage\IStorageFactory $loader
|
||||
* @param IUserMountCache $mountCache
|
||||
*/
|
||||
public function __construct(
|
||||
IStorageFactory $loader,
|
||||
IUserMountCache $mountCache,
|
||||
IEventLogger $eventLogger
|
||||
private IStorageFactory $loader,
|
||||
private IUserMountCache $mountCache,
|
||||
private IEventLogger $eventLogger,
|
||||
private IEventDispatcher $eventDispatcher,
|
||||
) {
|
||||
$this->loader = $loader;
|
||||
$this->mountCache = $mountCache;
|
||||
$this->eventLogger = $eventLogger;
|
||||
}
|
||||
|
||||
private function getMountsFromProvider(IMountProvider $provider, IUser $user, IStorageFactory $loader): array {
|
||||
@@ -91,12 +77,12 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||
}
|
||||
|
||||
public function getMountsForUser(IUser $user): array {
|
||||
return $this->getUserMountsForProviders($user, $this->providers);
|
||||
return $this->getUserMountsForProviders($user, $this->getProviders());
|
||||
}
|
||||
|
||||
public function getUserMountsForProviderClasses(IUser $user, array $mountProviderClasses): array {
|
||||
$providers = array_filter(
|
||||
$this->providers,
|
||||
$this->getProviders(),
|
||||
fn (IMountProvider $mountProvider) => (in_array(get_class($mountProvider), $mountProviderClasses))
|
||||
);
|
||||
return $this->getUserMountsForProviders($user, $providers);
|
||||
@@ -107,9 +93,9 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||
// to check for name collisions
|
||||
$firstMounts = [];
|
||||
if ($providerFilter) {
|
||||
$providers = array_filter($this->providers, $providerFilter);
|
||||
$providers = array_filter($this->getProviders(), $providerFilter);
|
||||
} else {
|
||||
$providers = $this->providers;
|
||||
$providers = $this->getProviders();
|
||||
}
|
||||
$firstProviders = array_filter($providers, function (IMountProvider $provider) {
|
||||
return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
|
||||
@@ -230,12 +216,17 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
||||
}
|
||||
|
||||
public function clearProviders() {
|
||||
$this->registerEventEmitted = false;
|
||||
$this->providers = [];
|
||||
$this->homeProviders = [];
|
||||
$this->rootProviders = [];
|
||||
}
|
||||
|
||||
public function getProviders(): array {
|
||||
if (!$this->registerEventEmitted) {
|
||||
$this->registerEventEmitted = true;
|
||||
$this->eventDispatcher->dispatchTyped(new RegisterMountProviderEvent($this));
|
||||
}
|
||||
return $this->providers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -889,7 +889,8 @@ class Server extends ServerContainer implements IServerContainer {
|
||||
$loader = $c->get(IStorageFactory::class);
|
||||
$mountCache = $c->get(IUserMountCache::class);
|
||||
$eventLogger = $c->get(IEventLogger::class);
|
||||
$manager = new MountProviderCollection($loader, $mountCache, $eventLogger);
|
||||
$eventDispatcher = $c->get(IEventDispatcher::class);
|
||||
$manager = new MountProviderCollection($loader, $mountCache, $eventLogger, $eventDispatcher);
|
||||
|
||||
// builtin providers
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Files\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\Files\Config\IMountProviderCollection;
|
||||
|
||||
/** @since 30.0.0 */
|
||||
class RegisterMountProviderEvent extends Event {
|
||||
/**
|
||||
* @since 30.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private IMountProviderCollection $mountProviderCollection,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mount provider collection to register new providers
|
||||
* @since 30.0.0
|
||||
*/
|
||||
public function getProviderCollection(): IMountProviderCollection {
|
||||
return $this->mountProviderCollection;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user