Пример #1
0
/**
 * getTestersForHtmlOptions
 * returns users that have role on ($tplanID,$tprojectID) with right
 * to execute a test case.
 *
 * @param resource &$db reference to database handler
 * @param integer $tplanID test plan id
 * @param integer $tprojectID test project id
 * @param $users UNUSED - remove
 * @param $additional_testers TBD
 * @param string $activeStatus. values: 'active','inactive','any'
 * 
 * @return array TBD  
 * @internal revisions
 * 20101023 - franciscom - BUGID 3931: Assign test case to test project fails for 
 *						   PRIVATE TEST PROJECT (tested with admin user)
 */
function XXXXgetTestersForHtmlOptions(&$db, $tplanID, $tproject, $users = null, $additional_testers = null, $activeStatus = 'active')
{
    $orOperand = false;
    $activeTarget = 1;
    switch ($activeStatus) {
        case 'any':
            $orOperand = true;
            break;
        case 'inactive':
            $activeTarget = 0;
            break;
        case 'active':
        default:
            break;
    }
    $users_roles = get_tplan_effective_role($db, $tplanID, $tproject, null, $users);
    $userFilter = array();
    foreach ($users_roles as $keyUserID => $roleInfo) {
        // Assign test case to test project fails for PRIVATE TEST PROJECT (tested with admin user)
        if (is_object($roleInfo['effective_role'])) {
            if ($roleInfo['effective_role']->hasRight('testplan_execute') && ($orOperand || $roleInfo['user']->isActive == $activeTarget)) {
                $userFilter[$keyUserID] = $roleInfo['user'];
            }
        }
    }
    return buildUserMap($userFilter, true, $additional_testers);
}
/**
 * getTestPlanEffectiveRoles
 *
 */
function getTestPlanEffectiveRolesNEW(&$dbHandler, &$tplanMgr, $tprojectMgr, &$argsObj, &$users)
{
    $features = array();
    $activeTestplans = $tprojectMgr->get_all_testplans($argsObj->testprojectID, array('plan_status' => 1));
    $ret = null;
    $status_ok = !is_null($activeTestplans);
    if ($status_ok) {
        $myAccessibleSet = $argsObj->user->getAccessibleTestPlans($dbHandler, $argsObj->testprojectID, null, array('output' => 'map'));
        //echo __LINE__;
        //echo __FUNCTION__;
        //new dBug($myAccessibleSet);
        // we want to change map key, from testplan id to a sequential index to maintain old logic
        $activeKeys = array_keys($activeTestplans);
        $myKeys = array_keys((array) $myAccessibleSet);
        $key2remove = $key2remove_diff = array_diff($activeKeys, $myKeys);
        if (!is_null($key2remove)) {
            foreach ($key2remove as $target) {
                unset($activeTestplans[$target]);
            }
        }
        // $activeTestplans = array_values($activeTestplans);
        //new dBug($activeTestplans);
        // 2013-04-01
        // now is not clear why this logic is right
        //
        // analisys has to go from detail (test plan) to general
        // Step 1 - check if user has specific role on test plan
        // Step 2 - If Step 1 fails
        //          check if user has specific role on test project
        //          that contains the test project
        // Step 3 - If Step 2 fails
        //          check Global Role.
        //
        if ($argsObj->user->hasRight($dbHandler, "mgt_users")) {
            $features = $activeTestplans;
        } else {
            //$loop2do = sizeof($activeTestplans);
            //for($idx = 0; $idx < $loop2do; $idx++)
            $features = array();
            $key2loop = array_keys($activeTestplans);
            foreach ($key2loop as $idx) {
                // Humm!!, think we need to check testplan_user_role_assignment and not "testplan_planning"
                if ($argsObj->user->hasRight($dbHandler, "testplan_user_role_assignment", null, $activeTestplans[$idx]['id']) == "yes") {
                    $features[$idx] = $activeTestplans[$idx];
                }
            }
        }
        //if nothing special was selected, use the one in the session or the first
        if (!$argsObj->featureID) {
            if (sizeof($features)) {
                if ($argsObj->testplanID) {
                    // $loop2do = sizeof($features);
                    // for($idx = 0; $idx < $loop2do; $idx++)
                    $key2loop = array_keys($features);
                    foreach ($key2loop as $idx) {
                        if ($argsObj->testplanID == $features[$idx]['id']) {
                            $argsObj->featureID = $argsObj->testplanID;
                        }
                    }
                }
                if (!$argsObj->featureID) {
                    $xx = current($features);
                    $argsObj->featureID = $xx['id'];
                }
            }
        }
        foreach ($users as &$user) {
            $user->readTestProjectRoles($dbHandler, $argsObj->testprojectID);
            $user->readTestPlanRoles($dbHandler, $argsObj->featureID);
        }
        $tproject_info = $tprojectMgr->get_by_id($argsObj->testprojectID);
        $effectiveRoles = get_tplan_effective_role($dbHandler, $argsObj->featureID, $tproject_info, null, $users);
        // it seems that here is the best place to check if current logged user
        // can manege roles on current selected test plan.
        // why I did not find this before ???
        $features = array();
        $key2loop = array_keys($activeTestplans);
        foreach ($key2loop as $idx) {
            $answer = $rolesCache[$testprojects[$idx]['effective_role']]->hasRight("user_role_assignment");
            //echo 'Question is: user_role_assignment - ANSWER IS:' . $answer . '<br>';
            if ($answer == false) {
                $answer = $rolesCache[$testprojects[$idx]['effective_role']]->hasRight("testproject_user_role_assignment");
                // echo 'Question is: testproject_user_role_assignment - ANSWER IS:' . $answer . '<br>';
            }
            if ($answer == true) {
                $features[$idx] = $testprojects[$idx];
            }
            // Humm!!, think we need to check testplan_user_role_assignment and not "testplan_planning"
            if ($argsObj->user->hasRight($dbHandler, "testplan_user_role_assignment", null, $activeTestplans[$idx]['id']) == "yes") {
                $features[$idx] = $activeTestplans[$idx];
            }
        }
        $ret = array($effectiveRoles, $features, $argsObj->featureID);
    }
    return $ret;
}
Пример #3
0
/**
 * getTestPlanEffectiveRoles
 *
 */
function getTestPlanEffectiveRoles(&$dbHandler, &$tplanMgr, $tprojectMgr, &$argsObj, &$users)
{
    $features = array();
    $activeTestplans = $tprojectMgr->get_all_testplans($argsObj->testprojectID, array('plan_status' => 1));
    if (!is_null($activeTestplans)) {
        // we want to change map key, from testplan id to a sequential index
        // to maintain old logic
        $activeTestplans = array_values($activeTestplans);
    }
    if ($argsObj->user->hasRight($dbHandler, "mgt_users")) {
        $features = $activeTestplans;
    } else {
        $loop2do = sizeof($activeTestplans);
        for ($idx = 0; $idx < $loop2do; $idx++) {
            // Humm!!, think we need to check testplan_user_role_assignment and not
            // "testplan_planning"
            if ($argsObj->user->hasRight($dbHandler, "testplan_user_role_assignment", null, $activeTestplans[$idx]['id']) == "yes") {
                $features[] = $activeTestplans[$idx];
            }
        }
    }
    //if nothing special was selected, use the one in the session or the first
    if (!$argsObj->featureID) {
        if (sizeof($features)) {
            if ($argsObj->testplanID) {
                $loop2do = sizeof($features);
                for ($idx = 0; $idx < $loop2do; $idx++) {
                    if ($argsObj->testplanID == $features[$idx]['id']) {
                        $argsObj->featureID = $argsObj->testplanID;
                    }
                }
            }
            if (!$argsObj->featureID) {
                $argsObj->featureID = $features[0]['id'];
            }
        }
    }
    foreach ($users as &$user) {
        $user->readTestProjectRoles($dbHandler, $argsObj->testprojectID);
        $user->readTestPlanRoles($dbHandler, $argsObj->featureID);
    }
    // 20101004 - asimon - adapted to new interface of getTestersForHtmlOptions
    $tproject_info = $tprojectMgr->get_by_id($argsObj->tproject_id);
    $effectiveRoles = get_tplan_effective_role($dbHandler, $argsObj->featureID, $tproject_info, null, $users);
    return array($effectiveRoles, $features, $argsObj->featureID);
}