]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use IBootstrap for the app federatedfilesharing 21816/head
authorMorris Jobke <hey@morrisjobke.de>
Mon, 13 Jul 2020 14:23:59 +0000 (16:23 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 14 Jul 2020 14:34:43 +0000 (16:34 +0200)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
15 files changed:
apps/dav/appinfo/v1/publicwebdav.php
apps/federatedfilesharing/appinfo/app.php [deleted file]
apps/federatedfilesharing/composer/composer/autoload_classmap.php
apps/federatedfilesharing/composer/composer/autoload_static.php
apps/federatedfilesharing/lib/AppInfo/Application.php
apps/federatedfilesharing/lib/Listeners/LoadAdditionalScriptsListener.php [new file with mode: 0644]
apps/files_sharing/lib/ShareBackend/File.php
apps/provisioning_api/composer/composer/autoload_classmap.php
apps/provisioning_api/composer/composer/autoload_static.php
apps/provisioning_api/lib/Controller/UsersController.php
apps/provisioning_api/lib/FederatedFileSharingFactory.php [deleted file]
apps/provisioning_api/lib/FederatedShareProviderFactory.php [new file with mode: 0644]
apps/provisioning_api/tests/Controller/UsersControllerTest.php
apps/settings/lib/Controller/UsersController.php
apps/settings/lib/Settings/Personal/PersonalInfo.php

index e72112aace4de3e3c1a08ab5987d23e9ea66bb0b..5020efd2ad8cef87f4453a7e96e913b16a5f8db5 100644 (file)
@@ -66,8 +66,8 @@ $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin();
 
 $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) {
        $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
-       $federatedSharingApp = \OC::$server->query(\OCA\FederatedFileSharing\AppInfo\Application::class);
-       $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider();
+       /** @var \OCA\FederatedFileSharing\FederatedShareProvider $shareProvider */
+       $federatedShareProvider = \OC::$server->query(\OCA\FederatedFileSharing\FederatedShareProvider::class);
        if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
                // this is what is thrown when trying to access a non-existing share
                throw new \Sabre\DAV\Exception\NotAuthenticated();
diff --git a/apps/federatedfilesharing/appinfo/app.php b/apps/federatedfilesharing/appinfo/app.php
deleted file mode 100644 (file)
index e4a94d8..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-use OCA\FederatedFileSharing\AppInfo\Application;
-
-\OC::$server->query(Application::class);
index 15573f5434f812ab26c95cd6776b84a6b6423405..0806082369289bc19ce981fb36577aa48fc76369 100644 (file)
@@ -12,6 +12,7 @@ return array(
     'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => $baseDir . '/../lib/Controller/MountPublicLinkController.php',
     'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => $baseDir . '/../lib/Controller/RequestHandlerController.php',
     'OCA\\FederatedFileSharing\\FederatedShareProvider' => $baseDir . '/../lib/FederatedShareProvider.php',
+    'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/LoadAdditionalScriptsListener.php',
     'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => $baseDir . '/../lib/Migration/Version1010Date20200630191755.php',
     'OCA\\FederatedFileSharing\\Notifications' => $baseDir . '/../lib/Notifications.php',
     'OCA\\FederatedFileSharing\\Notifier' => $baseDir . '/../lib/Notifier.php',
index 24c93eee973891441d23cbdecb08364d222a5723..b0e17eb568f1d77f0a972bd1e845b5146dea6d8b 100644 (file)
@@ -27,6 +27,7 @@ class ComposerStaticInitFederatedFileSharing
         'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => __DIR__ . '/..' . '/../lib/Controller/MountPublicLinkController.php',
         'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => __DIR__ . '/..' . '/../lib/Controller/RequestHandlerController.php',
         'OCA\\FederatedFileSharing\\FederatedShareProvider' => __DIR__ . '/..' . '/../lib/FederatedShareProvider.php',
+        'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadAdditionalScriptsListener.php',
         'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191755.php',
         'OCA\\FederatedFileSharing\\Notifications' => __DIR__ . '/..' . '/../lib/Notifications.php',
         'OCA\\FederatedFileSharing\\Notifier' => __DIR__ . '/..' . '/../lib/Notifier.php',
index f38f583d85a96bf79c7d08b74da676d3a2b4a138..09f881d5bb85c231a6b57a1f84c31fc9f5a65437 100644 (file)
@@ -2,7 +2,6 @@
 /**
  * @copyright Copyright (c) 2016, ownCloud, Inc.
  *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
  * @author Björn Schießle <bjoern@schiessle.org>
  * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
 
 namespace OCA\FederatedFileSharing\AppInfo;
 
-use OC\AppFramework\Utility\SimpleContainer;
-use OCA\FederatedFileSharing\AddressHandler;
-use OCA\FederatedFileSharing\Controller\RequestHandlerController;
-use OCA\FederatedFileSharing\FederatedShareProvider;
-use OCA\FederatedFileSharing\Notifications;
+use OCA\FederatedFileSharing\Listeners\LoadAdditionalScriptsListener;
 use OCA\FederatedFileSharing\Notifier;
 use OCA\FederatedFileSharing\OCM\CloudFederationProviderFiles;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
 use OCP\AppFramework\App;
-use OCP\GlobalScale\IConfig;
-
-class Application extends App {
-
-       /** @var FederatedShareProvider */
-       protected $federatedShareProvider;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
 
+class Application extends App implements IBootstrap {
        public function __construct() {
                parent::__construct('federatedfilesharing');
+       }
 
-               $container = $this->getContainer();
-               $server = $container->getServer();
+       public function register(IRegistrationContext $context): void {
+               $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class);
+       }
+
+       public function boot(IBootContext $context): void {
+               $server = $context->getServerContainer();
 
                $cloudFederationManager = $server->getCloudFederationProviderManager();
                $cloudFederationManager->addCloudFederationProvider('file',
                        'Federated Files Sharing',
-                       function () use ($container) {
-                               $server = $container->getServer();
-                               return new CloudFederationProviderFiles(
-                                       $server->getAppManager(),
-                                       $server->query(FederatedShareProvider::class),
-                                       $server->query(AddressHandler::class),
-                                       $server->getLogger(),
-                                       $server->getUserManager(),
-                                       $server->getShareManager(),
-                                       $server->getCloudIdManager(),
-                                       $server->getActivityManager(),
-                                       $server->getNotificationManager(),
-                                       $server->getURLGenerator(),
-                                       $server->getCloudFederationFactory(),
-                                       $server->getCloudFederationProviderManager(),
-                                       $server->getDatabaseConnection(),
-                                       $server->getGroupManager()
-                               );
+                       function () use ($server) {
+                               return $server->query(CloudFederationProviderFiles::class);
                        });
 
-               $container->registerService('RequestHandlerController', function (SimpleContainer $c) use ($server) {
-                       $addressHandler = new AddressHandler(
-                               $server->getURLGenerator(),
-                               $server->getL10N('federatedfilesharing'),
-                               $server->getCloudIdManager()
-                       );
-                       $notification = new Notifications(
-                               $addressHandler,
-                               $server->getHTTPClientService(),
-                               $server->query(\OCP\OCS\IDiscoveryService::class),
-                               \OC::$server->getJobList(),
-                               \OC::$server->getCloudFederationProviderManager(),
-                               \OC::$server->getCloudFederationFactory()
-                       );
-                       return new RequestHandlerController(
-                               $c->query('AppName'),
-                               $server->getRequest(),
-                               $this->getFederatedShareProvider(),
-                               $server->getDatabaseConnection(),
-                               $server->getShareManager(),
-                               $notification,
-                               $addressHandler,
-                               $server->getUserManager(),
-                               $server->getCloudIdManager(),
-                               $server->getLogger(),
-                               $server->getCloudFederationFactory(),
-                               $server->getCloudFederationProviderManager()
-                       );
-               });
-
-               // register events listeners
-               $eventDispatcher = $server->getEventDispatcher();
                $manager = $server->getNotificationManager();
-               $federatedShareProvider = $this->getFederatedShareProvider();
-
                $manager->registerNotifierService(Notifier::class);
-               
-               $eventDispatcher->addListener(
-                       'OCA\Files::loadAdditionalScripts',
-                       function () use ($federatedShareProvider) {
-                               if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) {
-                                       \OCP\Util::addScript('federatedfilesharing', 'external');
-                               }
-                       }
-               );
-       }
-
-       /**
-        * get instance of federated share provider
-        *
-        * @return FederatedShareProvider
-        */
-       public function getFederatedShareProvider() {
-               if ($this->federatedShareProvider === null) {
-                       $this->initFederatedShareProvider();
-               }
-               return $this->federatedShareProvider;
-       }
-
-       /**
-        * initialize federated share provider
-        */
-       protected function initFederatedShareProvider() {
-               $c = $this->getContainer();
-               $addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
-                       \OC::$server->getURLGenerator(),
-                       \OC::$server->getL10N('federatedfilesharing'),
-                       \OC::$server->getCloudIdManager()
-               );
-               $notifications = new \OCA\FederatedFileSharing\Notifications(
-                       $addressHandler,
-                       \OC::$server->getHTTPClientService(),
-                       \OC::$server->query(\OCP\OCS\IDiscoveryService::class),
-                       \OC::$server->getJobList(),
-                       \OC::$server->getCloudFederationProviderManager(),
-                       \OC::$server->getCloudFederationFactory()
-               );
-               $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler(
-                       \OC::$server->getSecureRandom()
-               );
-
-               $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider(
-                       \OC::$server->getDatabaseConnection(),
-                       $addressHandler,
-                       $notifications,
-                       $tokenHandler,
-                       \OC::$server->getL10N('federatedfilesharing'),
-                       \OC::$server->getLogger(),
-                       \OC::$server->getLazyRootFolder(),
-                       \OC::$server->getConfig(),
-                       \OC::$server->getUserManager(),
-                       \OC::$server->getCloudIdManager(),
-                       $c->query(IConfig::class),
-                       \OC::$server->getCloudFederationProviderManager()
-
-               );
        }
 }
diff --git a/apps/federatedfilesharing/lib/Listeners/LoadAdditionalScriptsListener.php b/apps/federatedfilesharing/lib/Listeners/LoadAdditionalScriptsListener.php
new file mode 100644 (file)
index 0000000..3901a1c
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
+ *
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\FederatedFileSharing\Listeners;
+
+use OCA\FederatedFileSharing\FederatedShareProvider;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+class LoadAdditionalScriptsListener implements IEventListener {
+       /** @var FederatedShareProvider */
+       protected $federatedShareProvider;
+
+       public function __construct(FederatedShareProvider $federatedShareProvider) {
+               $this->federatedShareProvider = $federatedShareProvider;
+       }
+
+       public function handle(Event $event): void {
+               if (!$event instanceof LoadAdditionalScriptsEvent) {
+                       return;
+               }
+
+               if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled()) {
+                       \OCP\Util::addScript('federatedfilesharing', 'external');
+               }
+       }
+}
index 60deebc5c01d2d9a766810c7f805231da8410efe..cdda89cbc6345ffd846a63c6d2975ee538befc7e 100644 (file)
@@ -34,7 +34,6 @@
 
 namespace OCA\Files_Sharing\ShareBackend;
 
-use OCA\FederatedFileSharing\AppInfo\Application;
 use OCA\FederatedFileSharing\FederatedShareProvider;
 use OCP\Share\IShare;
 
@@ -56,8 +55,7 @@ class File implements \OCP\Share_Backend_File_Dependent {
                if ($federatedShareProvider) {
                        $this->federatedShareProvider = $federatedShareProvider;
                } else {
-                       $federatedSharingApp = \OC::$server->query(Application::class);
-                       $this->federatedShareProvider = $federatedSharingApp->getFederatedShareProvider();
+                       $this->federatedShareProvider = \OC::$server->query(FederatedShareProvider::class);
                }
        }
 
index 760eae829787f76a04fbeb4201223ecbaebdb6b4..0690f069c2931e7a3ede347f1b2478f50eb4a1ac 100644 (file)
@@ -12,7 +12,7 @@ return array(
     'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php',
     'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php',
     'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php',
-    'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir . '/../lib/FederatedFileSharingFactory.php',
+    'OCA\\Provisioning_API\\FederatedShareProviderFactory' => $baseDir . '/../lib/FederatedShareProviderFactory.php',
     'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
     'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir . '/../lib/Middleware/ProvisioningApiMiddleware.php',
 );
index ccd4d54dccf2245d43e091d790dd4a42db5c3f56..d160f6ac64e82206d96b297bfd82c16d9facd372 100644 (file)
@@ -27,7 +27,7 @@ class ComposerStaticInitProvisioning_API
         'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php',
         'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php',
         'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php',
-        'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__ . '/..' . '/../lib/FederatedFileSharingFactory.php',
+        'OCA\\Provisioning_API\\FederatedShareProviderFactory' => __DIR__ . '/..' . '/../lib/FederatedShareProviderFactory.php',
         'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
         'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ProvisioningApiMiddleware.php',
     );
index 52a712dc8483ad6db384d2ef4c2672594430c2c4..6e8613085d0ad2d525e2e756af4df59d3f7d3f7f 100644 (file)
@@ -43,7 +43,7 @@ namespace OCA\Provisioning_API\Controller;
 use OC\Accounts\AccountManager;
 use OC\Authentication\Token\RemoteWipe;
 use OC\HintException;
-use OCA\Provisioning_API\FederatedFileSharingFactory;
+use OCA\Provisioning_API\FederatedShareProviderFactory;
 use OCA\Settings\Mailer\NewUserMailHelper;
 use OCP\App\IAppManager;
 use OCP\AppFramework\Http\DataResponse;
@@ -70,8 +70,8 @@ class UsersController extends AUserData {
        protected $l10nFactory;
        /** @var NewUserMailHelper */
        private $newUserMailHelper;
-       /** @var FederatedFileSharingFactory */
-       private $federatedFileSharingFactory;
+       /** @var FederatedShareProviderFactory */
+       private $federatedShareProviderFactory;
        /** @var ISecureRandom */
        private $secureRandom;
        /** @var RemoteWipe */
@@ -88,7 +88,7 @@ class UsersController extends AUserData {
                                                                ILogger $logger,
                                                                IFactory $l10nFactory,
                                                                NewUserMailHelper $newUserMailHelper,
-                                                               FederatedFileSharingFactory $federatedFileSharingFactory,
+                                                               FederatedShareProviderFactory $federatedShareProviderFactory,
                                                                ISecureRandom $secureRandom,
                                                                RemoteWipe $remoteWipe) {
                parent::__construct($appName,
@@ -104,7 +104,7 @@ class UsersController extends AUserData {
                $this->logger = $logger;
                $this->l10nFactory = $l10nFactory;
                $this->newUserMailHelper = $newUserMailHelper;
-               $this->federatedFileSharingFactory = $federatedFileSharingFactory;
+               $this->federatedShareProviderFactory = $federatedShareProviderFactory;
                $this->secureRandom = $secureRandom;
                $this->remoteWipe = $remoteWipe;
        }
@@ -418,8 +418,7 @@ class UsersController extends AUserData {
                }
 
                if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
-                       $federatedFileSharing = $this->federatedFileSharingFactory->get();
-                       $shareProvider = $federatedFileSharing->getFederatedShareProvider();
+                       $shareProvider = $this->federatedShareProviderFactory->get();
                        if ($shareProvider->isLookupServerUploadEnabled()) {
                                $permittedFields[] = AccountManager::PROPERTY_PHONE;
                                $permittedFields[] = AccountManager::PROPERTY_ADDRESS;
@@ -473,8 +472,7 @@ class UsersController extends AUserData {
                        }
 
                        if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
-                               $federatedFileSharing = \OC::$server->query(\OCA\FederatedFileSharing\AppInfo\Application::class);
-                               $shareProvider = $federatedFileSharing->getFederatedShareProvider();
+                               $shareProvider = $this->federatedShareProviderFactory->get();
                                if ($shareProvider->isLookupServerUploadEnabled()) {
                                        $permittedFields[] = AccountManager::PROPERTY_PHONE;
                                        $permittedFields[] = AccountManager::PROPERTY_ADDRESS;
diff --git a/apps/provisioning_api/lib/FederatedFileSharingFactory.php b/apps/provisioning_api/lib/FederatedFileSharingFactory.php
deleted file mode 100644 (file)
index 6a63054..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-declare(strict_types=1);
-
-namespace OCA\Provisioning_API;
-
-use OCA\FederatedFileSharing\AppInfo\Application;
-use OCP\IServerContainer;
-
-class FederatedFileSharingFactory {
-
-       /** @var IServerContainer */
-       private $serverContainer;
-
-       public function __construct(IServerContainer $serverContainer) {
-               $this->serverContainer = $serverContainer;
-       }
-
-       public function get(): Application {
-               return $this->serverContainer->query(Application::class);
-       }
-}
diff --git a/apps/provisioning_api/lib/FederatedShareProviderFactory.php b/apps/provisioning_api/lib/FederatedShareProviderFactory.php
new file mode 100644 (file)
index 0000000..45da52e
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+declare(strict_types=1);
+
+namespace OCA\Provisioning_API;
+
+use OCA\FederatedFileSharing\FederatedShareProvider;
+use OCP\IServerContainer;
+
+class FederatedShareProviderFactory {
+
+       /** @var IServerContainer */
+       private $serverContainer;
+
+       public function __construct(IServerContainer $serverContainer) {
+               $this->serverContainer = $serverContainer;
+       }
+
+       public function get(): FederatedShareProvider {
+               return $this->serverContainer->query(FederatedShareProvider::class);
+       }
+}
index f001611cebed9231feadfe750b434c0173b657b8..152a652665380d88e2b7d7651288cabb46acdb12 100644 (file)
@@ -42,10 +42,9 @@ use OC\Accounts\AccountManager;
 use OC\Authentication\Token\RemoteWipe;
 use OC\Group\Manager;
 use OC\SubAdmin;
-use OCA\FederatedFileSharing\AppInfo\Application;
 use OCA\FederatedFileSharing\FederatedShareProvider;
 use OCA\Provisioning_API\Controller\UsersController;
-use OCA\Provisioning_API\FederatedFileSharingFactory;
+use OCA\Provisioning_API\FederatedShareProviderFactory;
 use OCA\Settings\Mailer\NewUserMailHelper;
 use OCP\App\IAppManager;
 use OCP\AppFramework\Http\DataResponse;
@@ -89,8 +88,8 @@ class UsersControllerTest extends TestCase {
        private $l10nFactory;
        /** @var NewUserMailHelper|PHPUnit_Framework_MockObject_MockObject */
        private $newUserMailHelper;
-       /** @var FederatedFileSharingFactory|\PHPUnit_Framework_MockObject_MockObject */
-       private $federatedFileSharingFactory;
+       /** @var FederatedShareProviderFactory|\PHPUnit_Framework_MockObject_MockObject */
+       private $federatedShareProviderFactory;
        /** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
        private $secureRandom;
        /** @var RemoteWipe|MockObject */
@@ -109,7 +108,7 @@ class UsersControllerTest extends TestCase {
                $this->accountManager = $this->createMock(AccountManager::class);
                $this->l10nFactory = $this->createMock(IFactory::class);
                $this->newUserMailHelper = $this->createMock(NewUserMailHelper::class);
-               $this->federatedFileSharingFactory = $this->createMock(FederatedFileSharingFactory::class);
+               $this->federatedShareProviderFactory = $this->createMock(FederatedShareProviderFactory::class);
                $this->secureRandom = $this->createMock(ISecureRandom::class);
                $this->remoteWipe = $this->createMock(RemoteWipe::class);
 
@@ -126,7 +125,7 @@ class UsersControllerTest extends TestCase {
                                $this->logger,
                                $this->l10nFactory,
                                $this->newUserMailHelper,
-                               $this->federatedFileSharingFactory,
+                               $this->federatedShareProviderFactory,
                                $this->secureRandom,
                                $this->remoteWipe,
                        ])
@@ -388,7 +387,7 @@ class UsersControllerTest extends TestCase {
                                $this->logger,
                                $this->l10nFactory,
                                $this->newUserMailHelper,
-                               $this->federatedFileSharingFactory,
+                               $this->federatedShareProviderFactory,
                                $this->secureRandom,
                                $this->remoteWipe
                        ])
@@ -3124,7 +3123,7 @@ class UsersControllerTest extends TestCase {
                                $this->logger,
                                $this->l10nFactory,
                                $this->newUserMailHelper,
-                               $this->federatedFileSharingFactory,
+                               $this->federatedShareProviderFactory,
                                $this->secureRandom,
                                $this->remoteWipe,
                        ])
@@ -3188,7 +3187,7 @@ class UsersControllerTest extends TestCase {
                                $this->logger,
                                $this->l10nFactory,
                                $this->newUserMailHelper,
-                               $this->federatedFileSharingFactory,
+                               $this->federatedShareProviderFactory,
                                $this->secureRandom,
                                $this->remoteWipe,
                        ])
@@ -3555,14 +3554,9 @@ class UsersControllerTest extends TestCase {
                $shareprovider = $this->createMock(FederatedShareProvider::class);
                $shareprovider->method('isLookupServerUploadEnabled')->willReturn(true);
 
-               $federatedFileSharing = $this->createMock(Application::class);
-               $federatedFileSharing
-                       ->method('getFederatedShareProvider')
-                       ->willReturn($shareprovider);
-
-               $this->federatedFileSharingFactory
+               $this->federatedShareProviderFactory
                        ->method('get')
-                       ->willReturn($federatedFileSharing);
+                       ->willReturn($shareprovider);
 
                $expectedResp = new DataResponse($expected);
                $this->assertEquals($expectedResp, $this->api->getEditableFields());
index eab6c087d86261bc1ba3cb8d2cf77b0e768adb5e..b6e43fcae85d4ae7b28319af8b1d6e4ab7f95fd3 100644 (file)
@@ -36,6 +36,7 @@ use OC\AppFramework\Http;
 use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
 use OC\ForbiddenException;
 use OC\Security\IdentityProof\Manager;
+use OCA\FederatedFileSharing\FederatedShareProvider;
 use OCA\Settings\BackgroundJobs\VerifyUserData;
 use OCA\User_LDAP\User_Proxy;
 use OCP\App\IAppManager;
@@ -362,8 +363,7 @@ class UsersController extends Controller {
                        $data[AccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope];
                }
                if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
-                       $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
-                       $shareProvider = $federatedFileSharing->getFederatedShareProvider();
+                       $shareProvider = \OC::$server->query(FederatedShareProvider::class);
                        if ($shareProvider->isLookupServerUploadEnabled()) {
                                $data[AccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope];
                                $data[AccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope];
index 152259b743f3ddce7357c2a2ee3a614fad984ad7..c4b505c424854579b3ba86ecd415d90041cd6ae7 100644 (file)
@@ -32,7 +32,7 @@
 namespace OCA\Settings\Settings\Personal;
 
 use OC\Accounts\AccountManager;
-use OCA\FederatedFileSharing\AppInfo\Application;
+use OCA\FederatedFileSharing\FederatedShareProvider;
 use OCP\App\IAppManager;
 use OCP\AppFramework\Http\TemplateResponse;
 use OCP\Files\FileInfo;
@@ -96,8 +96,8 @@ class PersonalInfo implements ISettings {
                $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
                $lookupServerUploadEnabled = false;
                if ($federatedFileSharingEnabled) {
-                       $federatedFileSharing = \OC::$server->query(Application::class);
-                       $shareProvider = $federatedFileSharing->getFederatedShareProvider();
+                       /** @var FederatedShareProvider $shareProvider */
+                       $shareProvider = \OC::$server->query(FederatedShareProvider::class);
                        $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
                }