Пример #1
0
 /**
  * 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
  */
 function hasRight(&$db, $roleQuestion, $tprojectID = null, $tplanID = null)
 {
     global $g_propRights_global;
     global $g_propRights_product;
     $userGlobalRights = (array) $this->globalRole->rights;
     $globalRights = array();
     foreach ($userGlobalRights as $right) {
         $globalRights[] = $right->name;
     }
     if (!is_null($tplanID)) {
         $testPlanID = $tplanID;
     } else {
         //@TODO schlundus, should not be there
         // 20090726 - franciscom -> yes must be moved ASAP
         $testPlanID = isset($_SESSION['testPlanId']) ? $_SESSION['testPlanId'] : 0;
     }
     $userTestPlanRoles = $this->tplanRoles;
     if (!is_null($tprojectID)) {
         $testprojectID = $tprojectID;
     } else {
         //@TODO schlundus, should not be there
         $testprojectID = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
     }
     $allRights = $globalRights;
     $userTestProjectRoles = $this->tprojectRoles;
     /* if $testprojectID == -1 we dont check rights at test project level! */
     if (isset($userTestProjectRoles[$testprojectID])) {
         $userTestProjectRights = (array) $userTestProjectRoles[$testprojectID]->rights;
         $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;
     }
     /* if $tplanID == -1 we dont check rights at tp level! */
     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;
     }
     return checkForRights($allRights, $roleQuestion);
 }
Пример #2
0
 /**
  * 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);
 }