Skip to content

Commit

Permalink
Move files_sharing from app.php to IBootstrap
Browse files Browse the repository at this point in the history
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
  • Loading branch information
MorrisJobke committed Nov 10, 2020
1 parent f23c216 commit 0233977
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 65 deletions.
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

0 comments on commit 0233977

Please sign in to comment.