diff --git a/api/v1/entries/bug.php b/api/v1/entries/bug.php index 44c82e98e1..2e79f9889a 100644 --- a/api/v1/entries/bug.php +++ b/api/v1/entries/bug.php @@ -26,7 +26,7 @@ class bugEntry extends entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $bug = $data->data->bug; diff --git a/api/v1/entries/bugs.php b/api/v1/entries/bugs.php index e0fec1d8b6..725011b770 100644 --- a/api/v1/entries/bugs.php +++ b/api/v1/entries/bugs.php @@ -59,7 +59,7 @@ class bugsEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'bugs' => array_values($result))); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/build.php b/api/v1/entries/build.php index 68eef04ea9..3d840c6855 100644 --- a/api/v1/entries/build.php +++ b/api/v1/entries/build.php @@ -27,10 +27,7 @@ class buildEntry extends Entry if(isset($data->status) and $data->status == 'success') return $this->send(200, $this->format($data->data->build, 'stories:idList,bugs:idList,deleted:bool')); /* Exception handling. */ - if(isset($data->status) and $data->status == 'fail') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $this->sendError(400, 'error'); } diff --git a/api/v1/entries/builds.php b/api/v1/entries/builds.php index 456bdfe179..fff692e506 100644 --- a/api/v1/entries/builds.php +++ b/api/v1/entries/builds.php @@ -28,7 +28,7 @@ class buildsEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $result = array(); foreach($data->data->projectBuilds as $productID => $builds) diff --git a/api/v1/entries/doc.php b/api/v1/entries/doc.php index 1cd6aaf028..7be2c0d40b 100644 --- a/api/v1/entries/doc.php +++ b/api/v1/entries/doc.php @@ -24,6 +24,10 @@ class docEntry extends entry $control->view($docID); $data = $this->getData(); + + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + $doc = $data->data->doc; unset($doc->draft); diff --git a/api/v1/entries/execution.php b/api/v1/entries/execution.php index 260cdafc78..d002881789 100644 --- a/api/v1/entries/execution.php +++ b/api/v1/entries/execution.php @@ -27,7 +27,7 @@ class executionEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $execution = $this->format($data->data->execution, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,begin:date,end:date,realBegan:date,realEnd:date,deleted:bool'); diff --git a/api/v1/entries/executionbugs.php b/api/v1/entries/executionbugs.php index 786fe343ef..0a47390a56 100644 --- a/api/v1/entries/executionbugs.php +++ b/api/v1/entries/executionbugs.php @@ -59,7 +59,7 @@ class executionBugsEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'bugs' => array_values($result))); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/executionbuilds.php b/api/v1/entries/executionbuilds.php index baa7de8e6a..b6285739b9 100644 --- a/api/v1/entries/executionbuilds.php +++ b/api/v1/entries/executionbuilds.php @@ -28,7 +28,7 @@ class executionBuildsEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $result = array(); foreach($data->data->executionBuilds as $builds) diff --git a/api/v1/entries/executioncases.php b/api/v1/entries/executioncases.php index f0431fb2a6..fbdd958a41 100644 --- a/api/v1/entries/executioncases.php +++ b/api/v1/entries/executioncases.php @@ -42,7 +42,7 @@ class executionCasesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'cases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/executions.php b/api/v1/entries/executions.php index 507076dabb..63d2743108 100644 --- a/api/v1/entries/executions.php +++ b/api/v1/entries/executions.php @@ -32,7 +32,7 @@ class executionsEntry extends entry /* Response */ $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $executions = $data->data->executionStats; $pager = $data->data->pager; diff --git a/api/v1/entries/executionstories.php b/api/v1/entries/executionstories.php index 54a1f971e4..d20a842042 100644 --- a/api/v1/entries/executionstories.php +++ b/api/v1/entries/executionstories.php @@ -39,7 +39,7 @@ class executionStoriesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'stories' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/file.php b/api/v1/entries/file.php index b69ed0539d..833739c02a 100644 --- a/api/v1/entries/file.php +++ b/api/v1/entries/file.php @@ -11,6 +11,23 @@ */ class fileEntry extends Entry { + /** + * GET method. + * + * @access public + * @return void + */ + public function get($fileID) + { + $control = $this->loadController('file', 'download'); + $control->download($fileID); + + $data = $this->getData(); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $this->send(200, $data); + } /** * PUT method. * diff --git a/api/v1/entries/files.php b/api/v1/entries/files.php index 17faf9f28f..0783362176 100644 --- a/api/v1/entries/files.php +++ b/api/v1/entries/files.php @@ -27,10 +27,7 @@ class filesEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'error') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $this->send(200, array('id' => $data->id)); } diff --git a/api/v1/entries/issue.php b/api/v1/entries/issue.php index d5a4cc0825..211b43a1b5 100644 --- a/api/v1/entries/issue.php +++ b/api/v1/entries/issue.php @@ -30,7 +30,7 @@ class issueEntry extends Entry $data = $this->getData(); if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); if(isset($data->status) and $data->status == 'success') return $this->send(200, $this->format($data->data->issue, 'createdDate:time,editedDate:time,assignedDate:time')); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $this->sendError(400, 'error'); } diff --git a/api/v1/entries/issues.php b/api/v1/entries/issues.php index a387c246b1..444dc2e0b5 100644 --- a/api/v1/entries/issues.php +++ b/api/v1/entries/issues.php @@ -28,7 +28,7 @@ class issuesEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/meetings.php b/api/v1/entries/meetings.php index 8f077f0852..6466ded6a0 100644 --- a/api/v1/entries/meetings.php +++ b/api/v1/entries/meetings.php @@ -32,7 +32,7 @@ class meetingsEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/product.php b/api/v1/entries/product.php index cb99e5d62d..c59ea57f78 100644 --- a/api/v1/entries/product.php +++ b/api/v1/entries/product.php @@ -27,7 +27,7 @@ class productEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $product = $this->format($data->data->product, 'createdDate:time'); diff --git a/api/v1/entries/productplan.php b/api/v1/entries/productplan.php index 3df13abe58..ab10d35d26 100644 --- a/api/v1/entries/productplan.php +++ b/api/v1/entries/productplan.php @@ -27,10 +27,7 @@ class productplanEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $plan = $this->format($data->data->plan, 'begin:date,end:date,deleted:bool'); diff --git a/api/v1/entries/productplans.php b/api/v1/entries/productplans.php index 86fb7a84f0..e2f0296c32 100644 --- a/api/v1/entries/productplans.php +++ b/api/v1/entries/productplans.php @@ -53,7 +53,7 @@ class productplansEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'plans' => array_values($result))); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/productprojects.php b/api/v1/entries/productprojects.php index 6af80adba3..8826d1a5bd 100644 --- a/api/v1/entries/productprojects.php +++ b/api/v1/entries/productprojects.php @@ -49,7 +49,7 @@ class productProjectsEntry extends entry return $this->send(200, $data); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); // TODO There is no handle for 401. return $this->sendError(400, 'error'); diff --git a/api/v1/entries/products.php b/api/v1/entries/products.php index aad54b2939..1d86cd3410 100644 --- a/api/v1/entries/products.php +++ b/api/v1/entries/products.php @@ -34,7 +34,7 @@ class productsEntry extends entry /* Response */ $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $products = $data->data->products; @@ -113,7 +113,7 @@ class productsEntry extends entry $control->create($this->request('program', 0)); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); /* Response */ $product = $this->loadModel('product')->getByID($data->id); @@ -134,7 +134,7 @@ class productsEntry extends entry $control->ajaxGetDropMenu($this->request('productID', 0), $this->request('module', 'product'), $this->request('method', 'browse'), $this->request('extra', ''), $this->request('from', '')); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $dropMenu = array('owner' => array(), 'other' => array(), 'closed' => array()); foreach($data->data->products as $programID => $products) diff --git a/api/v1/entries/programs.php b/api/v1/entries/programs.php index 28989e0af5..0b8ac845a3 100644 --- a/api/v1/entries/programs.php +++ b/api/v1/entries/programs.php @@ -30,7 +30,7 @@ class programsEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $programs = $data->data->programs; $progressList = $data->data->progressList; diff --git a/api/v1/entries/project.php b/api/v1/entries/project.php index 6d77705f02..f17cdde548 100644 --- a/api/v1/entries/project.php +++ b/api/v1/entries/project.php @@ -28,7 +28,7 @@ class projectEntry extends entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $project = $this->format($data->data->project, 'begin:date,end:date,realBegan:date,realEnd:date,openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,deleted:bool'); @@ -114,7 +114,7 @@ class projectEntry extends entry $control->edit($projectID); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(!isset($data->result)) return $this->sendError(400, 'error'); $project = $this->project->getByID($projectID); diff --git a/api/v1/entries/projectbugs.php b/api/v1/entries/projectbugs.php index f799f78d12..c0fd1ce86e 100644 --- a/api/v1/entries/projectbugs.php +++ b/api/v1/entries/projectbugs.php @@ -59,7 +59,7 @@ class projectBugsEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'bugs' => array_values($result))); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/projectcases.php b/api/v1/entries/projectcases.php index e459c8f7c7..efdbde7ba0 100644 --- a/api/v1/entries/projectcases.php +++ b/api/v1/entries/projectcases.php @@ -45,8 +45,7 @@ class projectCasesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'cases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } } diff --git a/api/v1/entries/projectreleases.php b/api/v1/entries/projectreleases.php index af02e042fb..15beeab941 100644 --- a/api/v1/entries/projectreleases.php +++ b/api/v1/entries/projectreleases.php @@ -37,8 +37,7 @@ class projectReleasesEntry extends entry return $this->send(200, array('total' => count($result), 'releases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/projects.php b/api/v1/entries/projects.php index ae68b4319d..4dfcd56b23 100644 --- a/api/v1/entries/projects.php +++ b/api/v1/entries/projects.php @@ -64,9 +64,7 @@ class projectsEntry extends entry return $this->send(200, $data); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - - // TODO There is no handle for 401. + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/projectstories.php b/api/v1/entries/projectstories.php index b8be4683ab..e742871106 100644 --- a/api/v1/entries/projectstories.php +++ b/api/v1/entries/projectstories.php @@ -39,8 +39,7 @@ class projectStoriesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'stories' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } } diff --git a/api/v1/entries/release.php b/api/v1/entries/release.php index bced77d10f..41ab4c6661 100644 --- a/api/v1/entries/release.php +++ b/api/v1/entries/release.php @@ -25,10 +25,7 @@ class releaseEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $release = $this->format($data->data->release, 'date:date,deleted:bool'); diff --git a/api/v1/entries/releases.php b/api/v1/entries/releases.php index 688551ab67..a38c6be803 100644 --- a/api/v1/entries/releases.php +++ b/api/v1/entries/releases.php @@ -37,8 +37,7 @@ class releasesEntry extends entry return $this->send(200, array('total' => count($result), 'releases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } } diff --git a/api/v1/entries/risk.php b/api/v1/entries/risk.php index dc887f6b31..89ed1a1b2c 100644 --- a/api/v1/entries/risk.php +++ b/api/v1/entries/risk.php @@ -26,7 +26,7 @@ class riskEntry extends Entry $data = $this->getData(); if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); if(isset($data->status) and $data->status == 'success') return $this->send(200, $this->format($data->data->risk, 'createdDate:time,editedDate:time')); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $this->sendError(400, 'error'); } diff --git a/api/v1/entries/risks.php b/api/v1/entries/risks.php index 92026fd104..a18ef97f88 100644 --- a/api/v1/entries/risks.php +++ b/api/v1/entries/risks.php @@ -39,7 +39,7 @@ class risksEntry extends entry } if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/stakeholders.php b/api/v1/entries/stakeholders.php index e67a3a2d30..fe57064421 100644 --- a/api/v1/entries/stakeholders.php +++ b/api/v1/entries/stakeholders.php @@ -55,9 +55,7 @@ class stakeholdersEntry extends entry return $this->send(200, $data); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - - // TODO There is no handle for 401. + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/stories.php b/api/v1/entries/stories.php index 09e8182702..8966e29da6 100644 --- a/api/v1/entries/stories.php +++ b/api/v1/entries/stories.php @@ -28,7 +28,7 @@ class storiesEntry extends entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $stories = $data->data->stories; $pager = $data->data->pager; @@ -68,7 +68,7 @@ class storiesEntry extends entry $control->create($productID); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message); $story = $this->loadModel('story')->getByID($data->id); diff --git a/api/v1/entries/story.php b/api/v1/entries/story.php index be918e803b..41aa373862 100644 --- a/api/v1/entries/story.php +++ b/api/v1/entries/story.php @@ -26,7 +26,7 @@ class storyEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $story = $data->data->story; @@ -89,7 +89,7 @@ class storyEntry extends Entry foreach($executionTasks as $task) { if(!isset($data->data->executions->{$task->execution})) continue; - $storyTasks[] = $this->filterFields($task, 'id,name'); + $storyTasks[] = $this->filterFields($task, 'id,name,type'); } } $story->tasks = $storyTasks; diff --git a/api/v1/entries/storychange.php b/api/v1/entries/storychange.php index 4ae530c544..efe5b28f70 100644 --- a/api/v1/entries/storychange.php +++ b/api/v1/entries/storychange.php @@ -38,9 +38,10 @@ class storyChangeEntry extends Entry $this->requireFields('title,spec'); $control->change($storyID); - + $data = $this->getData(); - if($data->status == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $story = $this->loadModel('story')->getByID($storyID); diff --git a/api/v1/entries/task.php b/api/v1/entries/task.php index c6a540e1f1..9bc6433089 100644 --- a/api/v1/entries/task.php +++ b/api/v1/entries/task.php @@ -26,7 +26,7 @@ class taskEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $task = $data->data->task; diff --git a/api/v1/entries/taskassignto.php b/api/v1/entries/taskassignto.php index ed6477fd8f..f97c8656ba 100644 --- a/api/v1/entries/taskassignto.php +++ b/api/v1/entries/taskassignto.php @@ -29,9 +29,10 @@ class taskAssignToEntry extends Entry $this->requireFields('assignedTo'); $control->assignTo($task->execution, $taskID); - + $data = $this->getData(); - if($data->result == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $task = $this->loadModel('task')->getByID($taskID); diff --git a/api/v1/entries/taskfinish.php b/api/v1/entries/taskfinish.php index 80f20d20ce..28de8ae47e 100644 --- a/api/v1/entries/taskfinish.php +++ b/api/v1/entries/taskfinish.php @@ -34,9 +34,10 @@ class taskFinishEntry extends Entry $control = $this->loadController('task', 'finish'); $this->requireFields('assignedTo,currentConsumed,realStarted,finishedDate'); $control->finish($taskID); - + $data = $this->getData(); - if($data->result == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $task = $this->loadModel('task')->getByID($taskID); diff --git a/api/v1/entries/tasks.php b/api/v1/entries/tasks.php index 7d657f275a..476dd9654a 100644 --- a/api/v1/entries/tasks.php +++ b/api/v1/entries/tasks.php @@ -48,8 +48,7 @@ class tasksEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'tasks' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/taskstart.php b/api/v1/entries/taskstart.php index d5896bf748..cf5adaee15 100644 --- a/api/v1/entries/taskstart.php +++ b/api/v1/entries/taskstart.php @@ -28,9 +28,10 @@ class taskStartEntry extends Entry $control = $this->loadController('task', 'start'); $this->requireFields('left'); $control->start($taskID); - + $data = $this->getData(); - if($data->result == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $task = $this->loadModel('task')->getByID($taskID); diff --git a/api/v1/entries/testcase.php b/api/v1/entries/testcase.php index dd23826add..5e03cfc013 100644 --- a/api/v1/entries/testcase.php +++ b/api/v1/entries/testcase.php @@ -9,7 +9,7 @@ * @version 1 * @link http://www.zentao.net */ -class testcaseEntry extends entry +class testcaseEntry extends entry { /** * GET method. @@ -25,7 +25,7 @@ class testcaseEntry extends entry $data = $this->getData(); if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(!isset($data->case)) $this->sendError(400, 'error'); $case = $data->case; diff --git a/api/v1/entries/testcases.php b/api/v1/entries/testcases.php index 65169a22e3..91e9ef788c 100644 --- a/api/v1/entries/testcases.php +++ b/api/v1/entries/testcases.php @@ -42,8 +42,7 @@ class testcasesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testcases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/testtask.php b/api/v1/entries/testtask.php index 42d6740e50..e28080fce3 100644 --- a/api/v1/entries/testtask.php +++ b/api/v1/entries/testtask.php @@ -9,7 +9,7 @@ * @version 1 * @link http://www.zentao.net */ -class testtaskEntry extends entry +class testtaskEntry extends entry { /** * GET method. @@ -24,7 +24,7 @@ class testtaskEntry extends entry $control->view($testtaskID); $data = $this->getData(); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(!isset($data->data->task)) $this->sendError(400, 'error'); $testtask = $data->data->task; diff --git a/api/v1/entries/testtasks.php b/api/v1/entries/testtasks.php index 155af3a789..67beb2b580 100644 --- a/api/v1/entries/testtasks.php +++ b/api/v1/entries/testtasks.php @@ -29,7 +29,7 @@ class testtasksEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/todo.php b/api/v1/entries/todo.php index ff9f59a67b..466ca67b6c 100644 --- a/api/v1/entries/todo.php +++ b/api/v1/entries/todo.php @@ -9,7 +9,7 @@ * @version 1 * @link http://www.zentao.net */ -class todoEntry extends entry +class todoEntry extends entry { /** * GET method. @@ -25,7 +25,8 @@ class todoEntry extends entry $data = $this->getData(); if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $todo = $data->data->todo; $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time')); @@ -45,7 +46,7 @@ class todoEntry extends entry /* Set $_POST variables. */ $fields = 'date,type,name,pri,desc,status,begin,end,private'; $this->batchSetPost($fields, $oldTodo); - + $this->setPost('idvalue', 0); $this->setPost('date', $this->request('date', date("Y-m-d", strtotime($oldTodo->date)))); $this->setPost('begin', $this->request('begin') ? str_replace(':', '', $this->request('begin')) : $oldTodo->begin); @@ -57,7 +58,7 @@ class todoEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $todo = $this->todo->getByID($todoID); $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time')); diff --git a/api/v1/entries/todoactivate.php b/api/v1/entries/todoactivate.php index fe26a2ef2a..77005d42e3 100644 --- a/api/v1/entries/todoactivate.php +++ b/api/v1/entries/todoactivate.php @@ -24,7 +24,8 @@ class todoActivateEntry extends Entry $control->activate($todoID); $data = $this->getData(); - if($data->status == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $todo = $this->loadModel('todo')->getByID($todoID); $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time')); diff --git a/api/v1/entries/todofinish.php b/api/v1/entries/todofinish.php index 6d6f97339d..ebb60dbde8 100644 --- a/api/v1/entries/todofinish.php +++ b/api/v1/entries/todofinish.php @@ -24,7 +24,8 @@ class todoFinishEntry extends Entry $control->finish($todoID); $data = $this->getData(); - if($data->status == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $todo = $this->loadModel('todo')->getByID($todoID); $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time')); diff --git a/api/v1/entries/todos.php b/api/v1/entries/todos.php index 81e612c152..ac116d4d3e 100644 --- a/api/v1/entries/todos.php +++ b/api/v1/entries/todos.php @@ -24,7 +24,7 @@ class todosEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/users.php b/api/v1/entries/users.php index aa68973ca1..588bef02b2 100644 --- a/api/v1/entries/users.php +++ b/api/v1/entries/users.php @@ -73,7 +73,7 @@ class usersEntry extends entry $control->create(); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message); $user = $this->loadModel('user')->getByID($data->id, 'id'); diff --git a/module/file/control.php b/module/file/control.php index b25ccae783..cb23328f8b 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -115,7 +115,11 @@ class file extends control { if(session_id() != $this->app->sessionID) helper::restartSession($this->app->sessionID); $file = $this->file->getById($fileID); - if(empty($file)) die("
{$this->lang->file->fileNotFound}"); + if(empty($file)) + { + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'code' => 404, 'message' => $this->lang->file->fileNotFound)); + die("{$this->lang->file->fileNotFound}"); + } /* Judge the mode, down or open. */ $mode = 'down'; @@ -156,6 +160,7 @@ class file extends control } else { + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'code' => 404, 'message' => $this->lang->file->fileNotFound)); die("{$this->lang->file->fileNotFound}"); } } diff --git a/module/story/model.php b/module/story/model.php index a8754ba8d6..c81aeb462c 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -47,7 +47,7 @@ class storyModel extends model ->andWhere('t2.type')->in('sprint,stage') ->orderBy('t1.`order` DESC') ->fetchAll('project'); - $story->tasks = $this->dao->select('id, name, assignedTo, execution, status, consumed, `left`')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('deleted')->eq(0)->orderBy('id DESC')->fetchGroup('execution'); + $story->tasks = $this->dao->select('id, name, assignedTo, execution, status, consumed, `left`,type')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('deleted')->eq(0)->orderBy('id DESC')->fetchGroup('execution'); $story->stages = $this->dao->select('*')->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->fetchPairs('branch', 'stage'); //$story->bugCount = $this->dao->select('COUNT(*)')->alias('count')->from(TABLE_BUG)->where('story')->eq($storyID)->fetch('count'); //$story->caseCount = $this->dao->select('COUNT(*)')->alias('count')->from(TABLE_CASE)->where('story')->eq($storyID)->fetch('count');