Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib/AppInfo/Application.php')
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php116
1 files changed, 49 insertions, 67 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php
index 078a0a5f59d..056d246296f 100644
--- a/apps/files_sharing/lib/AppInfo/Application.php
+++ b/apps/files_sharing/lib/AppInfo/Application.php
@@ -5,7 +5,7 @@
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
@@ -27,13 +27,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
-
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;
@@ -48,68 +49,37 @@ use OCA\Files_Sharing\Notification\Listener;
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 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)
- );
- });
-
- /**
- * 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);
@@ -119,15 +89,26 @@ class Application extends App {
});
/**
- * 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();
+ Share::registerBackend('file', File::class);
+ Share::registerBackend('folder', Folder::class, 'file');
/**
* Always add main sharing script
@@ -135,12 +116,13 @@ class Application extends App {
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);
@@ -165,21 +147,21 @@ class Application extends App {
});
}
- protected function setupSharingMenus() {
- $config = \OC::$server->getConfig();
-
- if ($config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes' || !class_exists('\OCA\Files\App')) {
+ 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 () {
- $config = \OC::$server->getConfig();
- $l = \OC::$server->getL10N('files_sharing');
+ $navigationManager->add(function () use ($shareManager, $l10nFactory, $userSession) {
+ $l = $l10nFactory->get('files_sharing');
+ $user = $userSession->getUser();
+ $userId = $user ? $user->getUID() : null;
$sharingSublistArray = [];
- if (\OCP\Util::isSharingDisabledForUser() === false) {
+ if ($shareManager->sharingDisabledForUser($userId) === false) {
$sharingSublistArray[] = [
'id' => 'sharingout',
'appname' => 'files_sharing',
@@ -197,9 +179,9 @@ class Application extends App {
'name' => $l->t('Shared with you'),
];
- if (\OCP\Util::isSharingDisabledForUser() === false) {
+ if ($shareManager->sharingDisabledForUser($userId) === false) {
// Check if sharing by link is enabled
- if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') {
+ if ($shareManager->shareApiAllowLinks()) {
$sharingSublistArray[] = [
'id' => 'sharinglinks',
'appname' => 'files_sharing',