NEW API get users by email / login

This commit is contained in:
ptibogxiv 2020-08-31 17:09:14 +02:00 committed by GitHub
parent 0a93954134
commit c8e0bcd710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
/* Copyright (C) 2030 Thibault FOUCART <support@ptibogxiv.net>
/* Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -143,13 +143,13 @@ class Users extends DolibarrApi
/**
* Get properties of an user object
* Return an array with user informations
*
* @param int $id ID of user
* @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)
* @return array|mixed data without useless information
*
* @throws RestException
* @throws RestException 401 Insufficient rights
* @throws RestException 404 User or group not found
*/
public function get($id, $includepermissions = 0)
{
@ -174,6 +174,78 @@ class Users extends DolibarrApi
return $this->_cleanObjectDatas($this->useraccount);
}
/**
* Get properties of an user object by login
*
* @param string $login Login of user
* @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)
* @return array|mixed data without useless information
*
* @url GET login/{login}
*
* @throws RestException 401 Insufficient rights
* @throws RestException 404 User or group not found
*/
public function getByLogin($login, $includepermissions = 0)
{
//if (!DolibarrApiAccess::$user->rights->user->user->lire) {
//throw new RestException(401);
//}
$result = $this->useraccount->fetch('', $login);
if (!$result)
{
throw new RestException(404, 'User not found');
}
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
{
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ($includepermissions) {
$this->useraccount->getRights();
}
return $this->_cleanObjectDatas($this->useraccount);
}
/**
* Get properties of an user object by Email
*
* @param string $email Email of user
* @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)
* @return array|mixed data without useless information
*
* @url GET email/{email}
*
* @throws RestException 401 Insufficient rights
* @throws RestException 404 User or group not found
*/
public function getByEmail($email, $includepermissions = 0)
{
//if (!DolibarrApiAccess::$user->rights->user->user->lire) {
//throw new RestException(401);
//}
$result = $this->useraccount->fetch('', '', '', 0, -1, $email);
if (!$result)
{
throw new RestException(404, 'User not found');
}
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
{
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ($includepermissions) {
$this->useraccount->getRights();
}
return $this->_cleanObjectDatas($this->useraccount);
}
/**
* Get properties of user connected