From 79b950e19258dd94d15c12fefa57b15588a5385e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 2 Oct 2020 13:50:10 +0200 Subject: [PATCH] Quick fix for filtering out archived boards from calendar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/DAV/DeckCalendarBackend.php | 2 +- lib/Db/BoardMapper.php | 26 ++++++++++++++++++++------ lib/Service/BoardService.php | 12 ++++++------ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/lib/DAV/DeckCalendarBackend.php b/lib/DAV/DeckCalendarBackend.php index 6d3ca0239..a1849abe9 100644 --- a/lib/DAV/DeckCalendarBackend.php +++ b/lib/DAV/DeckCalendarBackend.php @@ -59,7 +59,7 @@ class DeckCalendarBackend { } public function getBoards(): array { - return $this->boardService->findAll(); + return $this->boardService->findAll(-1, null, false); } public function getBoard(int $id): Board { diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index f122e05a4..49cfebb88 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -93,10 +93,18 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { * @param null $offset * @return array */ - public function findAllByUser($userId, $limit = null, $offset = null, $since = -1) { - $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ? AND last_modified > ? UNION ' . + public function findAllByUser($userId, $limit = null, $offset = null, $since = -1, $includeArchived = true) { + // FIXME: One moving to QBMapper we should allow filtering the boards probably by method chaining for additional where clauses + $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ? AND last_modified > ?'; + if (!$includeArchived) { + $sql .= ' AND NOT archived'; + } + $sql .= ' UNION ' . 'SELECT boards.id, title, owner, color, archived, deleted_at, 1 as shared, last_modified FROM `*PREFIX*deck_boards` as boards ' . 'JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=? AND boards.owner != ? AND last_modified > ?'; + if (!$includeArchived) { + $sql .= ' AND NOT archived'; + } $entries = $this->findEntities($sql, [$userId, $since, $userId, Acl::PERMISSION_TYPE_USER, $userId, $since], $limit, $offset); /* @var Board $entry */ foreach ($entries as $entry) { @@ -120,7 +128,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { * @param null $offset * @return array */ - public function findAllByGroups($userId, $groups, $limit = null, $offset = null) { + public function findAllByGroups($userId, $groups, $limit = null, $offset = null, $since = -1,$includeArchived = true) { if (count($groups) <= 0) { return []; } @@ -132,7 +140,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { $sql .= ' OR '; } } - $sql .= ');'; + $sql .= ')'; + if (!$includeArchived) { + $sql .= ' AND NOT archived'; + } $entries = $this->findEntities($sql, array_merge([$userId, Acl::PERMISSION_TYPE_GROUP], $groups), $limit, $offset); /* @var Board $entry */ foreach ($entries as $entry) { @@ -142,7 +153,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { return $entries; } - public function findAllByCircles($userId, $limit = null, $offset = null) { + public function findAllByCircles($userId, $limit = null, $offset = null, $since = -1,$includeArchived = true) { if (!$this->circlesEnabled) { return []; } @@ -161,7 +172,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { $sql .= ' OR '; } } - $sql .= ');'; + $sql .= ')'; + if (!$includeArchived) { + $sql .= ' AND NOT archived'; + } $entries = $this->findEntities($sql, array_merge([$userId, Acl::PERMISSION_TYPE_CIRCLE], $circles), $limit, $offset); /* @var Board $entry */ foreach ($entries as $entry) { diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 91c0999bf..477add264 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -107,11 +107,11 @@ class BoardService { $this->userId = $userId; } - public function getUserBoards(int $since = -1): array { + public function getUserBoards(int $since = -1, $includeArchived = true): array { $userInfo = $this->getBoardPrerequisites(); - $userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since); - $groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since); - $circleBoards = $this->boardMapper->findAllByCircles($userInfo['user'], null, null, $since); + $userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since, $includeArchived); + $groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since, $includeArchived); + $circleBoards = $this->boardMapper->findAllByCircles($userInfo['user'], null, null, $since, $includeArchived); $mergedBoards = array_merge($userBoards, $groupBoards, $circleBoards); $result = []; /** @var Board $item */ @@ -125,11 +125,11 @@ class BoardService { /** * @return array */ - public function findAll($since = -1, $details = null) { + public function findAll($since = -1, $details = null, $includeArchived = true) { if ($this->boardsCache) { return $this->boardsCache; } - $complete = $this->getUserBoards($since); + $complete = $this->getUserBoards($since, $includeArchived); $result = []; /** @var Board $item */ foreach ($complete as &$item) {