Skip to content

Commit

Permalink
Deprecate user plainPassword in favor of using UserManipulator
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Mar 6, 2024
1 parent f6e45db commit 8e9a414
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -38,7 +38,7 @@
"require": {
"php": "^8.1",
"ext-json": "*",
"nucleos/user-bundle": "^3.3",
"nucleos/user-bundle": "^3.4",
"psr/container": "^1.0 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"sonata-project/admin-bundle": "^4.8.1",
Expand Down
22 changes: 20 additions & 2 deletions src/Admin/Model/UserAdmin.php
Expand Up @@ -18,6 +18,7 @@
use Nucleos\UserBundle\Model\LocaleAwareUser;
use Nucleos\UserBundle\Model\UserInterface;
use Nucleos\UserBundle\Model\UserManager;
use Nucleos\UserBundle\Util\UserManipulator;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
Expand All @@ -35,11 +36,14 @@ abstract class UserAdmin extends AbstractAdmin
{
protected UserManager $userManager;

public function __construct(UserManager $userManager)
private ?UserManipulator $userManipulator;

public function __construct(UserManager $userManager, UserManipulator $userManipulator = null)
{
parent::__construct();

$this->userManager = $userManager;
$this->userManager = $userManager;
$this->userManipulator = $userManipulator;
}

public function preUpdate($object): void
Expand All @@ -49,6 +53,11 @@ public function preUpdate($object): void
}
}

protected function postUpdate(object $object): void

Check warning on line 56 in src/Admin/Model/UserAdmin.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Model/UserAdmin.php#L56

Added line #L56 was not covered by tests
{
$this->updatePassword($object);

Check warning on line 58 in src/Admin/Model/UserAdmin.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Model/UserAdmin.php#L58

Added line #L58 was not covered by tests
}

protected function configureFormOptions(array &$formOptions): void
{
$formOptions['validation_groups'] = ['User', $this->isNewInstance() ? 'Registration' : 'Profile'];
Expand Down Expand Up @@ -191,6 +200,15 @@ protected function configureFormFields(FormMapper $form): void
;
}

private function updatePassword(UserInterface $user): void

Check warning on line 203 in src/Admin/Model/UserAdmin.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Model/UserAdmin.php#L203

Added line #L203 was not covered by tests
{
if (null === $user->getPlainPassword()) {
return;

Check warning on line 206 in src/Admin/Model/UserAdmin.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Model/UserAdmin.php#L205-L206

Added lines #L205 - L206 were not covered by tests
}

$this->userManipulator?->changePassword($user->getUsername(), $user->getPlainPassword());

Check failure on line 209 in src/Admin/Model/UserAdmin.php

View workflow job for this annotation

GitHub Actions / run / Static Code Analysis (8.3)

PossiblyNullArgument

src/Admin/Model/UserAdmin.php:209:71: PossiblyNullArgument: Argument 2 of Nucleos\UserBundle\Util\UserManipulator::changePassword cannot be null, possibly null value provided (see https://psalm.dev/078)

Check warning on line 209 in src/Admin/Model/UserAdmin.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Model/UserAdmin.php#L209

Added line #L209 was not covered by tests
}

private function isNewInstance(): bool
{
return !$this->hasSubject() || null === $this->id($this->getSubject());
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/admin_mongodb.php
Expand Up @@ -35,6 +35,7 @@
])
->args([
service('nucleos_user.user_manager'),
service('nucleos_user.util.user_manipulator'),

Check warning on line 38 in src/Resources/config/admin_mongodb.php

View check run for this annotation

Codecov / codecov/patch

src/Resources/config/admin_mongodb.php#L38

Added line #L38 was not covered by tests
])
->call('setTranslationDomain', [
'%nucleos_user_admin.admin.group.translation_domain%',
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/admin_orm.php
Expand Up @@ -35,6 +35,7 @@
])
->args([
service('nucleos_user.user_manager'),
service('nucleos_user.util.user_manipulator'),
])
->call('setTranslationDomain', [
'%nucleos_user_admin.admin.group.translation_domain%',
Expand Down

0 comments on commit 8e9a414

Please sign in to comment.