Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adapt URLs generated in the backend to new routes #6649

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Activity/DeckProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
];

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;
Expand Down Expand Up @@ -365,6 +365,6 @@ private function parseParamForChanges($subjectParams, $params, $event) {
}

public function deckUrl($endpoint) {
return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#' . $endpoint;
return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . trim($endpoint, '/');
}
}
2 changes: 1 addition & 1 deletion lib/Collaboration/Resources/ResourceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getType(): string {
*/
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,
Expand Down
5 changes: 4 additions & 1 deletion lib/Collaboration/Resources/ResourceProviderCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public function getResourceRichObject(IResource $resource): array {
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,
Expand Down
42 changes: 25 additions & 17 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public function prepare(INotification $notification, string $languageCode): INot

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();
}
Expand All @@ -110,13 +110,13 @@ public function prepare(INotification $notification, string $languageCode): INot
'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',
Expand All @@ -125,12 +125,12 @@ public function prepare(INotification $notification, string $languageCode): INot
]
]
);
$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();
}
Expand All @@ -147,22 +147,22 @@ public function prepare(INotification $notification, string $languageCode): INot
'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();
}
Expand All @@ -185,7 +185,7 @@ public function prepare(INotification $notification, string $languageCode): INot
'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',
Expand All @@ -197,10 +197,10 @@ public function prepare(INotification $notification, string $languageCode): INot
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();
}
Expand All @@ -220,7 +220,7 @@ public function prepare(INotification $notification, string $languageCode): INot
'type' => 'deck-board',
'id' => $boardId,
'name' => $params[0],
'link' => $this->url->linkToRouteAbsolute('deck.page.index') . '#/board/' . $boardId,
'link' => $this->getBoardUrl($boardId),
],
'user' => [
'type' => 'user',
Expand All @@ -229,9 +229,17 @@ public function prepare(INotification $notification, string $languageCode): INot
]
]
);
$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]);
}
}
2 changes: 1 addition & 1 deletion lib/Provider/DeckProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function improveSearchResult(ISearchResult $searchResult) {
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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Search/BoardSearchResultEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(Board $board, $urlGenerator) {
),
$board->getTitle(),
'',
$urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId(),
$urlGenerator->linkToRouteAbsolute('deck.page.indexBoard', ['boardId' => $board->getId()]),
'icon-deck');
}
}
4 changes: 0 additions & 4 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,6 @@ private function enrichWithUsers($board, $since = -1) {
$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
*/
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,13 @@ public function removeLabel($cardId, $labelId) {
$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]);
}
}
2 changes: 1 addition & 1 deletion lib/Sharing/ShareAPIHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function formatShare(IShare $share): array {
$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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Teams/DeckTeamResourceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getSharedWith($teamId): array {
$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')),
);
Expand Down
14 changes: 10 additions & 4 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Vue from 'vue'
import Router from 'vue-router'
import { generateUrl } from '@nextcloud/router'
import { generateUrl, getRootUrl } from '@nextcloud/router'
import { BOARD_FILTERS } from './store/main.js'
import Boards from './components/boards/Boards.vue'
import Board from './components/board/Board.vue'
Expand All @@ -16,9 +16,15 @@ import Overview from './components/overview/Overview.vue'

Vue.use(Router)

// We apply a dynamic base URL depending on the URL used in the browser
const baseUrl = generateUrl('/apps/deck/')
const webRootWithIndexPHP = getRootUrl() + '/index.php'
const doesURLContainIndexPHP = window.location.pathname.startsWith(webRootWithIndexPHP)
const currentBaseUrl = doesURLContainIndexPHP ? baseUrl : baseUrl.replace('/index.php/', '/')

const router = new Router({
mode: 'history',
base: generateUrl('/apps/deck/'),
base: currentBaseUrl,
linkActiveClass: 'active',
routes: [
{
Expand Down Expand Up @@ -144,8 +150,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('/#/', '/').trimEnd('/')
next(path)
return
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Activity/ActivityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function testCreateEventLabel() {
$this->assertEquals($event, $actual);
}

public function dataSendToUsers() {
public static function dataSendToUsers() {
return [
[ActivityManager::DECK_OBJECT_BOARD],
[ActivityManager::DECK_OBJECT_CARD],
Expand Down Expand Up @@ -344,7 +344,7 @@ public function testSendToUser($objectType) {
$this->invokePrivate($this->activityManager, 'sendToUsers', [$event]);
}

public function dataFindObjectForEntity() {
public static function dataFindObjectForEntity() {
$board = new Board();
$board->setId(1);
$stack = new Stack();
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/Activity/DeckProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testParseFailureApp() {
$this->provider->parse('en_US', $event, $event);
}

public function dataEventIcons() {
public static function dataEventIcons() {
return [
[ActivityManager::SUBJECT_LABEL_ASSIGN, 'core', 'actions/tag.svg'],
[ActivityManager::SUBJECT_CARD_CREATE, 'files', 'add-color.svg'],
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testDeckUrl() {
->with('deck.page.index')
->willReturn('http://localhost/index.php/apps/deck/');
$this->assertEquals(
'http://localhost/index.php/apps/deck/#board/1/card/1',
'http://localhost/index.php/apps/deck/board/1/card/1',
$this->provider->deckUrl('board/1/card/1')
);
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public function testParseObjectTypeBoard() {
'type' => 'highlight',
'id' => 1,
'name' => 'Board',
'link' => '#/board/1',
'link' => 'board/1',
],
'user' => [
'type' => 'user',
Expand Down Expand Up @@ -319,9 +319,9 @@ public function testParseParamForBoard() {
$expected = [
'board' => [
'type' => 'highlight',
'id' => 1,
'id' => '1',
'name' => 'Board name',
'link' => '#/board/1/',
'link' => 'board/1',
],
];
$actual = $this->invokePrivate($this->provider, 'parseParamForBoard', ['board', $subjectParams, $params]);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Db/CardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function createCard() {
return $card;
}

public function dataDuedate() {
public static function dataDuedate() {
return [
[(new DateTime()), Card::DUEDATE_NOW],
[(new DateTime())->sub(new DateInterval('P1D')), Card::DUEDATE_OVERDUE],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Middleware/ExceptionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setUp(): void {
}


public function dataAfterException() {
public static function dataAfterException() {
return [
[new NoPermissionException('No permission'), 403, 'No permission'],
[new NotFoundException('Not found'), 404, 'Not found']
Expand Down
Loading
Loading