fixing some style and renaming Account to User API
This commit is contained in:
parent
e5a447c148
commit
9ced1dc008
@ -98,16 +98,16 @@ class CommandeApi extends DolibarrApi
|
|||||||
* Get a list of orders
|
* Get a list of orders
|
||||||
*
|
*
|
||||||
* @param int $mode Use this param to filter list
|
* @param int $mode Use this param to filter list
|
||||||
* @param string $societe Societe filter field
|
|
||||||
* @param string $sortfield Sort field
|
* @param string $sortfield Sort field
|
||||||
* @param string $sortorder Sort order
|
* @param string $sortorder Sort order
|
||||||
* @param int $limit Limit for list
|
* @param int $limit Limit for list
|
||||||
* @param int $page Page number
|
* @param int $page Page number
|
||||||
|
* @param string $societe Societe filter field
|
||||||
*
|
*
|
||||||
* @url GET /order/list
|
* @url GET /order/list
|
||||||
* @return array Array of order objects
|
* @return array Array of order objects
|
||||||
*/
|
*/
|
||||||
function getList($mode=0, $societe = "", $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
|
function getList($mode=0, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $societe = 0) {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
@ -191,8 +191,8 @@ class CommandeApi extends DolibarrApi
|
|||||||
* @url GET /thirdparty/{socid}/order/list
|
* @url GET /thirdparty/{socid}/order/list
|
||||||
* @return array Array of order objects
|
* @return array Array of order objects
|
||||||
*/
|
*/
|
||||||
function getListForSoc($socid = "") {
|
function getListForSoc($socid = 0) {
|
||||||
return getList(0,$socid);
|
return getList(0,"s.rowid","ASC",0,0,$socid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ use Luracast\Restler\RestException;
|
|||||||
* @class DolibarrApiAccess {@requires user,external}
|
* @class DolibarrApiAccess {@requires user,external}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class AccountApi extends DolibarrApi
|
class UserApi extends DolibarrApi
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -38,68 +38,66 @@ class AccountApi extends DolibarrApi
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var User $account {@type User}
|
* @var User $user {@type User}
|
||||||
*/
|
*/
|
||||||
public $account;
|
public $useraccount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @url account/
|
* @url user/
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
function __construct() {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->account = new User($this->db);
|
$this->useraccount = new User($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get properties of an account object
|
* Get properties of an user object
|
||||||
*
|
*
|
||||||
* Return an array with account informations
|
* Return an array with user informations
|
||||||
*
|
*
|
||||||
* @param int $id ID of account
|
* @param int $id ID of user
|
||||||
* @return array|mixed data without useless information
|
* @return array|mixed data without useless information
|
||||||
*
|
*
|
||||||
* @url GET account/{user}
|
* @url GET user/{id}
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function get($id) {
|
function get($id) {
|
||||||
//if (!DolibarrApiAccess::$user->rights->user->lire)
|
//if (!DolibarrApiAccess::$user->rights->user->user->lire) {
|
||||||
//{
|
|
||||||
//throw new RestException(401);
|
//throw new RestException(401);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
$result = $this->account->fetch($id);
|
$result = $this->useraccount->fetch($id);
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
throw new RestException(404, 'User not found');
|
throw new RestException(404, 'User not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DolibarrApi::_checkAccessToResource('user', $this->account->id, 'user'))
|
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
|
||||||
{
|
{
|
||||||
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_cleanObjectDatas($this->account);
|
return $this->_cleanObjectDatas($this->useraccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create account object from contact
|
* Create useraccount object from contact
|
||||||
*
|
*
|
||||||
* @param int $contactid Id of contact
|
* @param int $contactid Id of contact
|
||||||
* @param array $request_data Request datas
|
* @param array $request_data Request datas
|
||||||
* @return int ID of account
|
* @return int ID of user
|
||||||
*
|
*
|
||||||
* @url POST /contact/{contactid}/createAccount
|
* @url POST /contact/{contactid}/createUser
|
||||||
*/
|
*/
|
||||||
function createFromContact($contactid, $request_data = NULL) {
|
function createFromContact($contactid, $request_data = NULL) {
|
||||||
//if (!DolibarrApiAccess::$user->rights->user->creer)
|
//if (!DolibarrApiAccess::$user->rights->user->user->creer) {
|
||||||
//{
|
|
||||||
//throw new RestException(401);
|
//throw new RestException(401);
|
||||||
//}
|
//}
|
||||||
//
|
|
||||||
if (!isset($request_data["login"]))
|
if (!isset($request_data["login"]))
|
||||||
throw new RestException(400, "login field missing");
|
throw new RestException(400, "login field missing");
|
||||||
if (!isset($request_data["password"]))
|
if (!isset($request_data["password"]))
|
||||||
@ -119,12 +117,12 @@ class AccountApi extends DolibarrApi
|
|||||||
// Check mandatory fields
|
// Check mandatory fields
|
||||||
$login = $request_data["login"];
|
$login = $request_data["login"];
|
||||||
$password = $request_data["password"];
|
$password = $request_data["password"];
|
||||||
$result = $this->account->create_from_contact($contact,$login,$password);
|
$result = $this->useraccount->create_from_contact($contact,$login,$password);
|
||||||
if ($result <= 0) {
|
if ($result <= 0) {
|
||||||
throw new RestException(500, "User not created");
|
throw new RestException(500, "User not created");
|
||||||
}
|
}
|
||||||
// password parameter not used in create_from_contact
|
// password parameter not used in create_from_contact
|
||||||
$this->account->setPassword($this->account,$password);
|
$this->useraccount->setPassword($this->useraccount,$password);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,31 +133,30 @@ class AccountApi extends DolibarrApi
|
|||||||
* @param array $request_data Datas
|
* @param array $request_data Datas
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
* @url PUT account/{id}
|
* @url PUT user/{id}
|
||||||
*/
|
*/
|
||||||
function put($id, $request_data = NULL) {
|
function put($id, $request_data = NULL) {
|
||||||
//if (!DolibarrApiAccess::$user->rights->user->creer)
|
//if (!DolibarrApiAccess::$user->rights->user->user->creer) {
|
||||||
//{//
|
|
||||||
//throw new RestException(401);
|
//throw new RestException(401);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
$result = $this->account->fetch($id);
|
$result = $this->useraccount->fetch($id);
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
throw new RestException(404, 'Account not found');
|
throw new RestException(404, 'Account not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DolibarrApi::_checkAccessToResource('user', $this->account->id, 'user'))
|
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
|
||||||
{
|
{
|
||||||
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($request_data as $field => $value)
|
foreach ($request_data as $field => $value)
|
||||||
{
|
{
|
||||||
$this->account->$field = $value;
|
$this->useraccount->$field = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->account->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
|
if ($this->useraccount->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
|
||||||
return $this->get($id);
|
return $this->get($id);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -171,25 +168,24 @@ class AccountApi extends DolibarrApi
|
|||||||
* @param int $id Account ID
|
* @param int $id Account ID
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @url DELETE account/{id}
|
* @url DELETE user/{id}
|
||||||
*/
|
*/
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
//if (!DolibarrApiAccess::$user->rights->user->supprimer)
|
//if (!DolibarrApiAccess::$user->rights->user->user->supprimer) {
|
||||||
//{
|
|
||||||
//throw new RestException(401);
|
//throw new RestException(401);
|
||||||
//}
|
//}
|
||||||
$result = $this->account->fetch($id);
|
$result = $this->useraccount->fetch($id);
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
throw new RestException(404, 'User not found');
|
throw new RestException(404, 'User not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DolibarrApi::_checkAccessToResource('user', $this->account->id, 'user'))
|
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
|
||||||
{
|
{
|
||||||
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->account->delete($id);
|
return $this->useraccount->delete($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Loading…
Reference in New Issue
Block a user