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");
380 if ($field ==
'pass') {
381 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'password')) {
382 throw new RestException(403,
'You are not allowed to modify/set password of other users');
384 if (!DolibarrApiAccess::$user->admin) {
385 throw new RestException(403,
'As a non admin user, you are not allowed to set a password from this API. Use the /setPassword endpoint for this.');
389 $canreadsalary = ((
isModEnabled(
'salaries') && DolibarrApiAccess::$user->hasRight(
'salaries',
'read')) || !
isModEnabled(
'salaries'));
390 if (!$canreadsalary) {
391 if (in_array($field, array(
'salary',
'salaryextra',
'thm',
'tjm'))) {
393 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs with permission on salaries");
397 if ($field ===
'caller') {
399 $this->useraccount->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
403 if (DolibarrApiAccess::$user->admin) {
404 if ($field ==
'admin' && $value != $this->useraccount->admin && empty($value)) {
405 throw new RestException(403,
'Reseting the admin status of a user is not possible using the API');
408 if ($field ==
'admin' && $value != $this->useraccount->admin) {
409 throw new RestException(403,
'Only an admin user can modify the admin status of another user');
413 $this->useraccount->$field = $this->
_checkValForAPI($field, $value, $this->useraccount);
416 if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) {
417 throw new RestException(500,
'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors));
419 return $this->useraccount->id;
438 public function put(
$id, $request_data =
null)
440 $isSelfUpdate = ((int)
$id === (
int) DolibarrApiAccess::$user->id);
444 !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')
445 && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'write')
449 DolibarrApiAccess::$user->hasRight(
'user',
'self',
'creer')
450 || DolibarrApiAccess::$user->hasRight(
'user',
'self',
'write')
453 && empty(DolibarrApiAccess::$user->admin)
455 throw new RestException(403,
"User update not allowed");
458 $result = $this->useraccount->fetch(
$id);
460 throw new RestException(404,
'Account not found');
464 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
467 foreach ($request_data as $field => $value) {
468 if (in_array($field, array(
'pass_crypted',
'pass_indatabase',
'pass_indatabase_crypted',
'pass_temp',
'api_key',
'openid'))) {
470 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs");
473 $canreadsalary = ((
isModEnabled(
'salaries') && DolibarrApiAccess::$user->hasRight(
'salaries',
'read')) || !
isModEnabled(
'salaries'));
474 if (!$canreadsalary) {
475 if (in_array($field, array(
'salary',
'salaryextra',
'thm',
'tjm'))) {
477 throw new RestException(405,
'The property '.$field.
" can't be set/modified using the APIs with permission on salaries");
481 if ($field ==
'id') {
484 if ($field ==
'pass') {
485 if ($this->useraccount->id != DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'password')) {
486 throw new RestException(403,
'You are not allowed to modify password of other users');
488 if ($this->useraccount->id == DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight(
'user',
'self',
'password')) {
489 throw new RestException(403,
'You are not allowed to modify your own password');
491 if (!DolibarrApiAccess::$user->admin) {
492 throw new RestException(403,
'As a non admin user, you are not allowed to set a password from this API. Use the /setPassword endpoint for this.');
495 if ($field ===
'caller') {
497 $this->useraccount->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
500 if ($field ==
'array_options' && is_array($value)) {
501 foreach ($value as $index => $val) {
507 if (DolibarrApiAccess::$user->admin) {
508 if ($field ==
'admin' && $value != $this->useraccount->admin && empty($value)) {
509 throw new RestException(403,
'Reseting the admin status of a user is not possible using the API');
512 if ($field ==
'admin' && $value != $this->useraccount->admin) {
513 throw new RestException(403,
'Only an admin user can modify the admin status of another user');
516 if ($field ==
'entity' && $value != $this->useraccount->entity) {
517 throw new RestException(403,
'Changing entity of a user using the APIs is not possible');
522 if ($field ==
'statut' || $field ==
'status') {
523 $result = $this->useraccount->setstatus($value);
525 throw new RestException(500,
'Error when updating status of user: '.$this->useraccount->error);
528 $this->useraccount->$field = $this->
_checkValForAPI($field, $value, $this->useraccount);
534 if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0) {
535 return $this->
get(
$id);
537 throw new RestException(500, $this->useraccount->error);
559 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.");
563 throw new RestException(403,
"Error: password reset APIs are disabled by default. To allow this, the option API_ALLOW_PASSWORD_RESET must be set.");
566 if (
$id != DolibarrApiAccess::$user->
id && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'password')) {
567 throw new RestException(403,
'You are not allowed to modify password of other users');
569 if (
$id == DolibarrApiAccess::$user->
id && !DolibarrApiAccess::$user->hasRight(
'user',
'self',
'password')) {
570 throw new RestException(403,
'You are not allowed to modify your own password');
573 $result = $this->useraccount->fetch(
$id);
575 throw new RestException(404,
'User not found, no password changed');
579 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
582 $newpassword = $this->useraccount->setPassword($this->useraccount,
'');
583 if (is_int($newpassword) && $newpassword < 0) {
584 throw new RestException(500,
'ErrorFailedToSetNewPassword'.$this->useraccount->error);
587 if ($send_password) {
588 if ($this->useraccount->send_password($this->useraccount, $newpassword) > 0) {
591 throw new RestException(500,
'ErrorFailedSendingNewPassword - '.$this->useraccount->error);
618 throw new RestException(400,
'No user with id=0 can exist');
621 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
622 throw new RestException(403);
625 $user =
new User($this->db);
626 $result = $user->fetch(
$id);
628 throw new RestException(404,
'User not found');
631 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
635 $groups = $usergroup->listGroupsForUser(
$id,
false);
637 foreach ($groups as $group) {
664 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer') && empty(DolibarrApiAccess::$user->admin)) {
665 throw new RestException(403,
'setGroup on users not allowed for login '.DolibarrApiAccess::$user->login);
668 $result = $this->useraccount->fetch(
$id);
670 throw new RestException(404,
'User not found');
674 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
677 if (
isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity)) {
678 $entity = (!empty($entity) ? (int) $entity :
$conf->entity);
682 $entity = (((int) DolibarrApiAccess::$user->entity) > 0 ? (int) DolibarrApiAccess::$user->entity :
$conf->entity);
685 $result = $this->useraccount->SetInGroup($group, $entity);
686 if (!($result > 0)) {
687 throw new RestException(500, $this->useraccount->error);
709 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'write') && empty(DolibarrApiAccess::$user->admin)) {
710 throw new RestException(403,
"Usergroup creation not allowed for login ".DolibarrApiAccess::$user->login);
713 foreach ($request_data as $field => $value) {
714 if ($field ===
'caller') {
716 $usergroup->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
719 if ($field ==
'id') {
720 throw new RestException(400,
'Creating with id field is forbidden');
723 $usergroup->$field = $this->
_checkValForAPI($field, $value, $usergroup);
726 if ($usergroup->create(1) < 0) {
727 throw new RestException(500,
'Error creating', array_merge(array($usergroup->error), $usergroup->errors));
729 return $usergroup->id;
752 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'write') && empty(DolibarrApiAccess::$user->admin)) {
753 throw new RestException(403,
"Usergroup update not allowed");
758 $result = $usergroup->fetch($group);
760 throw new RestException(404,
'Usergroup not found');
763 foreach ($request_data as $field => $value) {
764 if ($field ==
'id') {
765 throw new RestException(400,
'Updating with id field is forbidden');
767 if ($field ===
'caller') {
769 $usergroup->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
773 if ($field ==
'entity' && $value != $usergroup->entity) {
774 throw new RestException(403,
'Changing entity of a user using the APIs is not possible');
777 $usergroup->$field = $this->
_checkValForAPI($field, $value, $usergroup);
782 if ($usergroup->update() >= 0) {
785 throw new RestException(500, $usergroup->error);
806 if (!DolibarrApiAccess::$user->admin) {
807 throw new RestException(403,
'Only admin can remove users from groups');
810 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"usergroup_user";
811 $sql .=
" WHERE fk_user = " . ((int)
$id);
812 $sql .=
" AND fk_usergroup = " . ((int) $group);
814 $resql = $this->db->query($sql);
817 throw new RestException(503,
'DB error: ' . $this->db->lasterror());
822 'message' =>
"User $id removed from group $group"
850 public function listGroups($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $group_ids =
'0', $sqlfilters =
'', $properties =
'')
854 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) ||
855 getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'read') && empty(DolibarrApiAccess::$user->admin)) {
856 throw new RestException(403,
"You are not allowed to read groups");
862 $sql =
"SELECT t.rowid";
863 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup AS t LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_extrafields AS ef ON (ef.fk_object = t.rowid)";
864 $sql .=
' WHERE t.entity IN ('.getEntity(
'user').
')';
866 $sql .=
" AND t.rowid IN (".$this->db->sanitize($group_ids).
")";
873 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
877 $sql .= $this->db->order($sortfield, $sortorder);
882 $offset = $limit * $page;
884 $sql .= $this->db->plimit($limit + 1, $offset);
887 $result = $this->db->query($sql);
891 $num = $this->db->num_rows($result);
892 $min = min($num, ($limit <= 0 ? $num : $limit));
894 $obj = $this->db->fetch_object($result);
895 $group_static =
new UserGroup($this->db);
896 if ($group_static->fetch($obj->rowid)) {
902 throw new RestException(503,
'Error when retrieve Group list : '.$this->db->lasterror());
926 public function infoGroups($group, $load_members = 0, $includepermissions = 0)
929 throw new RestException(400,
'No usergroup with id=0 can exist');
932 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) ||
933 getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'read') && empty(DolibarrApiAccess::$user->admin)) {
934 throw new RestException(403,
"You are not allowed to read groups");
937 $group_static =
new UserGroup($this->db);
938 $result = $group_static->fetch($group,
'', (
bool) $load_members);
941 throw new RestException(404,
'Usergroup not found');
944 if ($includepermissions) {
945 $group_static->loadRights();
948 if ($load_members > 0 && is_array($group_static->members) && count($group_static->members) > 0) {
949 foreach ($group_static->members as &$member) {
970 public function delete(
$id)
972 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'supprimer') && empty(DolibarrApiAccess::$user->admin)) {
973 throw new RestException(403,
'Not allowed');
975 $result = $this->useraccount->fetch(
$id);
977 throw new RestException(404,
'User not found');
981 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
984 if ($this->useraccount->admin && empty(DolibarrApiAccess::$user->admin)) {
985 throw new RestException(403,
'Only admin users can delete admin users');
987 if ($this->useraccount->admin && empty($this->useraccount->entity) && !empty(DolibarrApiAccess::$user->entity)) {
988 throw new RestException(403,
'Only superadmin users can delete superadmin users');
991 $this->useraccount->oldcopy = clone $this->useraccount;
993 if (!$this->useraccount->delete(DolibarrApiAccess::$user)) {
994 throw new RestException(500);
1000 'message' =>
'User deleted'
1022 if (!DolibarrApiAccess::$user->hasRight(
'user',
'group_advance',
'delete') && empty(DolibarrApiAccess::$user->admin)) {
1023 throw new RestException(403,
'Not allowed');
1028 $result = $usergroup->fetch($group);
1030 throw new RestException(404,
'Usergroup not found');
1033 if (!$usergroup->delete(DolibarrApiAccess::$user)) {
1034 throw new RestException(500);
1040 'message' =>
'Usergroup deleted'
1065 throw new RestException(400,
'No user with id=0 can exist');
1067 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'lire') && empty(DolibarrApiAccess::$user->admin)) {
1068 throw new RestException(403);
1071 throw new RestException(403,
'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
1078 $sql =
"SELECT rowid as id, fk_action as event, fk_user, type, datec, tms";
1079 $sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1080 $sql .=
" WHERE fk_user = ".((int)
$id);
1082 $result = $this->db->query($sql);
1083 if ($this->db->num_rows($result) == 0) {
1084 throw new RestException(404,
'Notification not found');
1089 $notifications = array();
1092 $num = $this->db->num_rows($result);
1096 $obj = $this->db->fetch_object($result);
1097 $notifications[] = $obj;
1101 throw new RestException(404,
'No notifications found');
1104 $fields = array(
'id',
'fk_user',
'event',
'datec',
'tms',
'type');
1106 $returnNotifications = array();
1108 foreach ($notifications as $notification) {
1110 foreach ($notification as $key => $value) {
1111 if (in_array($key, $fields)) {
1115 $returnNotifications[] =
$object;
1119 return $returnNotifications;
1140 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1141 throw new RestException(403,
"User has no right to update users");
1143 if ($this->useraccount->fetch(
$id) <= 0) {
1144 throw new RestException(404,
'Error creating User Notification, User doesn\'t exists');
1146 $notification =
new Notify($this->db);
1148 $notification->fk_user =
$id;
1150 foreach ($request_data as $field => $value) {
1151 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1154 $event = $notification->event;
1156 throw new RestException(500,
'Error creating User Notification, request_data missing event');
1158 $fk_user = $notification->fk_user;
1160 $exists_sql =
"SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1161 $exists_sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1162 $exists_sql .=
" WHERE fk_action = '".$this->db->escape((
string) $event).
"'";
1163 $exists_sql .=
" AND fk_user = '".$this->db->escape((
string) $fk_user).
"'";
1165 $exists_result = $this->db->query($exists_sql);
1166 if ($this->db->num_rows($exists_result) > 0) {
1167 throw new RestException(403,
'Notification already exists');
1170 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1171 throw new RestException(500,
'Error creating User Notification');
1174 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1175 throw new RestException(500,
'Error updating values');
1201 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1202 throw new RestException(403,
"User has no right to update users");
1204 if ($this->useraccount->fetch(
$id) <= 0) {
1205 throw new RestException(404,
'Error creating User Notification, User doesn\'t exists');
1207 $notification =
new Notify($this->db);
1208 $notification->fk_user =
$id;
1210 $sql =
"SELECT t.rowid as id FROM ".MAIN_DB_PREFIX.
"c_action_trigger as t";
1211 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
1213 $result = $this->db->query($sql);
1214 if ($this->db->num_rows($result) == 0) {
1215 throw new RestException(404,
'Action Trigger code not found');
1218 $notification->event = $this->db->fetch_row($result)[0];
1219 foreach ($request_data as $field => $value) {
1220 if ($field ===
'event') {
1221 throw new RestException(500,
'Error creating User Notification, request_data contains event key');
1223 if ($field ===
'fk_action') {
1224 throw new RestException(500,
'Error creating User Notification, request_data contains fk_action key');
1226 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1229 $event = $notification->event;
1230 $fk_user = $notification->fk_user;
1232 $exists_sql =
"SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1233 $exists_sql .=
" FROM ".MAIN_DB_PREFIX.
"notify_def";
1234 $exists_sql .=
" WHERE fk_action = '".$this->db->escape((
string) $event).
"'";
1235 $exists_sql .=
" AND fk_user = '".$this->db->escape((
string) $fk_user).
"'";
1237 $exists_result = $this->db->query($exists_sql);
1238 if ($this->db->num_rows($exists_result) > 0) {
1239 throw new RestException(403,
'Notification already exists');
1242 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1243 throw new RestException(500,
'Error creating User Notification, are request_data well formed?');
1246 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1247 throw new RestException(500,
'Error updating values');
1269 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1270 throw new RestException(403,
"User has no right to update users");
1273 $notification =
new Notify($this->db);
1275 $notification->fetch($notification_id);
1277 $fk_user = (int) $notification->fk_user;
1279 if ($fk_user ==
$id) {
1280 return $notification->delete(DolibarrApiAccess::$user);
1282 throw new RestException(403,
"Not allowed due to bad consistency of input data");
1305 if (!DolibarrApiAccess::$user->hasRight(
'user',
'user',
'creer')) {
1306 throw new RestException(403,
"User has no right to update users");
1308 if ($this->useraccount->fetch(
$id) <= 0) {
1309 throw new RestException(404,
'Error creating Notification, User doesn\'t exists');
1311 $notification =
new Notify($this->db);
1314 $notification->fetch($notification_id,
$id);
1316 if ($notification->fk_user !=
$id) {
1317 throw new RestException(403,
"Not allowed due to bad consistency of input data");
1320 foreach ($request_data as $field => $value) {
1321 $notification->$field = $this->
_checkValForAPI($field, $value, $notification);
1324 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1325 throw new RestException(500,
'Error updating values');
1346 unset(
$object->default_values);
1347 unset(
$object->lastsearch_values);
1348 unset(
$object->lastsearch_values_tmp);
1352 unset(
$object->total_localtax1);
1353 unset(
$object->total_localtax2);
1356 unset(
$object->label_incoterms);
1357 unset(
$object->location_incoterms);
1359 unset(
$object->fk_delivery_address);
1361 unset(
$object->all_permissions_are_loaded);
1362 unset(
$object->shipping_method_id);
1366 unset(
$object->clicktodial_loaded);
1373 unset(
$object->pass_indatabase);
1374 unset(
$object->pass_indatabase_crypted);
1377 unset(
$object->clicktodial_password);
1380 $canreadsalary = ((
isModEnabled(
'salaries') && DolibarrApiAccess::$user->hasRight(
'salaries',
'read')) || !
isModEnabled(
'salaries'));
1381 if (!$canreadsalary) {
1403 unset(
$object->actiontypecode);
1404 unset(
$object->all_permissions_are_loaded);
1405 unset(
$object->barcode_type_coder);
1408 unset(
$object->civility_code);
1410 unset(
$object->clicktodial_loaded);
1411 unset(
$object->cond_reglement_id);
1412 unset(
$object->cond_reglement_supplier_id);
1414 unset(
$object->contacts_ids_internal);
1419 unset(
$object->date_creation);
1420 unset(
$object->date_modification);
1421 unset(
$object->date_validation);
1422 unset(
$object->default_values);
1423 unset(
$object->demand_reason_id);
1424 unset(
$object->deposit_percent);
1428 unset(
$object->fk_delivery_address);
1430 unset(
$object->fk_multicurrency);
1432 unset(
$object->fk_user_creat);
1433 unset(
$object->fk_user_modif);
1436 unset(
$object->last_main_doc);
1438 unset(
$object->lastsearch_values_tmp);
1439 unset(
$object->lastsearch_values);
1441 unset(
$object->libelle_incoterms);
1443 unset(
$object->linkedObjectsIds);
1444 unset(
$object->location_incoterms);
1446 unset(
$object->mode_reglement_id);
1448 unset(
$object->multicurrency_code);
1449 unset(
$object->multicurrency_total_ht);
1450 unset(
$object->multicurrency_total_localtax1);
1451 unset(
$object->multicurrency_total_localtax2);
1452 unset(
$object->multicurrency_total_ttc);
1453 unset(
$object->multicurrency_total_tva);
1454 unset(
$object->multicurrency_tx);
1464 unset(
$object->retained_warranty_fk_cond_reglement);
1467 unset(
$object->shipping_method_id);
1468 unset(
$object->shipping_method);
1474 unset(
$object->total_localtax1);
1475 unset(
$object->total_localtax2);
1478 unset(
$object->totalpaid_multicurrency);
1480 unset(
$object->transport_mode_id);
1481 unset(
$object->TRIGGER_PREFIX);
1482 unset(
$object->user_closing_id);
1483 unset(
$object->user_creation_id);
1484 unset(
$object->user_modification_id);
1485 unset(
$object->user_validation_id);
1487 unset(
$object->usergroup_entity);
1501 $cleanObjectList = array();
1503 foreach ($objectList as
$object) {
1504 $cleanObject = parent::_cleanObjectDatas(
$object);
1506 unset($cleanObject->default_values);
1507 unset($cleanObject->lastsearch_values);
1508 unset($cleanObject->lastsearch_values_tmp);
1510 unset($cleanObject->total_ht);
1511 unset($cleanObject->total_tva);
1512 unset($cleanObject->total_localtax1);
1513 unset($cleanObject->total_localtax2);
1514 unset($cleanObject->total_ttc);
1516 unset($cleanObject->libelle_incoterms);
1517 unset($cleanObject->location_incoterms);
1519 unset($cleanObject->fk_delivery_address);
1520 unset($cleanObject->fk_incoterms);
1521 unset($cleanObject->all_permissions_are_loaded);
1522 unset($cleanObject->shipping_method_id);
1523 unset($cleanObject->nb_rights);
1524 unset($cleanObject->search_sid);
1525 unset($cleanObject->ldap_sid);
1526 unset($cleanObject->clicktodial_loaded);
1528 unset($cleanObject->datec);
1529 unset($cleanObject->tms);
1530 unset($cleanObject->members);
1531 unset($cleanObject->note);
1532 unset($cleanObject->note_private);
1534 $cleanObjectList[] = $cleanObject;
1537 return $cleanObjectList;
1550 foreach (Users::$FIELDS as $field) {
1551 if (!isset($data[$field])) {
1552 throw new RestException(400,
"$field field missing");
1554 $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.