Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move files_sharing from app.php to IBootstrap #24035

Closed
wants to merge 2 commits into from
Closed
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
35 changes: 0 additions & 35 deletions apps/files_sharing/appinfo/app.php

This file was deleted.

73 changes: 43 additions & 30 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,62 @@
use OCA\Files_Sharing\Notification\Notifier;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCA\Files_Sharing\ShareBackend\File;
use OCA\Files_Sharing\ShareBackend\Folder;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudIdManager;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Group\Events\UserAddedEvent;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IServerContainer;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Util;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class Application extends App {
class Application extends App implements IBootstrap {
public const APP_ID = 'files_sharing';

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
}

public function register(IRegistrationContext $context): void {
/**
* Middleware
*/
$context->registerMiddleWare(SharingCheckMiddleware::class);
$context->registerMiddleWare(OCSShareAPIMiddleware::class);
$context->registerMiddleWare(ShareInfoMiddleware::class);

/**
* Capabilities
*/
$context->registerCapability(Capabilities::class);

/**
* Events
*/
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
$context->registerEventListener(ShareCreatedEvent::class, ShareInteractionListener::class);
$context->registerEventListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class);
$context->registerEventListener(UserAddedEvent::class, UserAddedToGroupListener::class);
}

$container = $this->getContainer();
public function boot(IBootContext $context): void {
\OCA\Files_Sharing\Helper::registerHooks();

/** @var IServerContainer $server */
$server = $container->getServer();
\OC\Share\Share::registerBackend('file', File::class);
\OC\Share\Share::registerBackend('folder', Folder::class, 'file');

$container = $context->getAppContainer();
$server = $context->getServerContainer();

/** @var IEventDispatcher $dispatcher */
$dispatcher = $container->query(IEventDispatcher::class);
Expand Down Expand Up @@ -100,14 +132,6 @@ public function __construct(array $urlParams = []) {
$server->query(IEventDispatcher::class)
);
});

/**
* Middleware
*/
$container->registerMiddleWare(SharingCheckMiddleware::class);
$container->registerMiddleWare(OCSShareAPIMiddleware::class);
$container->registerMiddleWare(ShareInfoMiddleware::class);

$container->registerService('ExternalMountProvider', function (ContainerInterface $c) {
return new \OCA\Files_Sharing\External\MountProvider(
$c->get(IDBConnection::class),
Expand All @@ -118,14 +142,14 @@ function () use ($c) {
);
});

$notifications->registerNotifierService(Notifier::class);

/**
* Register capabilities
* Mount provider
*/
$container->registerCapability(Capabilities::class);

$notifications->registerNotifierService(Notifier::class);
$mountProviderCollection->registerProvider($container->query(MountProvider::class));
$mountProviderCollection->registerProvider($container->query('ExternalMountProvider'));

$this->registerMountProviders($mountProviderCollection);
$this->registerEventsScripts($dispatcher, $oldDispatcher);
$this->setupSharingMenus();

Expand All @@ -135,22 +159,11 @@ function () use ($c) {
Util::addScript(self::APP_ID, 'dist/main');
}

protected function registerMountProviders(IMountProviderCollection $mountProviderCollection) {
$mountProviderCollection->registerProvider($this->getContainer()->query(MountProvider::class));
$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
}

protected function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) {
// sidebar and files scripts
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
$dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
$dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class);
$dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () {
\OCP\Util::addScript('files_sharing', 'dist/collaboration');
});
$dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class);
$dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class);

// notifications api to accept incoming user shares
$oldDispatcher->addListener('OCP\Share::postShare', function (GenericEvent $event) {
Expand Down
3 changes: 3 additions & 0 deletions apps/files_sharing/tests/SharedStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ protected function tearDown(): void {

\OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');

\OC\Share\Share::unregisterBackend('file');
\OC\Share\Share::unregisterBackend('folder');

parent::tearDown();
}

Expand Down
9 changes: 9 additions & 0 deletions lib/private/Share/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ public static function registerBackend($itemType, $class, $collectionOf = null,
return false;
}

/**
* Unregister a sharing backend
* @param string $itemType Item type
* @internal FOR TESTING ONLY
*/
public static function unregisterBackend($itemType) {
unset(self::$backendTypes[$itemType]);
}

/**
* Get the items of item type shared with the current user
* @param string $itemType
Expand Down