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 to IBootStrap #28314

Merged
merged 5 commits into from
Oct 20, 2021
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
59 changes: 25 additions & 34 deletions apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Sharing\Activity\Providers\RemoteShares;
use OCA\Files_Sharing\External\Manager;
use OCP\Activity\IManager as IActivityManager;
use OCP\App\IAppManager;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\Exceptions\ActionNotSupportedException;
use OCP\Federation\Exceptions\AuthenticationFailedException;
use OCP\Federation\Exceptions\BadRequestException;
Expand All @@ -59,7 +59,6 @@
use OCP\Share\IManager;
use OCP\Share\IShare;
use OCP\Util;
use Psr\Log\LoggerInterface;

class CloudFederationProviderFiles implements ICloudFederationProvider {

Expand Down Expand Up @@ -108,6 +107,9 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
/** @var IConfig */
private $config;

/** @var Manager */
private $externalShareManager;

/**
* CloudFederationProvider constructor.
*
Expand All @@ -125,22 +127,26 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
* @param ICloudFederationProviderManager $cloudFederationProviderManager
* @param IDBConnection $connection
* @param IGroupManager $groupManager
* @param IConfig $config
* @param Manager $externalShareManager
*/
public function __construct(IAppManager $appManager,
FederatedShareProvider $federatedShareProvider,
AddressHandler $addressHandler,
ILogger $logger,
IUserManager $userManager,
IManager $shareManager,
ICloudIdManager $cloudIdManager,
IActivityManager $activityManager,
INotificationManager $notificationManager,
IURLGenerator $urlGenerator,
ICloudFederationFactory $cloudFederationFactory,
ICloudFederationProviderManager $cloudFederationProviderManager,
IDBConnection $connection,
IGroupManager $groupManager,
IConfig $config
public function __construct(
IAppManager $appManager,
FederatedShareProvider $federatedShareProvider,
AddressHandler $addressHandler,
ILogger $logger,
IUserManager $userManager,
IManager $shareManager,
ICloudIdManager $cloudIdManager,
IActivityManager $activityManager,
INotificationManager $notificationManager,
IURLGenerator $urlGenerator,
ICloudFederationFactory $cloudFederationFactory,
ICloudFederationProviderManager $cloudFederationProviderManager,
IDBConnection $connection,
IGroupManager $groupManager,
IConfig $config,
Manager $externalShareManager
) {
$this->appManager = $appManager;
$this->federatedShareProvider = $federatedShareProvider;
Expand All @@ -157,6 +163,7 @@ public function __construct(IAppManager $appManager,
$this->connection = $connection;
$this->groupManager = $groupManager;
$this->config = $config;
$this->externalShareManager = $externalShareManager;
}


Expand Down Expand Up @@ -239,24 +246,8 @@ public function shareReceived(ICloudFederationShare $share) {
throw new ProviderCouldNotAddShareException('Group does not exists', '',Http::STATUS_BAD_REQUEST);
}

$externalManager = new \OCA\Files_Sharing\External\Manager(
\OC::$server->getDatabaseConnection(),
Filesystem::getMountManager(),
Filesystem::getLoader(),
\OC::$server->getHTTPClientService(),
\OC::$server->getNotificationManager(),
\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
\OC::$server->getCloudFederationProviderManager(),
\OC::$server->getCloudFederationFactory(),
\OC::$server->getGroupManager(),
\OC::$server->getUserManager(),
$shareWith,
\OC::$server->query(IEventDispatcher::class),
\OC::$server->get(LoggerInterface::class)
);

try {
$externalManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId);
$this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId);
$shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');

if ($shareType === IShare::TYPE_USER) {
Expand Down
34 changes: 0 additions & 34 deletions apps/files_sharing/appinfo/app.php

This file was deleted.

105 changes: 40 additions & 65 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
*/
namespace OCA\Files_Sharing\AppInfo;

use OC\AppFramework\Utility\SimpleContainer;
use OC\Share\Share;
use OCA\Files_Sharing\Capabilities;
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider as ExternalMountProvider;
use OCA\Files_Sharing\Helper;
use OCA\Files_Sharing\Listener\LegacyBeforeTemplateRenderedListener;
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
use OCA\Files_Sharing\Listener\LoadSidebarListener;
Expand All @@ -47,72 +49,37 @@
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\IUserSession;
use OCP\L10N\IFactory;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\IManager;
use OCP\Util;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
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);
}

$container = $this->getContainer();

/** @var IServerContainer $server */
$server = $container->getServer();

/** @var IEventDispatcher $dispatcher */
$dispatcher = $container->query(IEventDispatcher::class);
$oldDispatcher = $container->getServer()->getEventDispatcher();
$mountProviderCollection = $server->getMountProviderCollection();
$notifications = $server->getNotificationManager();

/**
* Core class wrappers
*/
$container->registerService(Manager::class, function (SimpleContainer $c) use ($server) {
$user = $server->getUserSession()->getUser();
$uid = $user ? $user->getUID() : null;
return new \OCA\Files_Sharing\External\Manager(
$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(),
$server->getHTTPClientService(),
$server->getNotificationManager(),
$server->query(\OCP\OCS\IDiscoveryService::class),
$server->getCloudFederationProviderManager(),
$server->getCloudFederationFactory(),
$server->getGroupManager(),
$server->getUserManager(),
$uid,
$server->query(IEventDispatcher::class),
$server->get(LoggerInterface::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(
public function register(IRegistrationContext $context): void {
$context->registerService(ExternalMountProvider::class, function (ContainerInterface $c) {
return new ExternalMountProvider(
$c->get(IDBConnection::class),
function () use ($c) {
return $c->get(Manager::class);
Expand All @@ -122,28 +89,40 @@ function () use ($c) {
});

/**
* Register capabilities
* Middleware
*/
$container->registerCapability(Capabilities::class);
$context->registerMiddleWare(SharingCheckMiddleware::class);
$context->registerMiddleWare(OCSShareAPIMiddleware::class);
$context->registerMiddleWare(ShareInfoMiddleware::class);

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

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

public function boot(IBootContext $context): void {
$context->injectFn([$this, 'registerMountProviders']);
$context->injectFn([$this, 'registerEventsScripts']);
$context->injectFn([$this, 'setupSharingMenus']);

Helper::registerHooks();

$this->registerMountProviders($mountProviderCollection);
$this->registerEventsScripts($dispatcher, $oldDispatcher);
$this->setupSharingMenus();
icewind1991 marked this conversation as resolved.
Show resolved Hide resolved
Share::registerBackend('file', File::class);
Share::registerBackend('folder', Folder::class, 'file');
icewind1991 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Always add main sharing script
*/
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'));

public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider) {
$mountProviderCollection->registerProvider($mountProvider);
$mountProviderCollection->registerProvider($externalMountProvider);
}

protected function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) {
public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) {
// sidebar and files scripts
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
$dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
Expand All @@ -168,19 +147,15 @@ protected function registerEventsScripts(IEventDispatcher $dispatcher, EventDisp
});
}

protected function setupSharingMenus() {
/** @var IManager $shareManager */
$shareManager = \OC::$server->get(IManager::class);

public function setupSharingMenus(IManager $shareManager, IFactory $l10nFactory, IUserSession $userSession) {
if (!$shareManager->shareApiEnabled() || !class_exists('\OCA\Files\App')) {
return;
}

$navigationManager = \OCA\Files\App::getNavigationManager();
// show_Quick_Access stored as string
\OCA\Files\App::getNavigationManager()->add(function () use ($shareManager) {
$l = \OC::$server->getL10N('files_sharing');
/** @var IUserSession $userSession */
$userSession = \OC::$server->get(IUserSession::class);
$navigationManager->add(function () use ($shareManager, $l10nFactory, $userSession) {
$l = $l10nFactory->get('files_sharing');
$user = $userSession->getUser();
$userId = $user ? $user->getUID() : null;

Expand Down
31 changes: 17 additions & 14 deletions apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Files_Sharing\External;

use Doctrine\DBAL\Driver\Exception;
Expand All @@ -47,6 +48,7 @@
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Notification\IManager;
use OCP\OCS\IDiscoveryService;
use OCP\Share;
Expand Down Expand Up @@ -83,7 +85,7 @@ class Manager {
/** @var ICloudFederationFactory */
private $cloudFederationFactory;

/** @var IGroupManager */
/** @var IGroupManager */
private $groupManager;

/** @var IUserManager */
Expand All @@ -96,25 +98,26 @@ class Manager {
private $logger;

public function __construct(
IDBConnection $connection,
\OC\Files\Mount\Manager $mountManager,
IStorageFactory $storageLoader,
IClientService $clientService,
IManager $notificationManager,
IDiscoveryService $discoveryService,
IDBConnection $connection,
\OC\Files\Mount\Manager $mountManager,
IStorageFactory $storageLoader,
IClientService $clientService,
IManager $notificationManager,
IDiscoveryService $discoveryService,
ICloudFederationProviderManager $cloudFederationProviderManager,
ICloudFederationFactory $cloudFederationFactory,
IGroupManager $groupManager,
IUserManager $userManager,
?string $uid,
IEventDispatcher $eventDispatcher,
LoggerInterface $logger
ICloudFederationFactory $cloudFederationFactory,
IGroupManager $groupManager,
IUserManager $userManager,
IUserSession $userSession,
IEventDispatcher $eventDispatcher,
LoggerInterface $logger
) {
$user = $userSession->getUser();
$this->connection = $connection;
$this->mountManager = $mountManager;
$this->storageLoader = $storageLoader;
$this->clientService = $clientService;
$this->uid = $uid;
$this->uid = $user ? $user->getUID() : null;
$this->notificationManager = $notificationManager;
$this->discoveryService = $discoveryService;
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
Expand Down
Loading