Skip to content

Commit

Permalink
Merge 5.x into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI authored Aug 27, 2024
2 parents 35fe4f6 + c56ae30 commit 5ca071e
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# It's auto-generated by sonata-project/dev-kit package.

github: [jordisala1991, OskarStark, VincentLanglet, core23]
github: [jordisala1991, VincentLanglet, OskarStark, core23]
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [5.13.0](https://github.com/sonata-project/SonataUserBundle/compare/5.12.0...5.13.0) - 2024-08-26
### Changed
- [[#1576](https://github.com/sonata-project/SonataUserBundle/pull/1576)] Make Reset Password Optional ([@Hanmac](https://github.com/Hanmac))

### Fixed
- [[#1689](https://github.com/sonata-project/SonataUserBundle/pull/1689)] Symfony 7.1 deprecation about `Symfony\Component\HttpKernel\DependencyInjection\Extension` usage ([@VincentLanglet](https://github.com/VincentLanglet))

### Removed
- [[#1695](https://github.com/sonata-project/SonataUserBundle/pull/1695)] After requesting new passwort the username isn't passed to CheckEmailAction anymode ([@VincentLanglet](https://github.com/VincentLanglet))

## [5.12.0](https://github.com/sonata-project/SonataUserBundle/compare/5.11.0...5.12.0) - 2024-04-18
### Added
- [[#1677](https://github.com/sonata-project/SonataUserBundle/pull/1677)] BaseUser3 with roles mapped type as `json` to be compatible with ORM 3 ([@RobinDev](https://github.com/RobinDev))
Expand Down
92 changes: 79 additions & 13 deletions src/Action/CheckEmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,98 @@

use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;

final class CheckEmailAction
{
private Pool $adminPool;
private TemplateRegistryInterface $templateRegistry;
private int $tokenTtl;

/**
* NEXT_MAJOR: Remove `$tokenTtlDeprecated` argument and only allow first types of arguments.
*/
public function __construct(
private Environment $twig,
private UrlGeneratorInterface $urlGenerator,
private Pool $adminPool,
private TemplateRegistryInterface $templateRegistry,
private int $tokenTtl
Pool|UrlGeneratorInterface $adminPool,
TemplateRegistryInterface|Pool $templateRegistry,
int|TemplateRegistryInterface $tokenTtl,
?int $tokenTtlDeprecated = null,
) {
}
// NEXT_MAJOR: Remove all checks and use constructor property promotion instead
if ($adminPool instanceof UrlGeneratorInterface) {
if (!$templateRegistry instanceof Pool) {
throw new \TypeError(\sprintf(
'Argument 3 passed to %s() must be an instance of %s, %s given.',
__METHOD__,
Pool::class,
$templateRegistry::class
));
}
$this->adminPool = $templateRegistry;

public function __invoke(Request $request): Response
{
$username = $request->query->get('username');
if (!$tokenTtl instanceof TemplateRegistryInterface) {
throw new \TypeError(\sprintf(
'Argument 4 passed to %s() must be an instance of %s, int given.',
__METHOD__,
TemplateRegistryInterface::class,
));
}
$this->templateRegistry = $tokenTtl;

if (!\is_int($tokenTtlDeprecated)) {
throw new \TypeError(\sprintf(
'Argument 5 passed to %s() must be type of %s, %s given.',
__METHOD__,
'integer',
\gettype($tokenTtlDeprecated)
));
}
$this->tokenTtl = $tokenTtlDeprecated;

if (null === $username) {
// the user does not come from the sendEmail action
return new RedirectResponse($this->urlGenerator->generate('sonata_user_admin_resetting_request'));
@trigger_error(\sprintf(
'Passing an instance of %s as argument 2 to "%s()" is deprecated since sonata-project/user-bundle 5.13 and will only accept an instance of %s in version 6.0.',
UrlGeneratorInterface::class,
__METHOD__,
Pool::class
), \E_USER_DEPRECATED);
} else {
$this->adminPool = $adminPool;
if (!$templateRegistry instanceof TemplateRegistryInterface) {
throw new \TypeError(\sprintf(
'Argument 3 passed to %s() must be an instance of %s, %s given.',
__METHOD__,
TemplateRegistryInterface::class,
$templateRegistry::class
));
}
$this->templateRegistry = $templateRegistry;

if (!\is_int($tokenTtl)) {
throw new \TypeError(\sprintf(
'Argument 4 passed to %s() must be type of %s, %s given.',
__METHOD__,
'integer',
\gettype($tokenTtl)
));
}
$this->tokenTtl = $tokenTtl;

if (null !== $tokenTtlDeprecated) {
throw new \TypeError(\sprintf(
'Argument 5 passed to %s() must be %s, %s given.',
__METHOD__,
'NULL',
\gettype($tokenTtlDeprecated)
));
}
}
}

public function __invoke(): Response
{
return new Response($this->twig->render('@SonataUser/Admin/Security/Resetting/checkEmail.html.twig', [
'base_template' => $this->templateRegistry->getTemplate('layout'),
'admin_pool' => $this->adminPool,
Expand Down
4 changes: 1 addition & 3 deletions src/Action/RequestAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public function __invoke(Request $request): Response
$this->userManager->save($user);
}

return new RedirectResponse($this->urlGenerator->generate('sonata_user_admin_resetting_check_email', [
'username' => $username,
]));
return new RedirectResponse($this->urlGenerator->generate('sonata_user_admin_resetting_check_email'));
}

return new Response($this->twig->render('@SonataUser/Admin/Security/Resetting/request.html.twig', [
Expand Down
2 changes: 1 addition & 1 deletion src/Action/ResetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __invoke(Request $request, string $token): Response
$user = $this->userManager->findUserByConfirmationToken($token);

if (null === $user) {
throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
throw new NotFoundHttpException(\sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
}

if (!$user->isPasswordRequestNonExpired($this->tokenTtl)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

$user->setEnabled(true);

$this->userManager->save($user);

$output->writeln(sprintf('User "%s" has been activated.', $username));
$output->writeln(\sprintf('User "%s" has been activated.', $username));

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

$user->setPlainPassword($password);

$this->userManager->updatePassword($user);
$this->userManager->save($user);

$output->writeln(sprintf('Changed password for user "%s".', $username));
$output->writeln(\sprintf('Changed password for user "%s".', $username));

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->userManager->save($user);

$output->writeln(sprintf('Created user "%s".', $username));
$output->writeln(\sprintf('Created user "%s".', $username));

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

$user->setEnabled(false);

$this->userManager->save($user);

$output->writeln(sprintf('User "%s" has been activated.', $username));
$output->writeln(\sprintf('User "%s" has been activated.', $username));

return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Command/DemoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

if ($superAdmin) {
$user->setSuperAdmin(false);

$output->writeln(sprintf('User "%s" has been demoted as a simple user. This change will not apply until the user logs out and back in again.', $username));
$output->writeln(\sprintf('User "%s" has been demoted as a simple user. This change will not apply until the user logs out and back in again.', $username));
} elseif ($user->hasRole($role)) {
$user->removeRole($role);

$output->writeln(sprintf('Role "%s" has been removed from user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
$output->writeln(\sprintf('Role "%s" has been removed from user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
} else {
$output->writeln(sprintf('User "%s" didn\'t have "%s" role.', $username, $role));
$output->writeln(\sprintf('User "%s" didn\'t have "%s" role.', $username, $role));
}

$this->userManager->save($user);
Expand Down
8 changes: 4 additions & 4 deletions src/Command/PromoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

if ($superAdmin) {
$user->setSuperAdmin(true);

$output->writeln(sprintf('User "%s" has been promoted as a super administrator. This change will not apply until the user logs out and back in again.', $username));
$output->writeln(\sprintf('User "%s" has been promoted as a super administrator. This change will not apply until the user logs out and back in again.', $username));
} elseif (!$user->hasRole($role)) {
$user->addRole($role);

$output->writeln(sprintf('Role "%s" has been added to user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
$output->writeln(\sprintf('Role "%s" has been added to user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
} else {
$output->writeln(sprintf('User "%s" did already have "%s" role.', $username, $role));
$output->writeln(\sprintf('User "%s" did already have "%s" role.', $username, $role));
}

$this->userManager->save($user);
Expand Down
10 changes: 5 additions & 5 deletions src/DependencyInjection/SonataUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public function load(array $configs, ContainerBuilder $container): void

if (isset($bundles['SonataAdminBundle'])) {
$loader->load('admin.php');
$loader->load(sprintf('admin_%s.php', $config['manager_type']));
$loader->load(\sprintf('admin_%s.php', $config['manager_type']));
$loader->load('actions.php');
}

$loader->load(sprintf('%s.php', $config['manager_type']));
$loader->load(\sprintf('%s.php', $config['manager_type']));
$container->setParameter('sonata.user.manager_type', $config['manager_type']);

$loader->load('twig.php');
Expand Down Expand Up @@ -121,7 +121,7 @@ private function configureResetting(array $config, ContainerBuilder $container):
->replaceArgument(9, $config['retry_ttl']);

$container->getDefinition('sonata.user.action.check_email')
->replaceArgument(4, $config['token_ttl']);
->replaceArgument(3, $config['token_ttl']);

$container->getDefinition('sonata.user.action.reset')
->replaceArgument(8, $config['token_ttl']);
Expand All @@ -139,7 +139,7 @@ private function checkManagerTypeToModelTypesMapping(array $config): void
$managerType = $config['manager_type'];

if (!\in_array($managerType, ['orm', 'mongodb'], true)) {
throw new \InvalidArgumentException(sprintf('Invalid manager type "%s".', $managerType));
throw new \InvalidArgumentException(\sprintf('Invalid manager type "%s".', $managerType));
}

$this->prohibitModelTypeMapping(
Expand All @@ -162,7 +162,7 @@ private function prohibitModelTypeMapping(
): void {
if (is_a($actualModelClass, $prohibitedModelClass, true)) {
throw new \InvalidArgumentException(
sprintf(
\sprintf(
'Model class "%s" does not correspond to manager type "%s".',
$actualModelClass,
$managerType
Expand Down
2 changes: 1 addition & 1 deletion src/Mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function sendResettingEmailMessage(UserInterface $user): void

$this->mailer->send(
(new Email())
->from(sprintf('%s <%s>', $fromName, $fromAddress))
->from(\sprintf('%s <%s>', $fromName, $fromAddress))
->to((string) $user->getEmail())
->subject($subject)
->html($body)
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/actions_resetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
->public()
->args([
service('twig'),
service('router'),
service('sonata.admin.pool'),
service('sonata.admin.global_template_registry'),
abstract_arg('token ttl'),
Expand Down
2 changes: 1 addition & 1 deletion src/Security/RolesBuilder/AdminRolesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function getAdminRolesByAdminCode(string $code, ?string $domain = null,
$adminLabelTranslated = $admin->getTranslator()->trans($admin->getLabel() ?? '', [], $admin->getTranslationDomain());
$isMasterAdmin = $this->isMaster($admin);
foreach (array_keys($admin->getSecurityInformation()) as $key) {
$role = sprintf($baseRole, $key);
$role = \sprintf($baseRole, $key);
$adminRoles[$role] = [
'role' => $role,
'label' => $key,
Expand Down
8 changes: 4 additions & 4 deletions src/Security/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function loadUserByIdentifier(string $identifier): SecurityUserInterface
$user = $this->findUser($identifier);

if (null === $user || !$user->isEnabled()) {
throw new UserNotFoundException(sprintf('Username "%s" does not exist.', $identifier));
throw new UserNotFoundException(\sprintf('Username "%s" does not exist.', $identifier));
}

return $user;
Expand All @@ -51,15 +51,15 @@ public function loadUserByIdentifier(string $identifier): SecurityUserInterface
public function refreshUser(SecurityUserInterface $user): SecurityUserInterface
{
if (!$user instanceof UserInterface) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', UserInterface::class, $user::class));
throw new UnsupportedUserException(\sprintf('Expected an instance of %s, but got "%s".', UserInterface::class, $user::class));
}

if (!$this->supportsClass($user::class)) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), $user::class));
throw new UnsupportedUserException(\sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), $user::class));
}

if (null === $reloadedUser = $this->userManager->findOneBy(['id' => $user->getId()])) {
throw new UserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId() ?? ''));
throw new UserNotFoundException(\sprintf('User with ID "%s" could not be reloaded.', $user->getId() ?? ''));
}

return $reloadedUser;
Expand Down
Loading

0 comments on commit 5ca071e

Please sign in to comment.