Add include_non_enabled parameter to /subusers endpoint
- Allow listing subusers with only non-enabled grants by introducing an optional `include_non_enabled` query parameter. - Update SQL query logic to conditionally include non-enabled subuser grants. - Extend OpenAPI documentation to reflect the new parameter with its description and schema.
This commit is contained in:
@@ -445,9 +445,17 @@ class subusersRoute
|
||||
$response->error('Unauthorized', 401);
|
||||
}
|
||||
|
||||
// Optional: include_non_enabled (boolean) — when true, include subusers that only have non-enabled grants
|
||||
$includeNonEnabled = false;
|
||||
if (self::isParametersSet(['include_non_enabled'])) {
|
||||
$tmp = filter_var(self::getParameter('include_non_enabled'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
||||
$includeNonEnabled = $tmp === null ? false : (bool)$tmp;
|
||||
}
|
||||
|
||||
// Only list subusers that have an enabled grant for the caller's customer number
|
||||
$existsClause = sprintf(
|
||||
"EXISTS (SELECT 1 FROM `subuser_grants` sg WHERE sg.`subuser` = `subusers`.`id` AND sg.`enabled` = 1 AND sg.`deleted_at` IS NULL AND sg.`billing_customer_number` = %d)",
|
||||
"EXISTS (SELECT 1 FROM `subuser_grants` sg WHERE sg.`subuser` = `subusers`.`id` AND %ssg.`deleted_at` IS NULL AND sg.`billing_customer_number` = %d)",
|
||||
$includeNonEnabled ? '' : 'sg.`enabled` = 1 AND ',
|
||||
$customerNumber
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user