From 7675ec1ec1cffaf831d2305f4660d8c1f315f01a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 12 Oct 2023 15:30:12 +0200 Subject: [PATCH] feat(federation): Register the OCM resource Signed-off-by: Joas Schilling --- lib/AppInfo/Application.php | 3 + .../Listener/ResourceTypeRegisterListener.php | 66 +++++++++++++++++++ .../features/bootstrap/FeatureContext.php | 29 ++++++++ .../features/federation/ocm.feature | 8 +++ 4 files changed, 106 insertions(+) create mode 100644 lib/Federation/Proxy/TalkV1/Listener/ResourceTypeRegisterListener.php create mode 100644 tests/integration/features/federation/ocm.feature diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index e4900b174c1..8b8f37308e6 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -84,6 +84,7 @@ use OCA\Talk\Events\SystemMessagesMultipleSentEvent; use OCA\Talk\Events\UserJoinedRoomEvent; use OCA\Talk\Federation\CloudFederationProviderTalk; +use OCA\Talk\Federation\Proxy\TalkV1\Listener\ResourceTypeRegisterListener; use OCA\Talk\Federation\Proxy\TalkV1\Notifier\BeforeRoomDeletedListener as TalkV1BeforeRoomDeletedListener; use OCA\Talk\Federation\Proxy\TalkV1\Notifier\CancelRetryOCMListener as TalkV1CancelRetryOCMListener; use OCA\Talk\Federation\Proxy\TalkV1\Notifier\MessageSentListener as TalkV1MessageSentListener; @@ -146,6 +147,7 @@ use OCP\IUser; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\OCM\Events\ResourceTypeRegisterEvent; use OCP\Security\CSP\AddContentSecurityPolicyEvent; use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent; use OCP\Server; @@ -288,6 +290,7 @@ public function register(IRegistrationContext $context): void { $context->registerEventListener(SystemMessageSentEvent::class, TalkV1MessageSentListener::class); $context->registerEventListener(SystemMessagesMultipleSentEvent::class, TalkV1MessageSentListener::class); $context->registerEventListener(AttendeeRemovedEvent::class, TalkV1CancelRetryOCMListener::class); + $context->registerEventListener(ResourceTypeRegisterEvent::class, ResourceTypeRegisterListener::class); // Signaling listeners (External) $context->registerEventListener(AttendeesAddedEvent::class, SignalingListener::class); diff --git a/lib/Federation/Proxy/TalkV1/Listener/ResourceTypeRegisterListener.php b/lib/Federation/Proxy/TalkV1/Listener/ResourceTypeRegisterListener.php new file mode 100644 index 00000000000..19d559de287 --- /dev/null +++ b/lib/Federation/Proxy/TalkV1/Listener/ResourceTypeRegisterListener.php @@ -0,0 +1,66 @@ + + * + * @author Joas Schilling + * + * @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 . + * + */ + +namespace OCA\Talk\Federation\Proxy\TalkV1\Listener; + +use OCA\Talk\Config; +use OCA\Talk\Federation\CloudFederationProviderTalk; +use OCA\Talk\Federation\FederationManager; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\OCM\Events\ResourceTypeRegisterEvent; +use OCP\OCM\IOCMProvider; + +/** + * @template-implements IEventListener + */ +class ResourceTypeRegisterListener implements IEventListener { + + public function __construct( + protected Config $talkConfig, + protected IOCMProvider $provider, + protected CloudFederationProviderTalk $talkProvider, + ) { + } + + public function handle(Event $event): void { + if (!$event instanceof ResourceTypeRegisterEvent) { + // Unrelated + return; + } + + if (!$this->talkConfig->isFederationEnabled()) { + return; + } + + $event->registerResourceType( + FederationManager::TALK_ROOM_RESOURCE, + $this->talkProvider->getSupportedShareTypes(), + [ + 'talk-v1' => '/ocs/v2.php/apps/spreed/api/', + ] + ); + } +} diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 466022b3cb3..697dd5aa0e2 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -3314,6 +3314,35 @@ public function setAppConfig(string $appId, TableNode $formData): void { $this->setCurrentUser($currentUser); } + /** + * @Given OCM provider has the following resource types + * + * @param TableNode $formData + */ + public function checkOCMProviderResourceTypes(TableNode $formData): void { + $this->sendFrontpageRequest('GET', '/ocm-provider'); + $data = json_decode($this->response->getBody()->getContents(), true); + $expectedTypes = $formData->getHash(); + + foreach ($expectedTypes as $expected) { + $found = false; + foreach ($data['resourceTypes'] as $type) { + if ($type['name'] === $expected['name']) { + $found = true; + Assert::assertEquals( + json_decode($expected['shareTypes'], true), + $type['shareTypes'], + ); + Assert::assertEquals( + json_decode($expected['protocols'], true), + $type['protocols'], + ); + } + } + Assert::assertTrue($found); + } + } + /** * @Then user :user has the following notifications * diff --git a/tests/integration/features/federation/ocm.feature b/tests/integration/features/federation/ocm.feature new file mode 100644 index 00000000000..863ff1c8194 --- /dev/null +++ b/tests/integration/features/federation/ocm.feature @@ -0,0 +1,8 @@ +Feature: federation/pcm + Background: + Given user "participant1" exists + + Scenario: Check that the OCM resource is registered + Given OCM provider has the following resource types + | name | shareTypes | protocols | + | talk-room | ["user"] | {"talk-v1":"/ocs/v2.php/apps/spreed/api/"} |