diff --git a/api/v1/entries/projectissue.php b/api/v1/entries/projectissue.php index b3f30d5154..bf6a5d56c4 100644 --- a/api/v1/entries/projectissue.php +++ b/api/v1/entries/projectissue.php @@ -17,16 +17,18 @@ class projectIssueEntry extends entry if(count($idParams) < 2) $this->sendError(400, 'The id of issue is wrong.'); $type = $idParams[0]; - $id = $idParams[1]; + $id = intval($idParams[1]); - $issue = new stdclass(); + $issue = new stdclass(); switch($type) { case 'story': $this->app->loadLang('story'); - $storyStatus = array('' => '', 'draft' => 'wait', 'active' => 'active', 'changed' => 'active', 'closed' => 'closed'); + $storyStatus = array('' => '', 'draft' => 'opened', 'active' => 'opened', 'changed' => 'opened', 'closed' => 'closed'); $story = $this->dao->select('*')->from(TABLE_STORY)->where('id')->eq($id)->fetch(); + if(!$story) $this->send404($issueID); + $issue->id = $issueID; $issue->title = $story->title; $issue->labels = array($this->app->lang->story->common, zget($this->app->lang->story->categoryList, $story->category)); @@ -35,17 +37,20 @@ class projectIssueEntry extends entry $issue->openedDate = $story->openedDate; $issue->openedBy = $story->openedBy; $issue->lastEditedDate = $story->lastEditedDate < '1970-01-01 01:01:01' ? $story->openedDate : $story->lastEditedDate; + $issue->lastEditedBy = $story->lastEditedDate < '1970-01-01 01:01:01' ? $story->openedBy : $story->lastEditedBy; $issue->status = $storyStatus[$story->status]; $issue->url = $this->createLink('story', 'view', "storyID=$id"); - $storySpec = $this->dao->select('*')->from(TABLE_STORYSPEC)->where('story')->eq($id)->andWhere('version')->eq($story->version)->fetch(); + $storySpec = $this->dao->select('*')->from(TABLE_STORYSPEC)->where('story')->eq($id)->andWhere('version')->eq($story->version)->fetch(); $issue->desc = $storySpec->spec; break; case 'bug': $this->app->loadLang('bug'); - $bugStatus = array('' => '', 'active' => 'active', 'resolved' => 'done', 'closed' => 'closed'); + $bugStatus = array('' => '', 'active' => 'opened', 'resolved' => 'opened', 'closed' => 'closed'); $bug = $this->dao->select('*')->from(TABLE_BUG)->where('id')->eq($id)->fetch(); + if(!$bug) $this->send404($issueID); + $issue->id = $issueID; $issue->title = $bug->title; $issue->labels = array($this->app->lang->bug->common, zget($this->app->lang->bug->typeList, $bug->type)); @@ -54,15 +59,17 @@ class projectIssueEntry extends entry $issue->openedDate = $bug->openedDate; $issue->openedBy = $bug->openedBy; $issue->lastEditedDate = $bug->lastEditedDate < '1970-01-01 01:01:01' ? $bug->openedDate : $bug->lastEditedDate; + $issue->lastEditedBy = $bug->lastEditedDate < '1970-01-01 01:01:01' ? $bug->openedBy : $bug->lastEditedBy; $issue->status = $bugStatus[$bug->status]; $issue->url = $this->createLink('bug', 'view', "bugID=$id"); $issue->desc = $bug->steps; break; case 'task': $this->app->loadLang('task'); - $taskStatus = array('' => '', 'wait' => 'wait', 'doing' => 'active', 'done' => 'done', 'pause' => 'pause', 'cancel' => 'cancel', 'closed' => 'closed'); + $taskStatus = array('' => '', 'wait' => 'opened', 'doing' => 'opened', 'done' => 'opened', 'pause' => 'opened', 'cancel' => 'opened', 'closed' => 'closed'); $task = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($id)->fetch(); + if(!$task) $this->send404($issueID); $issue->id = $issueID; $issue->title = $task->name; @@ -72,15 +79,32 @@ class projectIssueEntry extends entry $issue->openedDate = $task->openedDate; $issue->openedBy = $task->openedBy; $issue->lastEditedDate = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedDate : $task->lastEditedDate; + $issue->lastEditedBy = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedBy : $task->lastEditedBy; $issue->status = $taskStatus[$task->status]; $issue->url = $this->createLink('task', 'view', "taskID=$id"); $issue->desc = $task->desc; break; + default: + $this->send404($issueID); } + $actions = $this->loadModel('action')->getList($type, $issueID); + $this->send(200, array('issue' => $this->format($issue, 'openedDate:time,lastEditedDate:time'))); } + /** + * Send 404 response. + * + * @param string $issueID + * @access private + * @return string + */ + private function send404($issueID) + { + $this->sendError(404, 'The issue does not exist.'); + } + /** * Create url of issue. * diff --git a/api/v1/entries/projectissues.php b/api/v1/entries/projectissues.php index 5ceb24cb2e..0990d8b74f 100644 --- a/api/v1/entries/projectissues.php +++ b/api/v1/entries/projectissues.php @@ -15,36 +15,24 @@ class projectIssuesEntry extends entry $taskFields = 'id,status'; $taskStatus = array('' => ''); - $taskStatus['wait'] = 'wait'; - $taskStatus['active'] = 'doing'; - $taskStatus['done'] = 'done'; - $taskStatus['pause'] = 'pause'; - $taskStatus['cancel'] = 'cancel'; + $taskStatus['opened'] = 'wait,doing,done,pause'; $taskStatus['closed'] = 'closed'; $storyFields = 'id,status'; $storyStatus = array('' => ''); - $storyStatus['wait'] = 'draft'; - $storyStatus['active'] = 'active,changed'; - $storyStatus['done'] = ''; - $storyStatus['pause'] = ''; - $storyStatus['cancel'] = ''; + $storyStatus['opened'] = 'draft,active,changed'; $storyStatus['closed'] = 'closed'; $bugFields = 'id,status'; $bugStatus = array('' => ''); - $bugStatus['wait'] = ''; - $bugStatus['active'] = 'active'; - $bugStatus['done'] = 'resolved'; - $bugStatus['pause'] = ''; - $bugStatus['cancel'] = ''; + $bugStatus['opened'] = 'active,resolved'; $bugStatus['closed'] = 'closed'; $productID = (int)$productID; $status = $this->param('status', ''); $label = $this->param('label', ''); $search = $this->param('search', ''); - $page = $this->param('page', 0); + $page = intval($this->param('page', 1)); $limit = $this->param('limit', 20); $order = $this->param('order', 'openedDate_desc'); @@ -52,22 +40,28 @@ class projectIssuesEntry extends entry $order = $orderParams[0]; $sort = (isset($orderParams[1]) and strtolower($orderParams[1]) == 'desc') ? 'desc' : 'asc'; + if($status == 'all') $status = ''; + if(!in_array($status, array('opened', 'closed', ''))) return $this->sendError(400, 'The status is not supported'); + switch($order) { + case 'openedDate': + $taskFields .= ',openedDate'; + $storyFields .= ',openedDate'; + $bugFields .= ',openedDate'; + break; case 'title': $taskFields .= ',name as title'; $storyFields .= ',title'; $bugFields .= ',title'; + break; case 'lastEditedDate': $taskFields .= ",if(lastEditedDate < '1970-01-01 01-01-01', openedDate, lastEditedDate) as lastEditedDate"; $storyFields .= ",if(lastEditedDate < '1970-01-01 01-01-01', openedDate, lastEditedDate) as lastEditedDate"; $bugFields .= ",if(lastEditedDate < '1970-01-01 01-01-01', openedDate, lastEditedDate) as lastEditedDate"; + break; default: - $taskFields .= ',openedDate'; - $storyFields .= ',openedDate'; - $bugFields .= ',openedDate'; - - $order = 'openedDate'; + $this->sendError(400, 'The order is not supported'); } $issues = array(); @@ -100,10 +94,11 @@ class projectIssuesEntry extends entry } array_multisort(array_column($issues, 'order'), $sort == 'asc' ? SORT_ASC : SORT_DESC, $issues); - $issues = array_slice($issues, $page * $limit, $limit); + $total = count($issues); + $issues = $page < 1 ? array() : array_slice($issues, ($page-1) * $limit, $limit); $result = $this->processIssues($issues); - $this->send(200, array('page' => $page, 'total' => count($issues),'limit' => $limit, 'issues' => $result)); + $this->send(200, array('page' => $page, 'total' => $total, 'limit' => $limit, 'issues' => $result)); } /** @@ -151,7 +146,8 @@ class projectIssuesEntry extends entry $r->openedDate = $task->openedDate; $r->openedBy = $task->openedBy; $r->lastEditedDate = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedDate : $task->lastEditedDate; - $r->status = $task->status; + $r->lastEditedBy = $task->lastEditedDate < '1970-01-01 01:01:01' ? $task->openedBy : $task->lastEditedBy; + $r->status = $issue['status']; $r->url = $this->createLink('task', 'view', "taskID=$task->id"); } else if($issue['type'] == 'story') @@ -166,7 +162,8 @@ class projectIssuesEntry extends entry $r->openedDate = $story->openedDate; $r->openedBy = $story->openedBy; $r->lastEditedDate = $story->lastEditedDate < '1970-01-01 01:01:01' ? $story->openedDate : $story->lastEditedDate; - $r->status = $story->status; + $r->lastEditedBy = $story->lastEditedDate < '1970-01-01 01:01:01' ? $story->openedBy : $story->lastEditedBy; + $r->status = $issue['status']; $r->url = $this->createLink('story', 'view', "storyID=$story->id"); } else if($issue['type'] == 'bug') @@ -181,7 +178,8 @@ class projectIssuesEntry extends entry $r->openedDate = $bug->openedDate; $r->openedBy = $bug->openedBy; $r->lastEditedDate = $bug->lastEditedDate < '1970-01-01 01:01:01' ? $bug->openedDate : $bug->lastEditedDate; - $r->status = $bug->status; + $r->lastEditedBy = $bug->lastEditedDate < '1970-01-01 01:01:01' ? $bug->openedBy : $bug->lastEditedBy; + $r->status = $issue['status']; $r->url = $this->createLink('bug', 'view', "bugID=$bug->id"); } @@ -203,7 +201,7 @@ class projectIssuesEntry extends entry { foreach($array as $key => $values) { - if($values and strpos($value, $values) !== FALSE) return $key; + if($values and strpos($values, $value) !== FALSE) return $key; } return ''; diff --git a/config/filter.php b/config/filter.php index 0b6aa26736..2b07fbc15f 100644 --- a/config/filter.php +++ b/config/filter.php @@ -114,6 +114,7 @@ $filter->svn->cat = new stdclass(); $filter->svn->diff = new stdclass(); $filter->task->create = new stdclass(); $filter->task->export = new stdclass(); +$filter->execution->story = new stdclass(); $filter->testcase->default = new stdclass(); $filter->testcase->create = new stdclass(); $filter->testcase->browse = new stdclass();