From ec42c0c2b49c02091d35eb131e338a4dafc0fdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 7 Dec 2018 17:02:18 +0100 Subject: [PATCH 1/2] Fix numeric types and missing card id in card detail results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/AssignedUsers.php | 4 ++-- lib/Db/Label.php | 14 ++++++++------ lib/Db/LabelMapper.php | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/Db/AssignedUsers.php b/lib/Db/AssignedUsers.php index 425f2f184..69be2ec4e 100644 --- a/lib/Db/AssignedUsers.php +++ b/lib/Db/AssignedUsers.php @@ -33,8 +33,8 @@ class AssignedUsers extends RelationalEntity implements JsonSerializable { public function __construct() { $this->addType('id', 'integer'); - $this->addType('card_id', 'integer'); + $this->addType('cardId', 'integer'); $this->addResolvable('participant'); } -} \ No newline at end of file +} diff --git a/lib/Db/Label.php b/lib/Db/Label.php index 650af4162..47a3bc221 100644 --- a/lib/Db/Label.php +++ b/lib/Db/Label.php @@ -5,20 +5,20 @@ * @author Julius Härtl * * @license GNU AGPL version 3 or any later version - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * + * */ namespace OCA\Deck\Db; @@ -29,8 +29,10 @@ class Label extends RelationalEntity { protected $color; protected $boardId; protected $cardId; - + public function __construct() { $this->addType('id', 'integer'); + $this->addType('boardId', 'integer'); + $this->addType('cardId', 'integer'); } -} \ No newline at end of file +} diff --git a/lib/Db/LabelMapper.php b/lib/Db/LabelMapper.php index 3107b4310..ec0e653d5 100644 --- a/lib/Db/LabelMapper.php +++ b/lib/Db/LabelMapper.php @@ -45,7 +45,7 @@ class LabelMapper extends DeckMapper implements IPermissionMapper { } public function findAssignedLabelsForCard($cardId, $limit = null, $offset = null) { - $sql = 'SELECT l.* FROM `*PREFIX*deck_assigned_labels` as al INNER JOIN *PREFIX*deck_labels as l ON l.id = al.label_id WHERE `card_id` = ? ORDER BY l.id'; + $sql = 'SELECT l.*,card_id FROM `*PREFIX*deck_assigned_labels` as al INNER JOIN *PREFIX*deck_labels as l ON l.id = al.label_id WHERE `card_id` = ? ORDER BY l.id'; return $this->findEntities($sql, [$cardId], $limit, $offset); } public function findAssignedLabelsForBoard($boardId, $limit = null, $offset = null) { From af57c3bf4f2d5c713f3a159e857f51ee68ac048f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sat, 8 Dec 2018 11:28:33 +0100 Subject: [PATCH 2/2] Fix If-Modified-Since header parsing 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 | 10 ++++++++-- lib/Controller/StackApiController.php | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/Controller/BoardApiController.php b/lib/Controller/BoardApiController.php index c4f6ca223..7dcc601c8 100644 --- a/lib/Controller/BoardApiController.php +++ b/lib/Controller/BoardApiController.php @@ -24,12 +24,14 @@ namespace OCA\Deck\Controller; +use OCA\Deck\StatusException; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; use OCA\Deck\Service\BoardService; +use Sabre\HTTP\Util; /** * Class BoardApiController @@ -61,10 +63,14 @@ class BoardApiController extends ApiController { */ public function index() { $modified = $this->request->getHeader('If-Modified-Since'); - if ($modified === '') { + if ($modified === null || $modified === '') { $boards = $this->service->findAll(); } else { - $boards = $this->service->findAll(strtotime($modified)); + $date = Util::parseHTTPDate($modified); + if (!$date) { + throw new StatusException('Invalid If-Modified-Since header provided.'); + } + $boards = $this->service->findAll($date->getTimestamp()); } return new DataResponse($boards, HTTP::STATUS_OK); } diff --git a/lib/Controller/StackApiController.php b/lib/Controller/StackApiController.php index 021fae9c2..a9cec08cb 100644 --- a/lib/Controller/StackApiController.php +++ b/lib/Controller/StackApiController.php @@ -24,12 +24,14 @@ namespace OCA\Deck\Controller; +use OCA\Deck\StatusException; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; use OCA\Deck\Service\StackService; use OCA\Deck\Service\BoardService; +use Sabre\HTTP\Util; /** * Class StackApiController @@ -62,8 +64,12 @@ class StackApiController extends ApiController { public function index() { $since = 0; $modified = $this->request->getHeader('If-Modified-Since'); - if ($modified !== '') { - $since = strtotime($modified); + if ($modified !== null && $modified !== '') { + $date = Util::parseHTTPDate($modified); + if (!$date) { + throw new StatusException('Invalid If-Modified-Since header provided.'); + } + $since = $date->getTimestamp(); } $stacks = $this->stackService->findAll($this->request->getParam('boardId'), $since); return new DataResponse($stacks, HTTP::STATUS_OK);