From 715bc2b259e95145c9bb5af527a249c14ccf451d Mon Sep 17 00:00:00 2001 From: gekkedev <17025257+gekkedev@users.noreply.github.com> Date: Wed, 17 Oct 2018 14:31:05 +0200 Subject: [PATCH] New feature: RemoteControl list_users can now search for username --- .../remotecontrol/remotecontrol_handle.php | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index 452c52ee4fe..fd7c17d34ca 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -2228,30 +2228,37 @@ public function list_surveys($sSessionKey, $sUsername = null) * * Returns array of ids and info. * - * Failure status : No users found, Invalid session key, No permission (super admin is required) + * Failure status : Invalid user id, Invalid username, No users found, Invalid session key, Permission denied (super admin is required) * * @param string $sSessionKey Auth credentials - * @param int $uid Optional parameter user id. + * @param int $uid Optional; ID of the user + * @param string $username Optional; name of the user * @return array The list of users in case of success */ - public function list_users($sSessionKey = null, $uid = null) + public function list_users($sSessionKey = null, $uid = null, $username = null) { if ($this->_checkSessionKey($sSessionKey)) { if (Permission::model()->hasGlobalPermission('superadmin', 'read')) { $users = null; if ($uid) { - $uid = (int) $uid; - $user = User::model()->findByPk($uid); - if (!$user) { - return array('status' => 'Invalid user id'); - } - $users = array($user); + $uid = (int) $uid; + $user = User::model()->findByPk($uid); + if (!$user) { + return array('status' => 'Invalid user id'); + } + $users = array($user); + } else if ($username) { + $user = User::model()->findByUsername($username); + if (!$user) { + return array('status' => 'Invalid username'); + } + $users = array($user); } else { - $users = User::model()->findAll(); + $users = User::model()->findAll(); } if (count($users) == 0) { - return array('status' => 'No users found'); + return array('status' => 'No users found'); } foreach ($users as $user) {