dolibarr 24.0.0-beta
Users Class Reference
Inheritance diagram for Users:
Collaboration diagram for Users:

Public Member Functions

 __construct ()
 Constructor.
 
 index ($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $user_ids='0', $category=0, $sqlfilters='', $properties='')
 List users.
 
 get ($id, $includepermissions=0)
 Get a user.
 
 getByLogin ($login, $includepermissions=0)
 Get a user by login.
 
 getByEmail ($email, $includepermissions=0)
 Get a user by email.
 
 getInfo ($includepermissions=0)
 Get more properties of the current user (so user of API token).
 
 post ($request_data=null)
 Create a user.
 
 put ($id, $request_data=null)
 Update a user.
 
 setPassword ($id, $send_password=false)
 Update a user password.
 
 getGroups ($id)
 List the groups of a user.
 
 setGroup ($id, $group, $entity=1)
 Add a user to a group.
 
 postGroups ($request_data=null)
 Create user group.
 
 putGroups ($group, $request_data=null)
 Update user group.
 
 removeUserFromGroup ($id, $group)
 Remove user from group (only admin)
 
 listGroups ($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $group_ids='0', $sqlfilters='', $properties='')
 List groups of the current user (so user of API token)
 
 infoGroups ($group, $load_members=0, $includepermissions=0)
 Get properties of a user group.
 
 delete ($id)
 Delete a user.
 
 deleteGroups ($group)
 Delete a usergroup.
 
 getUserNotification ($id)
 Get notifications for a user.
 
 createUserNotification ($id, $request_data=null)
 Create a notification for a user.
 
 createUserNotificationByCode ($id, $code, $request_data=null)
 Create a notification for a user using action trigger code.
 
 deleteUserNotification ($id, $notification_id)
 Delete a notification attached to a user.
 
 updateUserNotification ($id, $notification_id, $request_data=null)
 Update a notification for a user.
 
- Public Member Functions inherited from DolibarrApi
 __construct ($db, $cachedir='', $refreshCache=false)
 Constructor.
 

Protected Member Functions

 _cleanObjectDatas ($object)
 Clean sensible object datas @phpstan-template T.
 
- Protected Member Functions inherited from DolibarrApi
 _checkValForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name.
 
 _checkValExtrafieldsForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name.
 
 _filterObjectProperties ($object, $properties)
 Filter properties that will be returned on object.
 
 _checkFilters ($sqlfilters, &$error='')
 Return if a $sqlfilters parameter is valid Function no more used.
 

Private Member Functions

 _cleanUserGroup ($object)
 Clean sensible usergroup object datas.
 
 _cleanUserGroupListDatas ($objectList)
 Clean sensible user group list datas.
 
 _validate ($data)
 Validate fields before create or update object.
 

Additional Inherited Members

- Static Protected Member Functions inherited from DolibarrApi
static _checkAccessToResource ($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
 Check access by user to a given resource.
 
static _forge_criteria_callback ($matches)
 Function to forge a SQL criteria from a Generic filter string.
 

Detailed Description

Definition at line 39 of file api_users.class.php.

Member Function Documentation

◆ _cleanObjectDatas()

Users::_cleanObjectDatas ( $object)
protected

Clean sensible object datas @phpstan-template T.

Parameters
Object$objectObject to clean
Returns
Object Object with cleaned properties @phpstan-param T $object @phpstan-return T

Reimplemented from DolibarrApi.

Definition at line 1289 of file api_users.class.php.

References $object, and isModEnabled().

Referenced by createUserNotification(), createUserNotificationByCode(), get(), getByEmail(), getByLogin(), getGroups(), getInfo(), index(), infoGroups(), listGroups(), and updateUserNotification().

◆ _cleanUserGroup()

Users::_cleanUserGroup ( $object)
private

Clean sensible usergroup object datas.

Parameters
Object$objectObject to clean
Returns
Object Object with cleaned properties

Definition at line 1347 of file api_users.class.php.

References $object.

Referenced by infoGroups().

◆ _cleanUserGroupListDatas()

Users::_cleanUserGroupListDatas ( $objectList)
private

Clean sensible user group list datas.

Parameters
array<UserGroup>$objectList Array of object to clean
Returns
array<UserGroup> Array of cleaned object properties

Definition at line 1448 of file api_users.class.php.

References $object.

Referenced by getInfo().

◆ _validate()

Users::_validate ( $data)
private

Validate fields before create or update object.

Parameters
?array<string,mixed>$data Data to validate
Returns
array<string,mixed>
Exceptions
RestException

Definition at line 1496 of file api_users.class.php.

◆ createUserNotification()

Users::createUserNotification ( $id,
$request_data = null )

Create a notification for a user.

Since
22.0.0 Initial implementation
Parameters
int$idID of the user
array$request_dataRequest data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
array|mixed Notification of the user

@url POST {id}/notifications

Exceptions
RestException

Definition at line 1086 of file api_users.class.php.

References $id, DolibarrApi\_checkValForAPI(), and _cleanObjectDatas().

◆ createUserNotificationByCode()

Users::createUserNotificationByCode ( $id,
$code,
$request_data = null )

Create a notification for a user using action trigger code.

Since
22.0.0 Initial implementation
Parameters
int$idID of the user
string$codeAction Trigger code
array$request_dataRequest data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
array|mixed Notification for the user @phan-return Notify

@url POST {id}/notificationsbycode/{code}

Exceptions
RestException

Definition at line 1147 of file api_users.class.php.

References $id, DolibarrApi\_checkValForAPI(), and _cleanObjectDatas().

◆ delete()

Users::delete ( $id)

Delete a user.

Since
5.0.0 Initial implementation
Parameters
int$idAccount ID
Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException403 Not allowed
RestException404 User not found

Definition at line 926 of file api_users.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deleteGroups()

Users::deleteGroups ( $group)

Delete a usergroup.

Since
23.0.0 Initial implementation
Parameters
int$groupusergroup ID
Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}

@url DELETE /groups/{group}

Exceptions
RestException403 Not allowed
RestException404 User not found

Definition at line 968 of file api_users.class.php.

◆ deleteUserNotification()

Users::deleteUserNotification ( $id,
$notification_id )

Delete a notification attached to a user.

Since
22.0.0 Initial implementation
Parameters
int$idID of the user
int$notification_idID of UserNotification
Returns
int -1 if error, 1 if correct deletion

@url DELETE {id}/notifications/{notification_id}

Exceptions
RestException

Definition at line 1215 of file api_users.class.php.

References $id.

◆ get()

Users::get ( $id,
$includepermissions = 0 )

Get a user.

Since
5.0.0 Initial implementation
Parameters
int$idID of user
int$includepermissionsSet this to 1 to have the array of permissions loaded (not done by default for performance purpose)
Returns
array|mixed data without useless information @phan-return Object @phpstan-return Object
Exceptions
RestException400 Bad request
RestException401 Insufficient rights
RestException404 User or group not found

Definition at line 168 of file api_users.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and _cleanObjectDatas().

◆ getByEmail()

Users::getByEmail ( $email,
$includepermissions = 0 )

Get a user by email.

Since
13.0.0 Initial implementation
Parameters
string$emailEmail of user
int$includepermissionsSet this to 1 to have the array of permissions loaded (not done by default for performance purpose)
Returns
array|mixed Data without useless information @phan-return Object @phpstan-return Object

@url GET email/{email}

Exceptions
RestException400 Bad request
RestException401 Insufficient rights
RestException404 User or group not found

Definition at line 258 of file api_users.class.php.

References DolibarrApi\_checkAccessToResource(), _cleanObjectDatas(), and email.

◆ getByLogin()

Users::getByLogin ( $login,
$includepermissions = 0 )

Get a user by login.

Since
13.0.0 Initial implementation
Parameters
string$loginLogin of user
int$includepermissionsSet this to 1 to have the array of permissions loaded (not done by default for performance purpose)
Returns
array|mixed Data without useless information @phan-return Object @phpstan-return Object

@url GET login/{login}

Exceptions
RestException400 Bad request
RestException401 Insufficient rights
RestException404 User or group not found

Definition at line 215 of file api_users.class.php.

References DolibarrApi\_checkAccessToResource(), and _cleanObjectDatas().

◆ getGroups()

Users::getGroups ( $id)

List the groups of a user.

Since
10.0.0 Initial implementation
Parameters
int$idId of user
Returns
array Array of group objects @phan-return Object[] @phpstan-return Object[]
Exceptions
RestException400 Bad request
RestException403 Not allowed
RestException404 Not found

@url GET {id}/groups

Definition at line 574 of file api_users.class.php.

References $id, and _cleanObjectDatas().

◆ getInfo()

Users::getInfo ( $includepermissions = 0)

Get more properties of the current user (so user of API token).

This route could also ave been named "/users/me".

Since
11.0.0 Initial implementation

@url GET /info

Parameters
int$includepermissionsSet this to 1 to have the array of permissions loaded (not done by default for performance purpose)
Returns
array|mixed Data without useless information
Exceptions
RestException401 Insufficient rights
RestException404 User or group not found

Definition at line 299 of file api_users.class.php.

References DolibarrApi\_checkAccessToResource(), _cleanObjectDatas(), and _cleanUserGroupListDatas().

◆ getUserNotification()

Users::getUserNotification ( $id)

Get notifications for a user.

Since
22.0.0 Initial implementation
Parameters
int$idID of the user
Returns
array @phan-return array<array{id:int,socid:int,event:string,contact_id:int,datec:int,tms:string,type:string}> @phpstan-return array<array{id:int,socid:int,event:string,contact_id:int,datec:int,tms:string,type:string}>

@url GET {id}/notifications

Exceptions
RestException400 Bad Request
RestException403 Access denied
RestException404 Not found

We select all the records that match the socid

Definition at line 1010 of file api_users.class.php.

References $id, $object, and DolibarrApi\_checkAccessToResource().

◆ index()

Users::index ( $sortfield = "t.rowid",
$sortorder = 'ASC',
$limit = 100,
$page = 0,
$user_ids = '0',
$category = 0,
$sqlfilters = '',
$properties = '' )

List users.

Get a list of Users

Since
5.0.0 Initial implementation
Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
string$user_idsUser ids filter field. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i}
int$categoryUse this param to filter list by category
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:>:'20160101')"
string$propertiesRestrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
Returns
array Array of User objects @phan-return Object[] @phpstan-return Object[]
Exceptions
RestException

Definition at line 86 of file api_users.class.php.

References _cleanObjectDatas(), and DolibarrApi\_filterObjectProperties().

◆ infoGroups()

Users::infoGroups ( $group,
$load_members = 0,
$includepermissions = 0 )

Get properties of a user group.

Return an array with group information

Since
11.0.0 Initial implementation

@url GET /groups/{group}

Parameters
int$groupID of group
int$load_membersLoad members list or not {@min 0} {@max 1}
int$includepermissionsSet this to 1 to have the array of permissions loaded (not done by default for performance purpose)
Returns
Object object of User objects
Exceptions
RestException400 Bad Request
RestException403 Not allowed
RestException404 User not found

Definition at line 882 of file api_users.class.php.

References _cleanObjectDatas(), _cleanUserGroup(), and getDolGlobalString().

Referenced by putGroups().

◆ listGroups()

Users::listGroups ( $sortfield = "t.rowid",
$sortorder = 'ASC',
$limit = 100,
$page = 0,
$group_ids = '0',
$sqlfilters = '',
$properties = '' )

List groups of the current user (so user of API token)

Return an array with a list of Groups

Since
11.0.0 Initial implementation

@url GET /groups

Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
string$group_idsGroups ids filter field. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i}
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:>:'20160101')"
string$propertiesRestrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
Returns
array Array of User objects @phan-return Object[] @phpstan-return Object[]
Exceptions
RestException403 Not allowed
RestException404 User not found
RestException503 Error

Definition at line 806 of file api_users.class.php.

References _cleanObjectDatas(), DolibarrApi\_filterObjectProperties(), and getDolGlobalString().

◆ post()

Users::post ( $request_data = null)

Create a user.

Since
5.0.0 Initial implementation
Parameters
array$request_dataNew user data @phan-param ?array<string,mixed> $request_data @phpstan-param ?array<string,mixed> $request_data
Returns
int
Exceptions
RestException403 Not allowed

Definition at line 343 of file api_users.class.php.

References DolibarrApi\_checkValForAPI(), and sanitizeVal().

◆ postGroups()

Users::postGroups ( $request_data = null)

Create user group.

Parameters
array$request_dataNew user group data @phan-param ?array<string,mixed> $request_data @phpstan-param ?array<string,mixed> $request_data
Returns
int

@url POST /groups

Exceptions
RestException400 Bad Request
RestException403 Not allowed
RestException500 Server Error

Definition at line 662 of file api_users.class.php.

References DolibarrApi\_checkValForAPI(), and sanitizeVal().

◆ put()

Users::put ( $id,
$request_data = null )

Update a user.

Since
5.0.0 Initial implementation
Parameters
int$idId of account to update
array$request_dataDatas @phan-param ?array<string,mixed> $request_data @phpstan-param ?array<string,mixed> $request_data
Returns
Object Updated object
Exceptions
RestException403 Not allowed
RestException404 Not found
RestException500 System error

Definition at line 412 of file api_users.class.php.

References $id, DolibarrApi\_checkAccessToResource(), DolibarrApi\_checkValExtrafieldsForAPI(), DolibarrApi\_checkValForAPI(), and sanitizeVal().

◆ putGroups()

Users::putGroups ( $group,
$request_data = null )

Update user group.

Since
23.0.0 Initial implementation
Parameters
int$groupId of usergroup to update
array$request_dataDatas @phan-param ?array<string,mixed> $request_data @phpstan-param ?array<string,mixed> $request_data
Returns
Object Updated object

@url PUT /groups/{group}

Exceptions
RestException400 Bad Request
RestException403 Not allowed
RestException500 Server Error

Definition at line 705 of file api_users.class.php.

References DolibarrApi\_checkValForAPI(), infoGroups(), and sanitizeVal().

◆ removeUserFromGroup()

Users::removeUserFromGroup ( $id,
$group )

Remove user from group (only admin)

Since
23.0.0 Initial implementation

@url POST {id}/remove-group/{group}

Parameters
int$idUser ID
int$groupGroup ID
Returns
array{success:boolean,message:string}
Exceptions
RestException403 Not allowed - only admin
RestException503 Error

Definition at line 760 of file api_users.class.php.

References $id.

◆ setGroup()

Users::setGroup ( $id,
$group,
$entity = 1 )

Add a user to a group.

Since
5.0.0 Initial implementation
Parameters
int$idUser ID
int$groupGroup ID
int$entityEntity ID (valid only for superadmin in multicompany transverse mode)
Returns
int 1 if success
Exceptions
RestException403 Not allowed
RestException404 User not found
RestException500 System error

@url GET {id}/setGroup/{group}

Definition at line 616 of file api_users.class.php.

References $conf, $id, DolibarrApi\_checkAccessToResource(), getDolGlobalString(), and isModEnabled().

◆ setPassword()

Users::setPassword ( $id,
$send_password = false )

Update a user password.

Since
21.0.0 Initial implementation
Parameters
int$idUser ID
bool$send_passwordOnly if set to true, the new password will send to the user
Returns
int 1 if password changed, 2 if password changed and sent
Exceptions
RestException403 Not allowed
RestException404 User not found
RestException500 System error

@url GET {id}/setPassword

Definition at line 518 of file api_users.class.php.

References $id, DolibarrApi\_checkAccessToResource(), getDolGlobalInt(), and getDolGlobalString().

◆ updateUserNotification()

Users::updateUserNotification ( $id,
$notification_id,
$request_data = null )

Update a notification for a user.

Since
22.0.0 Initial implementation
Parameters
int$idID of the User
int$notification_idID of UserNotification
array$request_dataRequest data
Returns
array|mixed Notification for the user

@phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data

@url PUT {id}/notifications/{notification_id}

Exceptions
RestException

Definition at line 1251 of file api_users.class.php.

References $id, DolibarrApi\_checkValForAPI(), and _cleanObjectDatas().


The documentation for this class was generated from the following file: