dolibarr 21.0.3
api_users.class.php
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21use Luracast\Restler\RestException;
22
23require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
24require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
25
26
33class Users extends DolibarrApi
34{
38 public static $FIELDS = array(
39 'login',
40 );
41
45 public $useraccount;
46
50 public function __construct()
51 {
52 global $db;
53
54 $this->db = $db;
55 $this->useraccount = new User($this->db);
56 }
57
58
76 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = '0', $category = 0, $sqlfilters = '', $properties = '')
77 {
78 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
79 throw new RestException(403, "You are not allowed to read list of users");
80 }
81
82 $obj_ret = array();
83
84 // case of external user, $societe param is ignored and replaced by user's socid
85 //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe;
86
87 $sql = "SELECT t.rowid";
88 $sql .= " FROM ".MAIN_DB_PREFIX."user AS t LEFT JOIN ".MAIN_DB_PREFIX."user_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
89 if ($category > 0) {
90 $sql .= ", ".$this->db->prefix()."categorie_user as c";
91 }
92 $sql .= ' WHERE t.entity IN ('.getEntity('user').')';
93 if ($user_ids) {
94 $sql .= " AND t.rowid IN (".$this->db->sanitize($user_ids).")";
95 }
96
97 // Select products of given category
98 if ($category > 0) {
99 $sql .= " AND c.fk_categorie = ".((int) $category);
100 $sql .= " AND c.fk_user = t.rowid";
101 }
102
103 // Add sql filters
104 if ($sqlfilters) {
105 $errormessage = '';
106 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
107 if ($errormessage) {
108 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
109 }
110 }
111
112 $sql .= $this->db->order($sortfield, $sortorder);
113 if ($limit) {
114 if ($page < 0) {
115 $page = 0;
116 }
117 $offset = $limit * $page;
118
119 $sql .= $this->db->plimit($limit + 1, $offset);
120 }
121
122 $result = $this->db->query($sql);
123
124 if ($result) {
125 $i = 0;
126 $num = $this->db->num_rows($result);
127 $min = min($num, ($limit <= 0 ? $num : $limit));
128 while ($i < $min) {
129 $obj = $this->db->fetch_object($result);
130 $user_static = new User($this->db);
131 if ($user_static->fetch($obj->rowid)) {
132 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($user_static), $properties);
133 }
134 $i++;
135 }
136 } else {
137 throw new RestException(503, 'Error when retrieve User list : '.$this->db->lasterror());
138 }
139
140 return $obj_ret;
141 }
142
155 public function get($id, $includepermissions = 0)
156 {
157 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin) && $id != 0 && DolibarrApiAccess::$user->id != $id) {
158 throw new RestException(403, 'Not allowed');
159 }
160
161 if ($id == 0) {
162 $result = $this->useraccount->initAsSpecimen();
163 } else {
164 $result = $this->useraccount->fetch($id);
165 }
166 if (!$result) {
167 throw new RestException(404, 'User not found');
168 }
169
170 if ($id > 0 && !DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
171 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
172 }
173
174 if ($includepermissions) {
175 $this->useraccount->loadRights();
176 }
177
178 return $this->_cleanObjectDatas($this->useraccount);
179 }
180
196 public function getByLogin($login, $includepermissions = 0)
197 {
198 if (empty($login)) {
199 throw new RestException(400, 'Bad parameters');
200 }
201
202 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->login != $login) {
203 throw new RestException(403, 'Not allowed');
204 }
205
206 $result = $this->useraccount->fetch(0, $login);
207 if (!$result) {
208 throw new RestException(404, 'User not found');
209 }
210
211 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
212 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
213 }
214
215 if ($includepermissions) {
216 $this->useraccount->loadRights();
217 }
218
219 return $this->_cleanObjectDatas($this->useraccount);
220 }
221
237 public function getByEmail($email, $includepermissions = 0)
238 {
239 if (empty($email)) {
240 throw new RestException(400, 'Bad parameters');
241 }
242
243 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->email != $email) {
244 throw new RestException(403, 'Not allowed');
245 }
246
247 $result = $this->useraccount->fetch(0, '', '', 0, -1, $email);
248 if (!$result) {
249 throw new RestException(404, 'User not found');
250 }
251
252 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
253 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
254 }
255
256 if ($includepermissions) {
257 $this->useraccount->loadRights();
258 }
259
260 return $this->_cleanObjectDatas($this->useraccount);
261 }
262
274 public function getInfo($includepermissions = 0)
275 {
276 if (!DolibarrApiAccess::$user->hasRight('user', 'self', 'creer') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
277 throw new RestException(403, 'Not allowed');
278 }
279
280 $apiUser = DolibarrApiAccess::$user;
281
282 $result = $this->useraccount->fetch($apiUser->id);
283 if (!$result) {
284 throw new RestException(404, 'User not found');
285 }
286
287 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
288 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
289 }
290
291 if ($includepermissions) {
292 $this->useraccount->loadRights();
293 }
294
295 $usergroup = new UserGroup($this->db);
296 $userGroupList = $usergroup->listGroupsForUser($apiUser->id, false);
297 if (!is_array($userGroupList)) {
298 throw new RestException(404, 'User group not found');
299 }
300
301 $this->useraccount->user_group_list = $this->_cleanUserGroupListDatas($userGroupList);
302
303 return $this->_cleanObjectDatas($this->useraccount);
304 }
305
316 public function post($request_data = null)
317 {
318 // Check user authorization
319 if (!DolibarrApiAccess::$user->hasRight('user', 'creer') && empty(DolibarrApiAccess::$user->admin)) {
320 throw new RestException(403, "User creation not allowed for login ".DolibarrApiAccess::$user->login);
321 }
322
323 // check mandatory fields
324 /*if (!isset($request_data["login"]))
325 throw new RestException(400, "login field missing");
326 if (!isset($request_data["password"]))
327 throw new RestException(400, "password field missing");
328 if (!isset($request_data["lastname"]))
329 throw new RestException(400, "lastname field missing");*/
330
331 //assign field values
332 foreach ($request_data as $field => $value) {
333 if (in_array($field, array('pass_crypted', 'pass_indatabase', 'pass_indatabase_crypted', 'pass_temp', 'api_key'))) {
334 // This properties can't be set/modified with API
335 throw new RestException(405, 'The property '.$field." can't be set/modified using the APIs");
336 }
337 if ($field === 'caller') {
338 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
339 $this->useraccount->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
340 continue;
341 }
342 /*if ($field == 'pass') {
343 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'password')) {
344 throw new RestException(403, 'You are not allowed to modify/set password of other users');
345 continue;
346 }
347 }
348 */
349
350 $this->useraccount->$field = $this->_checkValForAPI($field, $value, $this->useraccount);
351 }
352
353 if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) {
354 throw new RestException(500, 'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors));
355 }
356 return $this->useraccount->id;
357 }
358
359
373 public function put($id, $request_data = null)
374 {
375 // Check user authorization
376 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer') && empty(DolibarrApiAccess::$user->admin)) {
377 throw new RestException(403, "User update not allowed");
378 }
379
380 $result = $this->useraccount->fetch($id);
381 if (!$result) {
382 throw new RestException(404, 'Account not found');
383 }
384
385 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
386 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
387 }
388
389 foreach ($request_data as $field => $value) {
390 if (in_array($field, array('pass_crypted', 'pass_indatabase', 'pass_indatabase_crypted', 'pass_temp', 'api_key'))) {
391 // This properties can't be set/modified with API
392 throw new RestException(405, 'The property '.$field." can't be set/modified using the APIs");
393 }
394 if ($field == 'id') {
395 continue;
396 }
397 if ($field == 'pass') {
398 if ($this->useraccount->id != DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight('user', 'user', 'password')) {
399 throw new RestException(403, 'You are not allowed to modify password of other users');
400 }
401 if ($this->useraccount->id == DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight('user', 'self', 'password')) {
402 throw new RestException(403, 'You are not allowed to modify your own password');
403 }
404 }
405 if ($field === 'caller') {
406 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
407 $this->useraccount->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
408 continue;
409 }
410 if ($field == 'array_options' && is_array($value)) {
411 foreach ($value as $index => $val) {
412 $this->useraccount->array_options[$index] = $this->_checkValForAPI($field, $val, $this->useraccount);
413 }
414 continue;
415 }
416
417 if (DolibarrApiAccess::$user->admin) { // If user for API is admin
418 if ($field == 'admin' && $value != $this->useraccount->admin && empty($value)) {
419 throw new RestException(403, 'Reseting the admin status of a user is not possible using the API');
420 }
421 } else {
422 if ($field == 'admin' && $value != $this->useraccount->admin) {
423 throw new RestException(403, 'Only an admin user can modify the admin status of another user');
424 }
425 }
426 if ($field == 'entity' && $value != $this->useraccount->entity) {
427 throw new RestException(403, 'Changing entity of a user using the APIs is not possible');
428 }
429
430 // The status must be updated using setstatus() because it
431 // is not handled by the update() method.
432 if ($field == 'statut' || $field == 'status') {
433 $result = $this->useraccount->setstatus($value);
434 if ($result < 0) {
435 throw new RestException(500, 'Error when updating status of user: '.$this->useraccount->error);
436 }
437 } else {
438 $this->useraccount->$field = $this->_checkValForAPI($field, $value, $this->useraccount);
439 }
440 }
441
442 // If there is no error, update() returns the number of affected
443 // rows so if the update is a no op, the return value is zezo.
444 if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0) {
445 return $this->get($id);
446 } else {
447 throw new RestException(500, $this->useraccount->error);
448 }
449 }
450
464 public function setPassword($id, $send_password = false)
465 {
466 //$conf->global->API_DISABLE_LOGIN_API = 1;
467 if (getDolGlobalString('API_DISABLE_LOGIN_API')) {
468 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.");
469 }
470
471 //$conf->global->API_ALLOW_PASSWORD_RESET = 1;
472 if (!getDolGlobalString('API_ALLOW_PASSWORD_RESET')) {
473 throw new RestException(403, "Error: password reset APIs are disabled by default. To allow this, the option API_ALLOW_PASSWORD_RESET must be set.");
474 }
475
476 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer') && empty(DolibarrApiAccess::$user->admin)) {
477 throw new RestException(403, "setPassword on user not allowed for login ".DolibarrApiAccess::$user->login);
478 }
479
480 $result = $this->useraccount->fetch($id);
481 if (!$result) {
482 throw new RestException(404, 'User not found, no password changed');
483 }
484
485 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
486 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
487 }
488
489 $newpassword = $this->useraccount->setPassword($this->useraccount, ''); // This will generate a new password
490 if (is_int($newpassword) && $newpassword < 0) {
491 throw new RestException(500, 'ErrorFailedToSetNewPassword'.$this->useraccount->error);
492 } else {
493 // Success
494 if ($send_password) {
495 if ($this->useraccount->send_password($this->useraccount, $newpassword) > 0) {
496 return 2;
497 } else {
498 throw new RestException(500, 'ErrorFailedSendingNewPassword - '.$this->useraccount->error);
499 }
500 } else {
501 return 1;
502 }
503 }
504 }
505
519 public function getGroups($id)
520 {
521 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
522 throw new RestException(403);
523 }
524
525 $user = new User($this->db);
526 $result = $user->fetch($id);
527 if (!$result) {
528 throw new RestException(404, 'user not found');
529 }
530
531 $usergroup = new UserGroup($this->db);
532 $groups = $usergroup->listGroupsForUser($id, false);
533 $obj_ret = array();
534 foreach ($groups as $group) {
535 $obj_ret[] = $this->_cleanObjectDatas($group);
536 }
537 return $obj_ret;
538 }
539
540
555 public function setGroup($id, $group, $entity = 1)
556 {
557 global $conf;
558
559 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer') && empty(DolibarrApiAccess::$user->admin)) {
560 throw new RestException(403, 'setGroup on users not allowed for login '.DolibarrApiAccess::$user->login);
561 }
562
563 $result = $this->useraccount->fetch($id);
564 if (!$result) {
565 throw new RestException(404, 'User not found');
566 }
567
568 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
569 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
570 }
571
572 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity)) {
573 $entity = (!empty($entity) ? $entity : $conf->entity);
574 } else {
575 // When using API, action is done on entity of logged user because a user of entity X with permission to create user should not be able to
576 // hack the security by giving himself permissions on another entity.
577 $entity = (DolibarrApiAccess::$user->entity > 0 ? DolibarrApiAccess::$user->entity : $conf->entity);
578 }
579
580 $result = $this->useraccount->SetInGroup($group, $entity);
581 if (!($result > 0)) {
582 throw new RestException(500, $this->useraccount->error);
583 }
584
585 return 1;
586 }
587
610 public function listGroups($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $group_ids = '0', $sqlfilters = '', $properties = '')
611 {
612 $obj_ret = array();
613
614 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) ||
615 getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'read') && empty(DolibarrApiAccess::$user->admin)) {
616 throw new RestException(403, "You are not allowed to read groups");
617 }
618
619 // case of external user, $societe param is ignored and replaced by user's socid
620 //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe;
621
622 $sql = "SELECT t.rowid";
623 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup AS t LEFT JOIN ".MAIN_DB_PREFIX."usergroup_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
624 $sql .= ' WHERE t.entity IN ('.getEntity('user').')';
625 if ($group_ids) {
626 $sql .= " AND t.rowid IN (".$this->db->sanitize($group_ids).")";
627 }
628 // Add sql filters
629 if ($sqlfilters) {
630 $errormessage = '';
631 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
632 if ($errormessage) {
633 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
634 }
635 }
636
637 $sql .= $this->db->order($sortfield, $sortorder);
638 if ($limit) {
639 if ($page < 0) {
640 $page = 0;
641 }
642 $offset = $limit * $page;
643
644 $sql .= $this->db->plimit($limit + 1, $offset);
645 }
646
647 $result = $this->db->query($sql);
648
649 if ($result) {
650 $i = 0;
651 $num = $this->db->num_rows($result);
652 $min = min($num, ($limit <= 0 ? $num : $limit));
653 while ($i < $min) {
654 $obj = $this->db->fetch_object($result);
655 $group_static = new UserGroup($this->db);
656 if ($group_static->fetch($obj->rowid)) {
657 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($group_static), $properties);
658 }
659 $i++;
660 }
661 } else {
662 throw new RestException(503, 'Error when retrieve Group list : '.$this->db->lasterror());
663 }
664
665 return $obj_ret;
666 }
667
682 public function infoGroups($group, $load_members = 0)
683 {
684 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) ||
685 getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'read') && empty(DolibarrApiAccess::$user->admin)) {
686 throw new RestException(403, "You are not allowed to read groups");
687 }
688
689 $group_static = new UserGroup($this->db);
690 $result = $group_static->fetch($group, '', $load_members);
691
692 if (!$result) {
693 throw new RestException(404, 'Group not found');
694 }
695
696 return $this->_cleanObjectDatas($group_static);
697 }
698
710 public function delete($id)
711 {
712 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'supprimer') && empty(DolibarrApiAccess::$user->admin)) {
713 throw new RestException(403, 'Not allowed');
714 }
715 $result = $this->useraccount->fetch($id);
716 if (!$result) {
717 throw new RestException(404, 'User not found');
718 }
719
720 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
721 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
722 }
723 $this->useraccount->oldcopy = clone $this->useraccount;
724
725 if (!$this->useraccount->delete(DolibarrApiAccess::$user)) {
726 throw new RestException(500);
727 }
728
729 return array(
730 'success' => array(
731 'code' => 200,
732 'message' => 'Ticket deleted'
733 )
734 );
735 }
736
737 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
744 protected function _cleanObjectDatas($object)
745 {
746 // phpcs:enable
747 $object = parent::_cleanObjectDatas($object);
748
749 unset($object->default_values);
750 unset($object->lastsearch_values);
751 unset($object->lastsearch_values_tmp);
752
753 unset($object->total_ht);
754 unset($object->total_tva);
755 unset($object->total_localtax1);
756 unset($object->total_localtax2);
757 unset($object->total_ttc);
758
759 unset($object->label_incoterms);
760 unset($object->location_incoterms);
761
762 unset($object->fk_delivery_address);
763 unset($object->fk_incoterms);
764 unset($object->all_permissions_are_loaded);
765 unset($object->shipping_method_id);
766 unset($object->nb_rights);
767 unset($object->search_sid);
768 unset($object->ldap_sid);
769 unset($object->clicktodial_loaded);
770
771 // List of properties never returned by API, whatever are permissions
772 unset($object->pass);
773 unset($object->pass_indatabase);
774 unset($object->pass_indatabase_crypted);
775 unset($object->pass_temp);
776 unset($object->api_key);
777 unset($object->clicktodial_password);
778 unset($object->openid);
779
780 unset($object->lines);
781 unset($object->model_pdf);
782
783 $canreadsalary = ((isModEnabled('salaries') && DolibarrApiAccess::$user->hasRight('salaries', 'read')) || !isModEnabled('salaries'));
784
785 if (!$canreadsalary) {
786 unset($object->salary);
787 unset($object->salaryextra);
788 unset($object->thm);
789 unset($object->tjm);
790 }
791
792 return $object;
793 }
794
801 private function _cleanUserGroupListDatas($objectList)
802 {
803 $cleanObjectList = array();
804
805 foreach ($objectList as $object) {
806 $cleanObject = parent::_cleanObjectDatas($object);
807
808 unset($cleanObject->default_values);
809 unset($cleanObject->lastsearch_values);
810 unset($cleanObject->lastsearch_values_tmp);
811
812 unset($cleanObject->total_ht);
813 unset($cleanObject->total_tva);
814 unset($cleanObject->total_localtax1);
815 unset($cleanObject->total_localtax2);
816 unset($cleanObject->total_ttc);
817
818 unset($cleanObject->libelle_incoterms);
819 unset($cleanObject->location_incoterms);
820
821 unset($cleanObject->fk_delivery_address);
822 unset($cleanObject->fk_incoterms);
823 unset($cleanObject->all_permissions_are_loaded);
824 unset($cleanObject->shipping_method_id);
825 unset($cleanObject->nb_rights);
826 unset($cleanObject->search_sid);
827 unset($cleanObject->ldap_sid);
828 unset($cleanObject->clicktodial_loaded);
829
830 unset($cleanObject->datec);
831 unset($cleanObject->tms);
832 unset($cleanObject->members);
833 unset($cleanObject->note);
834 unset($cleanObject->note_private);
835
836 $cleanObjectList[] = $cleanObject;
837 }
838
839 return $cleanObjectList;
840 }
841
849 private function _validate($data) // @phpstan-ignore-line
850 {
851 $account = array();
852 foreach (Users::$FIELDS as $field) {
853 if (!isset($data[$field])) {
854 throw new RestException(400, "$field field missing");
855 }
856 $account[$field] = $data[$field];
857 }
858 return $account;
859 }
860}
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class for API REST v1.
Definition api.class.php:31
_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.
Definition api.class.php:83
Class to manage user groups.
Class to manage Dolibarr users.
put($id, $request_data=null)
Update user account.
listGroups($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $group_ids='0', $sqlfilters='', $properties='')
List Groups.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $user_ids='0', $category=0, $sqlfilters='', $properties='')
List Users.
_cleanObjectDatas($object)
Clean sensible object datas.
getInfo($includepermissions=0)
Get more properties of a user.
_cleanUserGroupListDatas($objectList)
Clean sensible user group list datas.
setGroup($id, $group, $entity=1)
Add a user into a group.
setPassword($id, $send_password=false)
Update a user password.
infoGroups($group, $load_members=0)
Get properties of an group object.
_validate($data)
Validate fields before create or update object.
getByEmail($email, $includepermissions=0)
Get properties of an user object by Email.
getGroups($id)
List the groups of a user.
post($request_data=null)
Create user account.
getByLogin($login, $includepermissions=0)
Get properties of an user object by login.
__construct()
Constructor.
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").
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79