Skip to content

Commit

Permalink
Merge pull request #2940 from sorenmalling/task/adjust-to-account-int…
Browse files Browse the repository at this point in the history
…erface

[TASK] Adjust codebase to support new Account and Roles API
  • Loading branch information
kitsunet committed Mar 20, 2020
2 parents ca650c1 + 0dd707a commit 24fd93b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Neos.Neos/Classes/Command/UserCommandController.php
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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()
]);
}
Expand All @@ -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) {
Expand Down
Expand Up @@ -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())
]);
}

Expand Down
12 changes: 6 additions & 6 deletions Neos.Neos/Classes/Domain/Service/UserService.php
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -463,15 +463,16 @@ 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);
}
}
Expand All @@ -490,7 +491,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);
Expand Down
Expand Up @@ -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);
}
}

0 comments on commit 24fd93b

Please sign in to comment.