From eff8898bd86fc306775fe0e68c66c9a8f82cda0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 21 Aug 2020 15:48:15 +0200 Subject: Dispatch event to allow change of the redirect url MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Controller/DocumentController.php | 10 ++++++ lib/Events/BeforeFederationRedirectEvent.php | 46 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 lib/Events/BeforeFederationRedirectEvent.php (limited to 'lib') diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index d021f536..aa98c239 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -11,6 +11,7 @@ namespace OCA\Richdocuments\Controller; +use OCA\Richdocuments\Events\BeforeFederationRedirectEvent; use OCA\Richdocuments\Service\FederationService; use OCA\Richdocuments\TokenManager; use \OCP\AppFramework\Controller; @@ -198,6 +199,15 @@ class DocumentController extends Controller { '&richdocuments_open=' . $item->getName() . '&richdocuments_fileId=' . $fileId . '&richdocuments_remote_access=' . $remote; + + $event = new BeforeFederationRedirectEvent( + $item, $relative, $remote + ); + $eventDispatcher = \OC::$server->getEventDispatcher(); + $eventDispatcher->dispatch(BeforeFederationRedirectEvent::class, $event); + if ($event->getRedirectUrl()) { + $url = $event->getRedirectUrl(); + } return new RedirectResponse($url); } $this->logger->warning('Failed to connect to remote collabora instance for ' . $fileId); diff --git a/lib/Events/BeforeFederationRedirectEvent.php b/lib/Events/BeforeFederationRedirectEvent.php new file mode 100644 index 00000000..40bb8b02 --- /dev/null +++ b/lib/Events/BeforeFederationRedirectEvent.php @@ -0,0 +1,46 @@ +node = $node; + $this->relativePath = $relativePath; + $this->remote = $remote; + } + + public function getRelativePath() { + return $this->relativePath; + } + + public function getNode() { + return $this->node; + } + + public function getRemote() { + return $this->remote; + } + + public function setRedirectUrl($redirectUrl) { + $this->redirectUrl = $redirectUrl; + } + + public function getRedirectUrl() { + return $this->redirectUrl; + } + +} \ No newline at end of file -- cgit v1.2.3