Skip to content
Permalink
Browse files

feature: 0008697: Last used test project persisted for next login

  • Loading branch information...
fmancardi committed Jul 27, 2019
1 parent eaff21b commit f61d171b035822a295920cad79abd7801683e1ce
Showing with 23 additions and 21 deletions.
  1. +23 −21 lib/functions/common.php
@@ -390,26 +390,35 @@ function initTopMenu(&$db)
* @uses initMenu()
* @internal revisions
**/
function initProject(&$db,$hash_user_sel)
{
function initProject(&$db,$hash_user_sel) {
$ckObj = new stdClass();
$ckCfg = config_get('cookie');
$tproject = new testproject($db);
$user_sel = array("tplan_id" => 0, "tproject_id" => 0 );
$user_sel["tproject_id"] = isset($hash_user_sel['testproject']) ? intval($hash_user_sel['testproject']) : 0;
$user_sel["tplan_id"] = isset($hash_user_sel['testplan']) ? intval($hash_user_sel['testplan']) : 0;
$tproject_id = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
// test project is Test Plan container, then we start checking the container
if( $user_sel["tproject_id"] != 0 )
{
$tproject_id = $user_sel["tproject_id"];
// test project is Test Plan container, then we start
// checking the container
$ckObj->name = $ckCfg->prefix .
"TL_user${_SESSION['userID']}_testProject";
if( $user_sel["tproject_id"] != 0 ) {
$ckObj->value = $tproject_id = $user_sel["tproject_id"];
$ckObj->expire = time()+60*60*24*90;
tlSetCookie($ckObj);
} else {
$tproject_id = intval($_COOKIE[$ckObj->name]);
}
// We need to do checks before updating the SESSION to cover the case that not defined but exists
if (!$tproject_id)
{
if (!$tproject_id) {
$all_tprojects = $tproject->get_all();
if ($all_tprojects)
{
if ($all_tprojects) {
$tproject_data = $all_tprojects[0];
$tproject_id = $tproject_data['id'];
}
@@ -422,31 +431,24 @@ function initProject(&$db,$hash_user_sel)
$tplan_id = isset($_SESSION['testplanID']) ? $_SESSION['testplanID'] : null;
// Now we need to validate the TestPlan
$ckObj = new stdClass();
$ckCfg = config_get('cookie');
$ckObj->name = $ckCfg->prefix . "TL_user${_SESSION['userID']}_proj${tproject_id}_testPlanId";
if($user_sel["tplan_id"] != 0)
{
if($user_sel["tplan_id"] != 0) {
$ckObj->value = $user_sel["tplan_id"];
$ckObj->expire = time()+60*60*24*90;
tlSetCookie($ckObj);
}
elseif (isset($_COOKIE[$ckObj->name]))
{
} elseif (isset($_COOKIE[$ckObj->name])) {
$tplan_id = intval($_COOKIE[$ckObj->name]);
}
// check if the specific combination of testprojectid and testplanid is valid
$tplan_data = $_SESSION['currentUser']->getAccessibleTestPlans($db,$tproject_id,$tplan_id);
if(is_null($tplan_data))
{
if(is_null($tplan_data)) {
// Need to get first accessible test plan for user, if any exists.
$tplan_data = $_SESSION['currentUser']->getAccessibleTestPlans($db,$tproject_id);
}
if(!is_null($tplan_data) && is_array($tplan_data))
{
if(!is_null($tplan_data) && is_array($tplan_data)) {
$tplan_data = $tplan_data[0];
setSessionTestPlan($tplan_data);
}

0 comments on commit f61d171

Please sign in to comment.
You can’t perform that action at this time.