From 6e4f8ca8ea1dbbfcc63a776f91299bb10b0d0b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 14 Mar 2019 22:32:06 +0100 Subject: [PATCH] Enrich board listing with stacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Controller/BoardApiController.php | 1 + lib/Db/Board.php | 2 ++ lib/Service/BoardService.php | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Controller/BoardApiController.php b/lib/Controller/BoardApiController.php index 7dcc601c8..68389b307 100644 --- a/lib/Controller/BoardApiController.php +++ b/lib/Controller/BoardApiController.php @@ -60,6 +60,7 @@ class BoardApiController extends ApiController { * @NoCSRFRequired * * Return all of the boards that the current user has access to. + * @throws StatusException */ public function index() { $modified = $this->request->getHeader('If-Modified-Since'); diff --git a/lib/Db/Board.php b/lib/Db/Board.php index fabf39061..ae26fe3ca 100644 --- a/lib/Db/Board.php +++ b/lib/Db/Board.php @@ -34,6 +34,7 @@ class Board extends RelationalEntity { protected $permissions = []; protected $users = []; protected $shared; + protected $stacks = []; protected $deletedAt = 0; protected $lastModified = 0; @@ -48,6 +49,7 @@ class Board extends RelationalEntity { $this->addRelation('shared'); $this->addRelation('users'); $this->addRelation('permissions'); + $this->addRelation('stacks'); $this->addResolvable('owner'); $this->shared = -1; } diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index dd11ad3e4..d39ba969b 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -31,6 +31,7 @@ use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\ChangeHelper; use OCA\Deck\Db\IPermissionMapper; use OCA\Deck\Db\Label; +use OCA\Deck\Db\StackMapper; use OCA\Deck\NoPermissionException; use OCA\Deck\Notification\NotificationHelper; use OCP\AppFramework\Db\DoesNotExistException; @@ -46,6 +47,7 @@ use OCA\Deck\BadRequestException; class BoardService { private $boardMapper; + private $stackMapper; private $labelMapper; private $aclMapper; private $l10n; @@ -60,6 +62,7 @@ class BoardService { public function __construct( BoardMapper $boardMapper, + StackMapper $stackMapper, IL10N $l10n, LabelMapper $labelMapper, AclMapper $aclMapper, @@ -73,6 +76,7 @@ class BoardService { $userId ) { $this->boardMapper = $boardMapper; + $this->stackMapper = $stackMapper; $this->labelMapper = $labelMapper; $this->aclMapper = $aclMapper; $this->l10n = $l10n; @@ -89,7 +93,7 @@ class BoardService { /** * @return array */ - public function findAll($since = -1) { + public function findAll($since = 0) { $userInfo = $this->getBoardPrerequisites(); $userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since); $groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since); @@ -104,6 +108,7 @@ class BoardService { $this->boardMapper->mapAcl($acl); } } + $this->enrichWithStacks($item); $permissions = $this->permissionService->matchPermissions($item); $item->setPermissions([ 'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ], @@ -527,4 +532,14 @@ class BoardService { return $this->aclMapper->delete($acl); } + private function enrichWithStacks($board, $since = -1) { + $stacks = $this->stackMapper->findAll($board->getId(), null, null, $since); + + if(\count($stacks) === 0) { + return; + } + + $board->setStacks($stacks); + } + }