From da1a2ac89d6d0535f935fc80d4c3f19cae14afb4 Mon Sep 17 00:00:00 2001 From: Soren Malling Date: Wed, 18 Mar 2020 09:42:52 +0100 Subject: [PATCH 1/2] [TASK] Adjust codebase to support new Account and Roles API --- .../Classes/Command/UserCommandController.php | 2 +- .../Module/Administration/UsersController.php | 4 ++-- .../Module/User/UserSettingsController.php | 2 +- Neos.Neos/Classes/Domain/Service/UserService.php | 14 ++++++++------ .../AuthenticationProviderLabelViewHelper.php | 3 ++- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Neos.Neos/Classes/Command/UserCommandController.php b/Neos.Neos/Classes/Command/UserCommandController.php index f0e1f20808c..9b705f291c9 100644 --- a/Neos.Neos/Classes/Command/UserCommandController.php +++ b/Neos.Neos/Classes/Command/UserCommandController.php @@ -385,7 +385,7 @@ protected function getTableRowForUser(User $user) $accountIdentifiers = []; foreach ($user->getAccounts() as $account) { /** @var Account $account */ - $authenticationProviderName = $account->getAuthenticationProviderName(); + $authenticationProviderName = (string) $account->getAuthenticationProviderName(); if ($authenticationProviderName !== $this->userService->getDefaultAuthenticationProviderName()) { $authenticationProviderLabel = ' (' . (isset($this->authenticationProviderSettings[$authenticationProviderName]['label']) ? $this->authenticationProviderSettings[$authenticationProviderName]['label'] : $authenticationProviderName) . ')'; } else { diff --git a/Neos.Neos/Classes/Controller/Module/Administration/UsersController.php b/Neos.Neos/Classes/Controller/Module/Administration/UsersController.php index d6ee0dd1392..3b7da720015 100644 --- a/Neos.Neos/Classes/Controller/Module/Administration/UsersController.php +++ b/Neos.Neos/Classes/Controller/Module/Administration/UsersController.php @@ -222,7 +222,7 @@ public function editAccountAction(Account $account): void { $this->view->assignMultiple([ 'account' => $account, - 'user' => $this->userService->getUser($account->getAccountIdentifier(), $account->getAuthenticationProviderName()), + 'user' => $this->userService->getUser($account->getAccountIdentifier(), (string) $account->getAuthenticationProviderName()), 'availableRoles' => $this->policyService->getRoles() ]); } @@ -242,7 +242,7 @@ public function editAccountAction(Account $account): void */ public function updateAccountAction(Account $account, array $roleIdentifiers, array $password = []): void { - $user = $this->userService->getUser($account->getAccountIdentifier(), $account->getAuthenticationProviderName()); + $user = $this->userService->getUser($account->getAccountIdentifier(), (string) $account->getAuthenticationProviderName()); if ($user === $this->currentUser) { $roles = []; foreach ($roleIdentifiers as $roleIdentifier) { diff --git a/Neos.Neos/Classes/Controller/Module/User/UserSettingsController.php b/Neos.Neos/Classes/Controller/Module/User/UserSettingsController.php index 6333f74135f..cd45f309a61 100644 --- a/Neos.Neos/Classes/Controller/Module/User/UserSettingsController.php +++ b/Neos.Neos/Classes/Controller/Module/User/UserSettingsController.php @@ -115,7 +115,7 @@ public function editAccountAction(Account $account) { $this->view->assignMultiple([ 'account' => $account, - 'user' => $this->userService->getUser($account->getAccountIdentifier(), $account->getAuthenticationProviderName()) + 'user' => $this->userService->getUser($account->getAccountIdentifier(), (string) $account->getAuthenticationProviderName()) ]); } diff --git a/Neos.Neos/Classes/Domain/Service/UserService.php b/Neos.Neos/Classes/Domain/Service/UserService.php index bdb0bc20744..551a27ddbb0 100644 --- a/Neos.Neos/Classes/Domain/Service/UserService.php +++ b/Neos.Neos/Classes/Domain/Service/UserService.php @@ -221,7 +221,7 @@ public function getUsername(User $user, $authenticationProviderName = null) $authenticationProviderName = $authenticationProviderName ?: $this->defaultAuthenticationProviderName; foreach ($user->getAccounts() as $account) { /** @var Account $account */ - if ($account->getAuthenticationProviderName() === $authenticationProviderName) { + if ((string) $account->getAuthenticationProviderName() === $authenticationProviderName) { return $account->getAccountIdentifier(); } } @@ -375,7 +375,7 @@ public function setUserPassword(User $user, $password) foreach ($user->getAccounts() as $account) { /** @var Account $account */ - $authenticationProviderName = $account->getAuthenticationProviderName(); + $authenticationProviderName = (string) $account->getAuthenticationProviderName(); if (isset($indexedTokens[$authenticationProviderName]) && $indexedTokens[$authenticationProviderName] instanceof UsernamePassword) { $account->setCredentialsSource($this->hashService->hashPassword($password)); $this->accountRepository->update($account); @@ -463,15 +463,18 @@ public function setRolesForAccount(Account $account, array $newRoleIdentifiers) { $currentRoles = $account->getRoles(); - foreach ($currentRoles as $roleIdentifier => $role) { - $roleIdentifier = $this->normalizeRoleIdentifier($roleIdentifier); + /** @var Role $role */ + foreach ($currentRoles as $role) { + + $roleIdentifier = $this->normalizeRoleIdentifier((string) $role); if (!in_array($roleIdentifier, $newRoleIdentifiers)) { $this->removeRoleFromAccount($account, $roleIdentifier); } } foreach ($newRoleIdentifiers as $roleIdentifier) { - if (!in_array($roleIdentifier, array_keys($currentRoles))) { + + if (!$currentRoles->has(new Role($roleIdentifier))) { $this->addRoleToAccount($account, $roleIdentifier); } } @@ -490,7 +493,6 @@ public function addRoleToAccount(Account $account, $roleIdentifier) { $roleIdentifier = $this->normalizeRoleIdentifier($roleIdentifier); $role = $this->policyService->getRole($roleIdentifier); - if (!$account->hasRole($role)) { $account->addRole($role); $this->accountRepository->update($account); diff --git a/Neos.Neos/Classes/ViewHelpers/Backend/AuthenticationProviderLabelViewHelper.php b/Neos.Neos/Classes/ViewHelpers/Backend/AuthenticationProviderLabelViewHelper.php index e14b3b4b07f..7c32eb3debb 100644 --- a/Neos.Neos/Classes/ViewHelpers/Backend/AuthenticationProviderLabelViewHelper.php +++ b/Neos.Neos/Classes/ViewHelpers/Backend/AuthenticationProviderLabelViewHelper.php @@ -43,7 +43,8 @@ public function initializeArguments() */ public function render(): string { - $identifier = $this->arguments['identifier']; + $identifier = (string) $this->arguments['identifier']; + return ($this->authenticationProviderSettings[$identifier]['label'] ?? $identifier); } } From 0dd707a16dd708a987cb2b63c66017d347f91bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20G=C3=BCnther?= Date: Fri, 20 Mar 2020 10:43:44 +0100 Subject: [PATCH 2/2] TASK: remove empty lines --- Neos.Neos/Classes/Domain/Service/UserService.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Neos.Neos/Classes/Domain/Service/UserService.php b/Neos.Neos/Classes/Domain/Service/UserService.php index 551a27ddbb0..72b0f804116 100644 --- a/Neos.Neos/Classes/Domain/Service/UserService.php +++ b/Neos.Neos/Classes/Domain/Service/UserService.php @@ -465,7 +465,6 @@ public function setRolesForAccount(Account $account, array $newRoleIdentifiers) /** @var Role $role */ foreach ($currentRoles as $role) { - $roleIdentifier = $this->normalizeRoleIdentifier((string) $role); if (!in_array($roleIdentifier, $newRoleIdentifiers)) { $this->removeRoleFromAccount($account, $roleIdentifier); @@ -473,7 +472,6 @@ public function setRolesForAccount(Account $account, array $newRoleIdentifiers) } foreach ($newRoleIdentifiers as $roleIdentifier) { - if (!$currentRoles->has(new Role($roleIdentifier))) { $this->addRoleToAccount($account, $roleIdentifier); }