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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Manager/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 🙂

$userRole = new UserRole();

$locales = [];
Expand Down