Skip to content

Commit

Permalink
API client class v1.1.94
Browse files Browse the repository at this point in the history
- minor fix based on Scrutinizer feedback
- re-added `update_admin()` method to the class; for some reason, the merge of #228 was not successful
  • Loading branch information
malle-pietje committed Aug 12, 2024
1 parent f82d1a6 commit f1fc80f
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ public function list_fingerprint_devices(int $fingerprint_source = 0)
}

/**
* Assign client device to another group
* Assign a client device to another group
*
* @param string $client_id _id value of the client device to be modified
* @param string $group_id _id value of the user group to assign client device to
Expand All @@ -1088,7 +1088,7 @@ public function set_usergroup(string $client_id, string $group_id): bool
}

/**
* Update client device fixed IP address (using REST)
* Update a client device's fixed IP address (using REST)
*
* @param string $client_id _id value for the client device
* @param bool $use_fixedip determines whether to enable the fixed IP address or not
Expand Down Expand Up @@ -1875,6 +1875,68 @@ public function assign_existing_admin(
return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/sitemgr', $payload);
}

/**
* Update an admin of the current site
*
* @param string $admin_id _id value of the admin user to update, can be obtained using the
* list_all_admins() method/function
* @param string $name update the name of the admin user
* @param string $email update the email address of the admin user
* @param string $password optionally update the password of the admin user
* @param bool $readonly optional, whether the new admin has readonly
* permissions, default value is false which gives the new admin
* Administrator permissions
* @param bool $device_adopt optional, whether the new admin has permissions to
* adopt devices, default value is false. With versions < 5.9.X this only applies
* when readonly is true.
* @param bool $device_restart optional, whether the new admin has permissions to
* restart devices, default value is false. With versions < 5.9.X this only applies
* when readonly is true.
* @return bool true on success
*/
public function update_admin(
string $admin_id,
string $name,
string $email,
string $password = '',
bool $readonly = false,
bool $device_adopt = false,
bool $device_restart = false
): bool
{
$email = trim($email);
$email_valid = filter_var($email, FILTER_VALIDATE_EMAIL);

if (!$email_valid) {
trigger_error('The email address provided is invalid!');
return false;
}

$payload = [
'admin' => trim($admin_id),
'name' => trim($name),
'email' => $email,
'cmd' => 'update-admin',
'role' => 'admin',
'x_password' => $password,
'permissions' => [],
];

if ($readonly) {
$payload['role'] = 'readonly';
}

if ($device_adopt) {
$payload['permissions'][] = 'API_DEVICE_ADOPT';
}

if ($device_restart) {
$payload['permissions'][] = 'API_DEVICE_RESTART';
}

return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/sitemgr', $payload);
}

/**
* Revoke an admin from the current site
*
Expand Down

0 comments on commit f1fc80f

Please sign in to comment.