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

Deprecate user plainPassword in favor of using UserManipulator #602

Merged
merged 1 commit into from Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 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
24 changes: 22 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 @@
{
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 @@
}
}

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,17 @@
;
}

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
{
$plainPassword = $user->getPlainPassword();

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

View check run for this annotation

Codecov / codecov/patch

src/Admin/Model/UserAdmin.php#L205

Added line #L205 was not covered by tests

if (null === $plainPassword) {
return;

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

View check run for this annotation

Codecov / codecov/patch

src/Admin/Model/UserAdmin.php#L207-L208

Added lines #L207 - L208 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

src/Admin/Model/UserAdmin.php#L211

Added line #L211 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