Skip to content
Permalink
Browse files

fix: has_been_executed setting logic

fix: minor refactoring to make intention clear
code layout
feature: #0008655: new right to allow add/remove keywords from executed test case versions
  • Loading branch information...
fmancardi committed May 4, 2019
1 parent 2e55da8 commit 0db4b7877dc6655cda11b3aff5b2784715c4c96b
@@ -58,10 +58,14 @@ var pF_remove_keyword = remove_keyword;
<td width="35%" style="vertical-align:top;"><a href={$kwView}>{$tcView_viewer_labels.keywords}</a>: &nbsp;
</td>
{*debug*}

{$removeEnabled = $args_edit_enabled && $gui->assign_keywords &&
$args_frozen_version == "no"}

<td style="vertical-align:top;">
{foreach item=tckw_link_item from=$args_keywords_map}
{$tckw_link_item.keyword|escape}
{if $args_edit_enabled && $gui->assign_keywords && $args_frozen_version == "no"}
{if $removeEnabled}
<a href="javascript:keyword_remove_confirmation({$gui->tcase_id},
{$tckw_link_item.tckw_link},
'{$tckw_link_item.keyword|escape:'javascript'}',
@@ -76,7 +80,8 @@ var pF_remove_keyword = remove_keyword;
</td>
</tr>
<tr>
{if $args_edit_enabled && null != $gui->currentVersionFreeKeywords}
{$addEnabled = $args_edit_enabled}
{if $addEnabled && null != $gui->currentVersionFreeKeywords}
<td>
&nbsp;
<td>
@@ -93,30 +93,35 @@ viewer for test case in test specification
{$warning_delete_msg=""}
{$edit_enabled=0}
{$delete_enabled=0}
{$has_been_executed=0}
{$show_relations=1}
{if $args_can_do->edit == "yes"}

{$has_been_executed=0}
{$has_been_executed=0}
{if $args_status_quo != null ||
$args_status_quo[$args_testcase.id].executed}
{$has_been_executed=1}
{/if}

{if $args_can_do->edit == "yes"}
{lang_get s='can_not_edit_tc' var="warning_edit_msg"}
{lang_get s='system_blocks_delete_executed_tc' var="warning_delete_msg"}

{if $args_status_quo == null || $args_status_quo[$args_testcase.id].executed == null}
{if $args_status_quo == null ||
$args_status_quo[$args_testcase.id].executed == null}
{$edit_enabled=1}
{$delete_enabled=1}
{$warning_edit_msg=""}
{$warning_delete_msg=""}
{else}
{if isset($args_tcase_cfg) && $args_tcase_cfg->can_edit_executed == 1}

{if isset($args_tcase_cfg) &&
$args_tcase_cfg->can_edit_executed == 1}
{$edit_enabled=1}
{$has_been_executed=1}
{lang_get s='warning_editing_executed_tc' var="warning_edit_msg"}
{/if}

{if isset($args_tcase_cfg)}
{if $args_tcase_cfg->can_delete_executed == 1}
{$delete_enabled=1}
{$has_been_executed=1}
{$warning_delete_msg=""}
{else}
{if ($args_can_do->delete_testcase == "yes" &&
@@ -415,11 +420,12 @@ function launchInsertStep(step_id)
<div {$addInfoDivStyle}>
{$kwRW = $args_frozen_version=="no" && $edit_enabled == 1 &&
$has_been_executed == 0}

{if $args_frozen_version=="no" &&
$args_tcase_cfg->can_edit_executed == 1 &&
$has_been_executed == 1}
{$kwRW = 1}

{if $args_frozen_version=="no" && $has_been_executed == 1 }
{if $args_tcase_cfg->can_edit_executed == 1 ||
$args_tcase_cfg->can_add_remove_kw_on_executed == 1}
{$kwRW = 1}
{/if}
{/if}

{include file="{$tplConfig['keywords.inc']}"
@@ -439,7 +445,8 @@ function launchInsertStep(step_id)
{/if}

{if $tlCfg->testcase_cfg->reqLinkingDisabledAfterExec == 1 &&
$has_been_executed == 1 && $args_tcase_cfg->can_edit_executed == 0}
$has_been_executed == 1 &&
$args_tcase_cfg->can_edit_executed == 0}
{$reqLinkingEnabled = 0}
{/if}

@@ -34,8 +34,7 @@
/**
* init global map with user rights and user rights description localized.
*/
function init_global_rights_maps()
{
function init_global_rights_maps() {
// Every array, defines a section in the define role page => HAS EFFECTS ONLY ON LAYOUT
global $g_rights_tp;
global $g_rights_mgttc;
@@ -89,15 +88,17 @@ function init_global_rights_maps()
'right_testplan_set_urgent_testcases' => null,
'right_testplan_show_testcases_newest_versions' => null,
'right_testcase_freeze' => null,
'right_exec_ro_access' => null);
'right_exec_ro_access' => null,
'right_testproject_add_remove_keywords_executed_tcversions' => null);
$l18n = init_labels($l18nCfg);
$g_rights_executions = array('exec_edit_notes' => $l18n['right_exec_edit_notes'],
'exec_delete' => $l18n['right_exec_delete'],
'exec_ro_access' => $l18n['right_exec_ro_access']);
$g_rights_executions =
array('exec_edit_notes' => $l18n['right_exec_edit_notes'],
'exec_delete' => $l18n['right_exec_delete'],
'exec_ro_access' => $l18n['right_exec_ro_access']);
// order is important ?
$g_rights_tp =
@@ -116,11 +117,20 @@ function init_global_rights_maps()
'testplan_set_urgent_testcases' => $l18n['right_testplan_set_urgent_testcases'],
'testplan_show_testcases_newest_versions' => $l18n['right_testplan_show_testcases_newest_versions']);
$g_rights_mgttc = array("mgt_view_tc" => $l18n['desc_mgt_view_tc'],
"mgt_modify_tc" => $l18n['desc_mgt_modify_tc'],
"testproject_delete_executed_testcases" => $l18n['right_testproject_delete_executed_testcases'],
"testproject_edit_executed_testcases" => $l18n['right_testproject_edit_executed_testcases'],
"testcase_freeze" => $l18n['right_testcase_freeze']);
"testproject_delete_executed_testcases" => null,
"testproject_edit_executed_testcases" => null ,
"testproject_add_remove_keywords_executed_tcversions" => null,
"testcase_freeze" => null);
foreach( $g_rights_mgttc as $tr => $lbl ) {
if( null == $lbl ) {
$g_rights_mgttc[$tr] = $l18n['right_' . $tr];
}
}
$g_rights_kw = array("mgt_view_key" => $l18n['desc_mgt_view_key'],
"keyword_assignment" => $l18n['desc_keyword_assignment'],
@@ -191,20 +201,19 @@ function init_global_rights_maps()
*
* @see tlUser
*/
function has_rights(&$db,$roleQuestion,$tprojectID = null,$tplanID = null)
{
function has_rights(&$db,$roleQuestion,$tprojectID = null,$tplanID = null) {
return $_SESSION['currentUser']->hasRight($db,$roleQuestion,$tprojectID,$tplanID);
}
function propagateRights($fromRights,$propRights,&$toRights)
{
/**
*
*/
function propagateRights($fromRights,$propRights,&$toRights) {
// the mgt_users right isn't test project related so this right is inherited from
// the global role (if set)
foreach($propRights as $right => $desc)
{
if (in_array($right,$fromRights) && !in_array($right,$toRights))
{
foreach($propRights as $right => $desc) {
if (in_array($right,$fromRights) && !in_array($right,$toRights)) {
$toRights[] = $right;
}
}
@@ -223,32 +232,23 @@ function propagateRights($fromRights,$propRights,&$toRights)
* @since 20.02.2006, 20:30:07
*
**/
function checkForRights($rights,$roleQuestion,$bAND = 1)
{
function checkForRights($rights,$roleQuestion,$bAND = 1) {
$ret = null;
//check to see if the $roleQuestion variable appears in the $roles variable
if (is_array($roleQuestion))
{
if (is_array($roleQuestion)) {
$r = array_intersect($roleQuestion,$rights);
if ($bAND)
{
if ($bAND) {
//for AND all rights must be present
if (sizeof($r) == sizeof($roleQuestion))
{
if (sizeof($r) == sizeof($roleQuestion)) {
$ret = 'yes';
}
}
else
{
} else {
//for OR one of all must be present
if (sizeof($r))
{
if (sizeof($r)) {
$ret = 'yes';
}
}
}
else
{
} else {
$ret = (in_array($roleQuestion,$rights) ? 'yes' : null);
}
return $ret;
@@ -276,8 +276,7 @@ function checkForRights($rights,$roleQuestion,$bAND = 1)
* effective_role_id user role for test project
* is_inherited
*/
function get_tproject_effective_role(&$db,$tproject,$user_id = null,$users = null)
{
function get_tproject_effective_role(&$db,$tproject,$user_id = null,$users = null) {
$effective_role = array();
$tproject_id = $tproject['id'];
if (!is_null($user_id))
@@ -6765,6 +6765,9 @@ private function initShowGui($guiObj,$grantsObj,$idCard) {
// In order to refactor less code, we will remap to OLD config options present on config file.
$goo->tcase_cfg->can_edit_executed = $grantsObj->testproject_edit_executed_testcases == 'yes' ? 1 : 0;
$goo->tcase_cfg->can_delete_executed = $grantsObj->testproject_delete_executed_testcases == 'yes' ? 1 : 0;
$goo->tcase_cfg->can_add_remove_kw_on_executed =
$grantsObj->testproject_add_remove_keywords_executed_tcversions == 'yes' ? 1 : 0;
$goo->view_req_rights = property_exists($grantsObj, 'mgt_view_req') ? $grantsObj->mgt_view_req : 0;
$goo->assign_keywords = property_exists($grantsObj, 'keyword_assignment') ? $grantsObj->keyword_assignment : 0;
$goo->req_tcase_link_management = property_exists($grantsObj, 'req_tcase_link_management') ? $grantsObj->req_tcase_link_management : 0;
@@ -178,43 +178,36 @@ public function readFromDB(&$db,$options = self::TLOBJ_O_SEARCH_BY_ID)
/**
* @param resource &$db reference to database handler
**/
public function writeToDB(&$db)
{
public function writeToDB(&$db) {
//@TODO schlundus, now i removed the potentially modified object from the cache
//another optimization could be: read the new contents if storing was successfully into the
//cache
$this->removeFromCache();
$result = $this->checkDetails($db);
if ($result >= tl::OK)
{
if ($this->dbID)
{
if ($result >= tl::OK) {
if ($this->dbID) {
$result = $this->deleteRightsFromDB($db);
if ($result >= tl::OK)
{
if ($result >= tl::OK) {
$sql = "UPDATE {$this->object_table} " .
" SET description = '".$db->prepare_string($this->name)."',".
" notes ='".$db->prepare_string($this->description)."'".
" WHERE id = {$this->dbID}";
$result = $db->exec_query($sql);
}
}
else
{
} else {
$sql = "INSERT INTO {$this->object_table} (description,notes) " .
" VALUES ('".$db->prepare_string($this->name)."',".
"'" . $db->prepare_string($this->description)."')";
$result = $db->exec_query($sql);
if($result)
{
if($result) {
$this->dbID = $db->insert_id($this->object_table);
}
}
$result = $result ? tl::OK : self::E_DBERROR;
if ($result >= tl::OK)
{
if ($result >= tl::OK) {
$result = $this->addRightsToDB($db);
}
}
@@ -225,21 +218,23 @@ public function writeToDB(&$db)
/**
* @param resource &$db reference to database handler
**/
public function checkDetails(&$db)
{
public function checkDetails(&$db) {
$this->name = trim($this->name);
$this->description = trim($this->description);
$result = tl::OK;
if (!sizeof($this->rights))
if (!sizeof($this->rights)) {
$result = self::E_EMPTYROLE;
if ($result >= tl::OK)
}
if ($result >= tl::OK) {
$result = self::checkRoleName($this->name);
}
if ($result >= tl::OK)
if ($result >= tl::OK) {
$result = self::doesRoleExist($db,$this->name,$this->dbID) ? self::E_NAMEALREADYEXISTS : tl::OK;
}
return $result;
}
@@ -455,24 +450,29 @@ protected function deleteRightsFromDB(&$db)
return $result ? tl::OK : tl::ERROR;
}
protected function addRightsToDB(&$db)
{
/**
*
*
*/
protected function addRightsToDB(&$db) {
$status_ok = 1;
if ($this->rights)
{
foreach($this->rights as $right)
{
if ($this->rights) {
foreach($this->rights as $right) {
$rightID = $right->dbID;
$sql = "INSERT INTO {$this->tables['role_rights']} (role_id,right_id) " .
"VALUES ({$this->dbID},{$rightID})";
$status_ok = $status_ok && ($db->exec_query($sql) ? 1 : 0);
}
}
return $status_ok ? tl::OK : tl::ERROR;
}
protected function readRights(&$db)
{
/**
*
*
*/
protected function readRights(&$db) {
$sql = "SELECT right_id,description FROM {$this->tables['role_rights']} a " .
"JOIN {$this->tables['rights']} b ON a.right_id = b.id " .
"WHERE role_id = {$this->dbID}";
@@ -208,9 +208,14 @@ function initializeEnv($dbHandler) {
$args = init_args($dbHandler);
$gui = new stdClass();
$grant2check = array('mgt_modify_tc','mgt_view_req','testplan_planning','mgt_modify_product',
'mgt_modify_req','testcase_freeze','keyword_assignment','req_tcase_link_management',
'testproject_edit_executed_testcases','testproject_delete_executed_testcases');
$grant2check =
array('mgt_modify_tc','mgt_view_req','testplan_planning',
'mgt_modify_product','mgt_modify_req','testcase_freeze',
'keyword_assignment','req_tcase_link_management',
'testproject_edit_executed_testcases',
'testproject_delete_executed_testcases',
'testproject_add_remove_keywords_executed_tcversions');
$grants = new stdClass();
foreach($grant2check as $right) {
$grants->$right = $_SESSION['currentUser']->hasRight($dbHandler,$right,$args->tproject_id);
@@ -2498,7 +2498,8 @@ $TLS_right_testplan_show_testcases_newest_versions = 'Show Test Cases Newest Ver

$TLS_right_testcase_freeze = 'Freeze/Unfreeze Test Case Version';


$TLS_right_testproject_add_remove_keywords_executed_tcversions =
'Add/Remove Keywords from Executed Test Case Versions';



0 comments on commit 0db4b78

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