Skip to content
Merged
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
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#redirectToCard', 'url' => '/card/{cardId}', 'verb' => 'GET'],

// boards
['name' => 'board#index', 'url' => '/boards', 'verb' => 'GET'],
Expand Down
8 changes: 6 additions & 2 deletions lib/Activity/DeckProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCA\Deck\Service\CardService;

class DeckProvider implements IProvider {

Expand All @@ -52,15 +53,18 @@ class DeckProvider implements IProvider {
private $l10nFactory;
/** @var IConfig */
private $config;
/** @var CardService */
private $cardService;

public function __construct(IURLGenerator $urlGenerator, ActivityManager $activityManager, IUserManager $userManager, ICommentsManager $commentsManager, IFactory $l10n, IConfig $config, $userId) {
public function __construct(IURLGenerator $urlGenerator, ActivityManager $activityManager, IUserManager $userManager, ICommentsManager $commentsManager, IFactory $l10n, IConfig $config, $userId, CardService $cardService) {
$this->userId = $userId;
$this->urlGenerator = $urlGenerator;
$this->activityManager = $activityManager;
$this->commentsManager = $commentsManager;
$this->userManager = $userManager;
$this->l10nFactory = $l10n;
$this->config = $config;
$this->cardService = $cardService;
}

/**
Expand Down Expand Up @@ -131,7 +135,7 @@ public function parse($language, IEvent $event, IEvent $previousEvent = null) {

if (array_key_exists('board', $subjectParams)) {
$archivedParam = $subjectParams['card']['archived'] ? 'archived/' : '';
$card['link'] = $this->deckUrl('/board/' . $subjectParams['board']['id'] . '/' . $archivedParam . 'card/' . $event->getObjectId());
$card['link'] = $this->cardService->getRedirectUrlForCard($event->getObjectId());
}
$params['card'] = $card;
}
Expand Down
29 changes: 28 additions & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,41 @@
use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Controller;
use OCA\Deck\Db\CardMapper;
use OCP\IURLGenerator;
use \OCP\AppFramework\Http\RedirectResponse;
use OCA\Deck\Db\Acl;
use OCA\Deck\Service\CardService;

class PageController extends Controller {
private $permissionService;
private $initialState;
private $configService;
private $eventDispatcher;
private $cardMapper;
private $urlGenerator;
private $cardService;

public function __construct(
$AppName,
IRequest $request,
PermissionService $permissionService,
IInitialStateService $initialStateService,
ConfigService $configService,
IEventDispatcher $eventDispatcher
IEventDispatcher $eventDispatcher,
CardMapper $cardMapper,
IURLGenerator $urlGenerator,
CardService $cardService
) {
parent::__construct($AppName, $request);

$this->permissionService = $permissionService;
$this->initialState = $initialStateService;
$this->configService = $configService;
$this->eventDispatcher = $eventDispatcher;
$this->cardMapper = $cardMapper;
$this->urlGenerator = $urlGenerator;
Comment on lines +69 to +70
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not needed anymore now, as the url generation has been moved to the CardService 😉

$this->cardService = $cardService;
}

/**
Expand Down Expand Up @@ -85,4 +99,17 @@ public function index() {

return $response;
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function redirectToCard($cardId): RedirectResponse {
try {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
return new RedirectResponse($this->cardService->getCardUrl($cardId));
} catch (\Exception $e) {
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('deck.page.index'));
}
}
}
9 changes: 8 additions & 1 deletion lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OCA\Deck\Db\LabelMapper;
use OCP\IUserManager;
use OCA\Deck\BadRequestException;
use OCP\IURLGenerator;

class BoardService {
private $boardMapper;
Expand All @@ -68,8 +69,8 @@ class BoardService {
private $activityManager;
private $eventDispatcher;
private $changeHelper;

private $boardsCache = null;
private $urlGenerator;


public function __construct(
Expand All @@ -87,6 +88,7 @@ public function __construct(
ActivityManager $activityManager,
IEventDispatcher $eventDispatcher,
ChangeHelper $changeHelper,
IURLGenerator $urlGenerator,
$userId
) {
$this->boardMapper = $boardMapper;
Expand All @@ -104,6 +106,7 @@ public function __construct(
$this->eventDispatcher = $eventDispatcher;
$this->changeHelper = $changeHelper;
$this->userId = $userId;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down Expand Up @@ -697,4 +700,8 @@ private function enrichWithUsers($board, $since = -1) {
}
$board->setUsers(array_values($boardUsers));
}

public function getBoardUrl($endpoint) {
return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#' . $endpoint;
}
}
14 changes: 14 additions & 0 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserManager;
use OCP\IURLGenerator;

class CardService {
private $cardMapper;
Expand All @@ -63,6 +64,7 @@ class CardService {
private $changeHelper;
private $eventDispatcher;
private $userManager;
private $urlGenerator;

public function __construct(
CardMapper $cardMapper,
Expand All @@ -79,6 +81,7 @@ public function __construct(
IUserManager $userManager,
ChangeHelper $changeHelper,
IEventDispatcher $eventDispatcher,
IURLGenerator $urlGenerator,
$userId
) {
$this->cardMapper = $cardMapper;
Expand All @@ -96,6 +99,7 @@ public function __construct(
$this->changeHelper = $changeHelper;
$this->eventDispatcher = $eventDispatcher;
$this->currentUser = $userId;
$this->urlGenerator = $urlGenerator;
}

public function enrich($card) {
Expand Down Expand Up @@ -602,4 +606,14 @@ public function removeLabel($cardId, $labelId) {

$this->eventDispatcher->dispatchTyped(new CardUpdatedEvent($card));
}

public function getCardUrl($cardId) {
$boardId = $this->cardMapper->findBoardId($cardId);

return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . "#/board/$boardId/card/$cardId";
}

public function getRedirectUrlForCard($cardId) {
return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . "card/$cardId";
}
}
8 changes: 7 additions & 1 deletion tests/unit/Activity/DeckProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\RichObjectStrings\IValidator;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use OCA\Deck\Service\CardService;

class DeckProviderTest extends TestCase {

Expand All @@ -56,6 +57,9 @@ class DeckProviderTest extends TestCase {
/** @var ICommentsManager|MockObject */
private $commentsManager;

/** @var CardService|MockObject */
private $cardService;

/** @var string */
private $userId = 'admin';

Expand All @@ -67,7 +71,9 @@ public function setUp(): void {
$this->commentsManager = $this->createMock(ICommentsManager::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->config = $this->createMock(IConfig::class);
$this->provider = new DeckProvider($this->urlGenerator, $this->activityManager, $this->userManager, $this->commentsManager, $this->l10nFactory, $this->config, $this->userId);
$this->config = $this->createMock(IConfig::class);
$this->cardService = $this->createMock(CardService::class);
$this->provider = new DeckProvider($this->urlGenerator, $this->activityManager, $this->userManager, $this->commentsManager, $this->l10nFactory, $this->config, $this->userId, $this->cardService);
}

private function mockEvent($objectType, $objectId, $objectName, $subject, $subjectParameters = []) {
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/Service/BoardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use OCP\IUserManager;
use OCP\IGroupManager;
use \Test\TestCase;
use OCP\IURLGenerator;

class BoardServiceTest extends TestCase {

Expand Down Expand Up @@ -74,6 +75,8 @@ class BoardServiceTest extends TestCase {
/** @var IEventDispatcher */
private $eventDispatcher;
private $userId = 'admin';
/** @var IURLGenerator */
private $urlGenerator;

public function setUp(): void {
parent::setUp();
Expand All @@ -91,6 +94,7 @@ public function setUp(): void {
$this->activityManager = $this->createMock(ActivityManager::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);

$this->service = new BoardService(
$this->boardMapper,
Expand All @@ -107,6 +111,7 @@ public function setUp(): void {
$this->activityManager,
$this->eventDispatcher,
$this->changeHelper,
$this->urlGenerator,
$this->userId
);

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/Service/CardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
use OCP\IURLGenerator;

class CardServiceTest extends TestCase {

Expand Down Expand Up @@ -76,6 +77,9 @@ class CardServiceTest extends TestCase {
/** @var ChangeHelper|MockObject */
private $changeHelper;

/** @var IURLGenerator|MockObject */
private $urlGenerator;

public function setUp(): void {
parent::setUp();
$this->cardMapper = $this->createMock(CardMapper::class);
Expand All @@ -92,6 +96,7 @@ public function setUp(): void {
$this->userManager = $this->createMock(IUserManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->cardService = new CardService(
$this->cardMapper,
$this->stackMapper,
Expand All @@ -107,6 +112,7 @@ public function setUp(): void {
$this->userManager,
$this->changeHelper,
$this->eventDispatcher,
$this->urlGenerator,
'user1'
);
}
Expand Down
34 changes: 29 additions & 5 deletions tests/unit/controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,56 @@

namespace OCA\Deck\Controller;

use OCA\Deck\Db\CardMapper;
use OCA\Deck\Service\CardService;
use OCA\Deck\Service\ConfigService;
use OCA\Deck\Service\PermissionService;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use PHPUnit\Framework\TestCase;

class PageControllerTest extends \Test\TestCase {
class PageControllerTest extends TestCase {
private $controller;
private $request;
private $l10n;
private $permissionService;
private $initialState;
private $configService;
private $eventDispatcher;
/**
* @var mixed|CardMapper|\PHPUnit\Framework\MockObject\MockObject
*/
private $cardMapper;
/**
* @var mixed|IURLGenerator|\PHPUnit\Framework\MockObject\MockObject
*/
private $urlGenerator;
/**
* @var mixed|CardService|\PHPUnit\Framework\MockObject\MockObject
*/
private $cardService;

public function setUp(): void {
$this->l10n = $this->createMock(IL10N::class);
$this->request = $this->createMock(IRequest::class);
$this->permissionService = $this->createMock(PermissionService::class);
$this->configService = $this->createMock(ConfigService::class);
$this->initialState = $this->createMock(IInitialStateService::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->cardMapper = $this->createMock(CardMapper::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->cardService = $this->createMock(CardService::class);

$this->controller = new PageController(
'deck', $this->request, $this->permissionService, $this->initialState, $this->configService, $this->eventDispatcher
'deck',
$this->request,
$this->permissionService,
$this->initialState,
$this->configService,
$this->eventDispatcher,
$this->cardMapper,
$this->urlGenerator,
$this->cardService
);
}

Expand Down