diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-07-13 15:43:42 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-07-23 08:33:17 +0200 |
commit | 0763a173321488acaadceb1eb0ecf1ec8691bf21 (patch) | |
tree | e3a722bae6695c6ce2e0feaf06298effcf92d773 /apps/federatedfilesharing | |
parent | 99d0ba5f7ea45bb636cfcfc2de144e25af88b916 (diff) | |
download | nextcloud-server-0763a173321488acaadceb1eb0ecf1ec8691bf21.tar.gz nextcloud-server-0763a173321488acaadceb1eb0ecf1ec8691bf21.zip |
Move federated_share_added into a typed event
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'apps/federatedfilesharing')
6 files changed, 78 insertions, 13 deletions
diff --git a/apps/federatedfilesharing/composer/composer/autoload_classmap.php b/apps/federatedfilesharing/composer/composer/autoload_classmap.php index 08060823692..8d1364c0d6a 100644 --- a/apps/federatedfilesharing/composer/composer/autoload_classmap.php +++ b/apps/federatedfilesharing/composer/composer/autoload_classmap.php @@ -11,6 +11,7 @@ return array( 'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => $baseDir . '/../lib/BackgroundJob/RetryJob.php', 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => $baseDir . '/../lib/Controller/MountPublicLinkController.php', 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => $baseDir . '/../lib/Controller/RequestHandlerController.php', + 'OCA\\FederatedFileSharing\\Events\\FederatedShareAddedEvent' => $baseDir . '/../lib/Events/FederatedShareAddedEvent.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', diff --git a/apps/federatedfilesharing/composer/composer/autoload_static.php b/apps/federatedfilesharing/composer/composer/autoload_static.php index b0e17eb568f..6e352d6f325 100644 --- a/apps/federatedfilesharing/composer/composer/autoload_static.php +++ b/apps/federatedfilesharing/composer/composer/autoload_static.php @@ -26,6 +26,7 @@ class ComposerStaticInitFederatedFileSharing 'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/RetryJob.php', 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => __DIR__ . '/..' . '/../lib/Controller/MountPublicLinkController.php', 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => __DIR__ . '/..' . '/../lib/Controller/RequestHandlerController.php', + 'OCA\\FederatedFileSharing\\Events\\FederatedShareAddedEvent' => __DIR__ . '/..' . '/../lib/Events/FederatedShareAddedEvent.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', diff --git a/apps/federatedfilesharing/lib/Events/FederatedShareAddedEvent.php b/apps/federatedfilesharing/lib/Events/FederatedShareAddedEvent.php new file mode 100644 index 00000000000..f1269b9f938 --- /dev/null +++ b/apps/federatedfilesharing/lib/Events/FederatedShareAddedEvent.php @@ -0,0 +1,54 @@ +<?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\Events; + +use OCP\EventDispatcher\Event; + +/** + * This event is triggered when a federated share is successfully added + * + * @since 20.0.0 + */ +class FederatedShareAddedEvent extends Event { + + /** @var string */ + private $remote; + + /** + * @since 20.0.0 + */ + public function __construct(string $remote) { + $this->remote = $remote; + } + + /** + * @since 20.0.0 + */ + public function getRemote(): string { + return $this->remote; + } +} diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php index 7b2105ecb0f..2dc3104e6a7 100644 --- a/apps/federatedfilesharing/lib/Notifications.php +++ b/apps/federatedfilesharing/lib/Notifications.php @@ -25,8 +25,10 @@ namespace OCA\FederatedFileSharing; +use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Http\Client\IClientService; @@ -53,21 +55,17 @@ class Notifications { /** @var ICloudFederationFactory */ private $cloudFederationFactory; - /** - * @param AddressHandler $addressHandler - * @param IClientService $httpClientService - * @param IDiscoveryService $discoveryService - * @param IJobList $jobList - * @param ICloudFederationProviderManager $federationProviderManager - * @param ICloudFederationFactory $cloudFederationFactory - */ + /** @var IEventDispatcher */ + private $eventDispatcher; + public function __construct( AddressHandler $addressHandler, IClientService $httpClientService, IDiscoveryService $discoveryService, IJobList $jobList, ICloudFederationProviderManager $federationProviderManager, - ICloudFederationFactory $cloudFederationFactory + ICloudFederationFactory $cloudFederationFactory, + IEventDispatcher $eventDispatcher ) { $this->addressHandler = $addressHandler; $this->httpClientService = $httpClientService; @@ -75,6 +73,7 @@ class Notifications { $this->jobList = $jobList; $this->federationProviderManager = $federationProviderManager; $this->cloudFederationFactory = $cloudFederationFactory; + $this->eventDispatcher = $eventDispatcher; } /** @@ -119,7 +118,8 @@ class Notifications { $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { - \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); + $event = new FederatedShareAddedEvent($remote); + $this->eventDispatcher->dispatchTyped($event); return true; } } diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index d427e324e1f..228e481655e 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -34,6 +34,7 @@ use OCA\Files_Sharing\Activity\Providers\RemoteShares; 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; @@ -240,7 +241,8 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { \OC::$server->getCloudFederationFactory(), \OC::$server->getGroupManager(), \OC::$server->getUserManager(), - $shareWith + $shareWith, + \OC::$server->query(IEventDispatcher::class) ); try { diff --git a/apps/federatedfilesharing/tests/NotificationsTest.php b/apps/federatedfilesharing/tests/NotificationsTest.php index af48b594380..32ceedd45c0 100644 --- a/apps/federatedfilesharing/tests/NotificationsTest.php +++ b/apps/federatedfilesharing/tests/NotificationsTest.php @@ -27,6 +27,7 @@ namespace OCA\FederatedFileSharing\Tests; use OCA\FederatedFileSharing\AddressHandler; use OCA\FederatedFileSharing\Notifications; use OCP\BackgroundJob\IJobList; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Http\Client\IClientService; @@ -52,6 +53,9 @@ class NotificationsTest extends \Test\TestCase { /** @var ICloudFederationFactory|\PHPUnit_Framework_MockObject_MockObject */ private $cloudFederationFactory; + /** @var IEventDispatcher|\PHPUnit_Framework_MockObject_MockObject */ + private $eventDispatcher; + protected function setUp(): void { parent::setUp(); @@ -62,6 +66,7 @@ class NotificationsTest extends \Test\TestCase { ->disableOriginalConstructor()->getMock(); $this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class); $this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); } /** @@ -78,7 +83,8 @@ class NotificationsTest extends \Test\TestCase { $this->discoveryService, $this->jobList, $this->cloudFederationProviderManager, - $this->cloudFederationFactory + $this->cloudFederationFactory, + $this->eventDispatcher ); } else { $instance = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications') @@ -89,7 +95,8 @@ class NotificationsTest extends \Test\TestCase { $this->discoveryService, $this->jobList, $this->cloudFederationProviderManager, - $this->cloudFederationFactory + $this->cloudFederationFactory, + $this->eventDispatcher ] )->setMethods($mockedMethods)->getMock(); } |