Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Adjust codebase to support new Account and Roles API #2940

Merged
merged 2 commits into from Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
14 changes: 8 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,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);
}
}
Expand All @@ -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);
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);
}
}