fix: KeycloakAdminService - constante PATH_GROUPS, fusion if imbriqués
- Ajout constante PATH_GROUPS = '/groups' (remplace 4 littéraux dupliqués) - Fusion des 2 if imbriqués dans ensureRequiredGroups en une seule condition avec && (in_array + createGroup) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
class KeycloakAdminService
|
||||
{
|
||||
private const PATH_USERS = '/users';
|
||||
private const PATH_GROUPS = '/groups';
|
||||
private const AUTH_BEARER = 'Bearer ';
|
||||
|
||||
/** Groupes requis pour le CRM SITECONSEIL */
|
||||
@@ -53,10 +54,8 @@ class KeycloakAdminService
|
||||
$created = [];
|
||||
|
||||
foreach (self::REQUIRED_GROUPS as $groupName) {
|
||||
if (!\in_array($groupName, $existingNames, true)) {
|
||||
if ($this->createGroup($groupName)) {
|
||||
$created[] = $groupName;
|
||||
}
|
||||
if (!\in_array($groupName, $existingNames, true) && $this->createGroup($groupName)) {
|
||||
$created[] = $groupName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +68,7 @@ class KeycloakAdminService
|
||||
public function createGroup(string $groupName): bool
|
||||
{
|
||||
$token = $this->getToken();
|
||||
$response = $this->httpClient->request('POST', $this->getAdminUrl('/groups'), [
|
||||
$response = $this->httpClient->request('POST', $this->getAdminUrl(self::PATH_GROUPS), [
|
||||
'headers' => ['Authorization' => self::AUTH_BEARER.$token],
|
||||
'json' => ['name' => $groupName],
|
||||
]);
|
||||
@@ -267,7 +266,7 @@ class KeycloakAdminService
|
||||
public function listGroups(): array
|
||||
{
|
||||
$token = $this->getToken();
|
||||
$response = $this->httpClient->request('GET', $this->getAdminUrl('/groups'), [
|
||||
$response = $this->httpClient->request('GET', $this->getAdminUrl(self::PATH_GROUPS), [
|
||||
'headers' => ['Authorization' => self::AUTH_BEARER.$token],
|
||||
]);
|
||||
|
||||
@@ -285,7 +284,7 @@ class KeycloakAdminService
|
||||
private function getGroupIdByName(string $groupName): ?string
|
||||
{
|
||||
$token = $this->getToken();
|
||||
$response = $this->httpClient->request('GET', $this->getAdminUrl('/groups'), [
|
||||
$response = $this->httpClient->request('GET', $this->getAdminUrl(self::PATH_GROUPS), [
|
||||
'headers' => ['Authorization' => self::AUTH_BEARER.$token],
|
||||
'query' => ['search' => $groupName, 'exact' => 'true'],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user