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:
Jeppe Bundgaard
2026-02-11 17:58:55 +01:00
parent 34ea4937e0
commit e9e0b3e19e
2 changed files with 15 additions and 1 deletions
+6
View File
@@ -106,6 +106,12 @@ paths:
required: false
schema:
type: string
- name: include_non_enabled
in: query
required: false
description: Include subusers that only have non-enabled grants (default false)
schema:
type: boolean
responses:
'200':
description: List of visible subusers
+9 -1
View File
@@ -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
);