/** * check right on effective role for user, using test project and test plan, * means that check right on effective role. * * @return string|null 'yes' or null * * @internal revisions */ function hasRight(&$db, $roleQuestion, $tprojectID = null, $tplanID = null, $getAccess = false) { global $g_propRights_global; global $g_propRights_product; // var_dump($this->tprojectRoles); if (!is_null($tplanID)) { $testPlanID = $tplanID; } else { $testPlanID = isset($_SESSION['testplanID']) ? $_SESSION['testplanID'] : 0; } if (!is_null($tprojectID)) { $testprojectID = $tprojectID; } else { $testprojectID = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0; } $accessPublic = null; if ($getAccess) { if ($testprojectID > 0) { $mgr = new testproject($db); $accessPublic['tproject'] = $mgr->getPublicAttr($testprojectID); unset($mgr); } if ($testPlanID > 0) { $mgr = new testplan($db); $accessPublic['tplan'] = $mgr->getPublicAttr($testPlanID); unset($mgr); } } $userGlobalRights = (array) $this->globalRole->rights; $globalRights = array(); foreach ($userGlobalRights as $right) { $globalRights[] = $right->name; } $allRights = $globalRights; $userTestProjectRoles = $this->tprojectRoles; $userTestPlanRoles = $this->tplanRoles; if (isset($userTestProjectRoles[$testprojectID])) { $userTestProjectRights = (array) $userTestProjectRoles[$testprojectID]->rights; // Special situation => just one right $doMoreAnalysis = true; if (count($userTestProjectRights) == 1) { $doMoreAnalysis = !is_null($userTestProjectRights[0]->dbID); } $allRights = null; if ($doMoreAnalysis) { //echo 'do more'; $testProjectRights = array(); foreach ($userTestProjectRights as $right) { $testProjectRights[] = $right->name; } // subtract global rights $testProjectRights = array_diff($testProjectRights, array_keys($g_propRights_global)); propagateRights($globalRights, $g_propRights_global, $testProjectRights); $allRights = $testProjectRights; } else { return false; } } else { if (!is_null($accessPublic) && $accessPublic['tproject'] == 0) { return false; } } if ($testPlanID > 0) { if (isset($userTestPlanRoles[$testPlanID])) { $userTestPlanRights = (array) $userTestPlanRoles[$testPlanID]->rights; $testPlanRights = array(); foreach ($userTestPlanRights as $right) { $testPlanRights[] = $right->name; } //subtract test projects rights $testPlanRights = array_diff($testPlanRights, array_keys($g_propRights_product)); propagateRights($allRights, $g_propRights_product, $testPlanRights); $allRights = $testPlanRights; } else { if (!is_null($accessPublic) && $accessPublic['tplan'] == 0) { return false; } } } return checkForRights($allRights, $roleQuestion); }