Exemple #1
0
function doOperation(&$dbHandler, $argsObj, $operation)
{
    $rights = implode("','", array_keys($argsObj->grant));
    $op = new stdClass();
    $op->role = new tlRole();
    $op->role->rights = tlRight::getAll($dbHandler, "WHERE description IN ('{$rights}')");
    $op->role->name = $argsObj->rolename;
    $op->role->description = $argsObj->notes;
    $op->role->dbID = $argsObj->roleid;
    $op->userFeedback = null;
    $op->template = 'rolesEdit.tpl';
    $result = $op->role->writeToDB($dbHandler);
    if ($result >= tl::OK) {
        $auditCfg = null;
        switch ($operation) {
            case 'doCreate':
                $auditCfg['msg'] = "audit_role_created";
                $auditCfg['activity'] = "CREATE";
                break;
            case 'doUpdate':
                $auditCfg['msg'] = "audit_role_saved";
                $auditCfg['activity'] = "SAVE";
                break;
        }
        logAuditEvent(TLS($auditCfg['msg'], $argsObj->rolename), $auditCfg['activity'], $op->role->dbID, "roles");
        $op->template = null;
    } else {
        $op->userFeedback = tlRole::getRoleErrorMessage($result);
    }
    return $op;
}
Exemple #2
0
/**
 * send mail to administrators (users that have default role = administrator) 
 * to warn about new user created.
 *
 */
function notifyGlobalAdmins(&$dbHandler, &$userObj)
{
    // Get email addresses for all users that have default role = administrator
    $roleMgr = new tlRole(TL_ROLES_ADMIN);
    $userSet = $roleMgr->getUsersWithGlobalRole($dbHandler);
    $mail['subject'] = lang_get('new_account');
    $key2loop = array_keys($userSet);
    foreach ($key2loop as $userID) {
        $mail['to'][$userID] = $userSet[$userID]->emailAddress;
    }
    // email_api uses ',' as list separator
    $mail['to'] = implode(',', $mail['to']);
    $mail['body'] = lang_get('new_account') . "\n";
    $mail['body'] .= " user:{$userObj->login}\n";
    $mail['body'] .= " first name:{$userObj->firstName} surname:{$userObj->lastName}\n";
    $mail['body'] .= " email:{$userObj->emailAddress}\n";
    // silence errors
    @email_send(config_get('from_email'), $mail['to'], $mail['subject'], $mail['body']);
}
Exemple #3
0
function initializeGui(&$dbHandler, &$argsObj)
{
    $guiObj = new stdClass();
    $guiObj->highlight = initialize_tabsmenu();
    $guiObj->highlight->view_roles = 1;
    $guiObj->roles = tlRole::getAll($dbHandler, null, null, null, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM);
    $guiObj->grants = $argsObj->currentUser->getGrantsForUserMgmt($dbHandler);
    $guiObj->id = $argsObj->roleid;
    $guiObj->role_id_replacement = config_get('role_replace_for_deleted_roles');
    $guiObj->affectedUsers = null;
    $guiObj->userFeedback = '';
    $guiObj->tproject_id = $argsObj->tproject_id;
    return $guiObj;
}
 /**
  * Inserts a testplan related role for a given user
  *
  * @param int $userID the id of the user
  * @param int $id the testplan id
  * @param int $roleID the role id
  * 
  * @return integer returns tl::OK on success, tl::ERROR else
  **/
 function addUserRole($userID, $id, $roleID)
 {
     $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
     $status = tl::ERROR;
     $sql = " /* {$debugMsg} */ INSERT INTO {$this->tables['user_testplan_roles']} (user_id,testplan_id,role_id) VALUES " . " ({$userID},{$id},{$roleID})";
     if ($this->db->exec_query($sql)) {
         $testPlan = $this->get_by_id($id);
         $role = tlRole::getByID($this->db, $roleID, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM);
         $user = tlUser::getByID($this->db, $userID, tlUser::TLOBJ_O_GET_DETAIL_MINIMUM);
         if ($user && $testPlan && $role) {
             logAuditEvent(TLS("audit_users_roles_added_testplan", $user->getDisplayName(), $testPlan['name'], $role->name), "ASSIGN", $id, "testplans");
         }
         $status = tl::OK;
     }
     return $status;
 }
Exemple #5
0
function decodeRoleId(&$dbHandler, $roleID)
{
    $roleInfo = tlRole::getByID($dbHandler, $roleID);
    return $roleInfo->name;
}
Exemple #6
0
 /** 
  * @param resource &$db reference to database handler
  **/
 public static function doesRoleExist(&$db, $name, $id)
 {
     $role = new tlRole();
     $role->name = $name;
     if ($role->readFromDB($db, self::ROLE_O_SEARCH_BYNAME) >= tl::OK && $role->dbID != $id) {
         return $role->dbID;
     }
     return null;
 }
 /**
  * Inserts a testproject related role for a given user
  *
  * @param integer $userID the id of the user
  * @param integer $tproject_id
  * @param integer $roleID the role id
  * 
  * @return integer tl::OK on success, tl::ERROR else
  **/
 function addUserRole($userID, $tproject_id, $roleID)
 {
     $query = "INSERT INTO {$this->tables['user_testproject_roles']} " . "(user_id,testproject_id,role_id) VALUES ({$userID},{$tproject_id},{$roleID})";
     if ($this->db->exec_query($query)) {
         $testProject = $this->get_by_id($tproject_id);
         $role = tlRole::getByID($this->db, $roleID, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM);
         $user = tlUser::getByID($this->db, $userID, tlUser::TLOBJ_O_GET_DETAIL_MINIMUM);
         if ($user && $testProject && $role) {
             logAuditEvent(TLS("audit_users_roles_added_testproject", $user->getDisplayName(), $testProject['name'], $role->name), "ASSIGN", $tproject_id, "testprojects");
         }
         return tl::OK;
     }
     return tl::ERROR;
 }
function initializeGui(&$dbHandler, $argsObj)
{
    $gui = new stdClass();
    $gui->highlight = initialize_tabsmenu();
    $gui->user_feedback = '';
    $gui->no_features = '';
    $gui->roles_updated = '';
    $gui->tproject_name = $argsObj->testprojectName;
    $gui->featureType = $argsObj->featureType;
    $gui->optRights = tlRole::getAll($dbHandler, null, null, null, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM);
    $gui->features = null;
    $gui->featureID = null;
    $gui->role_colour = null;
    $guiCfg = config_get('gui');
    if ($guiCfg->usersAssignGlobalRoleColoring == ENABLED) {
        $gui->role_colour = tlRole::getRoleColourCfg($dbHandler);
    }
    return $gui;
}
function getRoleColourCfg(&$db)
{
    $role_colour = config_get('role_colour');
    $roles = tlRole::getAll($db, null, null, null, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM);
    unset($roles[TL_ROLES_UNDEFINED]);
    foreach ($roles as $roleObj) {
        if (!isset($role_colour[$roleObj->name])) {
            $role_colour[$roleObj->name] = '';
        }
    }
    return $role_colour;
}
 /**
  * Assign a user to a project
  *
  * @param struct $args
  * @param string $args["devKey"]
  * @param string $args["user"]
  * @param string $args["role"]
  * @param int    $args["testprojectid"]
  * @access public
  */
 public function assignUserToProject($args)
 {
     $this->_setArgs($args);
     if (!$this->authenticate()) {
         return $this->errors;
     }
     $login = $this->args[self::$userParamName];
     $role = $this->args['role'];
     $projectId = $this->args[self::$testProjectIDParamName];
     $userId = tlUser::doesUserExist($this->dbObj, $login);
     $roleId = tlRole::doesRoleExist($this->dbObj, $role, 0);
     $testProject = $this->tprojectMgr->get_by_id($projectId);
     $hasError = false;
     if (is_null($userId)) {
         $this->errors[] = new IXR_ERROR(100005, 'User does not exists');
         $hasError = true;
     } else {
         if (is_null($roleId)) {
             $this->errors[] = new IXR_ERROR(100006, 'Role does not exists');
             $hasError = true;
         } else {
             if (is_null($testProject)) {
                 $this->errors[] = new IXR_ERROR(100007, 'Project does not exists');
                 $hasError = true;
             }
         }
     }
     if ($hasError) {
         return $this->errors;
     }
     $userRoles = $this->tprojectMgr->getUserRoleIDs($projectId);
     $this->tprojectMgr->deleteUserRoles($projectId);
     foreach ($userRoles as $user_id => $role_id) {
         if ($user_id != $userId) {
             $this->tprojectMgr->addUserRole($user_id, $projectId, $role_id['role_id']);
         }
     }
     $this->tprojectMgr->addUserRole($userId, $projectId, $roleId);
 }
Exemple #11
0
function initializeGui(&$dbHandler, &$argsObj, $orderBy)
{
    $guiObj = new stdClass();
    $guiObj->highlight = initialize_tabsmenu();
    $guiObj->highlight->view_users = 1;
    $guiObj->update_title_bar = 0;
    $guiObj->reload = 0;
    $guiObj->user_order_by = $argsObj->user_order_by;
    $guiObj->order_by_role_dir = $argsObj->order_by_dir['order_by_role_dir'];
    $guiObj->order_by_login_dir = $argsObj->order_by_dir['order_by_login_dir'];
    $guiObj->checked_hide_inactive_users = $argsObj->checked_hide_inactive_users;
    $guiObj->base_href = $argsObj->basehref;
    $guiObj->body_onload = $argsObj->body_onload;
    $guiObj->role_colour = tlRole::getRoleColourCfg($dbHandler);
    $guiObj->users = tlUser::getAllUsersRoles($dbHandler, get_order_by_clause($orderBy));
    $guiObj->grants = $argsObj->currentUser->getGrantsForUserMgmt($dbHandler, $argsObj->tproject_id);
    $guiObj->tproject_id = $argsObj->tproject_id;
    return $guiObj;
}
Exemple #12
0
$editorCfg = getWebEditorCfg('role');
require_once require_web_editor($editorCfg['type']);
testlinkInitPage($db, false, false, "checkRights");
init_global_rights_maps();
$templateCfg = templateConfiguration();
$args = init_args();
$gui = initialize_gui($editorCfg['type']);
$op = initialize_op();
$owebeditor = web_editor('notes', $args->basehref, $editorCfg);
$owebeditor->Value = getItemTemplateContents('role_template', $owebeditor->InstanceName, null);
$canManage = has_rights($db, "role_management") ? true : false;
switch ($args->doAction) {
    case 'create':
        break;
    case 'edit':
        $op->role = tlRole::getByID($db, $args->roleid);
        break;
    case 'doCreate':
    case 'doUpdate':
        if ($canManage) {
            $op = doOperation($db, $args, $args->doAction);
            $templateCfg->template = $op->template;
        }
        break;
    default:
        break;
}
$gui = complete_gui($db, $gui, $args, $op->role, $owebeditor);
$gui->userFeedback = $op->userFeedback;
$smarty = new TLSmarty();
$smarty->assign('gui', $gui);
Exemple #13
0
        if ($role) {
            $affectedUsers = $role->getAllUsersWithRole($db);
            $doDelete = sizeof($affectedUsers) == 0;
        }
        break;
    case 'confirmDelete':
        $doDelete = 1;
        break;
}
$userFeedback = null;
if ($doDelete) {
    $userFeedback = deleteRole($db, $args->roleid);
    //refresh the current user
    checkSessionValid($db);
}
$roles = tlRole::getAll($db, null, null, null, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM);
$highlight = initialize_tabsmenu();
$highlight->view_roles = 1;
$smarty = new TLSmarty();
$smarty->assign('highlight', $highlight);
$smarty->assign('grants', getGrantsForUserMgmt($db, $args->currentUser));
$smarty->assign('roles', $roles);
$smarty->assign('id', $args->roleid);
$smarty->assign('sqlResult', $userFeedback);
$smarty->assign('affectedUsers', $affectedUsers);
$smarty->assign('role_id_replacement', config_get('role_replace_for_deleted_roles'));
$smarty->display($templateCfg->template_dir . $templateCfg->default_template);
/**
 * @return object returns the arguments for the page
 */
function init_args()
Exemple #14
0
function deleteRole(&$db, $roleID)
{
    $userFeedback = '';
    $role = new tlRole($roleID);
    $role->readFromDb($db);
    if ($role->deleteFromDB($db) < tl::OK) {
        $userFeedback = lang_get("error_role_deletion");
    } else {
        logAuditEvent(TLS("audit_role_deleted", $role->getDisplayName()), "DELETE", $roleID, "roles");
    }
    return $userFeedback;
}
Exemple #15
0
 /**
  * Fetches all the testplan roles of of the user, and store them into the object. 
  * Result could be limited to a certain testplan
  * 
  * @param resource &$db reference to database handler
  * @param integer $testPlanID Identifier of the testplan to read the roles for, if null all roles are read
  * 
  * @return integer returns tl::OK 
  */
 public function readTestPlanRoles(&$db, $testPlanID = null)
 {
     $sql = "SELECT testplan_id,role_id " . " FROM {$this->tables['user_testplan_roles']} user_testplan_roles " . " WHERE user_id = {$this->dbID}";
     if ($testPlanID) {
         $sql .= " AND testplan_id = {$testPlanID}";
     }
     $allRoles = $db->fetchColumnsIntoMap($sql, 'testplan_id', 'role_id');
     $this->tplanRoles = null;
     if (sizeof($allRoles)) {
         $roleCache = null;
         foreach ($allRoles as $tplanID => $roleID) {
             if (!isset($roleCache[$roleID])) {
                 $tplanRole = tlRole::createObjectFromDB($db, $roleID, "tlRole", true);
                 $roleCache[$roleID] = $tplanRole;
             } else {
                 $tplanRole = clone $roleCache[$roleID];
             }
             if ($tplanRole) {
                 $this->tplanRoles[$tplanID] = $tplanRole;
             }
         }
     }
     return tl::OK;
 }
Exemple #16
0
/**
 * send mail to administrators (users that have default role = administrator) 
 * to warn about new user created.
 *
 */
function notifyGlobalAdmins(&$dbHandler, &$userObj)
{
    // Get email addresses for all users that have default role = administrator
    $cfg = config_get('notifications');
    if (!is_null($cfg->userSignUp->to->roles)) {
        foreach ($cfg->userSignUp->to->roles as $roleID) {
            $roleMgr = new tlRole($roleID);
            $userSet = $roleMgr->getUsersWithGlobalRole($dbHandler);
            $key2loop = array_keys($userSet);
            foreach ($key2loop as $userID) {
                if (!isset($mail['to'][$userID])) {
                    $mail['to'][$userID] = $userSet[$userID]->emailAddress;
                }
            }
        }
    }
    if (!is_null($cfg->userSignUp->to->users)) {
        // Brute force query
        $tables = tlObject::getDBTables('users');
        $sql = " SELECT id,email FROM {$tables['users']} " . " WHERE login IN('" . implode("','", $cfg->userSignUp->to->users) . "')";
        $userSet = $dbHandler->fetchRowsIntoMap($sql, 'id');
        if (!is_null($userSet)) {
            foreach ($userSet as $userID => $elem) {
                if (!isset($mail['to'][$userID])) {
                    $mail['to'][$userID] = $elem['email'];
                }
            }
        }
    }
    $mail['to'] = implode(',', $mail['to']);
    // email_api uses ',' as list separator
    $mail['subject'] = lang_get('new_account');
    $mail['body'] = lang_get('new_account') . "\n";
    $mail['body'] .= " user:{$userObj->login}\n";
    $mail['body'] .= " first name:{$userObj->firstName} surname:{$userObj->lastName}\n";
    $mail['body'] .= " email:{$userObj->emailAddress}\n";
    // silence errors
    @email_send(config_get('from_email'), $mail['to'], $mail['subject'], $mail['body']);
}
Exemple #17
0
$tprojectMgr = new testproject($db);
$tplanMgr = new testplan($db);
$args = init_args();
$gui = new stdClass();
$gui->highlight = initialize_tabsmenu();
$gui->user_feedback = '';
$gui->no_features = '';
$gui->roles_updated = '';
$gui->tproject_name = $args->testprojectName;
$gui->optRights = tlRole::getAll($db, null, null, null, tlRole::TLOBJ_O_GET_DETAIL_MINIMUM);
$gui->features = null;
$gui->featureType = $args->featureType;
$gui->featureID = null;
$gui->role_colour = null;
if ($guiCfg->usersAssignGlobalRoleColoring == ENABLED) {
    $gui->role_colour = tlRole::getRoleColourCfg($db);
}
$target = new stdClass();
$target->testprojectID = null;
$target->testplanID = null;
switch ($args->featureType) {
    case "testproject":
        $gui->highlight->assign_users_tproject = 1;
        $gui->roles_updated = lang_get("test_project_user_roles_updated");
        $gui->not_for_you = lang_get("testproject_roles_assign_disabled");
        $assignRolesFor = $args->featureType;
        $target->testprojectID = $args->featureID > 0 ? $args->featureID : null;
        $featureMgr =& $tprojectMgr;
        break;
    case "testplan":
        $gui->highlight->assign_users_tplan = 1;