24use Luracast\Restler\RestException;
26require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
44 public static $FIELDS = array(
61 $this->useraccount =
new User($this->db);
86 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $user_ids =
'0', $category = 0, $sqlfilters =
'', $properties =
'')
88 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
89 throw new RestException(403,
"You are not allowed to read list of users");
97 $sql =
"SELECT t.rowid";
98 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user AS t LEFT JOIN ".MAIN_DB_PREFIX.
"user_extrafields AS ef ON (ef.fk_object = t.rowid)";
100 $sql .=
", ".$this->db->prefix().
"categorie_user as c";
102 $sql .=
' WHERE t.entity IN ('.getEntity(
'user').
')';
104 $sql .=
" AND t.rowid IN (".$this->db->sanitize($user_ids).
")";
109 $sql .=
" AND c.fk_categorie = ".((int) $category);
110 $sql .=
" AND c.fk_user = t.rowid";
116 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
118 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
122 $sql .= $this->db->order($sortfield, $sortorder);
127 $offset = $limit * $page;
129 $sql .= $this->db->plimit($limit + 1, $offset);
132 $result = $this->db->query($sql);
136 $num = $this->db->num_rows($result);
137 $min = min($num, ($limit <= 0 ? $num : $limit));
139 $obj = $this->db->fetch_object($result);
140 $user_static =
new User($this->db);
141 if ($user_static->fetch($obj->rowid)) {
147 throw new RestException(503,
'Error when retrieve User list : '.$this->db->lasterror());
168 public function get(
$id, $includepermissions = 0)
171 throw new RestException(400,
'No user with id=0 can exist');
174 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin) &&
$id != 0 && DolibarrApiAccess::$user->
id !=
$id) {
175 throw new RestException(403,
'Not allowed');
179 $result = $this->useraccount->initAsSpecimen();
181 $result = $this->useraccount->fetch(
$id);
184 throw new RestException(404,
'User not found');
188 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
191 if ($includepermissions) {
192 $this->useraccount->loadRights();
218 throw new RestException(400,
'Bad parameters');
221 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->login != $login) {
222 throw new RestException(403,
'Not allowed');
225 $result = $this->useraccount->fetch(0, $login);
227 throw new RestException(404,
'User not found');
231 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
234 if ($includepermissions) {
235 $this->useraccount->loadRights();
261 throw new RestException(400,
'Bad parameters');
264 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->
email != $email) {
265 throw new RestException(403,
'Not allowed');
268 $result = $this->useraccount->fetch(0,
'',
'', 0, -1, $email);
270 throw new RestException(404,
'User not found');
274 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
277 if ($includepermissions) {
278 $this->useraccount->loadRights();
299 public function getInfo($includepermissions = 0)
301 if (!DolibarrApiAccess::$user->hasRight(
'user',
'self',
'creer') && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
302 throw new RestException(403,
'Not allowed');
305 $apiUser = DolibarrApiAccess::$user;
307 $result = $this->useraccount->fetch($apiUser->id);
309 throw new RestException(404,
'User not found');
313 throw new RestException(403,
'Access not allowed to current logged user');
316 if ($includepermissions) {
317 $this->useraccount->loadRights();
321 $userGroupList = $usergroup->listGroupsForUser($apiUser->id,
false);
322 if (!is_array($userGroupList)) {
323 throw new RestException(404,
'User group not found');
343 public function post($request_data =
null)
346 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer') && empty(DolibarrApiAccess::$user->admin)) {
347 throw new RestException(403,
"User creation not allowed for login ".DolibarrApiAccess::$user->login);
351 if (!isset($request_data[
"login"]))
352 throw new RestException(500,
"login field missing");
359 foreach ($request_data as $field => $value) {
360 if (in_array($field, array(
'pass_crypted',
'pass_indatabase',
'pass_indatabase_crypted',
'pass_temp',
'api_key'))) {
362 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs");
371 if ($field ===
'caller') {
373 $this->useraccount->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
377 if (DolibarrApiAccess::$user->admin) {
378 if ($field ==
'admin' && $value != $this->useraccount->admin && empty($value)) {
379 throw new RestException(403,
'Reseting the admin status of a user is not possible using the API');
382 if ($field ==
'admin' && $value != $this->useraccount->admin) {
383 throw new RestException(403,
'Only an admin user can modify the admin status of another user');
387 $this->useraccount->$field = $this->
_checkValForAPI($field, $value, $this->useraccount);
390 if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) {
391 throw new RestException(500,
'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors));
393 return $this->useraccount->id;
412 public function put(
$id, $request_data =
null)
414 $isSelfUpdate = ((int)
$id === (
int) DolibarrApiAccess::$user->id);
418 !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')
419 && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'write')
423 DolibarrApiAccess::$user->hasRight(
'user',
'self',
'creer')
424 || DolibarrApiAccess::$user->hasRight(
'user',
'self',
'write')
427 && empty(DolibarrApiAccess::$user->admin)
429 throw new RestException(403,
"User update not allowed");
432 $result = $this->useraccount->fetch(
$id);
434 throw new RestException(404,
'Account not found');
438 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
441 foreach ($request_data as $field => $value) {
442 if (in_array($field, array(
'pass_crypted',
'pass_indatabase',
'pass_indatabase_crypted',
'pass_temp',
'api_key'))) {
444 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs");
446 if ($field ==
'id') {
449 if ($field ==
'pass') {
450 if ($this->useraccount->id != DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'password')) {
451 throw new RestException(403,
'You are not allowed to modify password of other users');
453 if ($this->useraccount->id == DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight(
'user',
'self',
'password')) {
454 throw new RestException(403,
'You are not allowed to modify your own password');
457 if ($field ===
'caller') {
459 $this->useraccount->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
462 if ($field ==
'array_options' && is_array($value)) {
463 foreach ($value as $index => $val) {
469 if (DolibarrApiAccess::$user->admin) {
470 if ($field ==
'admin' && $value != $this->useraccount->admin && empty($value)) {
471 throw new RestException(403,
'Reseting the admin status of a user is not possible using the API');
474 if ($field ==
'admin' && $value != $this->useraccount->admin) {
475 throw new RestException(403,
'Only an admin user can modify the admin status of another user');
478 if ($field ==
'entity' && $value != $this->useraccount->entity) {
479 throw new RestException(403,
'Changing entity of a user using the APIs is not possible');
484 if ($field ==
'statut' || $field ==
'status') {
485 $result = $this->useraccount->setstatus($value);
487 throw new RestException(500,
'Error when updating status of user: '.$this->useraccount->error);
490 $this->useraccount->$field = $this->
_checkValForAPI($field, $value, $this->useraccount);
496 if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0) {
497 return $this->
get(
$id);
499 throw new RestException(500, $this->useraccount->error);
521 throw new RestException(403,
"Error: login and password reset APIs are disabled. You can get access token from the backoffice to get access permission but permission and password manipulation from APIs are forbidden.");
525 throw new RestException(403,
"Error: password reset APIs are disabled by default. To allow this, the option API_ALLOW_PASSWORD_RESET must be set.");
528 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer') && empty(DolibarrApiAccess::$user->admin)) {
529 throw new RestException(403,
"setPassword on user not allowed for login ".DolibarrApiAccess::$user->login);
532 $result = $this->useraccount->fetch(
$id);
534 throw new RestException(404,
'User not found, no password changed');
538 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
541 $newpassword = $this->useraccount->setPassword($this->useraccount,
'');
542 if (is_int($newpassword) && $newpassword < 0) {
543 throw new RestException(500,
'ErrorFailedToSetNewPassword'.$this->useraccount->error);
546 if ($send_password) {
547 if ($this->useraccount->send_password($this->useraccount, $newpassword) > 0) {
550 throw new RestException(500,
'ErrorFailedSendingNewPassword - '.$this->useraccount->error);
577 throw new RestException(400,
'No user with id=0 can exist');
580 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
581 throw new RestException(403);
584 $user =
new User($this->db);
585 $result = $user->fetch(
$id);
587 throw new RestException(404,
'user not found');
591 $groups = $usergroup->listGroupsForUser(
$id,
false);
593 foreach ($groups as $group) {
620 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer') && empty(DolibarrApiAccess::$user->admin)) {
621 throw new RestException(403,
'setGroup on users not allowed for login '.DolibarrApiAccess::$user->login);
624 $result = $this->useraccount->fetch(
$id);
626 throw new RestException(404,
'User not found');
630 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
633 if (
isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity)) {
634 $entity = (!empty($entity) ? (int) $entity :
$conf->entity);
638 $entity = (((int) DolibarrApiAccess::$user->entity) > 0 ? (int) DolibarrApiAccess::$user->entity :
$conf->entity);
641 $result = $this->useraccount->SetInGroup($group, $entity);
642 if (!($result > 0)) {
643 throw new RestException(500, $this->useraccount->error);
665 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'write') && empty(DolibarrApiAccess::$user->admin)) {
666 throw new RestException(403,
"Usergroup creation not allowed for login ".DolibarrApiAccess::$user->login);
669 foreach ($request_data as $field => $value) {
670 if ($field ===
'caller') {
672 $usergroup->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
675 if ($field ==
'id') {
676 throw new RestException(400,
'Creating with id field is forbidden');
679 $usergroup->$field = $this->
_checkValForAPI($field, $value, $usergroup);
682 if ($usergroup->create(1) < 0) {
683 throw new RestException(500,
'Error creating', array_merge(array($usergroup->error), $usergroup->errors));
685 return $usergroup->id;
708 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'write') && empty(DolibarrApiAccess::$user->admin)) {
709 throw new RestException(403,
"Usergroup update not allowed");
714 $result = $usergroup->fetch($group);
716 throw new RestException(404,
'Usergroup not found');
719 foreach ($request_data as $field => $value) {
720 if ($field ==
'id') {
721 throw new RestException(400,
'Updating with id field is forbidden');
723 if ($field ===
'caller') {
725 $usergroup->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
729 if ($field ==
'entity' && $value != $usergroup->entity) {
730 throw new RestException(403,
'Changing entity of a user using the APIs is not possible');
733 $usergroup->$field = $this->
_checkValForAPI($field, $value, $usergroup);
738 if ($usergroup->update() >= 0) {
741 throw new RestException(500, $usergroup->error);
762 if (!DolibarrApiAccess::$user->admin) {
763 throw new RestException(403,
'Only admin can remove users from groups');
766 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"usergroup_user";
767 $sql .=
" WHERE fk_user = " . ((int)
$id);
768 $sql .=
" AND fk_usergroup = " . ((int) $group);
770 $resql = $this->db->query($sql);
773 throw new RestException(503,
'DB error: ' . $this->db->lasterror());
778 'message' =>
"User $id removed from group $group"
806 public function listGroups($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $group_ids =
'0', $sqlfilters =
'', $properties =
'')
810 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) ||
811 getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'read') && empty(DolibarrApiAccess::$user->admin)) {
812 throw new RestException(403,
"You are not allowed to read groups");
818 $sql =
"SELECT t.rowid";
819 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup AS t LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_extrafields AS ef ON (ef.fk_object = t.rowid)";
820 $sql .=
' WHERE t.entity IN ('.getEntity(
'user').
')';
822 $sql .=
" AND t.rowid IN (".$this->db->sanitize($group_ids).
")";
827 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
829 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
833 $sql .= $this->db->order($sortfield, $sortorder);
838 $offset = $limit * $page;
840 $sql .= $this->db->plimit($limit + 1, $offset);
843 $result = $this->db->query($sql);
847 $num = $this->db->num_rows($result);
848 $min = min($num, ($limit <= 0 ? $num : $limit));
850 $obj = $this->db->fetch_object($result);
851 $group_static =
new UserGroup($this->db);
852 if ($group_static->fetch($obj->rowid)) {
858 throw new RestException(503,
'Error when retrieve Group list : '.$this->db->lasterror());
882 public function infoGroups($group, $load_members = 0, $includepermissions = 0)
885 throw new RestException(400,
'No usergroup with id=0 can exist');
888 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) ||
889 getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'read') && empty(DolibarrApiAccess::$user->admin)) {
890 throw new RestException(403,
"You are not allowed to read groups");
893 $group_static =
new UserGroup($this->db);
894 $result = $group_static->fetch($group,
'', (
bool) $load_members);
897 throw new RestException(404,
'Usergroup not found');
900 if ($includepermissions) {
901 $group_static->loadRights();
904 if ($load_members > 0 && is_array($group_static->members) && count($group_static->members) > 0) {
905 foreach ($group_static->members as &$member) {
926 public function delete(
$id)
928 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'supprimer') && empty(DolibarrApiAccess::$user->admin)) {
929 throw new RestException(403,
'Not allowed');
931 $result = $this->useraccount->fetch(
$id);
933 throw new RestException(404,
'User not found');
937 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
939 $this->useraccount->oldcopy = clone $this->useraccount;
941 if (!$this->useraccount->delete(DolibarrApiAccess::$user)) {
942 throw new RestException(500);
948 'message' =>
'User deleted'
970 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'delete') && empty(DolibarrApiAccess::$user->admin)) {
971 throw new RestException(403,
'Not allowed');
976 $result = $usergroup->fetch($group);
978 throw new RestException(404,
'Usergroup not found');
981 if (!$usergroup->delete(DolibarrApiAccess::$user)) {
982 throw new RestException(500);
988 'message' =>
'Usergroup deleted'
1013 throw new RestException(400,
'No user with id=0 can exist');
1015 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
1016 throw new RestException(403);
1019 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1026 $sql =
"SELECT rowid as id, fk_action as event, fk_user, type, datec, tms";
1027 $sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1028 $sql .=
" WHERE fk_user = ".((int)
$id);
1030 $result = $this->db->query($sql);
1031 if ($this->db->num_rows($result) == 0) {
1032 throw new RestException(404,
'Notification not found');
1037 $notifications = array();
1040 $num = $this->db->num_rows($result);
1044 $obj = $this->db->fetch_object($result);
1045 $notifications[] = $obj;
1049 throw new RestException(404,
'No notifications found');
1052 $fields = array(
'id',
'fk_user',
'event',
'datec',
'tms',
'type');
1054 $returnNotifications = array();
1056 foreach ($notifications as $notification) {
1058 foreach ($notification as $key => $value) {
1059 if (in_array($key, $fields)) {
1063 $returnNotifications[] =
$object;
1067 return $returnNotifications;
1088 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1089 throw new RestException(403,
"User has no right to update users");
1091 if ($this->useraccount->fetch(
$id) <= 0) {
1092 throw new RestException(404,
'Error creating User Notification, User doesn\'t exists');
1094 $notification =
new Notify($this->db);
1096 $notification->fk_user =
$id;
1098 foreach ($request_data as $field => $value) {
1099 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1102 $event = $notification->event;
1104 throw new RestException(500,
'Error creating User Notification, request_data missing event');
1106 $fk_user = $notification->fk_user;
1108 $exists_sql =
"SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1109 $exists_sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1110 $exists_sql .=
" WHERE fk_action = '".$this->db->escape((
string) $event).
"'";
1111 $exists_sql .=
" AND fk_user = '".$this->db->escape((
string) $fk_user).
"'";
1113 $exists_result = $this->db->query($exists_sql);
1114 if ($this->db->num_rows($exists_result) > 0) {
1115 throw new RestException(403,
'Notification already exists');
1118 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1119 throw new RestException(500,
'Error creating User Notification');
1122 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1123 throw new RestException(500,
'Error updating values');
1149 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1150 throw new RestException(403,
"User has no right to update users");
1152 if ($this->useraccount->fetch(
$id) <= 0) {
1153 throw new RestException(404,
'Error creating User Notification, User doesn\'t exists');
1155 $notification =
new Notify($this->db);
1156 $notification->fk_user =
$id;
1158 $sql =
"SELECT t.rowid as id FROM ".MAIN_DB_PREFIX.
"c_action_trigger as t";
1159 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
1161 $result = $this->db->query($sql);
1162 if ($this->db->num_rows($result) == 0) {
1163 throw new RestException(404,
'Action Trigger code not found');
1166 $notification->event = $this->db->fetch_row($result)[0];
1167 foreach ($request_data as $field => $value) {
1168 if ($field ===
'event') {
1169 throw new RestException(500,
'Error creating User Notification, request_data contains event key');
1171 if ($field ===
'fk_action') {
1172 throw new RestException(500,
'Error creating User Notification, request_data contains fk_action key');
1174 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1177 $event = $notification->event;
1178 $fk_user = $notification->fk_user;
1180 $exists_sql =
"SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1181 $exists_sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1182 $exists_sql .=
" WHERE fk_action = '".$this->db->escape((
string) $event).
"'";
1183 $exists_sql .=
" AND fk_user = '".$this->db->escape((
string) $fk_user).
"'";
1185 $exists_result = $this->db->query($exists_sql);
1186 if ($this->db->num_rows($exists_result) > 0) {
1187 throw new RestException(403,
'Notification already exists');
1190 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1191 throw new RestException(500,
'Error creating User Notification, are request_data well formed?');
1194 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1195 throw new RestException(500,
'Error updating values');
1217 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1218 throw new RestException(403,
"User has no right to update users");
1221 $notification =
new Notify($this->db);
1223 $notification->fetch($notification_id);
1225 $fk_user = (int) $notification->fk_user;
1227 if ($fk_user ==
$id) {
1228 return $notification->delete(DolibarrApiAccess::$user);
1230 throw new RestException(403,
"Not allowed due to bad consistency of input data");
1253 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1254 throw new RestException(403,
"User has no right to update users");
1256 if ($this->useraccount->fetch(
$id) <= 0) {
1257 throw new RestException(404,
'Error creating Notification, User doesn\'t exists');
1259 $notification =
new Notify($this->db);
1262 $notification->fetch($notification_id,
$id);
1264 if ($notification->fk_user !=
$id) {
1265 throw new RestException(403,
"Not allowed due to bad consistency of input data");
1268 foreach ($request_data as $field => $value) {
1269 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1272 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1273 throw new RestException(500,
'Error updating values');
1294 unset(
$object->default_values);
1295 unset(
$object->lastsearch_values);
1296 unset(
$object->lastsearch_values_tmp);
1300 unset(
$object->total_localtax1);
1301 unset(
$object->total_localtax2);
1304 unset(
$object->label_incoterms);
1305 unset(
$object->location_incoterms);
1307 unset(
$object->fk_delivery_address);
1309 unset(
$object->all_permissions_are_loaded);
1310 unset(
$object->shipping_method_id);
1314 unset(
$object->clicktodial_loaded);
1318 unset(
$object->pass_indatabase);
1319 unset(
$object->pass_indatabase_crypted);
1322 unset(
$object->clicktodial_password);
1328 $canreadsalary = ((
isModEnabled(
'salaries') && DolibarrApiAccess::$user->hasRight(
'salaries',
'read')) || !
isModEnabled(
'salaries'));
1330 if (!$canreadsalary) {
1352 unset(
$object->actiontypecode);
1353 unset(
$object->all_permissions_are_loaded);
1354 unset(
$object->barcode_type_coder);
1357 unset(
$object->civility_code);
1359 unset(
$object->clicktodial_loaded);
1360 unset(
$object->cond_reglement_id);
1361 unset(
$object->cond_reglement_supplier_id);
1363 unset(
$object->contacts_ids_internal);
1368 unset(
$object->date_creation);
1369 unset(
$object->date_modification);
1370 unset(
$object->date_validation);
1371 unset(
$object->default_values);
1372 unset(
$object->demand_reason_id);
1373 unset(
$object->deposit_percent);
1377 unset(
$object->fk_delivery_address);
1379 unset(
$object->fk_multicurrency);
1381 unset(
$object->fk_user_creat);
1382 unset(
$object->fk_user_modif);
1385 unset(
$object->last_main_doc);
1387 unset(
$object->lastsearch_values_tmp);
1388 unset(
$object->lastsearch_values);
1390 unset(
$object->libelle_incoterms);
1392 unset(
$object->linkedObjectsIds);
1393 unset(
$object->location_incoterms);
1395 unset(
$object->mode_reglement_id);
1397 unset(
$object->multicurrency_code);
1398 unset(
$object->multicurrency_total_ht);
1399 unset(
$object->multicurrency_total_localtax1);
1400 unset(
$object->multicurrency_total_localtax2);
1401 unset(
$object->multicurrency_total_ttc);
1402 unset(
$object->multicurrency_total_tva);
1403 unset(
$object->multicurrency_tx);
1413 unset(
$object->retained_warranty_fk_cond_reglement);
1416 unset(
$object->shipping_method_id);
1417 unset(
$object->shipping_method);
1423 unset(
$object->total_localtax1);
1424 unset(
$object->total_localtax2);
1427 unset(
$object->totalpaid_multicurrency);
1429 unset(
$object->transport_mode_id);
1430 unset(
$object->TRIGGER_PREFIX);
1431 unset(
$object->user_closing_id);
1432 unset(
$object->user_creation_id);
1433 unset(
$object->user_modification_id);
1434 unset(
$object->user_validation_id);
1436 unset(
$object->usergroup_entity);
1450 $cleanObjectList = array();
1452 foreach ($objectList as
$object) {
1453 $cleanObject = parent::_cleanObjectDatas(
$object);
1455 unset($cleanObject->default_values);
1456 unset($cleanObject->lastsearch_values);
1457 unset($cleanObject->lastsearch_values_tmp);
1459 unset($cleanObject->total_ht);
1460 unset($cleanObject->total_tva);
1461 unset($cleanObject->total_localtax1);
1462 unset($cleanObject->total_localtax2);
1463 unset($cleanObject->total_ttc);
1465 unset($cleanObject->libelle_incoterms);
1466 unset($cleanObject->location_incoterms);
1468 unset($cleanObject->fk_delivery_address);
1469 unset($cleanObject->fk_incoterms);
1470 unset($cleanObject->all_permissions_are_loaded);
1471 unset($cleanObject->shipping_method_id);
1472 unset($cleanObject->nb_rights);
1473 unset($cleanObject->search_sid);
1474 unset($cleanObject->ldap_sid);
1475 unset($cleanObject->clicktodial_loaded);
1477 unset($cleanObject->datec);
1478 unset($cleanObject->tms);
1479 unset($cleanObject->members);
1480 unset($cleanObject->note);
1481 unset($cleanObject->note_private);
1483 $cleanObjectList[] = $cleanObject;
1486 return $cleanObjectList;
1499 foreach (Users::$FIELDS as $field) {
1500 if (!isset($data[$field])) {
1501 throw new RestException(400,
"$field field missing");
1503 $account[$field] = $data[$field];
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
_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.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class to manage the table of subscription to notifications.
Class to manage user groups.
Class to manage Dolibarr users.
put($id, $request_data=null)
Update a user.
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)
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $user_ids='0', $category=0, $sqlfilters='', $properties='')
List users.
deleteGroups($group)
Delete a usergroup.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
getInfo($includepermissions=0)
Get more properties of the current user (so user of API token).
_cleanUserGroupListDatas($objectList)
Clean sensible user group list datas.
updateUserNotification($id, $notification_id, $request_data=null)
Update a notification for a user.
setGroup($id, $group, $entity=1)
Add a user to a group.
setPassword($id, $send_password=false)
Update a user password.
postGroups($request_data=null)
Create user group.
deleteUserNotification($id, $notification_id)
Delete a notification attached to a user.
_validate($data)
Validate fields before create or update object.
infoGroups($group, $load_members=0, $includepermissions=0)
Get properties of a user group.
getByEmail($email, $includepermissions=0)
Get a user by email.
getGroups($id)
List the groups of a user.
putGroups($group, $request_data=null)
Update user group.
createUserNotificationByCode($id, $code, $request_data=null)
Create a notification for a user using action trigger code.
post($request_data=null)
Create a user.
createUserNotification($id, $request_data=null)
Create a notification for a user.
getByLogin($login, $includepermissions=0)
Get a user by login.
removeUserFromGroup($id, $group)
Remove user from group (only admin)
getUserNotification($id)
Get notifications for a user.
__construct()
Constructor.
_cleanUserGroup($object)
Clean sensible usergroup object datas.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
isModEnabled($module)
Is Dolibarr module enabled.