**/ require_once 'config.inc.php'; require_once 'common.php'; require_once 'users.inc.php'; require_once 'email_api.php'; $templateCfg = templateConfiguration(); $args = init_args(); $gui = new stdClass(); $gui->external_password_mgmt = 0; $gui->page_title = lang_get('page_title_lost_passwd'); $gui->note = lang_get('your_info_for_passwd'); $gui->password_mgmt_feedback = ''; $op = doDBConnect($db, database::ONERROREXIT); $userID = false; if ($args->login != "") { $userID = tlUser::doesUserExist($db, $args->login); if (!$userID) { $gui->note = lang_get('bad_user'); } else { // need to know if auth method for user allows reset $user = new tlUser(intval($userID)); $user->readFromDB($db); if (tlUser::isPasswordMgtExternal($user->authentication, $user->authentication)) { $gui->external_password_mgmt = 1; $gui->password_mgmt_feedback = sprintf(lang_get('password_mgmt_feedback'), trim($args->login)); } } } if (!$gui->external_password_mgmt && $userID) { echo __LINE__; $result = resetPassword($db, $userID);
require_once 'email_api.php'; require_once 'Zend/Validate/Hostname.php'; testlinkInitPage($db, false, false, "checkRights"); $templateCfg = templateConfiguration(); $args = init_args(); $gui = initializeGui(); $user = null; $highlight = initialize_tabsmenu(); $actionOperation = array('create' => 'doCreate', 'edit' => 'doUpdate', 'doCreate' => 'doCreate', 'doUpdate' => 'doUpdate', 'resetPassword' => 'doUpdate'); switch ($args->doAction) { case "edit": $highlight->edit_user = 1; // Because we can arrive with login, we need to check if we can get // id from login if (strlen(trim($args->login)) > 0) { $args->user_id = tlUser::doesUserExist($db, $args->login); } if (is_null($args->user_id) || intval($args->user_id) <= 0) { // need to manage some sort of error message $gui->op->status = tl::ERROR; $gui->op->user_feedback = sprintf(lang_get('login_does_not_exist'), $args->login); } else { $user = new tlUser(intval($args->user_id)); $user->readFromDB($db); } break; case "doCreate": $highlight->create_user = 1; $gui->op = doCreate($db, $args); $user = $gui->op->user; $templateCfg->template = $gui->op->template;
/** * @param struct $args * @param string $args["devKey"] * @param string $args["action"]: assignOne, unassignOne, unassignAll * * @param int $args["testplanid"] * @param string $args["testcaseexternalid"] format PREFIX-NUMBER * @param int $args["buildid"] Mandatory => you can provide buildname as alternative * @param int $args["buildname"] Mandatory => you can provide buildid (DB ID) as alternative * @param int $args["platformid"] optional - BECOMES MANDATORY if Test plan has platforms * you can provide platformname as alternative * * @param int $args["platformname"] optional - BECOMES MANDATORY if Test plan has platforms * you can provide platformid as alternative * @param string $args["user'] - login name => tester * */ private function manageTestCaseExecutionTask($args, $msg_prefix) { $status_ok = true; $this->_setArgs($args); $resultInfo = array(); // Checks are done in order $checkFunctions = array('authenticate', 'checkTestPlanID', 'checkTestCaseIdentity', 'checkBuildID'); $status_ok = $this->_runChecks($checkFunctions, $msg_prefix); if ($status_ok) { switch ($args['action']) { case 'assignOne': case 'unassignOne': if ($status_ok = $this->_isParamPresent(self::$userParamName, $msg_prefix, self::SET_ERROR)) { $tester_id = tlUser::doesUserExist($this->dbObj, $this->args[self::$userParamName]); if (!($status_ok = !is_null($tester_id))) { $msg = $msg_prefix . sprintf(NO_USER_BY_THIS_LOGIN_STR, $this->args[self::$userParamName]); $this->errors[] = new IXR_Error(NO_USER_BY_THIS_LOGIN, $msg); } } break; case 'unassignAll': break; } } // Check if requested test case is linked to test plan // if answer is yes, get link info, in order to be able to check if // we need also platform info if ($status_ok) { $execContext = array('tplan_id' => $this->args[self::$testPlanIDParamName], 'platform_id' => null, 'build_id' => $this->args[self::$buildIDParamName]); $tplan_id = $this->args[self::$testPlanIDParamName]; $tcase_id = $this->args[self::$testCaseIDParamName]; $filters = array('exec_status' => "ALL", 'active_status' => "ALL", 'tplan_id' => $tplan_id, 'platform_id' => null); $info = $this->tcaseMgr->get_linked_versions($tcase_id, $filters, array('output' => "feature_id")); // more than 1 item => we have platforms // access key => tcversion_id, tplan_id, platform_id $link = current($info); $link = $link[$tplan_id]; // Inside test plan, is indexed by platform $hits = count($link); $platform_id = 0; $check_platform = count($hits) > 1 || !isset($link[0]); } if ($status_ok && $check_platform) { // this means that platform is MANDATORY if (!$this->_isParamPresent(self::$platformIDParamName, $msg_prefix) && !$this->_isParamPresent(self::$platformNameParamName, $msg_prefix)) { $status_ok = false; $pname = self::$platformNameParamName . ' OR ' . self::$platformIDParamName; $msg = $messagePrefix . sprintf(MISSING_REQUIRED_PARAMETER_STR, $pname); $this->errors[] = new IXR_Error(MISSING_REQUIRED_PARAMETER, $msg); } else { // get platform_id and check it if ($status_ok = $this->checkPlatformIdentity($tplan_id)) { $platform_set = $this->tplanMgr->getPlatforms($tplan_id, array('outputFormat' => 'mapAccessByID', 'outputDetails' => 'name')); // Now check if link has all 3 components // test plan, test case, platform $platform_id = $this->args[self::$platformIDParamName]; $platform_info = array($platform_id => $platform_set[$platform_id]); if ($status_ok = $this->_checkTCIDAndTPIDValid($platform_info, $msg_prefix)) { $execContext['platform_id'] = $platform_id; } } } } if ($status_ok) { $assignment_mgr = new assignment_mgr($this->dbObj); $types = $assignment_mgr->get_available_types(); // Remove old execution task assignment // `id` int(10) unsigned NOT NULL auto_increment, // `type` int(10) unsigned NOT NULL default '1', // `feature_id` int(10) unsigned NOT NULL default '0', // `user_id` int(10) unsigned default '0', // `build_id` int(10) unsigned default '0', // `deadline_ts` datetime NULL, // `assigner_id` int(10) unsigned default '0', // `creation_ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, // `status` int(10) unsigned default '1', // ATTENTION WITH PLATFORMS $link = is_null($execContext['platform_id']) ? $link[0] : $link[$execContext['platform_id']]; $feature = array($link['feature_id'] => array('build_id' => $execContext['build_id'])); switch ($args['action']) { case 'unassignOne': $signature[] = array('type' => $types['testcase_execution']['id'], 'user_id' => $tester_id, 'feature_id' => $link['feature_id'], 'build_id' => $execContext['build_id']); $assignment_mgr->deleteBySignature($signature); break; case 'assignOne': // Step 1 - remove if exists $signature[] = array('type' => $types['testcase_execution']['id'], 'user_id' => $tester_id, 'feature_id' => $link['feature_id'], 'build_id' => $execContext['build_id']); $assignment_mgr->deleteBySignature($signature); // Step 2 - Now assign $assign_status = $assignment_mgr->get_available_status(); $oo[$link['feature_id']]['type'] = $types['testcase_execution']['id']; $oo[$link['feature_id']]['status'] = $assign_status['open']['id']; $oo[$link['feature_id']]['user_id'] = $tester_id; $oo[$link['feature_id']]['assigner_id'] = $this->userID; $oo[$link['feature_id']]['build_id'] = $execContext['build_id']; $assignment_mgr->assign($oo); break; case 'unassignAll': $oo[$link['feature_id']]['type'] = $types['testcase_execution']['id']; $oo[$link['feature_id']]['build_id'] = $execContext['build_id']; $assignment_mgr->delete_by_feature_id_and_build_id($oo); break; } $resultInfo = array("status" => true, "args" => $this->args); unset($resultInfo['args']['devKey']); } return $status_ok ? $resultInfo : $this->errors; }
/** * @param struct $args * @param string $args["devKey"] * @param int $args["user"] user name * * @return true if everything OK, otherwise error structure * * @access public */ public function doesUserExist($args) { $operation = __FUNCTION__; $msg_prefix = "({$operation}) - "; $this->_setArgs($args); $user_id = tlUser::doesUserExist($this->dbObj, $this->args[self::$userParamName]); if (!($status_ok = !is_null($user_id))) { $msg = $msg_prefix . sprintf(NO_USER_BY_THIS_LOGIN_STR, $this->args[self::$userParamName]); $this->errors[] = new IXR_Error(NO_USER_BY_THIS_LOGIN, $msg); } return $status_ok ? $status_ok : $this->errors; }
/** * Assign a user to a project * * @param struct $args * @param string $args["devKey"] * @param string $args["user"] * @param string $args["role"] * @param int $args["testprojectid"] * @access public */ public function assignUserToProject($args) { $this->_setArgs($args); if (!$this->authenticate()) { return $this->errors; } $login = $this->args[self::$userParamName]; $role = $this->args['role']; $projectId = $this->args[self::$testProjectIDParamName]; $userId = tlUser::doesUserExist($this->dbObj, $login); $roleId = tlRole::doesRoleExist($this->dbObj, $role, 0); $testProject = $this->tprojectMgr->get_by_id($projectId); $hasError = false; if (is_null($userId)) { $this->errors[] = new IXR_ERROR(100005, 'User does not exists'); $hasError = true; } else { if (is_null($roleId)) { $this->errors[] = new IXR_ERROR(100006, 'Role does not exists'); $hasError = true; } else { if (is_null($testProject)) { $this->errors[] = new IXR_ERROR(100007, 'Project does not exists'); $hasError = true; } } } if ($hasError) { return $this->errors; } $userRoles = $this->tprojectMgr->getUserRoleIDs($projectId); $this->tprojectMgr->deleteUserRoles($projectId); foreach ($userRoles as $user_id => $role_id) { if ($user_id != $userId) { $this->tprojectMgr->addUserRole($user_id, $projectId, $role_id['role_id']); } } $this->tprojectMgr->addUserRole($userId, $projectId, $roleId); }
/** * createTestCase * */ public function createTestCase($args) { $operation = __FUNCTION__; $msg_prefix = "({$operation}) - "; $keywordSet = ''; $this->_setArgs($args); $checkFunctions = array('authenticate', 'checkTestProjectID', 'checkTestSuiteID', 'checkTestCaseName'); $status_ok = $this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight("mgt_modify_tc"); if ($status_ok) { $keys2check = array(self::$authorLoginParamName, self::$summaryParamName, self::$stepsParamName, self::$expectedResultsParamName); foreach ($keys2check as $key) { if (!$this->_isParamPresent($key)) { $msg = $msg_prefix . sprintf(MISSING_REQUIRED_PARAMETER_STR, $key); $this->errors[] = new IXR_Error(MISSING_REQUIRED_PARAMETER, $msg); } } } if ($status_ok) { $author_id = tlUser::doesUserExist($this->dbObj, $this->args[self::$authorLoginParamName]); $status_ok = !is_null($author_id); $this->errors[] = new IXR_Error(NO_USER_BY_THIS_LOGIN, $msg_prefix . NO_USER_BY_THIS_LOGIN_STR); } if ($status_ok) { if ($this->_isParamPresent(self::$keywordNameParamName)) { // Check that all keyword exists for target test project $keywordSet = $this->getValidKeywordSetByName($this->args[self::$keywordNameParamName], $this->args[self::$testProjectIDParamName]); } else { if ($this->_isParamPresent(self::$keywordIDParamName)) { $keywordSet = $this->getValidKeywordSetById($this->args[self::$keywordIDParamName], $this->args[self::$testProjectIDParamName]); } } } if ($status_ok) { // Optional parameters $opt = array(self::$importanceParamName => 2, self::$executionTypeParamName => TESTCASE_EXECUTION_TYPE_MANUAL, self::$orderParamName => testcase::DEFAULT_ORDER, self::$internalIDParamName => testcase::AUTOMATIC_ID, self::$checkDuplicatedNameParamName => testcase::DONT_CHECK_DUPLICATE_NAME, self::$actionOnDuplicatedNameParamName => 'generate_new'); foreach ($opt as $key => $value) { if ($this->_isParamPresent($key)) { $opt[$key] = $this->args[$key]; } } } if ($status_ok) { $op_result = $this->tcaseMgr->create($this->args[self::$testSuiteIDParamName], $this->args[self::$testCaseNameParamName], $this->args[self::$summaryParamName], $this->args[self::$stepsParamName], $this->args[self::$expectedResultsParamName], $author_id, $keywordSet, $opt[self::$orderParamName], $opt[self::$internalIDParamName], $opt[self::$checkDuplicatedNameParamName], $opt[self::$actionOnDuplicatedNameParamName], $opt[self::$executionTypeParamName], $opt[self::$importanceParamName]); $resultInfo = array(); $resultInfo[] = array("operation" => $operation, "status" => true, "id" => $op_result['external_id'], "additionalInfo" => $op_result, "message" => GENERAL_SUCCESS_STR); } return $status_ok ? $resultInfo : $this->errors; }