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 $forbiddenfilterfields = array(
123 $canreadsalary = ((
isModEnabled(
'salaries') && DolibarrApiAccess::$user->hasRight(
'salaries',
'read')) || !
isModEnabled(
'salaries'));
124 if (!$canreadsalary) {
125 $forbiddenfilterfields[] =
'salary';
126 $forbiddenfilterfields[] =
'salaryextra';
127 $forbiddenfilterfields[] =
'thm';
128 $forbiddenfilterfields[] =
'tjm';
134 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
138 $sql .= $this->db->order($sortfield, $sortorder);
143 $offset = $limit * $page;
145 $sql .= $this->db->plimit($limit + 1, $offset);
148 $result = $this->db->query($sql);
152 $num = $this->db->num_rows($result);
153 $min = min($num, ($limit <= 0 ? $num : $limit));
155 $obj = $this->db->fetch_object($result);
156 $user_static =
new User($this->db);
157 if ($user_static->fetch($obj->rowid)) {
163 throw new RestException(503,
'Error when retrieve User list : '.$this->db->lasterror());
184 public function get(
$id, $includepermissions = 0)
187 throw new RestException(400,
'No user with id=0 can exist');
190 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->
id !=
$id) {
191 throw new RestException(403,
'Not allowed');
195 $result = $this->useraccount->initAsSpecimen();
197 $result = $this->useraccount->fetch(
$id);
200 throw new RestException(404,
'User not found');
204 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
207 if ($includepermissions) {
208 $this->useraccount->loadRights();
234 throw new RestException(400,
'Bad parameters');
237 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->login != $login) {
238 throw new RestException(403,
'Not allowed');
241 $result = $this->useraccount->fetch(0, $login);
243 throw new RestException(404,
'User not found');
247 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
250 if ($includepermissions) {
251 $this->useraccount->loadRights();
277 throw new RestException(400,
'Bad parameters');
280 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->
email != $email) {
281 throw new RestException(403,
'Not allowed');
284 $result = $this->useraccount->fetch(0,
'',
'', 0, -1, $email);
286 throw new RestException(404,
'User not found');
290 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
293 if ($includepermissions) {
294 $this->useraccount->loadRights();
315 public function getInfo($includepermissions = 0)
317 if (!DolibarrApiAccess::$user->hasRight(
'user',
'self',
'creer') && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
318 throw new RestException(403,
'Not allowed');
321 $apiUser = DolibarrApiAccess::$user;
323 $result = $this->useraccount->fetch($apiUser->id);
325 throw new RestException(404,
'User not found');
329 throw new RestException(403,
'Access on this object not allowed to current logged user');
332 if ($includepermissions) {
333 $this->useraccount->loadRights();
337 $userGroupList = $usergroup->listGroupsForUser($apiUser->id,
false);
338 if (!is_array($userGroupList)) {
339 throw new RestException(404,
'User group not found');
359 public function post($request_data =
null)
362 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer') && empty(DolibarrApiAccess::$user->admin)) {
363 throw new RestException(403,
"User creation not allowed for login ".DolibarrApiAccess::$user->login);
367 if (!isset($request_data[
"login"]))
368 throw new RestException(500,
"login field missing");
375 foreach ($request_data as $field => $value) {
376 if (in_array($field, array(
'pass_crypted',
'pass_indatabase',
'pass_indatabase_crypted',
'pass_temp',
'api_key',
'openid'))) {
378 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs");
387 $canreadsalary = ((
isModEnabled(
'salaries') && DolibarrApiAccess::$user->hasRight(
'salaries',
'read')) || !
isModEnabled(
'salaries'));
388 if (!$canreadsalary) {
389 if (in_array($field, array(
'salary',
'salaryextra',
'thm',
'tjm'))) {
391 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs with permission on salaries");
395 if ($field ===
'caller') {
397 $this->useraccount->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
401 if (DolibarrApiAccess::$user->admin) {
402 if ($field ==
'admin' && $value != $this->useraccount->admin && empty($value)) {
403 throw new RestException(403,
'Reseting the admin status of a user is not possible using the API');
406 if ($field ==
'admin' && $value != $this->useraccount->admin) {
407 throw new RestException(403,
'Only an admin user can modify the admin status of another user');
411 $this->useraccount->$field = $this->
_checkValForAPI($field, $value, $this->useraccount);
414 if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) {
415 throw new RestException(500,
'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors));
417 return $this->useraccount->id;
436 public function put(
$id, $request_data =
null)
438 $isSelfUpdate = ((int)
$id === (
int) DolibarrApiAccess::$user->id);
442 !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')
443 && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'write')
447 DolibarrApiAccess::$user->hasRight(
'user',
'self',
'creer')
448 || DolibarrApiAccess::$user->hasRight(
'user',
'self',
'write')
451 && empty(DolibarrApiAccess::$user->admin)
453 throw new RestException(403,
"User update not allowed");
456 $result = $this->useraccount->fetch(
$id);
458 throw new RestException(404,
'Account not found');
462 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
465 foreach ($request_data as $field => $value) {
466 if (in_array($field, array(
'pass_crypted',
'pass_indatabase',
'pass_indatabase_crypted',
'pass_temp',
'api_key',
'openid'))) {
468 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs");
471 $canreadsalary = ((
isModEnabled(
'salaries') && DolibarrApiAccess::$user->hasRight(
'salaries',
'read')) || !
isModEnabled(
'salaries'));
472 if (!$canreadsalary) {
473 if (in_array($field, array(
'salary',
'salaryextra',
'thm',
'tjm'))) {
475 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs with permission on salaries");
479 if ($field ==
'id') {
482 if ($field ==
'pass') {
483 if ($this->useraccount->id != DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'password')) {
484 throw new RestException(403,
'You are not allowed to modify password of other users');
486 if ($this->useraccount->id == DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight(
'user',
'self',
'password')) {
487 throw new RestException(403,
'You are not allowed to modify your own password');
490 if ($field ===
'caller') {
492 $this->useraccount->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
495 if ($field ==
'array_options' && is_array($value)) {
496 foreach ($value as $index => $val) {
502 if (DolibarrApiAccess::$user->admin) {
503 if ($field ==
'admin' && $value != $this->useraccount->admin && empty($value)) {
504 throw new RestException(403,
'Reseting the admin status of a user is not possible using the API');
507 if ($field ==
'admin' && $value != $this->useraccount->admin) {
508 throw new RestException(403,
'Only an admin user can modify the admin status of another user');
511 if ($field ==
'entity' && $value != $this->useraccount->entity) {
512 throw new RestException(403,
'Changing entity of a user using the APIs is not possible');
517 if ($field ==
'statut' || $field ==
'status') {
518 $result = $this->useraccount->setstatus($value);
520 throw new RestException(500,
'Error when updating status of user: '.$this->useraccount->error);
523 $this->useraccount->$field = $this->
_checkValForAPI($field, $value, $this->useraccount);
529 if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0) {
530 return $this->
get(
$id);
532 throw new RestException(500, $this->useraccount->error);
554 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.");
558 throw new RestException(403,
"Error: password reset APIs are disabled by default. To allow this, the option API_ALLOW_PASSWORD_RESET must be set.");
561 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer') && empty(DolibarrApiAccess::$user->admin)) {
562 throw new RestException(403,
"setPassword on user not allowed for login ".DolibarrApiAccess::$user->login);
565 $result = $this->useraccount->fetch(
$id);
567 throw new RestException(404,
'User not found, no password changed');
571 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
574 $newpassword = $this->useraccount->setPassword($this->useraccount,
'');
575 if (is_int($newpassword) && $newpassword < 0) {
576 throw new RestException(500,
'ErrorFailedToSetNewPassword'.$this->useraccount->error);
579 if ($send_password) {
580 if ($this->useraccount->send_password($this->useraccount, $newpassword) > 0) {
583 throw new RestException(500,
'ErrorFailedSendingNewPassword - '.$this->useraccount->error);
610 throw new RestException(400,
'No user with id=0 can exist');
613 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
614 throw new RestException(403);
617 $user =
new User($this->db);
618 $result = $user->fetch(
$id);
620 throw new RestException(404,
'User not found');
623 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
627 $groups = $usergroup->listGroupsForUser(
$id,
false);
629 foreach ($groups as $group) {
656 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer') && empty(DolibarrApiAccess::$user->admin)) {
657 throw new RestException(403,
'setGroup on users not allowed for login '.DolibarrApiAccess::$user->login);
660 $result = $this->useraccount->fetch(
$id);
662 throw new RestException(404,
'User not found');
666 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
669 if (
isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity)) {
670 $entity = (!empty($entity) ? (int) $entity :
$conf->entity);
674 $entity = (((int) DolibarrApiAccess::$user->entity) > 0 ? (int) DolibarrApiAccess::$user->entity :
$conf->entity);
677 $result = $this->useraccount->SetInGroup($group, $entity);
678 if (!($result > 0)) {
679 throw new RestException(500, $this->useraccount->error);
701 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'write') && empty(DolibarrApiAccess::$user->admin)) {
702 throw new RestException(403,
"Usergroup creation not allowed for login ".DolibarrApiAccess::$user->login);
705 foreach ($request_data as $field => $value) {
706 if ($field ===
'caller') {
708 $usergroup->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
711 if ($field ==
'id') {
712 throw new RestException(400,
'Creating with id field is forbidden');
715 $usergroup->$field = $this->
_checkValForAPI($field, $value, $usergroup);
718 if ($usergroup->create(1) < 0) {
719 throw new RestException(500,
'Error creating', array_merge(array($usergroup->error), $usergroup->errors));
721 return $usergroup->id;
744 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'write') && empty(DolibarrApiAccess::$user->admin)) {
745 throw new RestException(403,
"Usergroup update not allowed");
750 $result = $usergroup->fetch($group);
752 throw new RestException(404,
'Usergroup not found');
755 foreach ($request_data as $field => $value) {
756 if ($field ==
'id') {
757 throw new RestException(400,
'Updating with id field is forbidden');
759 if ($field ===
'caller') {
761 $usergroup->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
765 if ($field ==
'entity' && $value != $usergroup->entity) {
766 throw new RestException(403,
'Changing entity of a user using the APIs is not possible');
769 $usergroup->$field = $this->
_checkValForAPI($field, $value, $usergroup);
774 if ($usergroup->update() >= 0) {
777 throw new RestException(500, $usergroup->error);
798 if (!DolibarrApiAccess::$user->admin) {
799 throw new RestException(403,
'Only admin can remove users from groups');
802 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"usergroup_user";
803 $sql .=
" WHERE fk_user = " . ((int)
$id);
804 $sql .=
" AND fk_usergroup = " . ((int) $group);
806 $resql = $this->db->query($sql);
809 throw new RestException(503,
'DB error: ' . $this->db->lasterror());
814 'message' =>
"User $id removed from group $group"
842 public function listGroups($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $group_ids =
'0', $sqlfilters =
'', $properties =
'')
846 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) ||
847 getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'read') && empty(DolibarrApiAccess::$user->admin)) {
848 throw new RestException(403,
"You are not allowed to read groups");
854 $sql =
"SELECT t.rowid";
855 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup AS t LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_extrafields AS ef ON (ef.fk_object = t.rowid)";
856 $sql .=
' WHERE t.entity IN ('.getEntity(
'user').
')';
858 $sql .=
" AND t.rowid IN (".$this->db->sanitize($group_ids).
")";
865 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
869 $sql .= $this->db->order($sortfield, $sortorder);
874 $offset = $limit * $page;
876 $sql .= $this->db->plimit($limit + 1, $offset);
879 $result = $this->db->query($sql);
883 $num = $this->db->num_rows($result);
884 $min = min($num, ($limit <= 0 ? $num : $limit));
886 $obj = $this->db->fetch_object($result);
887 $group_static =
new UserGroup($this->db);
888 if ($group_static->fetch($obj->rowid)) {
894 throw new RestException(503,
'Error when retrieve Group list : '.$this->db->lasterror());
918 public function infoGroups($group, $load_members = 0, $includepermissions = 0)
921 throw new RestException(400,
'No usergroup with id=0 can exist');
924 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) ||
925 getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'read') && empty(DolibarrApiAccess::$user->admin)) {
926 throw new RestException(403,
"You are not allowed to read groups");
929 $group_static =
new UserGroup($this->db);
930 $result = $group_static->fetch($group,
'', (
bool) $load_members);
933 throw new RestException(404,
'Usergroup not found');
936 if ($includepermissions) {
937 $group_static->loadRights();
940 if ($load_members > 0 && is_array($group_static->members) && count($group_static->members) > 0) {
941 foreach ($group_static->members as &$member) {
962 public function delete(
$id)
964 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'supprimer') && empty(DolibarrApiAccess::$user->admin)) {
965 throw new RestException(403,
'Not allowed');
967 $result = $this->useraccount->fetch(
$id);
969 throw new RestException(404,
'User not found');
973 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
975 $this->useraccount->oldcopy = clone $this->useraccount;
977 if (!$this->useraccount->delete(DolibarrApiAccess::$user)) {
978 throw new RestException(500);
984 'message' =>
'User deleted'
1006 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'delete') && empty(DolibarrApiAccess::$user->admin)) {
1007 throw new RestException(403,
'Not allowed');
1012 $result = $usergroup->fetch($group);
1014 throw new RestException(404,
'Usergroup not found');
1017 if (!$usergroup->delete(DolibarrApiAccess::$user)) {
1018 throw new RestException(500);
1024 'message' =>
'Usergroup deleted'
1049 throw new RestException(400,
'No user with id=0 can exist');
1051 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
1052 throw new RestException(403);
1055 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
1062 $sql =
"SELECT rowid as id, fk_action as event, fk_user, type, datec, tms";
1063 $sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1064 $sql .=
" WHERE fk_user = ".((int)
$id);
1066 $result = $this->db->query($sql);
1067 if ($this->db->num_rows($result) == 0) {
1068 throw new RestException(404,
'Notification not found');
1073 $notifications = array();
1076 $num = $this->db->num_rows($result);
1080 $obj = $this->db->fetch_object($result);
1081 $notifications[] = $obj;
1085 throw new RestException(404,
'No notifications found');
1088 $fields = array(
'id',
'fk_user',
'event',
'datec',
'tms',
'type');
1090 $returnNotifications = array();
1092 foreach ($notifications as $notification) {
1094 foreach ($notification as $key => $value) {
1095 if (in_array($key, $fields)) {
1099 $returnNotifications[] =
$object;
1103 return $returnNotifications;
1124 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1125 throw new RestException(403,
"User has no right to update users");
1127 if ($this->useraccount->fetch(
$id) <= 0) {
1128 throw new RestException(404,
'Error creating User Notification, User doesn\'t exists');
1130 $notification =
new Notify($this->db);
1132 $notification->fk_user =
$id;
1134 foreach ($request_data as $field => $value) {
1135 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1138 $event = $notification->event;
1140 throw new RestException(500,
'Error creating User Notification, request_data missing event');
1142 $fk_user = $notification->fk_user;
1144 $exists_sql =
"SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1145 $exists_sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1146 $exists_sql .=
" WHERE fk_action = '".$this->db->escape((
string) $event).
"'";
1147 $exists_sql .=
" AND fk_user = '".$this->db->escape((
string) $fk_user).
"'";
1149 $exists_result = $this->db->query($exists_sql);
1150 if ($this->db->num_rows($exists_result) > 0) {
1151 throw new RestException(403,
'Notification already exists');
1154 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1155 throw new RestException(500,
'Error creating User Notification');
1158 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1159 throw new RestException(500,
'Error updating values');
1185 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1186 throw new RestException(403,
"User has no right to update users");
1188 if ($this->useraccount->fetch(
$id) <= 0) {
1189 throw new RestException(404,
'Error creating User Notification, User doesn\'t exists');
1191 $notification =
new Notify($this->db);
1192 $notification->fk_user =
$id;
1194 $sql =
"SELECT t.rowid as id FROM ".MAIN_DB_PREFIX.
"c_action_trigger as t";
1195 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
1197 $result = $this->db->query($sql);
1198 if ($this->db->num_rows($result) == 0) {
1199 throw new RestException(404,
'Action Trigger code not found');
1202 $notification->event = $this->db->fetch_row($result)[0];
1203 foreach ($request_data as $field => $value) {
1204 if ($field ===
'event') {
1205 throw new RestException(500,
'Error creating User Notification, request_data contains event key');
1207 if ($field ===
'fk_action') {
1208 throw new RestException(500,
'Error creating User Notification, request_data contains fk_action key');
1210 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1213 $event = $notification->event;
1214 $fk_user = $notification->fk_user;
1216 $exists_sql =
"SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1217 $exists_sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1218 $exists_sql .=
" WHERE fk_action = '".$this->db->escape((
string) $event).
"'";
1219 $exists_sql .=
" AND fk_user = '".$this->db->escape((
string) $fk_user).
"'";
1221 $exists_result = $this->db->query($exists_sql);
1222 if ($this->db->num_rows($exists_result) > 0) {
1223 throw new RestException(403,
'Notification already exists');
1226 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1227 throw new RestException(500,
'Error creating User Notification, are request_data well formed?');
1230 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1231 throw new RestException(500,
'Error updating values');
1253 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1254 throw new RestException(403,
"User has no right to update users");
1257 $notification =
new Notify($this->db);
1259 $notification->fetch($notification_id);
1261 $fk_user = (int) $notification->fk_user;
1263 if ($fk_user ==
$id) {
1264 return $notification->delete(DolibarrApiAccess::$user);
1266 throw new RestException(403,
"Not allowed due to bad consistency of input data");
1289 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1290 throw new RestException(403,
"User has no right to update users");
1292 if ($this->useraccount->fetch(
$id) <= 0) {
1293 throw new RestException(404,
'Error creating Notification, User doesn\'t exists');
1295 $notification =
new Notify($this->db);
1298 $notification->fetch($notification_id,
$id);
1300 if ($notification->fk_user !=
$id) {
1301 throw new RestException(403,
"Not allowed due to bad consistency of input data");
1304 foreach ($request_data as $field => $value) {
1305 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1308 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1309 throw new RestException(500,
'Error updating values');
1330 unset(
$object->default_values);
1331 unset(
$object->lastsearch_values);
1332 unset(
$object->lastsearch_values_tmp);
1336 unset(
$object->total_localtax1);
1337 unset(
$object->total_localtax2);
1340 unset(
$object->label_incoterms);
1341 unset(
$object->location_incoterms);
1343 unset(
$object->fk_delivery_address);
1345 unset(
$object->all_permissions_are_loaded);
1346 unset(
$object->shipping_method_id);
1350 unset(
$object->clicktodial_loaded);
1357 unset(
$object->pass_indatabase);
1358 unset(
$object->pass_indatabase_crypted);
1361 unset(
$object->clicktodial_password);
1364 $canreadsalary = ((
isModEnabled(
'salaries') && DolibarrApiAccess::$user->hasRight(
'salaries',
'read')) || !
isModEnabled(
'salaries'));
1365 if (!$canreadsalary) {
1387 unset(
$object->actiontypecode);
1388 unset(
$object->all_permissions_are_loaded);
1389 unset(
$object->barcode_type_coder);
1392 unset(
$object->civility_code);
1394 unset(
$object->clicktodial_loaded);
1395 unset(
$object->cond_reglement_id);
1396 unset(
$object->cond_reglement_supplier_id);
1398 unset(
$object->contacts_ids_internal);
1403 unset(
$object->date_creation);
1404 unset(
$object->date_modification);
1405 unset(
$object->date_validation);
1406 unset(
$object->default_values);
1407 unset(
$object->demand_reason_id);
1408 unset(
$object->deposit_percent);
1412 unset(
$object->fk_delivery_address);
1414 unset(
$object->fk_multicurrency);
1416 unset(
$object->fk_user_creat);
1417 unset(
$object->fk_user_modif);
1420 unset(
$object->last_main_doc);
1422 unset(
$object->lastsearch_values_tmp);
1423 unset(
$object->lastsearch_values);
1425 unset(
$object->libelle_incoterms);
1427 unset(
$object->linkedObjectsIds);
1428 unset(
$object->location_incoterms);
1430 unset(
$object->mode_reglement_id);
1432 unset(
$object->multicurrency_code);
1433 unset(
$object->multicurrency_total_ht);
1434 unset(
$object->multicurrency_total_localtax1);
1435 unset(
$object->multicurrency_total_localtax2);
1436 unset(
$object->multicurrency_total_ttc);
1437 unset(
$object->multicurrency_total_tva);
1438 unset(
$object->multicurrency_tx);
1448 unset(
$object->retained_warranty_fk_cond_reglement);
1451 unset(
$object->shipping_method_id);
1452 unset(
$object->shipping_method);
1458 unset(
$object->total_localtax1);
1459 unset(
$object->total_localtax2);
1462 unset(
$object->totalpaid_multicurrency);
1464 unset(
$object->transport_mode_id);
1465 unset(
$object->TRIGGER_PREFIX);
1466 unset(
$object->user_closing_id);
1467 unset(
$object->user_creation_id);
1468 unset(
$object->user_modification_id);
1469 unset(
$object->user_validation_id);
1471 unset(
$object->usergroup_entity);
1485 $cleanObjectList = array();
1487 foreach ($objectList as
$object) {
1488 $cleanObject = parent::_cleanObjectDatas(
$object);
1490 unset($cleanObject->default_values);
1491 unset($cleanObject->lastsearch_values);
1492 unset($cleanObject->lastsearch_values_tmp);
1494 unset($cleanObject->total_ht);
1495 unset($cleanObject->total_tva);
1496 unset($cleanObject->total_localtax1);
1497 unset($cleanObject->total_localtax2);
1498 unset($cleanObject->total_ttc);
1500 unset($cleanObject->libelle_incoterms);
1501 unset($cleanObject->location_incoterms);
1503 unset($cleanObject->fk_delivery_address);
1504 unset($cleanObject->fk_incoterms);
1505 unset($cleanObject->all_permissions_are_loaded);
1506 unset($cleanObject->shipping_method_id);
1507 unset($cleanObject->nb_rights);
1508 unset($cleanObject->search_sid);
1509 unset($cleanObject->ldap_sid);
1510 unset($cleanObject->clicktodial_loaded);
1512 unset($cleanObject->datec);
1513 unset($cleanObject->tms);
1514 unset($cleanObject->members);
1515 unset($cleanObject->note);
1516 unset($cleanObject->note_private);
1518 $cleanObjectList[] = $cleanObject;
1521 return $cleanObjectList;
1534 foreach (Users::$FIELDS as $field) {
1535 if (!isset($data[$field])) {
1536 throw new RestException(400,
"$field field missing");
1538 $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.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
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.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
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.
isModEnabled($module)
Is Dolibarr module enabled.