From d83dcc198c317ca645f0b120d688c2c77863be24 Mon Sep 17 00:00:00 2001 From: songchenxuan Date: Mon, 11 Mar 2024 16:51:43 +0800 Subject: [PATCH] * Fix api bug. --- api/v1/entries/builds.php | 4 ++-- api/v1/entries/executionbuilds.php | 4 ++-- api/v1/entries/productplan.php | 7 +++---- api/v1/entries/projects.php | 4 +++- api/v1/entries/stories.php | 4 ++-- api/v1/entries/tasks.php | 9 ++++----- api/v1/entries/testcase.php | 2 +- api/v1/entries/user.php | 13 ++++++------- api/v1/entries/users.php | 9 +++++---- framework/api/entry.class.php | 9 ++++++--- framework/base/control.class.php | 2 +- lib/base/pager/pager.class.php | 8 ++++++-- module/action/model.php | 12 ++++++++---- module/bug/zen.php | 4 ++-- module/file/model.php | 5 ++++- module/productplan/config.php | 8 ++++---- module/productplan/control.php | 8 ++++++-- module/project/config/form.php | 2 +- module/task/control.php | 6 +++--- module/testcase/zen.php | 4 ++-- 20 files changed, 71 insertions(+), 53 deletions(-) diff --git a/api/v1/entries/builds.php b/api/v1/entries/builds.php index daab93cbad..3e8edfdb9d 100644 --- a/api/v1/entries/builds.php +++ b/api/v1/entries/builds.php @@ -31,9 +31,9 @@ class buildsEntry extends entry 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) + foreach($data->data->builds as $build) { - foreach($builds as $build) $result[] = $this->format($build, 'bugs:idList,stories:idList,builder:user,deleted:bool'); + $result[] = $this->format($build, 'bugs:idList,stories:idList,builder:user,deleted:bool'); } return $this->send(200, array('total' => count($result), 'builds' => $result)); diff --git a/api/v1/entries/executionbuilds.php b/api/v1/entries/executionbuilds.php index 72740d8c5d..fd850334bf 100644 --- a/api/v1/entries/executionbuilds.php +++ b/api/v1/entries/executionbuilds.php @@ -31,9 +31,9 @@ class executionBuildsEntry extends entry 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) + foreach($data->data->builds as $build) { - foreach($builds as $build) $result[] = $this->format($build, 'builder:user,bugs:idList,stories:idList,deleted:bool'); + $result[] = $this->format($build, 'builder:user,bugs:idList,stories:idList,deleted:bool'); } return $this->send(200, array('total' => count($result), 'builds' => $result)); diff --git a/api/v1/entries/productplan.php b/api/v1/entries/productplan.php index aad1a9ea94..6080e26ece 100644 --- a/api/v1/entries/productplan.php +++ b/api/v1/entries/productplan.php @@ -52,6 +52,8 @@ class productplanEntry extends entry /* Set $_POST variables. */ $fields = 'title,begin,end,desc'; $this->batchSetPost($fields, $oldPlan); + $this->setPost('product', $oldPlan->product); + $this->setPost('status', $oldPlan->status); $control = $this->loadController('productplan', 'edit'); $control->edit($planID); @@ -67,10 +69,7 @@ class productplanEntry extends entry 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); - $plan = $data->data->plan; - $plan->stories = $data->data->planStories; - $plan->bugs = $data->data->planBugs; - + $plan = $this->productplan->getByID($planID); return $this->send(200, $this->format($plan, 'begin:date,end:date,deleted:bool,stories:array,bugs:array')); } diff --git a/api/v1/entries/projects.php b/api/v1/entries/projects.php index d144ee8c17..c1c1806c4d 100644 --- a/api/v1/entries/projects.php +++ b/api/v1/entries/projects.php @@ -75,9 +75,11 @@ class projectsEntry extends entry */ public function post() { - $fields = 'name,begin,end,products'; + $fields = 'name,begin,end,products,multiple'; $this->batchSetPost($fields); if(isset($_POST['products'])) $_POST['hasProduct'] = true; + $multiple = $this->request('multiple', ''); + if($multiple !== 'no') $this->setPost('multiple', 'on'); $useCode = $this->checkCodeUsed(); diff --git a/api/v1/entries/stories.php b/api/v1/entries/stories.php index 4fd7b8e134..c463e0906e 100644 --- a/api/v1/entries/stories.php +++ b/api/v1/entries/stories.php @@ -71,9 +71,9 @@ class storiesEntry extends entry $fields = 'title,spec,verify,module,reviewer,type,parent,moduleOptionMenu,source,sourceNote,category,pri,estimate,mailto,keywords,notifyemail,uid,URS,status'; $this->batchSetPost($fields); - $this->setPost('plans', array($this->request('plan'))); + $this->setPost('plans', array($this->request('plan', 0))); $this->setPost('branches', array($this->request('branch'))); - $this->setPost('modules', array($this->request('module'))); + $this->setPost('modules', array($this->request('module', 0))); /* If reviewer is not post, set needNotReview. */ $reviewer = $this->request('reviewer'); diff --git a/api/v1/entries/tasks.php b/api/v1/entries/tasks.php index 5ebad8a818..2d2b0d8d33 100644 --- a/api/v1/entries/tasks.php +++ b/api/v1/entries/tasks.php @@ -104,9 +104,10 @@ class tasksEntry extends entry $fields = 'name,type,assignedTo,estimate,story,execution,project,module,pri,desc,estStarted,deadline,mailto,team,teamEstimate,multiple,uid'; $this->batchSetPost($fields); - $assignedTo = $this->request('assignedTo', array(0 => '')); - if($assignedTo and !is_array($assignedTo)) $assignedTo = array($assignedTo); - $this->setPost('assignedTo', $assignedTo); + $this->setPost('execution', $executionID); + $this->setPost('assignedTo', $this->request('assignedTo', '')); + $this->setPost('module', $this->request('module', 0)); + $this->setPost('story', $this->request('story', 0)); if($this->request('multiple')) { @@ -115,8 +116,6 @@ class tasksEntry extends entry $this->setPost('teamSource', array_fill(0, count($this->request('team')), '')); } - $this->setPost('execution', $executionID); - $control = $this->loadController('task', 'create'); $this->requireFields('name,assignedTo,type,estStarted,deadline'); diff --git a/api/v1/entries/testcase.php b/api/v1/entries/testcase.php index 44e86a0f0e..a06e5d9a49 100644 --- a/api/v1/entries/testcase.php +++ b/api/v1/entries/testcase.php @@ -29,7 +29,7 @@ class testcaseEntry extends entry if(!isset($data->case)) $this->sendError(400, 'error'); $case = $data->case; - $case->steps = (isset($case->steps) and !empty($case->steps)) ? array_values(get_object_vars($case->steps)) : array(); + $case->steps = (isset($case->steps) and !empty($case->steps)) ? array_values(get_object_vars((object)$case->steps)) : array(); return $this->send(200, $this->format($case, 'openedBy:user,openedDate:time,lastEditedBy:user,lastEditedDate:time,lastRunDate:time,scriptedDate:date,reviewedBy:user,reviewedDate:date,steps:array,deleted:bool')); } diff --git a/api/v1/entries/user.php b/api/v1/entries/user.php index 42339bb11b..b645866b0f 100644 --- a/api/v1/entries/user.php +++ b/api/v1/entries/user.php @@ -407,13 +407,12 @@ class userEntry extends entry if($this->request('gender') and !in_array($this->request('gender'), array('f', 'm'))) return $this->sendError(400, "The value of gendar must be 'f' or 'm'"); $this->setPost('gender', $gender); - $password = $this->request('password', zget($_POST, 'password', '')); - if($password) - { - $this->setPost('password1', md5($password)); - $this->setPost('password2', md5($password)); - $this->setPost('passwordStrength', 2); - } + $password = $this->request('password', zget($_POST, 'password', '')); + $setPassword = $password ? md5($password) . $this->app->session->rand : ''; + $this->setPost('password1', $setPassword); + $this->setPost('password2', $setPassword); + $this->setPost('passwordStrength', 3); + $this->setPost('passwordLength', strlen($setPassword)); $this->setPost('verifyPassword', md5($this->app->user->password . $this->app->session->rand)); $control = $this->loadController('user', 'edit'); diff --git a/api/v1/entries/users.php b/api/v1/entries/users.php index ab3e6839eb..8a3d06f0ed 100644 --- a/api/v1/entries/users.php +++ b/api/v1/entries/users.php @@ -58,7 +58,7 @@ class usersEntry extends entry $fields = 'type,dept,account,password,visions,realname,join,role,email,commiter,gender,group,passwordStrength'; $this->batchSetPost($fields); - if(!in_array($this->request('gendar', zget($_POST, 'gendar', 'f')), array('f', 'm'))) return $this->sendError(400, "The value of gendar must be 'f' or 'm'"); + if(!in_array($this->request('gender', zget($_POST, 'gender', 'f')), array('f', 'm'))) return $this->sendError(400, "The value of gender must be 'f' or 'm'"); $password = $this->request('password', zget($_POST, 'password', '')) ? md5($this->request('password', zget($_POST, 'password', ''))) : ''; @@ -66,15 +66,16 @@ class usersEntry extends entry if(!is_array($visions)) $visions = explode(',', $visions); if($this->request('group')) $this->setPost('group', explode(',', $this->request('group'))); - $this->setPost('password1', $password); - $this->setPost('password2', $password); + $this->setPost('password1', $password . $this->app->session->rand); + $this->setPost('password2', $password . $this->app->session->rand); $this->setPost('passwordStrength', 3); $this->setPost('visions', $visions); $this->setPost('verifyPassword', md5($this->app->user->password . $this->app->session->rand)); + $this->setPost('passwordLength', strlen($_POST['password1'])); unset($_POST['password']); $control = $this->loadController('user', 'create'); - $this->requireFields('account,password1,realname'); + $this->requireFields('account,gender,password1,realname'); $control->create(); diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index 2e385865b0..55b76125dd 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -219,11 +219,11 @@ class baseEntry * Send error response * * @param int $code - * @param string $msg + * @param string|object $msg * @access public * @return string */ - public function sendError(int $code, string $msg) + public function sendError(int $code, string|object $msg) { $response = new stdclass(); $response->error = $msg; @@ -495,7 +495,10 @@ class baseEntry { foreach($data as $object) $this->formatFields($object, $fields); } - $this->formatFields($data, $fields); + else + { + $this->formatFields($data, $fields); + } return $data; } diff --git a/framework/base/control.class.php b/framework/base/control.class.php index 5855d70461..4862a9a4c0 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -1085,7 +1085,7 @@ class baseControl { print(urldecode(json_encode($data))); $response = helper::removeUTF8Bom(ob_get_clean()); - return helper::end($response); + return print($response); } /* Zand will use ob_get_clean() to print, so cannot clean so early. */ diff --git a/lib/base/pager/pager.class.php b/lib/base/pager/pager.class.php index 4e59eb7765..5394182070 100644 --- a/lib/base/pager/pager.class.php +++ b/lib/base/pager/pager.class.php @@ -176,9 +176,13 @@ class basePager public function setRecPerPage($recPerPage) { /* Set the cookie name. */ - $this->pageCookie = 'pager' . ucfirst($this->app->getModuleName()) . ucfirst($this->app->getMethodName()); + if(!(defined('RUN_MODE') and RUN_MODE == 'api')) + { + $this->pageCookie = 'pager' . ucfirst($this->app->getModuleName()) . ucfirst($this->app->getMethodName()); + + if(isset($_COOKIE[$this->pageCookie])) $recPerPage = $_COOKIE[$this->pageCookie]; + } - if(isset($_COOKIE[$this->pageCookie])) $recPerPage = $_COOKIE[$this->pageCookie]; $this->recPerPage = ($recPerPage > 0) ? (int)$recPerPage : PAGER::DEFAULT_REC_PER_PAGE; } diff --git a/module/action/model.php b/module/action/model.php index ecd480cb6e..a9422876f4 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -1541,14 +1541,18 @@ class actionModel extends model * 处理操作记录用于API。 * Process action for API. * - * @param array $actions - * @param array $users - * @param array $objectLang + * @param array|object $actions + * @param array|object $users + * @param array|object $objectLang * @access public * @return array */ - public function processActionForAPI(array $actions, array $users = array(), array $objectLang = array()): array + public function processActionForAPI(array|object $actions, array|object $users = array(), array|object $objectLang = array()): array { + if(is_object($actions)) $actions = (array)$actions; + if(is_object($users)) $users = (array)$users; + if(is_object($objectLang)) $objectLang = (array)$objectLang; + foreach($actions as $action) { $action->actor = zget($users, $action->actor); diff --git a/module/bug/zen.php b/module/bug/zen.php index f980f5e15f..033fbd281c 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -2197,9 +2197,9 @@ class bugZen extends bug * @param array $params * @param string $message * @access protected - * @return bool + * @return bool|int */ - protected function responseAfterCreate(object $bug, array $params, string $message = ''): bool + protected function responseAfterCreate(object $bug, array $params, string $message = ''): bool|int { $executionID = $bug->execution ? $bug->execution : (int)zget($params, 'executionID', $this->session->execution); diff --git a/module/file/model.php b/module/file/model.php index a42ec99c91..0dae2fd462 100755 --- a/module/file/model.php +++ b/module/file/model.php @@ -684,11 +684,14 @@ class fileModel extends model * * @param object $data * @param string|array $editorList + * @param mixed $uid * @access public * @return object */ - public function processImgURL(object $data, string|array $editorList, string $uid = ''): object + public function processImgURL(object $data, string|array $editorList, mixed $uid = ''): object { + if(!is_string($uid)) return $data; + if(is_string($editorList)) $editorList = explode(',', str_replace(' ', '', $editorList)); if(empty($editorList)) return $data; diff --git a/module/productplan/config.php b/module/productplan/config.php index 558792cd55..690059b231 100644 --- a/module/productplan/config.php +++ b/module/productplan/config.php @@ -60,22 +60,22 @@ $config->productplan->actionList['createExecution']['notLoadModel'] = true; $config->productplan->actionList['linkStory']['icon'] = 'link'; $config->productplan->actionList['linkStory']['hint'] = $lang->productplan->linkStory; $config->productplan->actionList['linkStory']['text'] = $lang->productplan->linkStory; -$config->productplan->actionList['linkStory']['url'] = helper::createLink($app->rawModule, 'view', 'planID={id}&type=story&orderBy=id_desc&link=true'); +if($app->rawModule) $config->productplan->actionList['linkStory']['url'] = helper::createLink($app->rawModule, 'view', 'planID={id}&type=story&orderBy=id_desc&link=true'); $config->productplan->actionList['linkBug']['icon'] = 'bug'; $config->productplan->actionList['linkBug']['hint'] = $lang->productplan->linkBug; $config->productplan->actionList['linkBug']['text'] = $lang->productplan->linkBug; -$config->productplan->actionList['linkBug']['url'] = helper::createLink($app->rawModule, 'view', 'planID={id}&type=bug&orderBy=id_desc&link=true'); +if($app->rawModule) $config->productplan->actionList['linkBug']['url'] = helper::createLink($app->rawModule, 'view', 'planID={id}&type=bug&orderBy=id_desc&link=true'); $config->productplan->actionList['edit']['icon'] = 'edit'; $config->productplan->actionList['edit']['hint'] = $lang->productplan->edit; $config->productplan->actionList['edit']['text'] = $lang->productplan->edit; -$config->productplan->actionList['edit']['url'] = helper::createLink($app->rawModule, 'edit', 'planID={id}'); +if($app->rawModule) $config->productplan->actionList['edit']['url'] = helper::createLink($app->rawModule, 'edit', 'planID={id}'); $config->productplan->actionList['create']['icon'] = 'split'; $config->productplan->actionList['create']['hint'] = $lang->productplan->createChildren; $config->productplan->actionList['create']['text'] = $lang->productplan->createChildren; -$config->productplan->actionList['create']['url'] = helper::createLink($app->rawModule, 'create', 'product={product}&branch={branch}&parent={id}'); +if($app->rawModule) $config->productplan->actionList['create']['url'] = helper::createLink($app->rawModule, 'create', 'product={product}&branch={branch}&parent={id}'); $config->productplan->actionList['delete']['icon'] = 'trash'; $config->productplan->actionList['delete']['hint'] = $lang->productplan->delete; diff --git a/module/productplan/control.php b/module/productplan/control.php index 1323b35f43..672cd2631e 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -392,8 +392,12 @@ class productplan extends control $this->view->orderBy = $orderBy; $this->view->link = $link; $this->view->param = $param; - $this->view->storyPager = $storyPager; - $this->view->bugPager = $bugPager; + + if($this->viewType != 'json') + { + $this->view->storyPager = $storyPager; + $this->view->bugPager = $bugPager; + } $this->display(); } diff --git a/module/project/config/form.php b/module/project/config/form.php index b8f41decbd..1d7848df71 100755 --- a/module/project/config/form.php +++ b/module/project/config/form.php @@ -13,7 +13,7 @@ $config->project->form->manageProducts = array(); $config->project->form->create['parent'] = array('type' => 'int', 'required' => false, 'default' => 0); $config->project->form->create['name'] = array('type' => 'string', 'required' => true, 'filter' => 'trim'); -$config->project->form->create['multiple'] = array('type' => 'int', 'required' => false, 'default' => 1); +$config->project->form->create['multiple'] = array('type' => 'string', 'required' => false); $config->project->form->create['hasProduct'] = array('type' => 'string', 'required' => false, 'default' => ''); $config->project->form->create['stageBy'] = array('type' => 'string', 'required' => false, 'default' => 'product'); $config->project->form->create['PM'] = array('type' => 'string', 'required' => false, 'default' => ''); diff --git a/module/task/control.php b/module/task/control.php index 4b650be1b2..e3c8c66ab3 100755 --- a/module/task/control.php +++ b/module/task/control.php @@ -105,7 +105,7 @@ class task extends control $taskData->id = current($taskIdList); $this->task->afterCreate($taskData, $taskIdList, $bugID, $todoID); $this->task->updateKanbanData($taskData->execution, $taskIdList, (int)$this->post->lane, $columnID); - setCookie("lastTaskModule", $this->post->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + setCookie("lastTaskModule", (string)$this->post->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); /* Get the information returned after a task is created. */ $response = $this->taskZen->responseAfterCreate($taskData, $execution, $this->post->after ? $this->post->after : ''); @@ -457,7 +457,7 @@ class task extends control /* Get the information returned after a task is started. */ $from = zget($output, 'from'); $response = $this->taskZen->responseAfterChangeStatus($task, $from); - $this->send($response); + return $this->send($response); } /* Shows the variables needed to start the task page. */ @@ -716,7 +716,7 @@ class task extends control $this->executeHooks($taskID); $response = $this->taskZen->responseAfterChangeStatus($task, $from); - $this->send($response); + return $this->send($response); } $this->view->title = $this->view->execution->name . $this->lang->colon .$this->lang->task->restart; diff --git a/module/testcase/zen.php b/module/testcase/zen.php index 14ffe352cb..1171013c8c 100755 --- a/module/testcase/zen.php +++ b/module/testcase/zen.php @@ -2205,9 +2205,9 @@ class testcaseZen extends testcase * * @param int $caseID * @access protected - * @return array + * @return array|int */ - protected function responseAfterCreate(int $caseID): array + protected function responseAfterCreate(int $caseID): array|int { $message = $this->executeHooks($caseID); if(!$message) $message = $this->lang->saveSuccess;