From 294ce08fb3f3bf52f0a4ff56a44a091539a4a89d Mon Sep 17 00:00:00 2001 From: atisne Date: Mon, 29 Jul 2019 16:30:27 +0200 Subject: [PATCH 1/8] Add services to manage ITS Create, Update, Link with a test project --- lib/api/xmlrpc/v1/APIErrors.php | 2 + lib/api/xmlrpc/v1/xmlrpc.class.php | 118 +++++++++++++++++++++++++++++ locale/en_GB/strings.txt | 1 + locale/fr_FR/strings.txt | 1 + 4 files changed, 122 insertions(+) diff --git a/lib/api/xmlrpc/v1/APIErrors.php b/lib/api/xmlrpc/v1/APIErrors.php index 324e1f4fd3..de0c27369a 100644 --- a/lib/api/xmlrpc/v1/APIErrors.php +++ b/lib/api/xmlrpc/v1/APIErrors.php @@ -363,3 +363,5 @@ */ define('ITS_NOT_FOUND',13000); define('ITS_NOT_FOUND_STR', lang_get('API_ITS_NOT_FOUND',null,1)); +define('NO_ITSID', 13001); +define('NO_ITSID_STR', lang_get('API_NO_ITSID',null,1)); diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index d1f5220127..f450868c91 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -216,6 +216,10 @@ class TestlinkXMLRPCServer extends IXR_Server { public static $testCaseVersionParamName = "tcversion"; public static $itsNameParamName = "itsname"; public static $itsEnabledParamName = "itsenabled"; + public static $itsTypeParamName = "itstype"; + public static $itsCfgParamName = "itscfg"; + public static $itsIDParamName ="itsid"; + public static $copyTestersFromBuildParamName = "copytestersfrombuild"; /** @@ -8283,6 +8287,117 @@ protected function _updateStepsResult($execID = null) { return $xx; } + + /** + * Create an Issue Tracker System + * + * @param struct $args + * @param string $args["devKey"] + * @param string $args["itsname"] ITS name + * @param string $args["itstype"] ITS name + * @param string $args["itscfg"] ITS name + * @access public + */ + public function createIssueTrackerSystem($args) { + $operation=__FUNCTION__; + $msg_prefix="({$operation}) - "; + + $this->_setArgs($args); + + if ($this->authenticate($msg_prefix)) { + $item = new stdClass(); + $item->name = $this->args[self::$itsNameParamName]; + $item->type = $this->args[self::$itsTypeParamName]; + $item->cfg = $this->args[self::$itsCfgParamName]; + + if(is_null( $this->itsMgr )) { + $this->itsMgr = new tlIssueTracker( $this->dbObj ); + } + + return $this->itsMgr->create($item); + } else { + return $this->errors; + } + + } + + + /** + * Update Issue Tracker System + * + * @param struct $args + * @param string $args["devKey"] + * @param string $args["itsname"] ITS name + * @param string $args["itstype"] ITS name + * @param string $args["itscfg"] ITS name + * @access public + */ + public function updateIssueTrackerSystem($args) { + $operation=__FUNCTION__; + $msg_prefix="({$operation}) - "; + + $this->_setArgs($args); + + if($this->authenticate($msg_prefix)) { + $item = new stdClass(); + $item->name = $this->args[self::$itsNameParamName]; + $item->type = $this->args[self::$itsTypeParamName]; + $item->cfg = $this->args[self::$itsCfgParamName]; + $item->id = $this->args[self::$itsIDParamName]; + + if(is_null( $this->itsMgr )) { + $this->itsMgr = new tlIssueTracker( $this->dbObj ); + } + + return $this->itsMgr->update($item); + + } else { + return $this->errors; + } + + } + + /** + * Set link between a project and an ITS + * + * @param struct $args + * @param string $args["devKey"] + * @param string $args["itsid"] ITS ID + * @param string $args["testprojectid"] Project ID + * @access public + */ + public function setTestProjectITS($args) { + $operation=__FUNCTION__; + $msg_prefix="({$operation}) - "; + + $this->_setArgs($args); + + if($this->authenticate($msg_prefix)) { + if(!($this->_isTestProjectIDPresent())) { + $this->errors[] = new IXR_Error(NO_TESTPROJECTID, $messagePrefix . NO_TESTPROJECTID_STR); + return $this->errors; + } + + if ($this->args[self::$itsIDParamName] != "") { + if(is_null( $this->itsMgr )) { + $this->itsMgr = new tlIssueTracker( $this->dbObj ); + } + + $this->itsMgr->link($this->args[self::$itsIDParamName], $this->args[self::$testProjectIDParamName]); + $resultInfo = array(); + $resultInfo[]= array("operation" => __FUNCTION__, + "additionalInfo" => null, + "status" => true, "id" => $this->args[self::$testProjectIDParamName], "message" => GENERAL_SUCCESS_STR); + return $resultInfo; + } else { + $this->errors[] = new IXR_Error(NO_ITSID, $messagePrefix . NO_ITSID_STR); + return $this->errors; + } + } else { + return $this->errors; + } + } + /** */ function initMethodYellowPages() { @@ -8313,6 +8428,9 @@ function initMethodYellowPages() { 'tl.removePlatformFromTestPlan' => 'this:removePlatformFromTestPlan', 'tl.getExecCountersByBuild' => 'this:getExecCountersByBuild', 'tl.getIssueTrackerSystem' => 'this:getIssueTrackerSystem', + 'tl.createIssueTrackerSystem' => 'this:createIssueTrackerSystem', + 'tl.updateIssueTrackerSystem' => 'this:updateIssueTrackerSystem', + 'tl.setTestProjectITS' => 'this:setTestProjectITS', 'tl.getProjects' => 'this:getProjects', 'tl.getProjectKeywords' => 'this:getProjectKeywords', 'tl.getProjectPlatforms' => 'this:getProjectPlatforms', diff --git a/locale/en_GB/strings.txt b/locale/en_GB/strings.txt index 27d0e4ac8c..31caaaf52e 100644 --- a/locale/en_GB/strings.txt +++ b/locale/en_GB/strings.txt @@ -3162,6 +3162,7 @@ $TLS_API_NO_TESTSUITEID = "No testsuiteid provided."; $TLS_API_NO_TPID = "No testplan ID (testplanid) provided."; $TLS_API_NO_TCID = "No testcase ID (testcaseid) provided."; $TLS_API_NO_PLATFORMID = "No Platform ID (platformid) provided."; +$TLS_API_NO_ITSID = "NO ITS ID (itsid) provided."; $TLS_API_INVALID_TCASEID = "The Test Case ID (testcaseid: %s) provided does not exist!"; diff --git a/locale/fr_FR/strings.txt b/locale/fr_FR/strings.txt index 01c1acd5a3..6bce983fe1 100644 --- a/locale/fr_FR/strings.txt +++ b/locale/fr_FR/strings.txt @@ -3162,6 +3162,7 @@ $TLS_API_NO_TESTSUITEID = "Aucun ID de dossier de test fourni."; $TLS_API_NO_TPID = "Aucun ID de campagne de test fourni."; $TLS_API_NO_TCID = "Aucun ID de fiche de test fourni."; $TLS_API_NO_PLATFORMID = "Aucun ID de plateforme fourni."; +$TLS_API_NO_ITSID = "Aucun ID de gestionnaire d’anomalie (itsid) fourni."; $TLS_API_INVALID_TCASEID = "ID de fiche de test %s inconnu."; From b2ba1caa613d4620a5b52a1028bf8fe3b3f3a1ed Mon Sep 17 00:00:00 2001 From: atisne Date: Mon, 5 Aug 2019 10:34:18 +0200 Subject: [PATCH 2/8] Add the ability to enable the ITS when linking it with a project --- lib/api/xmlrpc/v1/xmlrpc.class.php | 32 ++++++++++++++++++++++++------ locale/en_GB/strings.txt | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index f450868c91..cadc57f77d 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -216,8 +216,8 @@ class TestlinkXMLRPCServer extends IXR_Server { public static $testCaseVersionParamName = "tcversion"; public static $itsNameParamName = "itsname"; public static $itsEnabledParamName = "itsenabled"; - public static $itsTypeParamName = "itstype"; - public static $itsCfgParamName = "itscfg"; + public static $itsTypeParamName = "type"; + public static $itsCfgParamName = "cfg"; public static $itsIDParamName ="itsid"; public static $copyTestersFromBuildParamName = "copytestersfrombuild"; @@ -8364,6 +8364,8 @@ public function updateIssueTrackerSystem($args) { * @param string $args["devKey"] * @param string $args["itsid"] ITS ID * @param string $args["testprojectid"] Project ID + * @param boolean $args["itsenabled"] Enabled the ITS or not + * OPTIONAL * @access public */ public function setTestProjectITS($args) { @@ -8378,16 +8380,34 @@ public function setTestProjectITS($args) { return $this->errors; } + $itsID = $this->args[self::$itsIDParamName]; if ($this->args[self::$itsIDParamName] != "") { if(is_null( $this->itsMgr )) { $this->itsMgr = new tlIssueTracker( $this->dbObj ); } - $this->itsMgr->link($this->args[self::$itsIDParamName], $this->args[self::$testProjectIDParamName]); + $projectID = $this->args[self::$testProjectIDParamName]; + $this->itsMgr->link($itsID, $projectID); $resultInfo = array(); - $resultInfo[]= array("operation" => __FUNCTION__, - "additionalInfo" => null, - "status" => true, "id" => $this->args[self::$testProjectIDParamName], "message" => GENERAL_SUCCESS_STR); + $resultInfo[]= array("operation" => "link ITS", + "additionalInfo" => "ITS ID " . $itsID, + "status" => true, + "id" => $projectID, "message" => GENERAL_SUCCESS_STR); + + // enable the ITS if needed + $isEnabled = false; + if ($this->_isParamPresent(self::$itsEnabledParamName)) { + $isEnabled = ($this->args[self::$itsEnabledParamName] > 0); + } + + if ($isEnabled) { + $this->tprojectMgr->enableIssueTracker($projectID); + $resultInfo[]= array("operation" => "enable ITS", + "additionalInfo" => null, + "status" => true, + "id" => $projectID, "message" => GENERAL_SUCCESS_STR); + } + return $resultInfo; } else { $this->errors[] = new IXR_Error(NO_ITSID, $messagePrefix . NO_ITSID_STR); diff --git a/locale/en_GB/strings.txt b/locale/en_GB/strings.txt index 9be2e499d1..88e34cc9e2 100644 --- a/locale/en_GB/strings.txt +++ b/locale/en_GB/strings.txt @@ -3162,7 +3162,7 @@ $TLS_API_NO_TESTSUITEID = "No testsuiteid provided."; $TLS_API_NO_TPID = "No testplan ID (testplanid) provided."; $TLS_API_NO_TCID = "No testcase ID (testcaseid) provided."; $TLS_API_NO_PLATFORMID = "No Platform ID (platformid) provided."; -$TLS_API_NO_ITSID = "NO ITS ID (itsid) provided."; +$TLS_API_NO_ITSID = "No Issue Tracker System ID (itsid) provided."; $TLS_API_INVALID_TCASEID = "The Test Case ID (testcaseid: %s) provided does not exist!"; From dd3c93ff866d3fea86f02290a7d36e947295df60 Mon Sep 17 00:00:00 2001 From: atisne Date: Thu, 8 Aug 2019 14:51:36 +0200 Subject: [PATCH 3/8] Add user's privilege control --- lib/api/xmlrpc/v1/xmlrpc.class.php | 131 ++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 41 deletions(-) diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index cadc57f77d..b9e9b32fe3 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -660,6 +660,31 @@ protected function checkTestSuiteID($messagePrefix = '') { return $status; } + /** + * Helper method to see if the ItsID provided is valid + * + * This is the only method that should be called directly to check the ItsID + * + * @param string $messagePrefix + * used to be prepended to error message + * + * @return boolean + * @access protected + */ + protected function checkItsID($messagePrefix = '') { + $status = true; + if(! $this->_isItsIDPresent()) { + $this->errors[] = new IXR_Error( NO_ITSID, $messagePrefix . NO_ITSID_STR ); + $status = false; + } else { + // See if this ITS ID exists in the db + $its = $this->getIssueTrackerSystem( $this->args, 'internal' ); + $status = is_null($its); + } + + return $status; + } + /** * Helper method to see if the guess is set * @@ -802,6 +827,17 @@ protected function _isTestCaseExternalIDPresent() { return $status; } + /** + * Helper method to see if an itsid is given as one of the arguments + * + * @return boolean + * @access protected + */ + protected function _isItsIDPresent() { + $status = isset( $this->args[self::$itsIDParamName] ) ? true : false; + return $status; + } + /** * Helper method to see if: * a timestamp is given as one of the arguments @@ -8294,9 +8330,11 @@ protected function _updateStepsResult($execID = null) { * @param struct $args * @param string $args["devKey"] * @param string $args["itsname"] ITS name - * @param string $args["itstype"] ITS name - * @param string $args["itscfg"] ITS name + * @param string $args["type"] ITS type + * @param string $args["cfg"] ITS config + * * @access public + * @since 1.9.20 */ public function createIssueTrackerSystem($args) { $operation=__FUNCTION__; @@ -8304,7 +8342,9 @@ public function createIssueTrackerSystem($args) { $this->_setArgs($args); - if ($this->authenticate($msg_prefix)) { + if ($this->authenticate($msg_prefix)&& + $this->userHasRight("issuetracker_management", self::CHECK_PUBLIC_PRIVATE_ATTR)) { + $item = new stdClass(); $item->name = $this->args[self::$itsNameParamName]; $item->type = $this->args[self::$itsTypeParamName]; @@ -8327,10 +8367,13 @@ public function createIssueTrackerSystem($args) { * * @param struct $args * @param string $args["devKey"] + * @param string $args["itsid"] ITS ID * @param string $args["itsname"] ITS name - * @param string $args["itstype"] ITS name - * @param string $args["itscfg"] ITS name + * @param string $args["type"] ITS type + * @param string $args["cfg"] ITS config + * * @access public + * @since 1.9.20 */ public function updateIssueTrackerSystem($args) { $operation=__FUNCTION__; @@ -8338,12 +8381,17 @@ public function updateIssueTrackerSystem($args) { $this->_setArgs($args); - if($this->authenticate($msg_prefix)) { + $checkFunctions = array('authenticate', + 'checkITSID'); + + if ($this->_runChecks($checkFunctions, $msg_prefix) && + $this->userHasRight("issuetracker_management", self::CHECK_PUBLIC_PRIVATE_ATTR)) { + $item = new stdClass(); + $item->id = $this->args[self::$itsIDParamName]; $item->name = $this->args[self::$itsNameParamName]; $item->type = $this->args[self::$itsTypeParamName]; $item->cfg = $this->args[self::$itsCfgParamName]; - $item->id = $this->args[self::$itsIDParamName]; if(is_null( $this->itsMgr )) { $this->itsMgr = new tlIssueTracker( $this->dbObj ); @@ -8364,9 +8412,11 @@ public function updateIssueTrackerSystem($args) { * @param string $args["devKey"] * @param string $args["itsid"] ITS ID * @param string $args["testprojectid"] Project ID - * @param boolean $args["itsenabled"] Enabled the ITS or not + * @param boolean $args["itsenabled"] Enable the ITS or not * OPTIONAL + * * @access public + * @since 1.9.20 */ public function setTestProjectITS($args) { $operation=__FUNCTION__; @@ -8374,45 +8424,44 @@ public function setTestProjectITS($args) { $this->_setArgs($args); - if($this->authenticate($msg_prefix)) { - if(!($this->_isTestProjectIDPresent())) { - $this->errors[] = new IXR_Error(NO_TESTPROJECTID, $messagePrefix . NO_TESTPROJECTID_STR); - return $this->errors; - } + $checkFunctions = array('authenticate', + 'checkTestProjectID', + 'checkITSID'); + + if($this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight( "mgt_modify_product" )) { $itsID = $this->args[self::$itsIDParamName]; - if ($this->args[self::$itsIDParamName] != "") { - if(is_null( $this->itsMgr )) { - $this->itsMgr = new tlIssueTracker( $this->dbObj ); - } + $projectID = $this->args[self::$testProjectIDParamName]; - $projectID = $this->args[self::$testProjectIDParamName]; - $this->itsMgr->link($itsID, $projectID); - $resultInfo = array(); - $resultInfo[]= array("operation" => "link ITS", - "additionalInfo" => "ITS ID " . $itsID, - "status" => true, - "id" => $projectID, "message" => GENERAL_SUCCESS_STR); + if(is_null( $this->itsMgr )) { + $this->itsMgr = new tlIssueTracker( $this->dbObj ); + } - // enable the ITS if needed - $isEnabled = false; - if ($this->_isParamPresent(self::$itsEnabledParamName)) { - $isEnabled = ($this->args[self::$itsEnabledParamName] > 0); - } + $this->itsMgr->link($itsID, $projectID); + $resultInfo = array(); + $resultInfo[]= array("operation" => "link ITS", + "additionalInfo" => "ITS ID " . $itsID, + "status" => true, + "id" => $projectID, + "message" => GENERAL_SUCCESS_STR); + + // enable the ITS if needed + $isEnabled = false; + if ($this->_isParamPresent(self::$itsEnabledParamName)) { + $isEnabled = ($this->args[self::$itsEnabledParamName] > 0); + } + + if ($isEnabled) { + $this->tprojectMgr->enableIssueTracker($projectID); + $resultInfo[]= array("operation" => "enable ITS", + "additionalInfo" => null, + "status" => true, + "id" => $projectID, + "message" => GENERAL_SUCCESS_STR); + } - if ($isEnabled) { - $this->tprojectMgr->enableIssueTracker($projectID); - $resultInfo[]= array("operation" => "enable ITS", - "additionalInfo" => null, - "status" => true, - "id" => $projectID, "message" => GENERAL_SUCCESS_STR); - } + return $resultInfo; - return $resultInfo; - } else { - $this->errors[] = new IXR_Error(NO_ITSID, $messagePrefix . NO_ITSID_STR); - return $this->errors; - } } else { return $this->errors; } From ccab618a62e50ccc492294820eae8cd4efba9d90 Mon Sep 17 00:00:00 2001 From: atisne Date: Thu, 8 Aug 2019 16:16:06 +0200 Subject: [PATCH 4/8] Add checks on mandatory parameters --- lib/api/xmlrpc/v1/xmlrpc.class.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index b9e9b32fe3..cfa682dd20 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -8342,7 +8342,19 @@ public function createIssueTrackerSystem($args) { $this->_setArgs($args); - if ($this->authenticate($msg_prefix)&& + $params = array(self::$$itsNameParamName, + self::$itsTypeParamName, + self::$itsCfgParamName); + + $missingArg = false; + foreach($params as $param) { + $missingArg = $missingArg || _isParamPresent($param); + } + if ($missingArg) { + return $this->errors; + } + + if ($this->authenticate($msg_prefix) && $this->userHasRight("issuetracker_management", self::CHECK_PUBLIC_PRIVATE_ATTR)) { $item = new stdClass(); @@ -8381,6 +8393,18 @@ public function updateIssueTrackerSystem($args) { $this->_setArgs($args); + $params = array(self::$$itsNameParamName, + self::$itsTypeParamName, + self::$itsCfgParamName); + + $missingArg = false; + foreach($params as $param) { + $missingArg = $missingArg || _isParamPresent($param); + } + if ($missingArg) { + return $this->errors; + } + $checkFunctions = array('authenticate', 'checkITSID'); From 6efbdd0b385ba228ed25530990146e1f48ba39e9 Mon Sep 17 00:00:00 2001 From: atisne Date: Mon, 12 Aug 2019 14:53:41 +0200 Subject: [PATCH 5/8] Add a service to unlink an ITS to a Test Project --- lib/api/xmlrpc/v1/xmlrpc.class.php | 53 +++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index cfa682dd20..b91e5dee90 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -8437,7 +8437,7 @@ public function updateIssueTrackerSystem($args) { * @param string $args["itsid"] ITS ID * @param string $args["testprojectid"] Project ID * @param boolean $args["itsenabled"] Enable the ITS or not - * OPTIONAL + * OPTIONAL default is false * * @access public * @since 1.9.20 @@ -8454,8 +8454,8 @@ public function setTestProjectITS($args) { if($this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight( "mgt_modify_product" )) { - $itsID = $this->args[self::$itsIDParamName]; - $projectID = $this->args[self::$testProjectIDParamName]; + $itsID = intval($this->args[self::$itsIDParamName]); + $projectID = intval($this->args[self::$testProjectIDParamName]); if(is_null( $this->itsMgr )) { $this->itsMgr = new tlIssueTracker( $this->dbObj ); @@ -8472,7 +8472,7 @@ public function setTestProjectITS($args) { // enable the ITS if needed $isEnabled = false; if ($this->_isParamPresent(self::$itsEnabledParamName)) { - $isEnabled = ($this->args[self::$itsEnabledParamName] > 0); + $isEnabled = ($this->args[self::$itsEnabledParamName]); } if ($isEnabled) { @@ -8491,6 +8491,50 @@ public function setTestProjectITS($args) { } } + /** + * Remove the link between a project and an ITS + * + * @param struct $args + * @param string $args["devKey"] + * @param string $args["itsid"] ITS ID + * @param string $args["testprojectid"] Project ID + * + * @access public + * @since 1.9.20 + */ + public function removeTestProjectITS($args) { + $operation=__FUNCTION__; + $msg_prefix="({$operation}) - "; + + $this->_setArgs($args); + + $checkFunctions = array('authenticate', + 'checkTestProjectID'); + + if($this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight( "mgt_modify_product" )) { + + if(is_null( $this->itsMgr )) { + $this->itsMgr = new tlIssueTracker( $this->dbObj ); + } + + $itsID = intval($this->args[self::$itsIDParamName]); + $projectID = intval($this->args[self::$testProjectIDParamName]); + + $this->itsMgr->unlink($itsID, $projectID); + $resultInfo = array(); + $resultInfo[]= array("operation" => "unlink ITS", + "status" => true, + "id" => $projectID, + "message" => GENERAL_SUCCESS_STR); + + return $resultInfo; + + } else { + return $this->errors; + } + } + + /** */ function initMethodYellowPages() { @@ -8524,6 +8568,7 @@ function initMethodYellowPages() { 'tl.createIssueTrackerSystem' => 'this:createIssueTrackerSystem', 'tl.updateIssueTrackerSystem' => 'this:updateIssueTrackerSystem', 'tl.setTestProjectITS' => 'this:setTestProjectITS', + 'tl.removeTestProjectITS' => 'this:removeTestProjectITS', 'tl.getProjects' => 'this:getProjects', 'tl.getProjectKeywords' => 'this:getProjectKeywords', 'tl.getProjectPlatforms' => 'this:getProjectPlatforms', From a28e9b579cce72ac9af29d2548b3ef9262d5f665 Mon Sep 17 00:00:00 2001 From: atisne Date: Mon, 12 Aug 2019 14:54:46 +0200 Subject: [PATCH 6/8] Add files to test services around the ITS feature --- .../php/clientCreateIssueTrackerSystem.php | 43 ++++++++++++++++++ .../php/clientRemoveTestProjectITS.php | 27 ++++++++++++ .../php/clientSetTestProjectITS.php | 28 ++++++++++++ .../php/clientUpdateIssueTrackerSystem.php | 44 +++++++++++++++++++ lib/api/xmlrpc/v1/sample_clients/php/util.php | 2 +- 5 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 lib/api/xmlrpc/v1/sample_clients/php/clientCreateIssueTrackerSystem.php create mode 100644 lib/api/xmlrpc/v1/sample_clients/php/clientRemoveTestProjectITS.php create mode 100644 lib/api/xmlrpc/v1/sample_clients/php/clientSetTestProjectITS.php create mode 100644 lib/api/xmlrpc/v1/sample_clients/php/clientUpdateIssueTrackerSystem.php diff --git a/lib/api/xmlrpc/v1/sample_clients/php/clientCreateIssueTrackerSystem.php b/lib/api/xmlrpc/v1/sample_clients/php/clientCreateIssueTrackerSystem.php new file mode 100644 index 0000000000..d51533d0e0 --- /dev/null +++ b/lib/api/xmlrpc/v1/sample_clients/php/clientCreateIssueTrackerSystem.php @@ -0,0 +1,43 @@ + +USERNAME +PASSWORD +http://bugzilla.mozilla.org/ + +BUGZILLA PRODUCT +BUGZILLA PRODUCT + + +"; + +$debug=true; +$client = new IXR_Client($server_url); +$client->debug=$debug; +$answer = runTest($client,$method,$args); \ No newline at end of file diff --git a/lib/api/xmlrpc/v1/sample_clients/php/clientRemoveTestProjectITS.php b/lib/api/xmlrpc/v1/sample_clients/php/clientRemoveTestProjectITS.php new file mode 100644 index 0000000000..f6f7b48aa8 --- /dev/null +++ b/lib/api/xmlrpc/v1/sample_clients/php/clientRemoveTestProjectITS.php @@ -0,0 +1,27 @@ +debug=$debug; +$answer = runTest($client,$method,$args); \ No newline at end of file diff --git a/lib/api/xmlrpc/v1/sample_clients/php/clientSetTestProjectITS.php b/lib/api/xmlrpc/v1/sample_clients/php/clientSetTestProjectITS.php new file mode 100644 index 0000000000..9cb2b49574 --- /dev/null +++ b/lib/api/xmlrpc/v1/sample_clients/php/clientSetTestProjectITS.php @@ -0,0 +1,28 @@ +debug=$debug; +$answer = runTest($client,$method,$args); \ No newline at end of file diff --git a/lib/api/xmlrpc/v1/sample_clients/php/clientUpdateIssueTrackerSystem.php b/lib/api/xmlrpc/v1/sample_clients/php/clientUpdateIssueTrackerSystem.php new file mode 100644 index 0000000000..31635dda27 --- /dev/null +++ b/lib/api/xmlrpc/v1/sample_clients/php/clientUpdateIssueTrackerSystem.php @@ -0,0 +1,44 @@ + +USERNAME +PASSWORD +http://my.bugzilla.org/ + +BUGZILLA PRODUCT +BUGZILLA PRODUCT + + +"; + +$debug=true; +$client = new IXR_Client($server_url); +$client->debug=$debug; +$answer = runTest($client,$method,$args); \ No newline at end of file diff --git a/lib/api/xmlrpc/v1/sample_clients/php/util.php b/lib/api/xmlrpc/v1/sample_clients/php/util.php index c726286edf..be16440998 100644 --- a/lib/api/xmlrpc/v1/sample_clients/php/util.php +++ b/lib/api/xmlrpc/v1/sample_clients/php/util.php @@ -24,7 +24,7 @@ function show_api_db_sample_msg() function runTest(&$client,$method,$args,$feedback_id=1) { - echo __FUNCTION__ . '
'; + echo __FUNCTION__ . ' -> ' . $method . '
'; new dBug($args); $html_id="result_{$feedback_id}"; From e7affbe7b17ddb80052a42e8e71d0d6037975c5b Mon Sep 17 00:00:00 2001 From: atisne Date: Wed, 22 Jul 2020 18:33:34 +0200 Subject: [PATCH 7/8] Improve checks and error management --- lib/api/xmlrpc/v1/xmlrpc.class.php | 56 ++++++++++++------------------ 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index bdd1f661bf..286f4fe013 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -680,7 +680,7 @@ protected function checkItsID($messagePrefix = '') { $status = false; } else { // See if this ITS ID exists in the db - $its = $this->getIssueTrackerSystem( $this->args, 'internal' ); + $its = $this->getITSMgr()->getByID( $this->args[self::$itsIDParamName] ); $status = is_null($its); } @@ -1228,6 +1228,18 @@ protected function _getLatestBuildForTestPlan($args) { return $maxbuild; } + /** + * ITS manager getter + * + */ + private function getITSMgr() { + if(is_null( $this->itsMgr )) { + $this->itsMgr = new tlIssueTracker( $this->dbObj ); + } + + return $this->itsMgr; + } + /** * Gets the result of LAST EXECUTION for a particular testcase on a test plan. * If there are no filter criteria regarding platform and build, @@ -1898,7 +1910,6 @@ public function createTestProject($args) { $its = null; if($optional[self::$itsNameParamName] != "") { - $this->itsMgr = new tlIssueTracker( $this->dbObj ); $its = $this->getIssueTrackerSystem( $this->args, 'internal' ); $itsOK = ! is_null( $its ); @@ -1915,7 +1926,7 @@ public function createTestProject($args) { // link & enable its? if($itsOK && $tproject_id > 0) { // link - $this->itsMgr->link( $its["id"], $tproject_id ); + $this->getITSMgr()->link( $its["id"], $tproject_id ); // enable if($optional[self::$itsEnabledParamName] > 0) { @@ -7822,12 +7833,7 @@ public function getIssueTrackerSystem($args, $call = null) { $this->authenticate(); } - $ret = null; - if(is_null( $this->itsMgr )) { - $this->itsMgr = new tlIssueTracker( $this->dbObj ); - } - - $ret = $this->itsMgr->getByName( $this->args[self::$itsNameParamName] ); + $ret = $this->getITSMgr()->getByName( $this->args[self::$itsNameParamName] ); $status_ok = ! is_null( $ret ); if(! $status_ok) { $msg = $msg_prefix . sprintf( ITS_NOT_FOUND_STR, $this->args[self::$itsNameParamName] ); @@ -8370,13 +8376,13 @@ public function createIssueTrackerSystem($args) { $this->_setArgs($args); - $params = array(self::$$itsNameParamName, + $params = array(self::$itsNameParamName, self::$itsTypeParamName, self::$itsCfgParamName); $missingArg = false; foreach($params as $param) { - $missingArg = $missingArg || _isParamPresent($param); + $missingArg = $missingArg || ! $this->_isParamPresent($param, $msg_prefix, true); } if ($missingArg) { return $this->errors; @@ -8390,11 +8396,7 @@ public function createIssueTrackerSystem($args) { $item->type = $this->args[self::$itsTypeParamName]; $item->cfg = $this->args[self::$itsCfgParamName]; - if(is_null( $this->itsMgr )) { - $this->itsMgr = new tlIssueTracker( $this->dbObj ); - } - - return $this->itsMgr->create($item); + return $this->getITSMgr()->create($item); } else { return $this->errors; } @@ -8421,13 +8423,13 @@ public function updateIssueTrackerSystem($args) { $this->_setArgs($args); - $params = array(self::$$itsNameParamName, + $params = array(self::$itsNameParamName, self::$itsTypeParamName, self::$itsCfgParamName); $missingArg = false; foreach($params as $param) { - $missingArg = $missingArg || _isParamPresent($param); + $missingArg = $missingArg || ! $this->_isParamPresent($param, $msg_prefix, true); } if ($missingArg) { return $this->errors; @@ -8445,11 +8447,7 @@ public function updateIssueTrackerSystem($args) { $item->type = $this->args[self::$itsTypeParamName]; $item->cfg = $this->args[self::$itsCfgParamName]; - if(is_null( $this->itsMgr )) { - $this->itsMgr = new tlIssueTracker( $this->dbObj ); - } - - return $this->itsMgr->update($item); + return $this->getITSMgr()->update($item); } else { return $this->errors; @@ -8485,11 +8483,7 @@ public function setTestProjectITS($args) { $itsID = intval($this->args[self::$itsIDParamName]); $projectID = intval($this->args[self::$testProjectIDParamName]); - if(is_null( $this->itsMgr )) { - $this->itsMgr = new tlIssueTracker( $this->dbObj ); - } - - $this->itsMgr->link($itsID, $projectID); + $this->getITSMgr()->link($itsID, $projectID); $resultInfo = array(); $resultInfo[]= array("operation" => "link ITS", "additionalInfo" => "ITS ID " . $itsID, @@ -8541,14 +8535,10 @@ public function removeTestProjectITS($args) { if($this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight( "mgt_modify_product" )) { - if(is_null( $this->itsMgr )) { - $this->itsMgr = new tlIssueTracker( $this->dbObj ); - } - $itsID = intval($this->args[self::$itsIDParamName]); $projectID = intval($this->args[self::$testProjectIDParamName]); - $this->itsMgr->unlink($itsID, $projectID); + $this->getITSMgr()->unlink($itsID, $projectID); $resultInfo = array(); $resultInfo[]= array("operation" => "unlink ITS", "status" => true, From f5ae7816b25960217ed1b8a993a757835313c992 Mon Sep 17 00:00:00 2001 From: atisne Date: Tue, 21 Nov 2023 12:09:26 +0100 Subject: [PATCH 8/8] Fix issues when checking the ITS ID parameter before updating an ITS --- lib/api/xmlrpc/v1/xmlrpc.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index 27d0e65e4b..47fd756263 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -868,7 +868,7 @@ protected function checkItsID($messagePrefix = '') { } else { // See if this ITS ID exists in the db $its = $this->getITSMgr()->getByID( $this->args[self::$itsIDParamName] ); - $status = is_null($its); + $status = ! is_null($its); } return $status; @@ -9079,7 +9079,7 @@ public function updateIssueTrackerSystem($args) { } $checkFunctions = array('authenticate', - 'checkITSID'); + 'checkItsID'); if ($this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight("issuetracker_management", self::CHECK_PUBLIC_PRIVATE_ATTR)) { @@ -9119,7 +9119,7 @@ public function setTestProjectITS($args) { $checkFunctions = array('authenticate', 'checkTestProjectID', - 'checkITSID'); + 'checkItsID'); if($this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight( "mgt_modify_product" )) {