Files
itflow/api/v1/technicians/read.php
johnnyq 2a5533ea2b Roles stage 3: roles and agents in the API and Admin > API Keys rebuilt; new api/v1/roles/read.php where an admin key reads every role with its level per module and agent count, archived on request, and any other key reads only its own user's role, and new api/v1/technicians/read.php listing agents with their role under Support at Read; API role refusals now say what the call needs and what the key's user has, naming the module, level and role, and technicians/time.php needs Read instead of Modify; Admin > API Keys shows each key's agent and role, what it can open and for which clients, whether it works (works until, expires in N days, expired, or won't work with the reason when its agent is disabled, archived, has no role or is missing) and when it was last used, with search by key or agent name; New and Edit windows show the picked agent's access as they are picked and offer only active agents, Create before ticking the copied box opens the Key tab, new keys default to a year and must end after today, and an expired key can be renamed and stay expired; handlers moved to functions/api_keys.php with validation, escaped messages and audit entries naming the agent and what an edit changed, fixing empty names on revoke, delete and bulk delete, a backslash shown for apostrophes in names, the bulk count of keys ticked rather than deleted, keys created already expired and expired keys that could not be renamed; database 3.1.7 adds api_keys.api_key_last_used_at, set at most once a minute in the configured timezone; changelog updated
2026-10-17 21:10:48 -04:00

43 lines
1.6 KiB
PHP

<?php
/*
* API - Technicians - Read
* GET /api/v1/technicians/read.php
*
* The agents - who tickets can be assigned to - with their role. Needs Read
* on Support. Sign in details (password, MFA, tokens) are never included.
*
* Parameters (GET):
* api_key required - Your API key
* technician_id optional - One agent, archived or not
* archived optional - 1 to include archived agents in the list
* limit optional - Max rows to return (default 50)
* offset optional - Offset for pagination (default 0)
*
* Each: technician_id, technician_name, technician_email, technician_status
* (1 active, 0 disabled), role_id, role_name, role_is_admin (1 or 0),
* technician_created_at and technician_archived_at.
*/
require_once '../validate_api_key.php';
require_once '../require_get_method.php';
$where = 'user_type = 1';
if (isset($_GET['technician_id'])) {
$where .= ' AND user_id = ' . intval($_GET['technician_id']);
} elseif (intval($_GET['archived'] ?? 0) !== 1) {
$where .= ' AND user_archived_at IS NULL';
}
$sql = mysqli_query($mysqli, "SELECT user_id AS technician_id, user_name AS technician_name, user_email AS technician_email,
user_status AS technician_status, user_role_id AS role_id, role_name, IFNULL(role_is_admin, 0) AS role_is_admin,
user_created_at AS technician_created_at, user_archived_at AS technician_archived_at
FROM users
LEFT JOIN user_roles ON role_id = user_role_id
WHERE $where
ORDER BY user_name ASC LIMIT $limit OFFSET $offset");
// Output
require_once "../read_output.php";