/** * authorization function verifies login & password and set user session data * return map * */ function doAuthorize(&$db, $login, $pwd) { $result = array('status' => tl::ERROR, 'msg' => null); $_SESSION['locale'] = TL_DEFAULT_LOCALE; if (!is_null($pwd) && !is_null($login)) { $user = new tlUser(); $user->login = $login; $login_exists = $user->readFromDB($db, tlUser::USER_O_SEARCH_BYLOGIN) >= tl::OK; if ($login_exists) { $password_check = auth_does_password_match($user, $pwd); if ($password_check->status_ok && $user->isActive) { // 20051007 MHT Solved 0000024 Session confusion // Disallow two sessions within one browser if (isset($_SESSION['currentUser']) && !is_null($_SESSION['currentUser'])) { $result['msg'] = lang_get('login_msg_session_exists1') . ' <a style="color:white;" href="logout.php">' . lang_get('logout_link') . '</a>' . lang_get('login_msg_session_exists2'); } else { //Setting user's session information $_SESSION['currentUser'] = $user; $_SESSION['lastActivity'] = time(); global $g_tlLogger; $g_tlLogger->endTransaction(); $g_tlLogger->startTransaction(); setUserSession($db, $user->login, $user->dbID, $user->globalRoleID, $user->emailAddress, $user->locale, null); $result['status'] = tl::OK; } } else { logAuditEvent(TLS("audit_login_failed", $login, $_SERVER['REMOTE_ADDR']), "LOGIN_FAILED", $user->dbID, "users"); } } } return $result; }
function initializeGui() { $gui = new stdClass(); $gui->external_password_mgmt = tlUser::isPasswordMgtExternal(); $gui->page_title = lang_get('page_title_lost_passwd'); $gui->note = lang_get('your_info_for_passwd'); return $gui; }
/** * authorization function verifies login & password and set user session data * return map * */ function doAuthorize(&$db, $login, $pwd) { $result = array('status' => tl::ERROR, 'msg' => null); $_SESSION['locale'] = TL_DEFAULT_LOCALE; if (!is_null($pwd) && !is_null($login)) { $user = new tlUser(); $user->login = $login; $login_exists = $user->readFromDB($db, tlUser::USER_O_SEARCH_BYLOGIN) >= tl::OK; if ($login_exists) { $check = auth_does_password_match($user, $pwd); if (!$check->status_ok) { $result = array('status' => tl::ERROR, 'msg' => $check->msg); } if ($check->status_ok && $user->isActive) { // Need to do set COOKIE following Mantis model $auth_cookie_name = config_get('auth_cookie'); $expireOnBrowserClose = false; setcookie($auth_cookie_name, $user->getSecurityCookie(), $expireOnBrowserClose, '/'); // Disallow two sessions within one browser if (isset($_SESSION['currentUser']) && !is_null($_SESSION['currentUser'])) { $result['msg'] = lang_get('login_msg_session_exists1') . ' <a style="color:white;" href="logout.php">' . lang_get('logout_link') . '</a>' . lang_get('login_msg_session_exists2'); } else { // Setting user's session information $_SESSION['currentUser'] = $user; $_SESSION['lastActivity'] = time(); $user->setUserSession($db); global $g_tlLogger; $g_tlLogger->endTransaction(); $g_tlLogger->startTransaction(); // setUserSession($db,$user->login, $user->dbID,$user->globalRoleID,$user->emailAddress, $user->locale,null); $result['status'] = tl::OK; } } else { logAuditEvent(TLS("audit_login_failed", $login, $_SERVER['REMOTE_ADDR']), "LOGIN_FAILED", $user->dbID, "users"); } } } return $result; }
function doUpdate($argsObj, &$tprojectMgr, $sessionTprojectID) { $key2get = array('status_ok', 'msg'); $op = new stdClass(); $op->ui = new stdClass(); $op->status_ok = 0; $op->msg = ''; $op->template = null; $op->reloadType = 'none'; $oldObjData = $tprojectMgr->get_by_id($argsObj->tprojectID); $op->oldName = $oldObjData['name']; $check_op = crossChecks($argsObj, $tprojectMgr); foreach ($key2get as $key) { $op->{$key} = $check_op[$key]; } if ($op->status_ok) { $options = prepareOptions($argsObj); if ($tprojectMgr->update($argsObj->tprojectID, trim($argsObj->tprojectName), $argsObj->color, $argsObj->notes, $options, $argsObj->active, $argsObj->tcasePrefix, $argsObj->is_public)) { $op->msg = ''; $tprojectMgr->activate($argsObj->tprojectID, $argsObj->active); $tprojectMgr->setIssueTrackerEnabled($argsObj->tprojectID, $argsObj->issue_tracker_enabled); $itMgr = new tlIssueTracker($tprojectMgr->db); if ($doLink = $argsObj->issue_tracker_id > 0) { $itMgr->link($argsObj->issue_tracker_id, $argsObj->tprojectID); } else { $issueT = $itMgr->getLinkedTo($argsObj->tprojectID); if (!is_null($issueT)) { $itMgr->unlink($issueT['issuetracker_id'], $issueT['testproject_id']); } } $tprojectMgr->setReqMgrIntegrationEnabled($argsObj->tprojectID, $argsObj->reqmgr_integration_enabled); $mgr = new tlReqMgrSystem($tprojectMgr->db); if ($doLink = $argsObj->reqmgrsystem_id > 0) { $mgr->link($argsObj->reqmgrsystem_id, $argsObj->tprojectID); } else { $et = $mgr->getLinkedTo($argsObj->tprojectID); if (!is_null($et)) { $mgr->unlink($et['reqmgrsystem_id'], $et['testproject_id']); } } if (!$argsObj->is_public) { // does user have an SPECIFIC role on Test Project ? // if answer is yes => do nothing if (!tlUser::hasRoleOnTestProject($tprojectMgr->db, $argsObj->userID, $argsObj->tprojectID)) { $tprojectMgr->addUserRole($argsObj->userID, $argsObj->tprojectID, $argsObj->user->globalRole->dbID); } } $event = new stdClass(); $event->message = TLS("audit_testproject_saved", $argsObj->tprojectName); $event->logLevel = "AUDIT"; $event->source = "GUI"; $event->objectID = $argsObj->tprojectID; $event->objectType = "testprojects"; $event->code = "UPDATE"; logEvent($event); } else { $op->status_ok = 0; } } if ($op->status_ok) { if ($sessionTprojectID == $argsObj->tprojectID) { $op->reloadType = 'reloadNavBar'; } } else { $op->ui->doActionValue = 'doUpdate'; $op->ui->buttonValue = lang_get('btn_save'); $op->ui->caption = sprintf(lang_get('caption_edit_tproject'), $op->oldName); } return $op; }
/** * TestLink Open Source Project - http://testlink.sourceforge.net/ * This script is distributed under the GNU General Public License 2 or later. * * Get list of users with a project right * * @package TestLink * @author Martin Havlat * @copyright 2009, TestLink community * @version CVS: $Id: getUsersWithRight.php,v 1.1 2010/02/12 00:20:12 havlat Exp $ * * @internal Revisions: * None * **/ require_once '../../config.inc.php'; require_once 'common.php'; testlinkInitPage($db); $data = array(); $iParams = array("right" => array(tlInputParameter::STRING_N, 0, 100, '/^[a-z0-9_]+$/')); $args = G_PARAMS($iParams); // user must have the same right as requested (security) if (has_rights($db, $args['right'])) { $tlUser = new tlUser($_SESSION['userID']); $data['rows'] = $tlUser->getNamesForProjectRight($db, $args['right'], $_SESSION['testprojectID']); $data['rows'][] = array('id' => '0', 'login' => ' ', 'first' => ' ', 'last' => ' '); // option for no owner } else { tLog('Invalid right for the user: '******'right'], 'ERROR'); } echo json_encode($data);
/** * checks if the default password for the admin accout is still set * * @return boolean returns true if the default password for the admin account is set, * false else * @author Andreas Morsing **/ function checkForAdminDefaultPwd(&$db) { $passwordHasDefaultValue = false; $user = new tlUser(); $user->login = "******"; if ($user->readFromDB($db, tlUser::USER_O_SEARCH_BYLOGIN) >= tl::OK && $user->comparePassword("admin") >= tl::OK) { $passwordHasDefaultValue = true; } return $passwordHasDefaultValue; }
/** * Get info about user(s) role at test project level, * with indication about the nature of role: inherited or assigned. * * To get a user role we consider a 3 layer model: * layer 1 - user <--- uplayer * layer 2 - test project <--- in this fuction we are interested in this level. * layer 3 - test plan * * args : $tproject_id * [$user_id] * * @return array map with effetive_role in context ($tproject_id) * key: user_id * value: map with keys: * login (from users table - useful for debug) * user_role_id (from users table - useful for debug) * uplayer_role_id (always = user_role_id) * uplayer_is_inherited * effective_role_id user role for test project * is_inherited */ function get_tproject_effective_role(&$db, $tproject, $user_id = null, $users = null) { $effective_role = array(); $tproject_id = $tproject['id']; if (!is_null($user_id)) { $users = tlUser::getByIDs($db, (array) $user_id); } else { if (is_null($users)) { $users = tlUser::getAll($db); } } if ($users) { foreach ($users as $id => $user) { // manage admin exception $isInherited = 1; $effectiveRoleID = $user->globalRoleID; $effectiveRole = $user->globalRole; if ($user->globalRoleID != TL_ROLES_ADMIN && !$tproject['is_public']) { $isInherited = $tproject['is_public']; $effectiveRoleID = TL_ROLES_NO_RIGHTS; $effectiveRole = '<no rights>'; } if (isset($user->tprojectRoles[$tproject_id])) { $isInherited = 0; $effectiveRoleID = $user->tprojectRoles[$tproject_id]->dbID; $effectiveRole = $user->tprojectRoles[$tproject_id]; } $effective_role[$id] = array('login' => $user->login, 'user' => $user, 'user_role_id' => $user->globalRoleID, 'uplayer_role_id' => $user->globalRoleID, 'uplayer_is_inherited' => 0, 'effective_role_id' => $effectiveRoleID, 'effective_role' => $effectiveRole, 'is_inherited' => $isInherited); } } return $effective_role; }
* * Get inventory data * * @package TestLink * @author Martin Havlat * @copyright 2009, TestLink community * @version CVS: $Id: getInventory.php,v 1.2 2010/02/20 09:27:29 franciscom Exp $ * * @internal Revisions: * None * **/ require_once '../../config.inc.php'; require_once 'common.php'; testlinkInitPage($db); $tlIs = new tlInventory($_SESSION['testprojectID'], $db); $data = $tlIs->getAll(); $tlUser = new tlUser($_SESSION['userID']); $users = $tlUser->getNames($db); // fill login instead of user ID if (!is_null($data)) { foreach ($data as $k => $v) { if ($v['owner_id'] != '0') { $data[$k]['owner'] = $users[$v['owner_id']]['login']; } else { $data[$k]['owner'] = ''; } } } //new dBug($data); echo json_encode($data);
* @author - * @copyright 2007-2011, TestLink community * @version CVS: $Id: userInfo.php,v 1.34 2011/01/10 15:38:55 asimon83 Exp $ * @link http://www.teamst.org/index.php * * * @internal Revisions: * 20101008 - Julian - reload navBar after changing personal data (localization) */ require_once '../../config.inc.php'; require_once 'users.inc.php'; require_once '../../lib/api/APIKey.php'; testlinkInitPage($db); $templateCfg = templateConfiguration(); $args = init_args(); $user = new tlUser($args->userID); $user->readFromDB($db); $gui = new stdClass(); $gui->tproject_id = $args->tproject_id; $gui->update_title_bar = 0; $gui->external_password_mgmt = tlUser::isPasswordMgtExternal(); $gui->mgt_view_events = $user->hasRight($db, "mgt_view_events", $gui->tproject_id); $op = new stdClass(); $op->auditMsg = null; $op->user_feedback = null; $op->status = tl::OK; $doUpdate = false; switch ($args->doAction) { case 'editUser': $doUpdate = true; foreach ($args->user as $key => $value) {
function saveImportedResultData(&$db, $resultData, $context) { if (!$resultData) { return; } $debugMsg = ' FUNCTION: ' . __FUNCTION__; $tables = tlObjectWithDB::getDBTables(array('executions', 'execution_bugs')); $l18n = array('import_results_tc_not_found' => '', 'import_results_invalid_result' => '', 'tproject_id_not_found' => '', 'import_results_ok' => ''); foreach ($l18n as $key => $value) { $l18n[$key] = lang_get($key); } // Get Column definitions to get size dinamically instead of create constants $columnDef = array(); $adodbObj = $db->get_dbmgr_object(); $columnDef['execution_bugs'] = $adodbObj->MetaColumns($tables['execution_bugs']); $keySet = array_keys($columnDef['execution_bugs']); foreach ($keySet as $keyName) { if (($keylow = strtolower($keyName)) != $keyName) { $columnDef['execution_bugs'][$keylow] = $columnDef['execution_bugs'][$keyName]; unset($columnDef['execution_bugs'][$keyName]); } } $user = new tlUser($context->userID); $user->readFromDB($db); $tcase_mgr = new testcase($db); $resulstCfg = config_get('results'); $tcaseCfg = config_get('testcase_cfg'); $resultMap = array(); $tplan_mgr = null; $tc_qty = sizeof($resultData); if ($tc_qty) { $tplan_mgr = new testplan($db); $tproject_mgr = new testproject($db); $build_mgr = new build_mgr($db); } // Need to do checks on common settings // // test project exists // // test plan id: // belongs to target test project // is active // build id: // belongs to target test plan // is open // // platform id: // is linked to target test plan // // execution type if not present -> set to MANUAL // if presente is valid i.e. inside the TL domain // $checks = array(); $checks['status_ok'] = true; $checks['msg'] = null; $dummy = null; if (!is_null($context->tprojectID) && intval($context->tprojectID) > 0) { $dummy = array($tproject_mgr->get_by_id($context->tprojectID, array('output' => 'existsByID'))); } else { if (!is_null($context->tprojectName)) { $dummy = $tproject_mgr->get_by_name($context->tprojectName, null, array('output' => 'existsByName')); } } $checks['status_ok'] = !is_null($dummy); if (!$checks['status_ok']) { $checks['msg'][] = sprintf($l18n['tproject_id_not_found'], $context->tprojectID); } if (!$checks['status_ok']) { foreach ($checks['msg'] as $warning) { $resultMap[] = array($warning); } } if ($doIt = $checks['status_ok']) { $context->tprojectID = $dummy[0]['id']; } // -------------------------------------------------------------------- $dummy = null; if (!is_null($context->tplanID) && intval($context->tplanID) > 0) { $dummy = $tplan_mgr->get_by_id($context->tplanID, array('output' => 'minimun')); if (!is_null($dummy)) { $dummy['id'] = $context->tplanID; } } else { if (!is_null($context->tplanName)) { $dummy = $tplan_mgr->get_by_name($context->tplanName, $context->tprojectID, array('output' => 'minimun')); if (!is_null($dummy)) { $dummy = $dummy[0]; } } } if (!is_null($dummy)) { $context->tplanID = $dummy['id']; } if (intval($context->tprojectID) <= 0 && intval($context->tplanID) > 0) { $dummy = $tplan_mgr->tree_manager->get_node_hierarchy_info($context->tplanID); $context->tprojectID = $dummy['parent_id']; } // -------------------------------------------------------------------- // -------------------------------------------------------------------- $dummy = null; $tplan_mgr->platform_mgr->setTestProjectID($context->tprojectID); if (!is_null($context->platformID) && intval($context->platformID) > 0) { $dummy = array($tplan_mgr->platform_mgr->getByID($context->platformID)); } else { if (property_exists($context, 'platformName') && !is_null($context->platformName)) { if (!is_null($xx = $tplan_mgr->platform_mgr->getID($context->platformName))) { $dummy = array(0 => array('id' => $xx)); } } } if (!is_null($dummy)) { $context->platformID = $dummy[0]['id']; } // -------------------------------------------------------------------- // -------------------------------------------------------------------- $optGB = array('tplan_id' => $context->tplanID, 'output' => 'minimun'); $dummy = null; if (!is_null($context->buildID) && intval($context->buildID) > 0) { $dummy = array($build_mgr->get_by_id($context->buildID, $optGB)); } else { if (!is_null($context->buildName)) { $dummy = $build_mgr->get_by_name($context->buildName, $optGB); } } if (!is_null($dummy)) { $context->buildID = $dummy[0]['id']; } // -------------------------------------------------------------------- // -------------------------------------------------------------------- for ($idx = 0; $doIt && $idx < $tc_qty; $idx++) { $tester_id = 0; $tester_name = ''; $using_external_id = false; $message = null; $status_ok = true; $tcase_exec = $resultData[$idx]; // New attribute "execution type" makes old XML import files incompatible // Important NOTICE: // tcase_exec is passed BY REFERENCE to allow check_exec_values()change execution type if needed // $checks = check_exec_values($db, $tcase_mgr, $user_mgr, $tcaseCfg, $tcase_exec, $columnDef['execution_bugs']); $status_ok = $checks['status_ok']; if ($status_ok) { $tcase_id = $checks['tcase_id']; $tcase_external_id = trim($tcase_exec['tcase_external_id']); $tester_id = $checks['tester_id']; // external_id has precedence over internal id $using_external_id = $tcase_external_id != ""; } else { foreach ($checks['msg'] as $warning) { $resultMap[] = array($warning); } } if ($status_ok) { $tcase_identity = $using_external_id ? $tcase_external_id : $tcase_id; $result_code = strtolower($tcase_exec['result']); $result_is_acceptable = isset($resulstCfg['code_status'][$result_code]) ? true : false; $notes = $tcase_exec['notes']; $message = null; $info_on_case = $tplan_mgr->getLinkInfo($context->tplanID, $tcase_id, $context->platformID); if (is_null($info_on_case)) { $message = sprintf($l18n['import_results_tc_not_found'], $tcase_identity); } else { if (!$result_is_acceptable) { $message = sprintf($l18n['import_results_invalid_result'], $tcase_identity, $tcase_exec['result']); } else { $info_on_case = current($info_on_case); $tcversion_id = $info_on_case['tcversion_id']; $version = $info_on_case['version']; $notes = $db->prepare_string(trim($notes)); // N.B.: db_now() returns an string ready to be used in an SQL insert // example '2008-09-04', while $tcase_exec["timestamp"] => 2008-09-04 // $execution_ts = $tcase_exec['timestamp'] != '' ? "'" . $tcase_exec["timestamp"] . "'" : $db->db_now(); if ($tester_id != 0) { $tester_name = $tcase_exec['tester']; } else { $tester_name = $user->login; $tester_id = $context->userID; } $addExecDuration = strlen($tcase_exec['execution_duration']) > 0 && is_numeric($tcase_exec['execution_duration']); $sql = " /* {$debugMsg} */ " . " INSERT INTO {$tables['executions']} (build_id,tester_id,status,testplan_id," . " tcversion_id,execution_ts,notes,tcversion_number,platform_id,execution_type" . ($addExecDuration ? ',execution_duration' : '') . ")" . " VALUES ({$context->buildID}, {$tester_id},'{$result_code}',{$context->tplanID}, " . " {$tcversion_id},{$execution_ts},'{$notes}', {$version}, " . " {$context->platformID}, {$tcase_exec['execution_type']}" . ($addExecDuration ? ",{$tcase_exec['execution_duration']}" : '') . ")"; $db->exec_query($sql); if (isset($tcase_exec['bug_id']) && !is_null($tcase_exec['bug_id']) && is_array($tcase_exec['bug_id'])) { $execution_id = $db->insert_id($tables['executions']); foreach ($tcase_exec['bug_id'] as $bug_id) { $bug_id = trim($bug_id); $sql = " /* {$debugMsg} */ " . " SELECT execution_id AS check_qty FROM {$tables['execution_bugs']} " . " WHERE bug_id = '{$bug_id}' AND execution_id={$execution_id} "; $rs = $db->get_recordset($sql); if (is_null($rs)) { $sql = " /* {$debugMsg} */ " . " INSERT INTO {$tables['execution_bugs']} (bug_id,execution_id)" . " VALUES ('" . $db->prepare_string($bug_id) . "', {$execution_id} )"; $db->exec_query($sql); } } } $message = sprintf($l18n['import_results_ok'], $tcase_identity, $version, $tester_name, $resulstCfg['code_status'][$result_code], $execution_ts); } } } if (!is_null($message)) { $resultMap[] = array($message); } } return $resultMap; }
/** * * @internal revisions: * **/ function initEnv(&$dbHandler, &$argsObj, &$tprojectMgr, $userID) { $my = array(); $doc = new stdClass(); $my['options'] = array('recursive' => true, 'prepareNode' => null, 'order_cfg' => array("type" => 'spec_order')); $my['filters'] = array('exclude_node_types' => array('testplan' => 'exclude me', 'requirement_spec' => 'exclude me', 'requirement' => 'exclude me'), 'exclude_children_of' => array('testcase' => 'exclude my children', 'requirement_spec' => 'exclude my children')); $lblKey = array(DOC_TEST_SPEC => 'title_test_spec', DOC_TEST_PLAN_DESIGN => 'report_test_plan_design', DOC_TEST_PLAN_EXECUTION => 'report_test_plan_execution', DOC_TEST_PLAN_EXECUTION_ON_BUILD => 'report_test_plan_execution_on_build', DOC_REQ_SPEC => 'req_spec'); $doc->content_range = $argsObj->level; $doc->type = $argsObj->doc_type; $doc->type_name = lang_get($lblKey[$doc->type]); $doc->author = ''; $doc->title = ''; switch ($doc->type) { case DOC_TEST_PLAN_DESIGN: $my['options']['order_cfg'] = array("type" => 'exec_order', "tplan_id" => $argsObj->tplan_id); break; case DOC_TEST_PLAN_EXECUTION: case DOC_TEST_PLAN_EXECUTION_ON_BUILD: $my['options']['order_cfg'] = array("type" => 'exec_order', "tplan_id" => $argsObj->tplan_id); $my['options']['prepareNode'] = array('viewType' => 'executionTree'); break; case DOC_REQ_SPEC: $my['filters'] = array('exclude_node_types' => array('testplan' => 'exclude me', 'testsuite' => 'exclude me', 'testcase' => 'exclude me'), 'exclude_children_of' => array('testcase' => 'exclude my children', 'testsuite' => 'exclude my children', 'requirement' => 'exclude my children')); break; } $user = tlUser::getById($dbHandler, $userID); if ($user) { $doc->author = htmlspecialchars($user->getDisplayName()); } unset($user); $dummy = $tprojectMgr->get_by_id($argsObj->tproject_id); $doc->tproject_name = htmlspecialchars($dummy['name']); $doc->tproject_scope = $dummy['notes']; $doc->test_priority_enabled = $dummy['opt']->testPriorityEnabled; return array($doc, $my); }
/** * initialize common test case information, useful when working on steps * */ function initTestCaseBasicInfo(&$argsObj, &$guiObj, $opt = null) { $my['opt'] = array('accessByStepID' => true); $my['opt'] = array_merge($my['opt'], (array) $opt); $greenCard = array('tcase_id' => $argsObj->tcase_id, 'tcversion_id' => $argsObj->tcversion_id); if ($my['opt']['accessByStepID']) { foreach ($greenCard as $ky) { // this logic need to be explained BETTER if ($ky == 0) { $greenCard = $this->tcaseMgr->getIdCardByStepID($argsObj->step_id); break; } } } $tcaseInfo = $this->tcaseMgr->get_by_id($greenCard['tcase_id'], $greenCard['tcversion_id'], null, array('output' => 'full_without_steps', 'renderGhost' => true, 'renderImageInline' => true)); $external = $this->tcaseMgr->getExternalID($greenCard['tcase_id'], $argsObj->testproject_id); $tcaseInfo[0]['tc_external_id'] = $external[0]; $guiObj->testcase = $tcaseInfo[0]; if (!isset($guiObj->testcase['ghost'])) { $guiObj->testcase['ghost'] = null; } $guiObj->authorObj = tlUser::getByID($this->db, $guiObj->testcase['author_id'], 'id'); $guiObj->updaterObj = null; if (!is_null($guiObj->testcase['updater_id'])) { $guiObj->updaterObj = tlUser::getByID($this->db, $guiObj->testcase['updater_id'], 'id'); } }
/** * @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; }
/** * * */ function decode_users(&$rs) { $userCache = null; // key: user id, value: display name $key2loop = array_keys($rs); $labels['undefined'] = lang_get('undefined'); $user_keys = array('author' => 'author_id', 'modifier' => 'modifier_id'); foreach ($key2loop as $key) { foreach ($user_keys as $ukey => $userid_field) { $rs[$key][$ukey] = ''; if (trim($rs[$key][$userid_field]) != "") { if (!isset($userCache[$rs[$key][$userid_field]])) { $user = tlUser::getByID($this->db, $rs[$key][$userid_field]); $rs[$key][$ukey] = $user ? $user->getDisplayName() : $labels['undefined']; $userCache[$rs[$key][$userid_field]] = $rs[$key][$ukey]; } else { $rs[$key][$ukey] = $userCache[$rs[$key][$userid_field]]; } } } } }
/** * Inserts a testproject related role for a given user * * @param integer $userID the id of the user * @param integer $tproject_id * @param integer $roleID the role id * * @return integer tl::OK on success, tl::ERROR else **/ function addUserRole($userID, $tproject_id, $roleID) { $query = "INSERT INTO {$this->tables['user_testproject_roles']} " . "(user_id,testproject_id,role_id) VALUES ({$userID},{$tproject_id},{$roleID})"; if ($this->db->exec_query($query)) { $testProject = $this->get_by_id($tproject_id); $role = tlRole::getByID($this->db, $roleID, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM); $user = tlUser::getByID($this->db, $userID, tlUser::TLOBJ_O_GET_DETAIL_MINIMUM); if ($user && $testProject && $role) { logAuditEvent(TLS("audit_users_roles_added_testproject", $user->getDisplayName(), $testProject['name'], $role->name), "ASSIGN", $tproject_id, "testprojects"); } return tl::OK; } return tl::ERROR; }
/** * get relations for a given requirement ID * * @author Andreas Simon * * @param int $id Requirement ID * * @return array $relations in which this req is either source or destination */ public function get_relations($id) { $debugMsg = '/* Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__ . ' */'; $relations = array(); $relations['num_relations'] = 0; $relations['req'] = current($this->get_by_id($id)); $relations['relations'] = array(); $tproject_mgr = new testproject($this->db); $interproject_linking = config_get('req_cfg')->relations->interproject_linking; $sql = " {$debugMsg} SELECT id, source_id, destination_id, relation_type, author_id, creation_ts " . " FROM {$this->tables['req_relations']} " . " WHERE source_id={$id} OR destination_id={$id} " . " ORDER BY id ASC "; $relations['relations'] = $this->db->get_recordset($sql); if (!is_null($relations['relations']) && count($relations['relations']) > 0) { $labels = $this->get_all_relation_labels(); $label_keys = array_keys($labels); foreach ($relations['relations'] as $key => $rel) { // is this relation type is configured? if ($relTypeAllowed = in_array($rel['relation_type'], $label_keys)) { $relations['relations'][$key]['source_localized'] = $labels[$rel['relation_type']]['source']; $relations['relations'][$key]['destination_localized'] = $labels[$rel['relation_type']]['destination']; if ($id == $rel['source_id']) { $type_localized = 'source_localized'; $other_key = 'destination_id'; } else { $type_localized = 'destination_localized'; $other_key = 'source_id'; } $relations['relations'][$key]['type_localized'] = $relations['relations'][$key][$type_localized]; $other_req = $this->get_by_id($rel[$other_key]); // only add it, if either interproject linking is on or if it is in the same project $relTypeAllowed = false; if ($interproject_linking || $other_req[0]['testproject_id'] == $relations['req']['testproject_id']) { $relTypeAllowed = true; $relations['relations'][$key]['related_req'] = $other_req[0]; $other_tproject = $tproject_mgr->get_by_id($other_req[0]['testproject_id']); $relations['relations'][$key]['related_req']['testproject_name'] = $other_tproject['name']; $user = tlUser::getByID($this->db, $rel['author_id']); $relations['relations'][$key]['author'] = $user->getDisplayName(); } } if (!$relTypeAllowed) { unset($relations['relations'][$key]); } } // end foreach $relations['num_relations'] = count($relations['relations']); } return $relations; }
/** * Verify if user is log in. Redirect to login page if not. * * @param integer $db DB identifier * @param boolean $redirect if true (default) redirects user to login page, otherwise returns true/false as login status **/ function checkSessionValid(&$db, $redirect = true) { $isValidSession = false; if (isset($_SESSION['userID']) && $_SESSION['userID'] > 0) { /** @TODO martin: Talk with Andreas to understand: 1. advantages of this approach 2. do we need to recreate it every time ? why ? * a) store just data -not all object * b) do not read again and again the same data from DB * c) this function check JUST session validity **/ $now = time(); $lastActivity = $_SESSION['lastActivity']; if ($now - $lastActivity <= config_get("sessionInactivityTimeout") * 60) { $_SESSION['lastActivity'] = $now; $user = new tlUser($_SESSION['userID']); $user->readFromDB($db); $_SESSION['currentUser'] = $user; $isValidSession = true; } } if (!$isValidSession && $redirect) { $ip = $_SERVER["REMOTE_ADDR"]; tLog('Invalid session from ' . $ip . '. Redirected to login page.', 'INFO'); $fName = "login.php"; $baseDir = dirname($_SERVER['SCRIPT_FILENAME']); while (!file_exists($baseDir . DIRECTORY_SEPARATOR . $fName)) { $fName = "../" . $fName; } redirect($fName . "?note=expired", "top.location"); exit; } return $isValidSession; }
/** * Check if the user has the needed rights to view this page (testplan metrics). * * @author Andreas Simon * @param Database $db reference to database object * @param tlUser $user reference to user object */ function checkRights(&$db, &$user) { return $user->hasRight($db, 'testplan_metrics'); }
/** * initialize common test case information, useful when working on steps * */ function initTestCaseBasicInfo(&$argsObj, &$guiObj) { $greenCard = array('tcase_id' => $argsObj->tcase_id, 'tcversion_id' => $argsObj->tcversion_id); foreach ($greenCard as $ky) { if ($ky == 0) { $greenCard = $this->tcaseMgr->getIdCardByStepID($argsObj->step_id); break; } } $tcaseInfo = $this->tcaseMgr->get_by_id($greenCard['tcase_id'], $greenCard['tcversion_id'], null, array('output' => 'full_without_steps', 'renderGhost' => true)); $external = $this->tcaseMgr->getExternalID($greenCard['tcase_id'], $argsObj->testproject_id); $tcaseInfo[0]['tc_external_id'] = $external[0]; $guiObj->testcase = $tcaseInfo[0]; if (!isset($guiObj->testcase['ghost'])) { $guiObj->testcase['ghost'] = null; } $guiObj->authorObj = tlUser::getByID($this->db, $guiObj->testcase['author_id'], 'id'); $guiObj->updaterObj = null; if (!is_null($guiObj->testcase['updater_id'])) { $guiObj->updaterObj = tlUser::getByID($this->db, $guiObj->testcase['updater_id'], 'id'); } }
/** * Inserts a testplan related role for a given user * * @param int $userID the id of the user * @param int $id the testplan id * @param int $roleID the role id * * @return integer returns tl::OK on success, tl::ERROR else **/ function addUserRole($userID, $id, $roleID) { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $status = tl::ERROR; $sql = " /* {$debugMsg} */ INSERT INTO {$this->tables['user_testplan_roles']} (user_id,testplan_id,role_id) VALUES " . " ({$userID},{$id},{$roleID})"; if ($this->db->exec_query($sql)) { $testPlan = $this->get_by_id($id); $role = tlRole::getByID($this->db, $roleID, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM); $user = tlUser::getByID($this->db, $userID, tlUser::TLOBJ_O_GET_DETAIL_MINIMUM); if ($user && $testPlan && $role) { logAuditEvent(TLS("audit_users_roles_added_testplan", $user->getDisplayName(), $testPlan['name'], $role->name), "ASSIGN", $id, "testplans"); } $status = tl::OK; } return $status; }
/** * * @param id: test plan id * @return map: * key: user id * value: map with key=platform id * value: map with keys: 'total' and verbose status * values: test case count. * */ public function getStatusTotalsByTester($id) { $unassigned = lang_get('unassigned'); $data_set = $this->getStatusTotalsByAssignedTesterPlatform($id); if (!is_null($data_set)) { $code_verbose = $this->getStatusForReports(); $userSet = array_keys($data_set); // need to find a better way (with less overhead and data movement) to do this $userCol = tlUser::getByIDs($this->db, $userSet, tlUser::TLOBJ_O_GET_DETAIL_MINIMUM); foreach ($userSet as $testedBy) { $user_platform[$testedBy]['type'] = 'tester'; $user_platform[$testedBy]['name'] = $unassigned; if ($testedBy > 0) { $user_platform[$testedBy]['name'] = $userCol[$testedBy]->getDisplayName(); } $user_platform[$testedBy]['total_tc'] = 0; foreach ($code_verbose as $status_code => $status_verbose) { $user_platform[$testedBy]['details'][$status_verbose]['qty'] = 0; } // this will be removed from final result $user_platform[$testedBy]['details']['total']['qty'] = 0; $platformIDSet = array_keys($data_set[$assignedTo]); foreach ($platformIDSet as $platformID) { foreach ($data_set[$testedBy][$platformID] as $verboseStatus => $counter) { if (!isset($user_platform[$testedBy]['details'][$verboseStatus])) { $user_platform[$testedBy]['details'][$verboseStatus]['qty'] = 0; } $user_platform[$testedBy]['details'][$verboseStatus]['qty'] += $counter; } } $user_platform[$testedBy]['total_tc'] = $user_platform[$testedBy]['details']['total']['qty']; unset($user_platform[$testedBy]['details']['total']); } } return $user_platform; }
break; case "create": default: $highlight->create_user = 1; $user = new tlUser(); break; } $gui->op->operation = $actionOperation[$args->doAction]; $roles = tlRole::getAll($db, null, null, null, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM); unset($roles[TL_ROLES_UNDEFINED]); $smarty = new TLSmarty(); $smarty->assign('gui', $gui); $smarty->assign('highlight', $highlight); $smarty->assign('operation', $gui->op->operation); $smarty->assign('user_feedback', $gui->op->user_feedback); $smarty->assign('external_password_mgmt', tlUser::isPasswordMgtExternal($user->authentication)); $smarty->assign('mgt_view_events', $_SESSION['currentUser']->hasRight($db, "mgt_view_events")); $smarty->assign('grants', getGrantsForUserMgmt($db, $_SESSION['currentUser'])); $smarty->assign('optRights', $roles); $smarty->assign('userData', $user); renderGui($smarty, $args, $templateCfg); /** * * */ function init_args() { $_REQUEST = strings_stripSlashes($_REQUEST); $iParams = array("delete" => array(tlInputParameter::INT_N), "user" => array(tlInputParameter::INT_N), "user_id" => array(tlInputParameter::INT_N), "rights_id" => array(tlInputParameter::INT_N), "doAction" => array(tlInputParameter::STRING_N, 0, 30), "firstName" => array(tlInputParameter::STRING_N, 0, 30), "lastName" => array(tlInputParameter::STRING_N, 0, 100), "emailAddress" => array(tlInputParameter::STRING_N, 0, 100), "locale" => array(tlInputParameter::STRING_N, 0, 10), "login" => array(tlInputParameter::STRING_N, 0, 30), "password" => array(tlInputParameter::STRING_N, 0, 32), "authentication" => array(tlInputParameter::STRING_N, 0, 10), "user_is_active" => array(tlInputParameter::CB_BOOL)); $args = new stdClass(); R_PARAMS($iParams, $args);
} 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); $gui->note = $result['msg']; if ($result['status'] >= tl::OK) { $user = new tlUser($userID); if ($user->readFromDB($db) >= tl::OK) { logAuditEvent(TLS("audit_pwd_reset_requested", $user->login), "PWD_RESET", $userID, "users"); } redirect(TL_BASE_HREF . "login.php?note=lost"); exit; } else { if ($result['status'] == tlUser::E_EMAILLENGTH) { $gui->note = lang_get('mail_empty_address'); } else { if ($note != "") { $gui->note = getUserErrorMessage($result['status']); } } } }
function initializeGui(&$dbHandler, $argsObj, &$tplanMgr, &$tcaseMgr) { $platform_mgr = new tlPlatform($dbHandler, $argsObj->tproject_id); $tcase_cfg = config_get('testcase_cfg'); $gui = new stdClass(); $gui->platforms = $platform_mgr->getLinkedToTestplanAsMap($argsObj->tplan_id); $gui->usePlatforms = $platform_mgr->platformsActiveForTestplan($argsObj->tplan_id); $gui->bulk_platforms = $platform_mgr->getLinkedToTestplanAsMap($argsObj->tplan_id); $gui->bulk_platforms[0] = lang_get("all_platforms"); ksort($gui->bulk_platforms); $gui->send_mail = $argsObj->send_mail; $gui->send_mail_checked = ""; if ($gui->send_mail) { $gui->send_mail_checked = ' checked="checked" '; } $gui->glueChar = $tcase_cfg->glue_character; if ($argsObj->level != 'testproject') { $gui->testCasePrefix = $tcaseMgr->tproject_mgr->getTestCasePrefix($argsObj->tproject_id); $gui->testCasePrefix .= $tcase_cfg->glue_character; $gui->keywordsFilterType = $argsObj->keywordsFilterType; $gui->build_id = $argsObj->build_id; $gui->tplan_id = $argsObj->tplan_id; $tplan_info = $tplanMgr->get_by_id($argsObj->tplan_id); $gui->testPlanName = $tplan_info['name']; $build_info = $tplanMgr->get_build_by_id($argsObj->tplan_id, $argsObj->build_id); $gui->buildName = $build_info['name']; $gui->main_descr = sprintf(lang_get('title_tc_exec_assignment'), $gui->buildName, $gui->testPlanName); $tproject_mgr = new testproject($dbHandler); $tproject_info = $tproject_mgr->get_by_id($argsObj->tproject_id); $gui->all_users = tlUser::getAll($dbHandler, null, "id", null); $gui->users = getUsersForHtmlOptions($dbHandler, null, null, null, $gui->all_users); $gui->testers = getTestersForHtmlOptions($dbHandler, $argsObj->tplan_id, $tproject_info, $gui->all_users); } return $gui; }
} logAuditEvent(TLS("audit_users_self_signup", $args->login), "CREATE", $user->dbID, "users"); redirect(TL_BASE_HREF . "login.php?note=first"); exit; } else { $message = getUserErrorMessage($result); } } else { $message = $rx['msg']; } } } $smarty = new TLSmarty(); $gui = $args; // we get info about THE DEFAULT AUTHENTICATION METHOD $gui->external_password_mgmt = tlUser::isPasswordMgtExternal(); $gui->message = $message; $smarty->assign('gui', $gui); $smarty->display($templateCfg->default_template); /** * get input from user and return it in some sort of namespace * */ function init_args() { $iParams = array("doEditUser" => array(tlInputParameter::STRING_N, 0, 1), "login" => array(tlInputParameter::STRING_N, 0, 30), "password" => array(tlInputParameter::STRING_N, 0, 32), "password2" => array(tlInputParameter::STRING_N, 0, 32), "firstName" => array(tlInputParameter::STRING_N, 0, 30), "lastName" => array(tlInputParameter::STRING_N, 0, 30), "email" => array(tlInputParameter::STRING_N, 0, 100)); $args = new stdClass(); P_PARAMS($iParams, $args); return $args; } /**
/** * for SSL Cliente Certificate we can not check password but * 1. login exists * 2. SSL context exist * * return map * */ function doSSOClientCertificate(&$dbHandler, $apache_mod_ssl_env, $authCfg = null) { global $g_tlLogger; $result = array('status' => tl::ERROR, 'msg' => null); if (!isset($apache_mod_ssl_env['SSL_PROTOCOL'])) { return $result; } // With this we trust SSL is enabled => go ahead with login control $authCfg = is_null($authCfg) ? config_get('authentication') : $authCfg; $login = $apache_mod_ssl_env[$authCfg['SSO_uid_field']]; if (!is_null($login)) { $user = new tlUser(); $user->login = $login; $login_exists = $user->readFromDB($dbHandler, tlUser::USER_O_SEARCH_BYLOGIN) >= tl::OK; if ($login_exists && $user->isActive) { // Need to do set COOKIE following Mantis model $auth_cookie_name = config_get('auth_cookie'); $expireOnBrowserClose = false; setcookie($auth_cookie_name, $user->getSecurityCookie(), $expireOnBrowserClose, '/'); // Disallow two sessions within one browser if (isset($_SESSION['currentUser']) && !is_null($_SESSION['currentUser'])) { $result['msg'] = lang_get('login_msg_session_exists1') . ' <a style="color:white;" href="logout.php">' . lang_get('logout_link') . '</a>' . lang_get('login_msg_session_exists2'); } else { // Setting user's session information $_SESSION['currentUser'] = $user; $_SESSION['lastActivity'] = time(); $g_tlLogger->endTransaction(); $g_tlLogger->startTransaction(); setUserSession($dbHandler, $user->login, $user->dbID, $user->globalRoleID, $user->emailAddress, $user->locale, null); $result['status'] = tl::OK; } } else { logAuditEvent(TLS("audit_login_failed", $login, $_SERVER['REMOTE_ADDR']), "LOGIN_FAILED", $user->dbID, "users"); } } return $result; }
function get_by_id($id) { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $sql = "/* {$debugMsg} */ " . " SELECT '' AS author, '' AS modifier, NH.node_order, " . " RSPEC.id,testproject_id,RSPEC.scope,RSPEC.total_req,RSPEC.type," . " RSPEC.author_id,RSPEC.creation_ts,RSPEC.modifier_id," . " RSPEC.modification_ts,NH.name AS title,RSPEC.doc_id " . " FROM {$this->object_table} RSPEC, {$this->tables['nodes_hierarchy']} NH" . " WHERE RSPEC.id = NH.id " . " AND RSPEC.id = {$id}"; $recordset = $this->db->get_recordset($sql); $rs = null; if (!is_null($recordset)) { // Decode users $rs = $recordset[0]; if (trim($rs['author_id']) != "") { $user = tlUser::getByID($this->db, $rs['author_id']); // need to manage deleted users if ($user) { $rs['author'] = $user->getDisplayName(); } else { $rs['author'] = lang_get('undefined'); } } if (trim($rs['modifier_id']) != "") { $user = tlUser::getByID($this->db, $rs['modifier_id']); // need to manage deleted users if ($user) { $rs['modifier'] = $user->getDisplayName(); } else { $rs['modifier'] = lang_get('undefined'); } } } return $rs; }
} else { logAuditEvent(TLS("audit_testplan_created", $args->tproject_name, $args->testplan_name), "CREATED", $new_tplan_id, "testplans"); $cf_map = $tplan_mgr->get_linked_cfields_at_design($new_tplan_id, $args->tproject_id); $tplan_mgr->cfield_mgr->design_values_to_db($_REQUEST, $new_tplan_id, $cf_map); $status_ok = true; $template = null; $gui->user_feedback = ''; // Operations Order is CRITIC if ($args->copy) { $options = array('items2copy' => $args->copy_options, 'copy_assigned_to' => $args->copy_assigned_to, 'tcversion_type' => $args->tcversion_type); $tplan_mgr->copy_as($args->source_tplanid, $new_tplan_id, $args->testplan_name, $args->tproject_id, $args->user_id, $options); } if (!$args->is_public) { // does user have an SPECIFIC role on TestPlan ? // if answer is yes => do nothing if (!tlUser::hasRoleOnTestPlan($db, $args->user_id, $new_tplan_id)) { $effectiveRole = $args->user->getEffectiveRole($db, $args->tproject_id, null); $tplan_mgr->addUserRole($args->user_id, $new_tplan_id, $effectiveRole->dbID); } } // End critic block } } else { $gui->user_feedback = lang_get("warning_duplicate_tplan_name"); } if (!$status_ok) { // $gui->tplan_id=$new_tplan_id; $gui->tproject_name = $args->tproject_name; $gui->notes = $of->CreateHTML(); } break;
/** * Show Test Case * * * @internal * * returns: * * rev : * */ function show(&$smarty, $guiObj, $identity, $grants) { $env_tproject_id = $identity->tproject_id; $id = $identity->id; $version_id = isset($identity->version_id) ? $identity->version_id : self::ALL_VERSIONS; $idSet = is_array($id) ? $id : (array) $id; $status_ok = $idSet[0] > 0 ? 1 : 0; $idCard = new stdClass(); $idCard->tcase_id = intval($idSet[0]); $idCard->tcversion_id = $version_id; $idCard->tproject_id = $identity->tproject_id; $gui = $this->initShowGui($guiObj, $grants, $idSet[0], $idCard); $userIDSet = array(); if ($status_ok) { // Add To Testplan button will be disabled if the testcase doesn't belong to the current selected testproject // $gui->can_do->add2tplan = 'no'; if ($env_tproject_id == $gui->tproject_id) { $gui->can_do->add2tplan = $gui->can_do->add2tplan == 'yes' ? $grants->testplan_planning : 'no'; } else { $gui->can_do->add2tplan = 'no'; } } if ($status_ok && sizeof($idSet)) { $cfx = 0; $cfPlaces = $this->buildCFLocationMap(); $req_mgr = new requirement_mgr($this->db); $allReqs = $req_mgr->get_all_for_tcase($idSet); $allTCKeywords = $this->getKeywords($idSet, null, 'testcase_id', ' ORDER BY keyword ASC '); $ovx = 0; foreach ($idSet as $key => $tc_id) { // using $version_id has sense only when we are working on ONE SPECIFIC Test Case // if we are working on a set of test cases $version_id will be ALL VERSIONS if (!($tc_array = $this->get_by_id($tc_id, $version_id, null, array('renderGhost' => true, 'withGhostString' => true)))) { continue; } $tc_array[0]['tc_external_id'] = $gui->tcasePrefix . $tc_array[0]['tc_external_id']; $tc_array[0]['ghost'] = '[ghost]"TestCase":"' . $tc_array[0]['tc_external_id'] . '","Version":"' . $tc_array[0]['version'] . '"[/ghost]'; // status quo of execution and links of tc versions $gui->status_quo[] = $this->get_versions_status_quo($tc_id); $gui->linked_versions[] = $this->get_linked_versions($tc_id); $gui->keywords_map[] = isset($allTCKeywords[$tc_id]) ? $allTCKeywords[$tc_id] : null; $tc_current = $tc_array[0]; $gui->tc_current_version[] = array($tc_current); // Get UserID and Updater ID for current Version $userIDSet[$tc_current['author_id']] = null; $userIDSet[$tc_current['updater_id']] = null; foreach ($cfPlaces as $locationKey => $locationFilter) { $gui->cf_current_version[$cfx][$locationKey] = $this->html_table_of_custom_field_values($tc_id, 'design', $locationFilter, null, null, $gui->tproject_id, null, $tc_current['id']); } // Other versions (if exists) if (count($tc_array) > 1) { $gui->testcase_other_versions[] = array_slice($tc_array, 1); $target_idx = count($gui->testcase_other_versions) - 1; $loop2do = count($gui->testcase_other_versions[$target_idx]); $ref =& $gui->testcase_other_versions[$target_idx]; for ($qdx = 0; $qdx < $loop2do; $qdx++) { $ref[$qdx]['ghost'] = '[ghost]"TestCase":"' . $tc_array[0]['tc_external_id'] . '","Version":"' . $ref[$qdx]['version'] . '"[/ghost]'; $target_tcversion = $gui->testcase_other_versions[$target_idx][$qdx]['id']; foreach ($cfPlaces as $locationKey => $locationFilter) { $gui->cf_other_versions[$cfx][$qdx][$locationKey] = $this->html_table_of_custom_field_values($tc_id, 'design', $locationFilter, null, null, $gui->tproject_id, null, $target_tcversion); } } } else { $gui->testcase_other_versions[] = null; $gui->cf_other_versions[$cfx] = null; } $cfx++; // Get author and updater id for each version if ($gui->testcase_other_versions[0]) { foreach ($gui->testcase_other_versions[0] as $key => $version) { $userIDSet[$version['author_id']] = null; $userIDSet[$version['updater_id']] = null; } } $gui->arrReqs[] = isset($allReqs[$tc_id]) ? $allReqs[$tc_id] : null; } } // Removing duplicate and NULL id's unset($userIDSet['']); $gui->users = tlUser::getByIDs($this->db, array_keys($userIDSet), 'id'); $gui->cf = null; $this->initShowGuiActions($gui); $tplCfg = templateConfiguration('tcView'); $smarty->assign('gui', $gui); $smarty->display($tplCfg->template_dir . $tplCfg->default_template); }
/** * */ function init_args() { $_REQUEST = strings_stripSlashes($_REQUEST); $args = new stdClass(); try { // ATTENTION - give a look to $tlCfg->reports_list $typeSize = 30; $iParams = array("apikey" => array(tlInputParameter::STRING_N, 32, 64), "tproject_id" => array(tlInputParameter::INT_N), "tplan_id" => array(tlInputParameter::INT_N), "level" => array(tlInputParameter::STRING_N, 0, 16), "type" => array(tlInputParameter::STRING_N, 0, $typeSize)); } catch (Exception $e) { echo $e->getMessage(); exit; } R_PARAMS($iParams, $args); $args->light = 'red'; $opt = array('setPaths' => true, 'clearSession' => true); if (strlen($args->apikey) == 32) { setUpEnvForRemoteAccess($dbHandler, $args->apikey, null, $opt); $user = tlUser::getByAPIKey($dbHandler, $args->apikey); $args->light = count($user) == 1 ? 'green' : 'red'; } else { $kerberos = new stdClass(); $kerberos->args = $args; $kerberos->method = null; if (setUpEnvForAnonymousAccess($dbHandler, $args->apikey, $kerberos, $opt)) { $args->light = 'green'; } } return $args; }