dolibarr 21.0.0-beta
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
411 if (DolibarrApiAccess::$user->admin) { // If user for API is admin
412 if ($field == 'admin' && $value != $this->useraccount->admin && empty($value)) {
413 throw new RestException(403, 'Reseting the admin status of a user is not possible using the API');
414 }
415 } else {
416 if ($field == 'admin' && $value != $this->useraccount->admin) {
417 throw new RestException(403, 'Only an admin user can modify the admin status of another user');
418 }
419 }
420 if ($field == 'entity' && $value != $this->useraccount->entity) {
421 throw new RestException(403, 'Changing entity of a user using the APIs is not possible');
422 }
423
424 // The status must be updated using setstatus() because it
425 // is not handled by the update() method.
426 if ($field == 'statut' || $field == 'status') {
427 $result = $this->useraccount->setstatus($value);
428 if ($result < 0) {
429 throw new RestException(500, 'Error when updating status of user: '.$this->useraccount->error);
430 }
431 } else {
432 $this->useraccount->$field = $this->_checkValForAPI($field, $value, $this->useraccount);
433 }
434 }
435
436 // If there is no error, update() returns the number of affected
437 // rows so if the update is a no op, the return value is zezo.
438 if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0) {
439 return $this->get($id);
440 } else {
441 throw new RestException(500, $this->useraccount->error);
442 }
443 }
444
458 public function setPassword($id, $send_password = false)
459 {
460 //$conf->global->API_DISABLE_LOGIN_API = 1;
461 if (getDolGlobalString('API_DISABLE_LOGIN_API')) {
462 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.");
463 }
464
465 //$conf->global->API_ALLOW_PASSWORD_RESET = 1;
466 if (!getDolGlobalString('API_ALLOW_PASSWORD_RESET')) {
467 throw new RestException(403, "Error: password reset APIs are disabled by default. To allow this, the option API_ALLOW_PASSWORD_RESET must be set.");
468 }
469
470 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer') && empty(DolibarrApiAccess::$user->admin)) {
471 throw new RestException(403, "setPassword on user not allowed for login ".DolibarrApiAccess::$user->login);
472 }
473
474 $result = $this->useraccount->fetch($id);
475 if (!$result) {
476 throw new RestException(404, 'User not found, no password changed');
477 }
478
479 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
480 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
481 }
482
483 $newpassword = $this->useraccount->setPassword($this->useraccount, ''); // This will generate a new password
484 if (is_int($newpassword) && $newpassword < 0) {
485 throw new RestException(500, 'ErrorFailedToSetNewPassword'.$this->useraccount->error);
486 } else {
487 // Success
488 if ($send_password) {
489 if ($this->useraccount->send_password($this->useraccount, $newpassword) > 0) {
490 return 2;
491 } else {
492 throw new RestException(500, 'ErrorFailedSendingNewPassword - '.$this->useraccount->error);
493 }
494 } else {
495 return 1;
496 }
497 }
498 }
499
513 public function getGroups($id)
514 {
515 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
516 throw new RestException(403);
517 }
518
519 $user = new User($this->db);
520 $result = $user->fetch($id);
521 if (!$result) {
522 throw new RestException(404, 'user not found');
523 }
524
525 $usergroup = new UserGroup($this->db);
526 $groups = $usergroup->listGroupsForUser($id, false);
527 $obj_ret = array();
528 foreach ($groups as $group) {
529 $obj_ret[] = $this->_cleanObjectDatas($group);
530 }
531 return $obj_ret;
532 }
533
534
549 public function setGroup($id, $group, $entity = 1)
550 {
551 global $conf;
552
553 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer') && empty(DolibarrApiAccess::$user->admin)) {
554 throw new RestException(403, 'setGroup on users not allowed for login '.DolibarrApiAccess::$user->login);
555 }
556
557 $result = $this->useraccount->fetch($id);
558 if (!$result) {
559 throw new RestException(404, 'User not found');
560 }
561
562 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
563 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
564 }
565
566 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity)) {
567 $entity = (!empty($entity) ? $entity : $conf->entity);
568 } else {
569 // 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
570 // hack the security by giving himself permissions on another entity.
571 $entity = (DolibarrApiAccess::$user->entity > 0 ? DolibarrApiAccess::$user->entity : $conf->entity);
572 }
573
574 $result = $this->useraccount->SetInGroup($group, $entity);
575 if (!($result > 0)) {
576 throw new RestException(500, $this->useraccount->error);
577 }
578
579 return 1;
580 }
581
604 public function listGroups($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $group_ids = '0', $sqlfilters = '', $properties = '')
605 {
606 $obj_ret = array();
607
608 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) ||
609 getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'read') && empty(DolibarrApiAccess::$user->admin)) {
610 throw new RestException(403, "You are not allowed to read groups");
611 }
612
613 // case of external user, $societe param is ignored and replaced by user's socid
614 //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe;
615
616 $sql = "SELECT t.rowid";
617 $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
618 $sql .= ' WHERE t.entity IN ('.getEntity('user').')';
619 if ($group_ids) {
620 $sql .= " AND t.rowid IN (".$this->db->sanitize($group_ids).")";
621 }
622 // Add sql filters
623 if ($sqlfilters) {
624 $errormessage = '';
625 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
626 if ($errormessage) {
627 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
628 }
629 }
630
631 $sql .= $this->db->order($sortfield, $sortorder);
632 if ($limit) {
633 if ($page < 0) {
634 $page = 0;
635 }
636 $offset = $limit * $page;
637
638 $sql .= $this->db->plimit($limit + 1, $offset);
639 }
640
641 $result = $this->db->query($sql);
642
643 if ($result) {
644 $i = 0;
645 $num = $this->db->num_rows($result);
646 $min = min($num, ($limit <= 0 ? $num : $limit));
647 while ($i < $min) {
648 $obj = $this->db->fetch_object($result);
649 $group_static = new UserGroup($this->db);
650 if ($group_static->fetch($obj->rowid)) {
651 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($group_static), $properties);
652 }
653 $i++;
654 }
655 } else {
656 throw new RestException(503, 'Error when retrieve Group list : '.$this->db->lasterror());
657 }
658
659 return $obj_ret;
660 }
661
676 public function infoGroups($group, $load_members = 0)
677 {
678 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) ||
679 getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'read') && empty(DolibarrApiAccess::$user->admin)) {
680 throw new RestException(403, "You are not allowed to read groups");
681 }
682
683 $group_static = new UserGroup($this->db);
684 $result = $group_static->fetch($group, '', $load_members);
685
686 if (!$result) {
687 throw new RestException(404, 'Group not found');
688 }
689
690 return $this->_cleanObjectDatas($group_static);
691 }
692
704 public function delete($id)
705 {
706 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'supprimer') && empty(DolibarrApiAccess::$user->admin)) {
707 throw new RestException(403, 'Not allowed');
708 }
709 $result = $this->useraccount->fetch($id);
710 if (!$result) {
711 throw new RestException(404, 'User not found');
712 }
713
714 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
715 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
716 }
717 $this->useraccount->oldcopy = clone $this->useraccount;
718
719 if (!$this->useraccount->delete(DolibarrApiAccess::$user)) {
720 throw new RestException(500);
721 }
722
723 return array(
724 'success' => array(
725 'code' => 200,
726 'message' => 'Ticket deleted'
727 )
728 );
729 }
730
731 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
738 protected function _cleanObjectDatas($object)
739 {
740 // phpcs:enable
741 $object = parent::_cleanObjectDatas($object);
742
743 unset($object->default_values);
744 unset($object->lastsearch_values);
745 unset($object->lastsearch_values_tmp);
746
747 unset($object->total_ht);
748 unset($object->total_tva);
749 unset($object->total_localtax1);
750 unset($object->total_localtax2);
751 unset($object->total_ttc);
752
753 unset($object->label_incoterms);
754 unset($object->location_incoterms);
755
756 unset($object->fk_delivery_address);
757 unset($object->fk_incoterms);
758 unset($object->all_permissions_are_loaded);
759 unset($object->shipping_method_id);
760 unset($object->nb_rights);
761 unset($object->search_sid);
762 unset($object->ldap_sid);
763 unset($object->clicktodial_loaded);
764
765 // List of properties never returned by API, whatever are permissions
766 unset($object->pass);
767 unset($object->pass_indatabase);
768 unset($object->pass_indatabase_crypted);
769 unset($object->pass_temp);
770 unset($object->api_key);
771 unset($object->clicktodial_password);
772 unset($object->openid);
773
774 unset($object->lines);
775 unset($object->model_pdf);
776
777 $canreadsalary = ((isModEnabled('salaries') && DolibarrApiAccess::$user->hasRight('salaries', 'read')) || !isModEnabled('salaries'));
778
779 if (!$canreadsalary) {
780 unset($object->salary);
781 unset($object->salaryextra);
782 unset($object->thm);
783 unset($object->tjm);
784 }
785
786 return $object;
787 }
788
795 private function _cleanUserGroupListDatas($objectList)
796 {
797 $cleanObjectList = array();
798
799 foreach ($objectList as $object) {
800 $cleanObject = parent::_cleanObjectDatas($object);
801
802 unset($cleanObject->default_values);
803 unset($cleanObject->lastsearch_values);
804 unset($cleanObject->lastsearch_values_tmp);
805
806 unset($cleanObject->total_ht);
807 unset($cleanObject->total_tva);
808 unset($cleanObject->total_localtax1);
809 unset($cleanObject->total_localtax2);
810 unset($cleanObject->total_ttc);
811
812 unset($cleanObject->libelle_incoterms);
813 unset($cleanObject->location_incoterms);
814
815 unset($cleanObject->fk_delivery_address);
816 unset($cleanObject->fk_incoterms);
817 unset($cleanObject->all_permissions_are_loaded);
818 unset($cleanObject->shipping_method_id);
819 unset($cleanObject->nb_rights);
820 unset($cleanObject->search_sid);
821 unset($cleanObject->ldap_sid);
822 unset($cleanObject->clicktodial_loaded);
823
824 unset($cleanObject->datec);
825 unset($cleanObject->tms);
826 unset($cleanObject->members);
827 unset($cleanObject->note);
828 unset($cleanObject->note_private);
829
830 $cleanObjectList[] = $cleanObject;
831 }
832
833 return $cleanObjectList;
834 }
835
843 private function _validate($data) // @phpstan-ignore-line
844 {
845 $account = array();
846 foreach (Users::$FIELDS as $field) {
847 if (!isset($data[$field])) {
848 throw new RestException(400, "$field field missing");
849 }
850 $account[$field] = $data[$field];
851 }
852 return $account;
853 }
854}
$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:30
_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:82
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