Adding Users using the api

Discussion and information for XML-RPC interface.

Moderators: Amaradana, TurboPT, TL Developers

Adding Users using the api

Postby Tharindu_Amila » Thu Mar 27, 2014 9:27 am

Hello,

Is there a method to add users to the user base using the api. What I need is to authenticate users using an external LDAP. I was following this tutorial
http://blog.frogslayer.com/get-testlink ... ntication/ . But adding users manually is cumbersome.
Tharindu_Amila
TestLink user
 
Posts: 4
Joined: Wed Mar 19, 2014 8:22 pm

Re: Adding Users using the api

Postby fman » Thu Mar 27, 2014 10:40 am

most updated info is in the xmlrpc code => all the available methods are there.

IMHO having API for this is not very useful.
IMHO is enough that you are able to create all the SQL statements you need to add users on users table, for the initial/massive user creation.

feel free to add the call to the API and provide your implementation to community

Just for the records. the link you have provided is nothing more that same info that exists on config.inc.php file, just with better cosmetics.
fman
Member of TestLink Community
 
Posts: 3024
Joined: Tue Nov 15, 2005 7:19 am

Re: Adding Users using the api

Postby Tharindu_Amila » Mon Mar 31, 2014 12:42 pm

Thank you for the feedback fman :D.
My scenario is like this.
1] The application that is going to integrate TestLink is an application creation and management application.
2] There will be multiple projects in one instance of the application.
3] The roles in our app are app owners, developers, devops and testers.
4] When an app promotes to the life cycle stage of dev to test testlink must create a test project for it.
5] The testers assigned must be able to login with there usual credentials and see the projects assigned to them.

The current api enabled creating projects and assignment but user provisioning was not there. I'm going to add users only on need to stop clutering of the database and easy management.
I'm currently writing addUser function for the api. Hope it is not going out of your concepts. :D
Tharindu_Amila
TestLink user
 
Posts: 4
Joined: Wed Mar 19, 2014 8:22 pm

Re: Adding Users using the api

Postby fman » Mon Mar 31, 2014 10:05 pm

if you create the method there is no problem, I would ask you to share it with community.
My point is : I do not consider it worth enough to put in my task list, but if someone do the effort, after reviewing the code I can add it to standard code.
fman
Member of TestLink Community
 
Posts: 3024
Joined: Tue Nov 15, 2005 7:19 am

Re: Adding Users using the api

Postby Tharindu_Amila » Tue Apr 01, 2014 7:59 am

I've created two functions one to add a user and the other to delete the user
The function to delete users which may create database issues so maybe not needed.
/**
*Delete a user from the users table
*@param struct $args should contain $args['login'] parameter and $args['devKey']
*/
public function deleteUser($args){
$this->_setArgs($args);
$checkFunctions = array('authenticate');
$status_ok = $this->_runChecks($checkFunctions)
&& $this->userHasRight('mgt_users');
if($this->args['login']!=null && $status_ok){
$sql = "DELETE FROM `{$this->tables['users']}` ".
"WHERE (`login` = '{$this->args['login']}');";
$result = $this->dbObj->exec_query($sql);
}else{
$result = "Invalid arguments";
}
return $status_ok ? $result : $this->errors;
}

But the issue with user addition is setting the cookie_string which needs to be unique. What is it used for?. And can you please explain how it should be generated.
This is the user addition with just a dummy cookie_string assignment which needs to be refractored.

/**
*Add a user to the users table
*Input must include a login
*Input can include email,first name, last name and a role id
*A dev key is needed in the struct if a role is being assigned to the user
*/
public function insertUser($args){
$this->_setArgs($args);
if($this->args['login']!= null){
$checkFunctions = array('authenticate');
$status_ok = $this->_runChecks($checkFunctions)
&& $this->userHasRight('user_role_assignment')
&& $this->userHasRight('mgt_users');

$sqlPart1 = "INSERT INTO `{$this->tables['users']}` (`login`";
$sqlPart2 = "VALUES ('{$this->args['login']}'";

if($this->args['email'] != null){
$sqlPart1 .= ", `email`";
$sqlPart2 .= ", '{$this->args['email']}'";
}
if($this->args['first'] != null){
$sqlPart1 .= ", `first`";
$sqlPart2 .= ", '{$this->args['first']}'";
}
if($this->args['last'] != null){
$sqlPart1 .= ", `last`";
$sqlPart2 .= ", '{$this->args['last']}'";
}
if($this->args['role_id'] != null){
if($status_ok){
$sqlPart1 .= ", `role_id`";
$sqlPart2 .= ", '{$this->args['role_id']}'";
}else{
return $this->errors;
}
}
$cookieString = $this->args['login'] . "just_checking";
$sqlPart1 .= ", `cookie_string`";
$sqlPart2 .= ", '{$cookieString}'";
$sql = $sqlPart1 . ") " . $sqlPart2 . ") ;";
$result = $this->dbObj->exec_query($sql);
return $result;
}else{
return "invalid arguments";
}
}
Tharindu_Amila
TestLink user
 
Posts: 4
Joined: Wed Mar 19, 2014 8:22 pm

Re: Adding Users using the api

Postby Tharindu_Amila » Wed Apr 02, 2014 5:09 pm

Created mantis feature request and added code as a note. http://mantis.testlink.org/view.php?id=6278
Tharindu_Amila
TestLink user
 
Posts: 4
Joined: Wed Mar 19, 2014 8:22 pm


Return to XML-RPC API



Who is online

Users browsing this forum: No registered users and 2 guests