diff --git a/src/Controller/Backend/ProfileController.php b/src/Controller/Backend/ProfileController.php index dc093dfa6..c0bc051a3 100644 --- a/src/Controller/Backend/ProfileController.php +++ b/src/Controller/Backend/ProfileController.php @@ -57,14 +57,14 @@ public function edit(): Response /** * @Route("/profile-edit", methods={"POST"}, name="bolt_profile_edit_post") */ - public function save(ValidatorInterface $validator): Response + public function save(ValidatorInterface $validator, string $defaultLocale): Response { $this->validateCsrf('profileedit'); /** @var User $user */ $user = $this->getUser(); $displayName = $user->getDisplayName(); - $locale = Json::findScalar($this->getFromRequest('locale')); + $locale = Json::findScalar($this->getFromRequest('locale')) ?: $defaultLocale; $user->setDisplayName((string) $this->getFromRequest('displayName')); $user->setEmail((string) $this->getFromRequest('email')); diff --git a/src/Controller/Backend/UserEditController.php b/src/Controller/Backend/UserEditController.php index 2f9729471..346462c28 100644 --- a/src/Controller/Backend/UserEditController.php +++ b/src/Controller/Backend/UserEditController.php @@ -135,7 +135,7 @@ public function delete(?User $user): Response /** * @Route("/user-edit/{id}", methods={"POST"}, name="bolt_user_edit_post", requirements={"id": "\d+"}) */ - public function save(?User $user, ValidatorInterface $validator): Response + public function save(?User $user, ValidatorInterface $validator, string $defaultLocale): Response { $this->validateCsrf('useredit'); @@ -144,9 +144,9 @@ public function save(?User $user, ValidatorInterface $validator): Response } $displayName = $user->getDisplayName(); - $locale = Json::findScalar($this->getFromRequest('locale')); + $locale = Json::findScalar($this->getFromRequest('locale')) ?: $defaultLocale; $roles = Json::findArray($this->getFromRequest('roles')); - $status = Json::findScalar($this->getFromRequest('ustatus', UserStatus::ENABLED)); + $status = Json::findScalar($this->getFromRequest('ustatus')) ?: UserStatus::ENABLED; if (empty($user->getUsername())) { $user->setUsername($this->getFromRequest('username')); diff --git a/tests/e2e/users.feature b/tests/e2e/users.feature index cfbbd90d3..b98db751a 100644 --- a/tests/e2e/users.feature +++ b/tests/e2e/users.feature @@ -59,7 +59,8 @@ Feature: Users & Permissions Then I should be on "/bolt/user-edit/0" And I should see "New User" in the ".admin__header--title" element - + And I wait 0.1 seconds + When I fill in the following: | username | test_user | | displayName | Test user | @@ -151,6 +152,7 @@ Feature: Users & Permissions And I should see "Suggested secure password" @javascript + @foo Scenario: Edit my user with incorrect display name Given I am logged in as "jane_admin" with password "jane%1" @@ -162,9 +164,10 @@ Feature: Users & Permissions And I should see "Jane Doe" in the "h1" element And the field "username" should contain "jane_admin" - + And I wait 0.1 seconds When I fill "displayName" element with " " And I scroll "Save changes" into view + And I press "Save changes" Then I should see "Invalid display name"