diff --git a/main/inc/lib/webservices/Rest.php b/main/inc/lib/webservices/Rest.php index 3621c89319..39ccf80707 100644 --- a/main/inc/lib/webservices/Rest.php +++ b/main/inc/lib/webservices/Rest.php @@ -1156,10 +1156,12 @@ class Rest extends WebService /** * Get the list of users from extra field. - * + * @param string $fieldName The name of the extra_field (as in extra_field.variable) we want to filter on. + * @param string $fieldValue The value of the extra_field we want to filter on. If a user doesn't have the given extra_field set to that value, it will not be returned. + * @param int $active Additional filter. If 1, only return active users. Otherwise, return them all. * @throws Exception */ - public function getUsersProfilesByExtraField(string $fieldName, string $fieldValue): array + public function getUsersProfilesByExtraField(string $fieldName, string $fieldValue, int $active = 0): array { self::protectAdminEndpoint(); $users = []; @@ -1171,6 +1173,10 @@ class Rest extends WebService foreach ($extraValues as $value) { $userId = (int) $value; $user = api_get_user_entity($userId); + if ($active && !$user->getActive()) { + // If this user is not active, and we only asked for active users, skip to next user. + continue; + } $pictureInfo = UserManager::get_user_picture_path_by_id($user->getId(), 'web'); $users[$userId] = [ 'pictureUri' => $pictureInfo['dir'].$pictureInfo['file'], @@ -1180,7 +1186,7 @@ class Rest extends WebService 'username' => $user->getUsername(), 'officialCode' => $user->getOfficialCode(), 'phone' => $user->getPhone(), - 'extra' => [], + //'extra' => [], ]; } } diff --git a/main/webservices/api/v2.php b/main/webservices/api/v2.php index 195806bc90..9673eb3962 100644 --- a/main/webservices/api/v2.php +++ b/main/webservices/api/v2.php @@ -195,7 +195,9 @@ try { break; case Rest::GET_PROFILES_BY_EXTRA_FIELD: Event::addEvent(LOG_WS.$action, 'extra_field_name', $_POST['field_name']); - $users = $restApi->getUsersProfilesByExtraField($_POST['field_name'], $_POST['field_value']); + $active = !empty($_POST['active']) && $_POST['active'] == 1 ? 1 : 0; + // If "active" is set, will drop inactive users (user.active = 0) from the response + $users = $restApi->getUsersProfilesByExtraField($_POST['field_name'], $_POST['field_value'], $active); $restResponse->setData($users); break; case Rest::GET_COURSES_DETAILS_BY_EXTRA_FIELD: