From 7b4586a43a0cecfddd33885b7fe6297d7587a738 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Wed, 8 Jan 2025 10:47:07 +0100 Subject: [PATCH] fix: Adapt URLs generated in the backend to new routes Signed-off-by: Julius Knorr --- lib/Activity/DeckProvider.php | 4 +- .../Resources/ResourceProvider.php | 2 +- .../Resources/ResourceProviderCard.php | 5 ++- lib/Notification/Notifier.php | 42 +++++++++++-------- lib/Provider/DeckProvider.php | 2 +- lib/Search/BoardSearchResultEntry.php | 2 +- lib/Service/BoardService.php | 4 -- lib/Service/CardService.php | 8 ++-- lib/Sharing/ShareAPIHelper.php | 2 +- lib/Teams/DeckTeamResourceProvider.php | 2 +- src/router.js | 4 +- 11 files changed, 42 insertions(+), 35 deletions(-) diff --git a/lib/Activity/DeckProvider.php b/lib/Activity/DeckProvider.php index 63cdd2d9c..f18842f48 100644 --- a/lib/Activity/DeckProvider.php +++ b/lib/Activity/DeckProvider.php @@ -131,7 +131,7 @@ class DeckProvider implements IProvider { ]; if (array_key_exists('board', $subjectParams)) { - $card['link'] = $this->cardService->getRedirectUrlForCard($event->getObjectId()); + $card['link'] = $this->cardService->getCardUrl($event->getObjectId()); $event->setLink($card['link']); } $params['card'] = $card; @@ -365,6 +365,6 @@ class DeckProvider implements IProvider { } public function deckUrl($endpoint) { - return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#' . $endpoint; + return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . trim($endpoint, '/'); } } diff --git a/lib/Collaboration/Resources/ResourceProvider.php b/lib/Collaboration/Resources/ResourceProvider.php index 299c2498f..36ae8f112 100644 --- a/lib/Collaboration/Resources/ResourceProvider.php +++ b/lib/Collaboration/Resources/ResourceProvider.php @@ -57,7 +57,7 @@ class ResourceProvider implements IProvider { */ public function getResourceRichObject(IResource $resource): array { $board = $this->getBoard($resource); - $link = $this->urlGenerator->linkToRoute('deck.page.index') . '#/board/' . $resource->getId(); + $link = $this->urlGenerator->linkToRoute('deck.page.indexBoard', ['boardId' => $resource->getId()]); return [ 'type' => self::RESOURCE_TYPE, diff --git a/lib/Collaboration/Resources/ResourceProviderCard.php b/lib/Collaboration/Resources/ResourceProviderCard.php index 2c9e9d19d..77c226da9 100644 --- a/lib/Collaboration/Resources/ResourceProviderCard.php +++ b/lib/Collaboration/Resources/ResourceProviderCard.php @@ -66,7 +66,10 @@ class ResourceProviderCard implements IProvider { throw new ResourceException('No unique card found for resource, this should never happen'); } - $link = $this->urlGenerator->linkToRoute('deck.page.index') . '#/board/' . $board->getId() . '/card/' . $resource->getId(); + $link = $this->urlGenerator->linkToRoute('deck.page.indexCard', [ + 'boardId' => $board->getId(), + 'cardId' => $card->getId() + ]); return [ 'type' => self::RESOURCE_TYPE, diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index dbba06332..6d3887ba6 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -85,9 +85,9 @@ class Notifier implements INotifier { switch ($notification->getSubject()) { case 'card-assigned': - $cardId = $notification->getObjectId(); + $cardId = (int)$notification->getObjectId(); $stack = $this->stackMapper->findStackFromCardId($cardId); - $boardId = $stack ? $stack->getBoardId() : null; + $boardId = $stack ? (int)$stack->getBoardId() : null; if (!$boardId) { throw new AlreadyProcessedException(); } @@ -110,13 +110,13 @@ class Notifier implements INotifier { 'name' => $params[0], 'boardname' => $params[1], 'stackname' => $stack->getTitle(), - 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . '', + 'link' => $this->getCardUrl($boardId, $cardId), ], 'deck-board' => [ 'type' => 'deck-board', 'id' => $boardId, 'name' => $params[1], - 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId, + 'link' => $this->getBoardUrl($boardId), ], 'user' => [ 'type' => 'user', @@ -125,12 +125,12 @@ class Notifier implements INotifier { ] ] ); - $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . ''); + $notification->setLink($this->getCardUrl($boardId, $cardId)); break; case 'card-overdue': - $cardId = $notification->getObjectId(); + $cardId = (int)$notification->getObjectId(); $stack = $this->stackMapper->findStackFromCardId($cardId); - $boardId = $stack ? $stack->getBoardId() : null; + $boardId = $stack ? (int)$stack->getBoardId() : null; if (!$boardId) { throw new AlreadyProcessedException(); } @@ -147,22 +147,22 @@ class Notifier implements INotifier { 'name' => $params[0], 'boardname' => $params[1], 'stackname' => $stack->getTitle(), - 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . '', + 'link' => $this->getCardUrl($boardId, $cardId), ], 'deck-board' => [ 'type' => 'deck-board', 'id' => $boardId, 'name' => $params[1], - 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId, + 'link' => $this->getBoardUrl($boardId), ], ] ); - $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . ''); + $notification->setLink($this->getCardUrl($boardId, $cardId)); break; case 'card-comment-mentioned': - $cardId = $notification->getObjectId(); + $cardId = (int)$notification->getObjectId(); $stack = $this->stackMapper->findStackFromCardId($cardId); - $boardId = $stack ? $stack->getBoardId() : null; + $boardId = $stack ? (int)$stack->getBoardId() : null; if (!$boardId) { throw new AlreadyProcessedException(); } @@ -185,7 +185,7 @@ class Notifier implements INotifier { 'name' => $params[0], 'boardname' => $params[1], 'stackname' => $stack->getTitle(), - 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . '', + 'link' => $this->getCardUrl($boardId, $cardId), ], 'user' => [ 'type' => 'user', @@ -197,10 +197,10 @@ class Notifier implements INotifier { if ($notification->getMessage() === '{message}') { $notification->setParsedMessage($notification->getMessageParameters()['message']); } - $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $cardId . ''); + $notification->setLink($this->getCardUrl($boardId, $cardId)); break; case 'board-shared': - $boardId = $notification->getObjectId(); + $boardId = (int)$notification->getObjectId(); if (!$boardId) { throw new AlreadyProcessedException(); } @@ -220,7 +220,7 @@ class Notifier implements INotifier { 'type' => 'deck-board', 'id' => $boardId, 'name' => $params[0], - 'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId, + 'link' => $this->getBoardUrl($boardId), ], 'user' => [ 'type' => 'user', @@ -229,9 +229,17 @@ class Notifier implements INotifier { ] ] ); - $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/'); + $notification->setLink($this->getBoardUrl($boardId)); break; } return $notification; } + + private function getBoardUrl(int $boardId): string { + return $this->url->linkToRouteAbsolute('deck.page.indexBoard', ['boardId' => $boardId]); + } + + private function getCardUrl(int $boardId, int $cardId): string { + return $this->url->linkToRouteAbsolute('deck.page.indexCard', ['boardId' => $boardId, 'cardId' => $cardId]); + } } diff --git a/lib/Provider/DeckProvider.php b/lib/Provider/DeckProvider.php index cda55c4db..7e962952c 100644 --- a/lib/Provider/DeckProvider.php +++ b/lib/Provider/DeckProvider.php @@ -219,7 +219,7 @@ class DeckProvider implements IFullTextSearchProvider { try { $board = $this->fullTextSearchService->getBoardFromCardId((int)$document->getId()); - $path = '#/board/' . $board->getId() . '/card/' . $document->getId(); + $path = '/board/' . $board->getId() . '/card/' . $document->getId(); $document->setLink($this->urlGenerator->linkToRoute('deck.page.index') . $path); } catch (DoesNotExistException $e) { } catch (MultipleObjectsReturnedException $e) { diff --git a/lib/Search/BoardSearchResultEntry.php b/lib/Search/BoardSearchResultEntry.php index 5fd435f0d..d2ed4b4e0 100644 --- a/lib/Search/BoardSearchResultEntry.php +++ b/lib/Search/BoardSearchResultEntry.php @@ -22,7 +22,7 @@ class BoardSearchResultEntry extends SearchResultEntry { ), $board->getTitle(), '', - $urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId(), + $urlGenerator->linkToRouteAbsolute('deck.page.indexBoard', ['boardId' => $board->getId()]), 'icon-deck'); } } diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 103aaec2c..18bc3d24d 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -746,10 +746,6 @@ class BoardService { $board->setUsers(array_values($boardUsers)); } - public function getBoardUrl($endpoint) { - return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#' . $endpoint; - } - /** * Clean a given board data from the Cache */ diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 30fd754c5..639fa078e 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -655,13 +655,13 @@ class CardService { $this->eventDispatcher->dispatchTyped(new CardUpdatedEvent($card)); } - public function getCardUrl($cardId) { + public function getCardUrl(int $cardId): string { $boardId = $this->cardMapper->findBoardId($cardId); - return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . "#/board/$boardId/card/$cardId"; + return $this->urlGenerator->linkToRouteAbsolute('deck.page.indexCard', ['boardId' => $boardId, 'cardId' => $cardId]); } - public function getRedirectUrlForCard($cardId) { - return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . "card/$cardId"; + public function getRedirectUrlForCard(int $cardId): string { + return $this->urlGenerator->linkToRouteAbsolute('deck.page.redirectToCard', ['cardId' => $cardId]); } } diff --git a/lib/Sharing/ShareAPIHelper.php b/lib/Sharing/ShareAPIHelper.php index 1a14f59db..6ed1f04a3 100644 --- a/lib/Sharing/ShareAPIHelper.php +++ b/lib/Sharing/ShareAPIHelper.php @@ -47,7 +47,7 @@ class ShareAPIHelper { $boardId = $this->cardMapper->findBoardId($card->getId()); $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = $card->getTitle(); - $result['share_with_link'] = $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId . '/card/' . $card->getId(); + $result['share_with_link'] = $this->urlGenerator->linkToRouteAbsolute('deck.page.indexCard', ['boardId' => $boardId, 'cardId' => $card->getId()]); return $result; } diff --git a/lib/Teams/DeckTeamResourceProvider.php b/lib/Teams/DeckTeamResourceProvider.php index 19e5670d5..b8cece026 100644 --- a/lib/Teams/DeckTeamResourceProvider.php +++ b/lib/Teams/DeckTeamResourceProvider.php @@ -43,7 +43,7 @@ class DeckTeamResourceProvider implements \OCP\Teams\ITeamResourceProvider { $this, (string)$board->getId(), $board->getTitle(), - $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId(), + $this->urlGenerator->linkToRouteAbsolute('deck.page.indexBoard', ['boardId' => $board->getId()]), $this->getBoardBulletIcon($board), $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('deck', 'deck-current.svg')), ); diff --git a/src/router.js b/src/router.js index 5942fa37a..ad5621161 100644 --- a/src/router.js +++ b/src/router.js @@ -144,8 +144,8 @@ const router = new Router({ router.beforeEach((to, from, next) => { // Redirect if fullPath begins with a hash (ignore hashes later in path) - if (to.fullPath.substring(0, 2) === '/#') { - const path = to.fullPath.substring(2) + if (to.hash.substring(0, 2) === '#/') { + const path = to.fullPath.replace('/apps/deck/#/', '/apps/deck/') next(path) return }