This commit is contained in:
35
common.php
35
common.php
@ -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 ---
|
||||
|
||||
Reference in New Issue
Block a user