added functionality to archive clients
Some checks failed
PHPUnit / test (push) Has been cancelled

This commit is contained in:
2026-06-12 20:55:12 +02:00
parent 59ea2cd667
commit 5dff24a232
15 changed files with 436 additions and 48 deletions

View File

@ -309,25 +309,40 @@ function require_valid_token_web(): array {
* Returns [string $clause, array $params].
* $clientAlias is the table alias or name that has a coachID column (e.g. 'client').
*/
function rbac_client_filter(array $tokenRecord, string $clientAlias = 'client'): array {
/**
* @param string $archiveMode active — non-archived only (default); archived — archived only; all — no archive filter
*/
function rbac_client_filter(
array $tokenRecord,
string $clientAlias = 'client',
string $archiveMode = 'active'
): array {
$role = $tokenRecord['role'] ?? '';
$entityID = $tokenRecord['entityID'] ?? '';
switch ($role) {
case 'admin':
return ['1=1', []];
$clause = '1=1';
$params = [];
break;
case 'supervisor':
return [
"$clientAlias.coachID IN (SELECT coachID FROM coach WHERE supervisorID = :rbac_eid)",
[':rbac_eid' => $entityID]
];
$clause = "$clientAlias.coachID IN (SELECT coachID FROM coach WHERE supervisorID = :rbac_eid)";
$params = [':rbac_eid' => $entityID];
break;
case 'coach':
return [
"$clientAlias.coachID = :rbac_eid",
[':rbac_eid' => $entityID]
];
$clause = "$clientAlias.coachID = :rbac_eid";
$params = [':rbac_eid' => $entityID];
break;
default:
return ['0=1', []];
}
$archiveClause = match ($archiveMode) {
'archived' => "COALESCE($clientAlias.archived, 0) = 1",
'all' => '1=1',
default => "COALESCE($clientAlias.archived, 0) = 0",
};
return ["($clause) AND ($archiveClause)", $params];
}
// --- Translations: German (de) is the canonical source language ---