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

Fix registration error caused by a non-existing role name. #143

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from

Conversation

szz
Copy link

@szz szz commented Sep 10, 2021

UserManager->createUserRole uses the role key instead of the role name to create a new user, because the role name should be only a human readable value and not a key

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets fixes #issuenum
Related issues/PRs #issuenum
License MIT

What's in this PR?

the commit-msg describes itself

Why?

UserManager->createUserRole uses the role key instead of the role name to create a new user, because the role name should be only a human readable value and not a key
@@ -180,7 +180,7 @@ public function getUniqueToken(string $field): string
protected function createUserRole(User $user, string $webspaceKey, string $roleName): UserRole
{
/** @var RoleInterface $role */
$role = $this->roleRepository->findOneBy(['name' => $roleName]);
$role = $this->roleRepository->findOneBy(['key' => $roleName]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request! It looks like this is a bug and was forgotten to be changed in #130.

Unfortunately, the new implementation might break things for users that use an older Sulu version. Therefore we need to fallback to the old behaviour like in the InitCommand:

if (\method_exists(Role::class, 'setKey')) {
/** @var RoleInterface|null $role */
$role = $roleRepository->findOneBy(['key' => $roleName, 'system' => $system]);
} else {
// can be removed when min requirement sulu 2.1
/** @var RoleInterface|null $role */
$role = $roleRepository->findOneBy(['name' => $roleName, 'system' => $system]);
}

Also, i think it would be nice to update the code and use roleKey instead of roleName as variable name in the InitCommand, UserManager and UserManagerInterface 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants