From 64db8bd5b102489e2b7ef8c601c0aaa10105cbc6 Mon Sep 17 00:00:00 2001 From: mamazu <14860264+mamazu@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:07:16 +0200 Subject: [PATCH 1/4] Fixing workflow badge (#169) Refs sulu/sulu#7010 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6858474..78b402c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ <img src="https://img.shields.io/github/license/sulu/SuluCommunityBundle.svg" alt="GitHub license"> </a> <a href="https://github.com/sulu/SuluCommunityBundle/actions" target="_blank"> - <img src="https://img.shields.io/github/workflow/status/sulu/SuluCommunityBundle/Test%20application?label=test-workflow" alt="Test workflow status"> + <img src="https://img.shields.io/github/actions/workflow/status/sulu/SuluCommunityBundle/test-application.yaml" alt="Test workflow status"> </a> <a href="https://github.com/sulu/sulu/releases" target="_blank"> <img src="https://img.shields.io/badge/sulu%20compatibility-%3E=2.0-52b6ca.svg" alt="Sulu compatibility"> From 723b4b40fdbd08c69db1a27631ab69641495ec73 Mon Sep 17 00:00:00 2001 From: dev-newvisibility <89986734+dev-newvisibility@users.noreply.github.com> Date: Thu, 25 Apr 2024 18:20:18 +0200 Subject: [PATCH 2/4] Add compatibility with Sulu 2.5 - Symfony 6 (#162) --- .github/workflows/test-application.yaml | 20 ++++- .php-cs-fixer.dist.php | 41 +++++----- Controller/AbstractController.php | 34 +++++--- Controller/BlacklistItemController.php | 3 +- Controller/SaveMediaTrait.php | 4 +- .../CommunityManagerCompilerPass.php | 1 - DependencyInjection/Configuration.php | 4 +- .../SuluCommunityExtension.php | 2 +- Entity/BlacklistItem.php | 4 - EventListener/CompletionListener.php | 2 +- EventListener/LastLoginListener.php | 2 +- Form/Type/RegistrationType.php | 2 +- Mail/Mail.php | 2 - Mail/MailFactory.php | 57 +++++++++++-- Manager/CommunityManager.php | 1 - Manager/CommunityManagerInterface.php | 11 +-- Tests/Application/Kernel.php | 2 +- Tests/Application/config/config.php | 28 +++++++ .../{config_admin.yml => context_admin.yml} | 2 +- Tests/Application/config/context_website.yml | 9 +++ .../{config_website.yml => security-5-4.yml} | 10 --- Tests/Application/config/security-6.yml | 29 +++++++ .../config/{config.yml => sulu.yml} | 5 +- .../Controller/RegistrationTest.php | 64 ++++++++------- .../Entity/BlacklistItemRepositoryTest.php | 2 +- Tests/Unit/Listener/BlacklistListenerTest.php | 2 +- .../EmailConfirmationListenerTest.php | 2 +- Tests/Unit/Mail/MailFactoryTest.php | 79 ++++++++----------- Tests/phpstan/object-manager.php | 2 +- composer.json | 51 +++++++----- phpstan-baseline.neon | 64 ++++++++++++++- 31 files changed, 360 insertions(+), 181 deletions(-) create mode 100644 Tests/Application/config/config.php rename Tests/Application/config/{config_admin.yml => context_admin.yml} (81%) create mode 100644 Tests/Application/config/context_website.yml rename Tests/Application/config/{config_website.yml => security-5-4.yml} (79%) create mode 100644 Tests/Application/config/security-6.yml rename Tests/Application/config/{config.yml => sulu.yml} (86%) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index d4cb96d..05db631 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -41,12 +41,25 @@ jobs: SYMFONY_DEPRECATIONS_HELPER: weak - php-version: '8.1' - lint: true + lint: false + dependency-versions: 'highest' + tools: 'composer:v2' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + + - php-version: '8.2' + lint: false dependency-versions: 'highest' tools: 'composer:v2' env: SYMFONY_DEPRECATIONS_HELPER: weak + - php-version: '8.3' + lint: true + dependency-versions: 'highest' + tools: 'composer:v2' + env: + SYMFONY_DEPRECATIONS_HELPER: weak services: mysql: image: mysql:5.7 @@ -71,6 +84,11 @@ jobs: if: ${{ matrix.php-version == '7.2' }} run: composer remove php-cs-fixer/shim --dev --no-interaction + - name: Install additional lowest dependencies + if: ${{ matrix.dependency-versions == 'lowest' }} + run: | + composer require symfony/swiftmailer-bundle --no-interaction --no-update + - name: Install composer dependencies uses: ramsey/composer-install@v1 with: diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 7434ac2..3a06d53 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -17,38 +17,33 @@ $config->setRiskyAllowed(true) ->setRules([ '@Symfony' => true, - '@Symfony:risky' => true, - 'ordered_imports' => true, - 'concat_space' => ['spacing' => 'one'], 'array_syntax' => ['syntax' => 'short'], - 'phpdoc_align' => ['align' => 'left'], - 'class_definition' => [ - 'multi_line_extends_each_single_line' => true, - ] , - 'linebreak_after_opening_tag' => true, -// 'declare_strict_types' => true, - 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], + 'class_definition' => false, + 'concat_space' => ['spacing' => 'one'], + 'function_declaration' => ['closure_function_spacing' => 'none'], + 'header_comment' => ['header' => $header], 'native_constant_invocation' => true, 'native_function_casing' => true, 'native_function_invocation' => ['include' => ['@internal']], - 'no_php4_constructor' => true, + 'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false], 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true], - 'no_unreachable_default_argument_value' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'php_unit_strict' => true, - 'phpdoc_order' => true, - 'semicolon_after_instruction' => true, - 'strict_comparison' => true, - 'strict_param' => true, - 'array_indentation' => true, - 'multiline_whitespace_before_semicolons' => true, + 'ordered_imports' => true, + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_types_order' => false, 'single_line_throw' => false, - 'visibility_required' => ['elements' => ['property', 'method', 'const']], + 'single_line_comment_spacing' => false, 'phpdoc_to_comment' => [ 'ignored_tags' => ['todo', 'var'], ], - 'trailing_comma_in_multiline' => ['elements' => ['arrays', /*'arguments', 'parameters' */]], + 'phpdoc_separation' => [ + 'groups' => [ + ['Serializer\\*', 'VirtualProperty', 'Accessor', 'Type', 'Groups', 'Expose', 'Exclude', 'SerializedName', 'Inline', 'ExclusionPolicy'], + ], + ], + 'get_class_to_class_keyword' => false, // should be enabled as soon as support for php < 8 is dropped + 'nullable_type_declaration_for_default_null_value' => true, + 'no_null_property_initialization' => false, + 'fully_qualified_strict_types' => false, ]) ->setFinder($finder); diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 38cf035..148a1b1 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -26,7 +26,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; -use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; /** * Contains helper function for all controllers. @@ -75,12 +75,26 @@ protected function setUserPasswordAndSalt(User $user, FormInterface $form): User } $user->setSalt($salt); - $password = $this->getUserPasswordEncoder()->encodePassword($user, $plainPassword); + $password = $this->encodePassword($user, $plainPassword); $user->setPassword($password); return $user; } + protected function encodePassword(User $user, string $plainPassword): string + { + if ($this->container->has('?security.password_hasher')) { + /** @var UserPasswordHasherInterface $hasher */ + $hasher = $this->container->get('?security.password_hasher'); + + return $hasher->hashPassword($user, $plainPassword); + } + /** @var \Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface $encoder */ + $encoder = $this->container->get('?security.password_encoder'); + + return $encoder->encodePassword($user, $plainPassword); + } + /** * Check if user should be logged in. */ @@ -132,9 +146,6 @@ private function getTemplateAttributes(array $custom = []): array return $this->getTemplateAttributeResolver()->resolve($custom); } - /** - * @return User - */ public function getUser(): ?User { $user = parent::getUser(); @@ -175,7 +186,7 @@ private function addAddress(User $user): void /** * @param mixed[] $parameters */ - public function render(string $view, array $parameters = [], Response $response = null): Response + public function render(string $view, array $parameters = [], ?Response $response = null): Response { return parent::render( $view, @@ -207,11 +218,6 @@ protected function getSaltGenerator(): SaltGenerator return $this->container->get('sulu_security.salt_generator'); } - protected function getUserPasswordEncoder(): UserPasswordEncoderInterface - { - return $this->container->get('security.password_encoder'); - } - protected function getTemplateAttributeResolver(): TemplateAttributeResolverInterface { return $this->container->get('sulu_website.resolver.template_attribute'); @@ -232,9 +238,13 @@ public static function getSubscribedServices(): array $subscribedServices['sulu_community.community_manager.registry'] = CommunityManagerRegistryInterface::class; $subscribedServices['sulu_core.webspace.request_analyzer'] = RequestAnalyzerInterface::class; $subscribedServices['sulu_security.salt_generator'] = SaltGenerator::class; - $subscribedServices['security.password_encoder'] = UserPasswordEncoderInterface::class; $subscribedServices['sulu_website.resolver.template_attribute'] = TemplateAttributeResolverInterface::class; $subscribedServices['doctrine.orm.entity_manager'] = EntityManagerInterface::class; + $subscribedServices['?security.password_hasher'] = UserPasswordHasherInterface::class; + + if (\class_exists('Symfony\\Component\\Security\\Core\\Encoder\\UserPasswordEncoderInterface')) { + $subscribedServices['?security.password_encoder'] = 'Symfony\\Component\\Security\\Core\\Encoder\\UserPasswordEncoderInterface'; + } return $subscribedServices; } diff --git a/Controller/BlacklistItemController.php b/Controller/BlacklistItemController.php index 1d46d1c..75c628b 100644 --- a/Controller/BlacklistItemController.php +++ b/Controller/BlacklistItemController.php @@ -34,6 +34,7 @@ * Provides admin-api for blacklist-items. * * @NamePrefix("sulu_community.") + * * @RouteResource("blacklist-item") */ class BlacklistItemController extends AbstractRestController implements ClassResourceInterface @@ -148,7 +149,7 @@ public function deleteAction(int $id): Response */ public function cdeleteAction(Request $request): Response { - $ids = \array_map(function ($id) { + $ids = \array_map(function($id) { return (int) $id; }, \array_filter(\explode(',', (string) $request->query->get('ids', '')))); diff --git a/Controller/SaveMediaTrait.php b/Controller/SaveMediaTrait.php index 15762e4..36b22a0 100644 --- a/Controller/SaveMediaTrait.php +++ b/Controller/SaveMediaTrait.php @@ -99,7 +99,7 @@ private function saveMedia(UploadedFile $uploadedFile, ?int $id, string $locale, */ private function getSystemCollectionManager(): SystemCollectionManagerInterface { - return $this->get('sulu_media.system_collections.manager'); + return $this->container->get('sulu_media.system_collections.manager'); } /** @@ -107,7 +107,7 @@ private function getSystemCollectionManager(): SystemCollectionManagerInterface */ private function getMediaManager(): MediaManagerInterface { - return $this->get('sulu_media.media_manager'); + return $this->container->get('sulu_media.media_manager'); } /** diff --git a/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php b/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php index bde28d3..5be3d11 100644 --- a/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php +++ b/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php @@ -38,7 +38,6 @@ * }, * delete_user: bool, * } - * * @phpstan-type Config array{ * from: string|string[], * to: string|string[], diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ce818d0..cc9cdcb 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -136,7 +136,7 @@ public function getConfigTreeBuilder() ->end() ->beforeNormalization() ->ifString() - ->then(function ($value) { + ->then(function($value) { return [ self::EMAIL_FROM_NAME => $value, self::EMAIL_FROM_EMAIL => $value, @@ -151,7 +151,7 @@ public function getConfigTreeBuilder() ->end() ->beforeNormalization() ->ifString() - ->then(function ($value) { + ->then(function($value) { return [ self::EMAIL_TO_NAME => $value, self::EMAIL_TO_EMAIL => $value, diff --git a/DependencyInjection/SuluCommunityExtension.php b/DependencyInjection/SuluCommunityExtension.php index d456bda..a219ffe 100644 --- a/DependencyInjection/SuluCommunityExtension.php +++ b/DependencyInjection/SuluCommunityExtension.php @@ -153,7 +153,7 @@ public function prepend(ContainerBuilder $container): void 'orm' => [ 'dql' => [ 'string_functions' => [ - 'regexp' => RegExp::class, + 'regexp' => Regexp::class, ], ], ], diff --git a/Entity/BlacklistItem.php b/Entity/BlacklistItem.php index e7bfd6e..d8d85cc 100644 --- a/Entity/BlacklistItem.php +++ b/Entity/BlacklistItem.php @@ -44,10 +44,6 @@ class BlacklistItem */ private $type; - /** - * @param string $pattern - * @param string $type - */ public function __construct(?string $pattern = null, ?string $type = null) { $this->type = $type; diff --git a/EventListener/CompletionListener.php b/EventListener/CompletionListener.php index d61acb1..cb738e6 100644 --- a/EventListener/CompletionListener.php +++ b/EventListener/CompletionListener.php @@ -104,7 +104,7 @@ public function onRequest(RequestEvent $event): void $request = $event->getRequest(); $completionUrl = $this->router->generate('sulu_community.completion'); - if (!$event->isMasterRequest() + if (!$event->isMainRequest() || !$request->isMethodSafe() || $request->isXmlHttpRequest() || $request->getPathInfo() === $completionUrl diff --git a/EventListener/LastLoginListener.php b/EventListener/LastLoginListener.php index 97d60bd..73f8458 100644 --- a/EventListener/LastLoginListener.php +++ b/EventListener/LastLoginListener.php @@ -66,7 +66,7 @@ public static function getSubscribedEvents() */ public function onRequest(RequestEvent $event): void { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } diff --git a/Form/Type/RegistrationType.php b/Form/Type/RegistrationType.php index 176ea05..0534bba 100644 --- a/Form/Type/RegistrationType.php +++ b/Form/Type/RegistrationType.php @@ -73,7 +73,7 @@ public function configureOptions(OptionsResolver $resolver): void [ 'data_class' => User::class, 'validation_groups' => ['registration'], - 'empty_data' => function (FormInterface $form) { + 'empty_data' => function(FormInterface $form) { $user = new User(); $user->setContact(new Contact()); diff --git a/Mail/Mail.php b/Mail/Mail.php index 76f0d35..a4b7f52 100644 --- a/Mail/Mail.php +++ b/Mail/Mail.php @@ -28,8 +28,6 @@ class Mail * user_template: string|null, * admin_template: string|null, * } $config - * - * @return Mail */ public static function create($from, $to, array $config): self { diff --git a/Mail/MailFactory.php b/Mail/MailFactory.php index 663ca4e..55c91f3 100644 --- a/Mail/MailFactory.php +++ b/Mail/MailFactory.php @@ -12,6 +12,10 @@ namespace Sulu\Bundle\CommunityBundle\Mail; use Sulu\Bundle\SecurityBundle\Entity\User; +use Symfony\Component\Mailer\Mailer; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Address; +use Symfony\Component\Mime\Email; use Symfony\Contracts\Translation\LocaleAwareInterface; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; @@ -22,7 +26,7 @@ class MailFactory implements MailFactoryInterface { /** - * @var \Swift_Mailer + * @var MailerInterface|\Swift_Mailer */ protected $mailer; @@ -36,7 +40,7 @@ class MailFactory implements MailFactoryInterface */ protected $translator; - public function __construct(\Swift_Mailer $mailer, Environment $twig, TranslatorInterface $translator) + public function __construct($mailer, Environment $twig, TranslatorInterface $translator) { $this->mailer = $mailer; $this->twig = $twig; @@ -80,12 +84,49 @@ protected function sendEmail($from, $to, string $subject, string $template, arra { $body = $this->twig->render($template, $data); - $message = new \Swift_Message(); - $message->setSubject($this->translator->trans($subject)); - $message->setFrom($from); - $message->setTo($to); - $message->setBody($body, 'text/html'); + if ($this->mailer instanceof \Swift_Mailer) { + $email = $this->mailer->createMessage() + ->setSubject($this->translator->trans($subject)) + ->setFrom($from) + ->setTo($to) + ->setBody($body, 'text/html'); + } else { + if (!$this->getAddress($from) || !$this->getAddress($to)) { + return; + } - $this->mailer->send($message); + $email = (new Email()) + ->subject($this->translator->trans($subject)) + ->from($this->getAddress($from)) + ->to($this->getAddress($to)) + ->html($body); + } + + $this->mailer->send($email); + } + + /** + * Convert string/array email address to an Address object. + * + * @param mixed $address + */ + protected function getAddress($address): ?Address + { + $name = ''; + + if (\is_array($address)) { + if (empty($address)) { + return null; + } elseif (!isset($address['email'])) { + $email = $address[\array_keys($address)[0]]; + } else { + $email = $address['email']; + $name = $address['name'] ?? ''; + } + } else { + $email = $address; + } + + return new Address($email, $name); } } diff --git a/Manager/CommunityManager.php b/Manager/CommunityManager.php index 9e2a073..a5471d4 100644 --- a/Manager/CommunityManager.php +++ b/Manager/CommunityManager.php @@ -153,7 +153,6 @@ public function login(User $user, Request $request): void $token = new UsernamePasswordToken( $user, - null, $this->getConfigProperty(Configuration::FIREWALL), $user->getRoles() ); diff --git a/Manager/CommunityManagerInterface.php b/Manager/CommunityManagerInterface.php index f26e8a1..ff6beca 100644 --- a/Manager/CommunityManagerInterface.php +++ b/Manager/CommunityManagerInterface.php @@ -34,7 +34,6 @@ * }, * delete_user: bool, * } - * * @phpstan-type Config array{ * from: string|string[], * to: string|string[], @@ -109,9 +108,9 @@ public function getConfig(): array; * * @param TConfig $property * - * @throws \InvalidArgumentException - * * @return Config[TTypeConfig] + * + * @throws \InvalidArgumentException */ public function getConfigProperty(string $property); @@ -124,9 +123,9 @@ public function getConfigProperty(string $property); * @param TConfig $type * @param TTypeConfigProperty $property * - * @throws \InvalidArgumentException - * * @return Config[TConfig][TTypeConfigProperty] + * + * @throws \InvalidArgumentException */ public function getConfigTypeProperty(string $type, string $property); @@ -137,8 +136,6 @@ public function sendEmails(string $type, User $user): void; /** * Save profile for given user. - * - * @return User */ public function saveProfile(User $user): ?User; } diff --git a/Tests/Application/Kernel.php b/Tests/Application/Kernel.php index d7cf535..a72f8f2 100644 --- a/Tests/Application/Kernel.php +++ b/Tests/Application/Kernel.php @@ -35,7 +35,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void { parent::registerContainerConfiguration($loader); - $loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yml'); + $loader->load(__DIR__ . '/config/config.php'); } /** diff --git a/Tests/Application/config/config.php b/Tests/Application/config/config.php new file mode 100644 index 0000000..4fd9d10 --- /dev/null +++ b/Tests/Application/config/config.php @@ -0,0 +1,28 @@ +<?php + +/* + * This file is part of Sulu. + * + * (c) Sulu GmbH + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; +use Symfony\Component\HttpKernel\Kernel; + +return static function(PhpFileLoader $loader, ContainerBuilder $container) { + $context = $container->getParameter('sulu.context'); + + $loader->import('context_' . $context . '.yml'); + + if ('website' === $context) { + if (\version_compare(Kernel::VERSION, '6.0.0', '>=')) { + $loader->import('security-6.yml'); + } else { + $loader->import('security-5-4.yml'); + } + } +}; diff --git a/Tests/Application/config/config_admin.yml b/Tests/Application/config/context_admin.yml similarity index 81% rename from Tests/Application/config/config_admin.yml rename to Tests/Application/config/context_admin.yml index f597699..32bb46b 100644 --- a/Tests/Application/config/config_admin.yml +++ b/Tests/Application/config/context_admin.yml @@ -1,5 +1,5 @@ imports: - - config.yml + - { resource: sulu.yml } parameters: secret: test diff --git a/Tests/Application/config/context_website.yml b/Tests/Application/config/context_website.yml new file mode 100644 index 0000000..26d562e --- /dev/null +++ b/Tests/Application/config/context_website.yml @@ -0,0 +1,9 @@ +imports: + - { resource: sulu.yml } + +framework: + router: { resource: '%kernel.project_dir%/config/routing_website.yml' } + profiler: { only_exceptions: false } + +sulu_test: + enable_test_user_provider: true diff --git a/Tests/Application/config/config_website.yml b/Tests/Application/config/security-5-4.yml similarity index 79% rename from Tests/Application/config/config_website.yml rename to Tests/Application/config/security-5-4.yml index 663a718..d961f1e 100644 --- a/Tests/Application/config/config_website.yml +++ b/Tests/Application/config/security-5-4.yml @@ -1,10 +1,3 @@ -imports: - - config.yml - -framework: - router: { resource: '%kernel.project_dir%/config/routing_website.yml' } - profiler: { only_exceptions: false } - security: access_decision_manager: strategy: affirmative @@ -34,6 +27,3 @@ security: logout: path: sulu_community.logout target: / - -sulu_test: - enable_test_user_provider: true diff --git a/Tests/Application/config/security-6.yml b/Tests/Application/config/security-6.yml new file mode 100644 index 0000000..9c354cc --- /dev/null +++ b/Tests/Application/config/security-6.yml @@ -0,0 +1,29 @@ +security: + access_decision_manager: + strategy: affirmative + + password_hashers: + Sulu\Bundle\SecurityBundle\Entity\User: 'plaintext' + + providers: + testprovider: + id: test_user_provider + + access_control: + - { path: /profile, roles: ROLE_USER } + - { path: /completion, roles: ROLE_USER } + + firewalls: + sulu-io: + pattern: ^/ + entry_point: http_basic + http_basic: + provider: testprovider + form_login: + login_path: sulu_community.login + check_path: sulu_community.login + default_target_path: sulu_community.profile + always_use_default_target_path: true + logout: + path: sulu_community.logout + target: / diff --git a/Tests/Application/config/config.yml b/Tests/Application/config/sulu.yml similarity index 86% rename from Tests/Application/config/config.yml rename to Tests/Application/config/sulu.yml index 204b8d4..c9cf83f 100644 --- a/Tests/Application/config/config.yml +++ b/Tests/Application/config/sulu.yml @@ -1,5 +1,6 @@ -swiftmailer: - disable_delivery: true +framework: + mailer: + dsn: 'null://null' doctrine: orm: diff --git a/Tests/Functional/Controller/RegistrationTest.php b/Tests/Functional/Controller/RegistrationTest.php index 5020135..b57ac46 100644 --- a/Tests/Functional/Controller/RegistrationTest.php +++ b/Tests/Functional/Controller/RegistrationTest.php @@ -22,10 +22,10 @@ use Sulu\Bundle\TestBundle\Testing\SuluTestCase; use Sulu\Component\HttpKernel\SuluKernel; use Symfony\Bundle\FrameworkBundle\KernelBrowser; -use Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector; use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Profiler\Profile; +use Symfony\Component\Mime\RawMessage; /** * This testcases covers the whole registration, confirmation and login process. @@ -113,6 +113,13 @@ public function testConfirmation(): User public function testLogin(): void { $this->testConfirmation(); + $user = $this->findUser(); + + if ($user) { + $user->setSalt(''); + $user->setPassword('my-sulu'); + $this->getEntityManager()->flush(); + } $crawler = $this->client->request('GET', '/login'); $this->assertHttpStatusCode(200, $this->client->getResponse()); @@ -181,8 +188,12 @@ public function testRegistrationBlacklistedBlocked(): void $this->assertNull($this->findUser()); } - public function testRegistrationBlacklistedRequested(): \Swift_Message + public function testRegistrationBlacklistedRequested(): ?RawMessage { + if (\class_exists(\Swift_Mailer::class)) { + $this->markTestSkipped('Skip test for swift mailer.'); + } + $this->createBlacklistItem($this->getEntityManager(), '*@sulu.io', BlacklistItem::TYPE_REQUEST); $crawler = $this->client->request('GET', '/registration'); @@ -209,11 +220,10 @@ public function testRegistrationBlacklistedRequested(): \Swift_Message $profile = $this->client->getProfile(); $this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); - /** @var MessageDataCollector $mailCollector */ - $mailCollector = $profile->getCollector('swiftmailer'); - $this->assertSame(1, $mailCollector->getMessageCount()); - $message = $mailCollector->getMessages()[0]; - $this->assertSame('admin@localhost', \key($message->getTo())); + $this->assertEmailCount(1); + + $message = $this->getMailerMessage(); + $this->assertSame('admin@localhost', $message->getTo()[0]->getAddress()); return $message; } @@ -223,7 +233,7 @@ public function testBlacklistConfirm(): void $message = $this->testRegistrationBlacklistedRequested(); $emailCrawler = new Crawler(); - $emailCrawler->addContent($message->getBody()); + $emailCrawler->addContent($message->getHtmlBody()); $links = $emailCrawler->filter('a'); $firstLink = $links->first()->attr('href'); @@ -241,11 +251,10 @@ public function testBlacklistConfirm(): void $profile = $this->client->getProfile(); $this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); - /** @var MessageDataCollector $mailCollector */ - $mailCollector = $profile->getCollector('swiftmailer'); - $this->assertSame(1, $mailCollector->getMessageCount()); - $message = $mailCollector->getMessages()[0]; - $this->assertSame('hikaru@sulu.io', \key($message->getTo())); + $this->assertEmailCount(1); + + $message = $this->getMailerMessage(); + $this->assertSame('hikaru@sulu.io', $message->getTo()[0]->getAddress()); } public function testBlacklistBlocked(): void @@ -253,7 +262,7 @@ public function testBlacklistBlocked(): void $message = $this->testRegistrationBlacklistedRequested(); $emailCrawler = new Crawler(); - $emailCrawler->addContent($message->getBody()); + $emailCrawler->addContent($message->getHtmlBody()); $links = $emailCrawler->filter('a'); $lastLink = $links->last()->attr('href'); @@ -271,13 +280,15 @@ public function testBlacklistBlocked(): void $profile = $this->client->getProfile(); $this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); - /** @var MessageDataCollector $mailCollector */ - $mailCollector = $profile->getCollector('swiftmailer'); - $this->assertSame(0, $mailCollector->getMessageCount()); + $this->assertEmailCount(0); } public function testPasswordForget(): void { + if (\class_exists(\Swift_Mailer::class)) { + $this->markTestSkipped('Skip test for swift mailer.'); + } + $user = $this->testConfirmation(); $crawler = $this->client->request('GET', '/password-forget'); @@ -298,14 +309,13 @@ public function testPasswordForget(): void $profile = $this->client->getProfile(); $this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); - /** @var MessageDataCollector $mailCollector */ - $mailCollector = $profile->getCollector('swiftmailer'); - $this->assertSame(1, $mailCollector->getMessageCount()); - $message = $mailCollector->getMessages()[0]; - $this->assertSame('hikaru@sulu.io', \key($message->getTo())); + $this->assertEmailCount(1); + + $message = $this->getMailerMessage(); + $this->assertSame('hikaru@sulu.io', $message->getTo()[0]->getAddress()); $emailCrawler = new Crawler(); - $emailCrawler->addContent($message->getBody()); + $emailCrawler->addContent($message->getHtmlBody()); $links = $emailCrawler->filter('a'); $firstLink = $links->first()->attr('href'); @@ -325,10 +335,10 @@ public function testPasswordForget(): void ); $this->client->submit($form); - $this->getEntityManager()->clear(); + //$this->getEntityManager()->clear(); /** @var User $user */ - $user = $this->findUser(); + $user = $this->findUser('sulu'); $password = $user->getPassword(); $this->assertNotNull($password); $this->assertStringStartsWith('my-new-password', $password); @@ -339,14 +349,12 @@ public function testPasswordForget(): void */ private function findUser(string $username = 'sulu'): ?User { - // clear entity-manager to ensure newest user - $this->getEntityManager()->clear(); - $repository = $this->getContainer()->get('sulu.repository.user'); try { /** @var User $user */ $user = $repository->findUserByUsername($username); + $this->getEntityManager()->refresh($user); return $user; } catch (NoResultException $exception) { diff --git a/Tests/Functional/Entity/BlacklistItemRepositoryTest.php b/Tests/Functional/Entity/BlacklistItemRepositoryTest.php index 6f9e201..2bd84c9 100644 --- a/Tests/Functional/Entity/BlacklistItemRepositoryTest.php +++ b/Tests/Functional/Entity/BlacklistItemRepositoryTest.php @@ -39,7 +39,7 @@ public function testFindBySender(): void $entityManager->clear(); $items = \array_map( - function (BlacklistItem $item) { + function(BlacklistItem $item) { return ['pattern' => $item->getPattern(), 'type' => $item->getType()]; }, $repository->findBySender('test@sulu.io') diff --git a/Tests/Unit/Listener/BlacklistListenerTest.php b/Tests/Unit/Listener/BlacklistListenerTest.php index a80079f..b36e934 100644 --- a/Tests/Unit/Listener/BlacklistListenerTest.php +++ b/Tests/Unit/Listener/BlacklistListenerTest.php @@ -92,7 +92,7 @@ public function testValidateEmail(): void $this->entityManager->persist( Argument::that( - function (BlacklistUser $item) use ($user) { + function(BlacklistUser $item) use ($user) { return '123-123-123' === $item->getToken() && 'sulu-io' === $item->getWebspaceKey() && $item->getUser() === $user->reveal(); diff --git a/Tests/Unit/Listener/EmailConfirmationListenerTest.php b/Tests/Unit/Listener/EmailConfirmationListenerTest.php index 7da5a11..95d61be 100644 --- a/Tests/Unit/Listener/EmailConfirmationListenerTest.php +++ b/Tests/Unit/Listener/EmailConfirmationListenerTest.php @@ -114,7 +114,7 @@ public function testSendConfirmation(): void $this->entityManager->persist( Argument::that( - function (EmailConfirmationToken $token) { + function(EmailConfirmationToken $token) { return '123-123-123' === $token->getToken() && $token->getUser() === $this->user->reveal(); } ) diff --git a/Tests/Unit/Mail/MailFactoryTest.php b/Tests/Unit/Mail/MailFactoryTest.php index e2c7f3a..6712b33 100644 --- a/Tests/Unit/Mail/MailFactoryTest.php +++ b/Tests/Unit/Mail/MailFactoryTest.php @@ -17,13 +17,15 @@ use Sulu\Bundle\CommunityBundle\Mail\Mail; use Sulu\Bundle\CommunityBundle\Mail\MailFactory; use Sulu\Bundle\SecurityBundle\Entity\User; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Email; use Symfony\Component\Translation\Translator; use Twig\Environment; class MailFactoryTest extends TestCase { /** - * @var ObjectProphecy<\Swift_Mailer> + * @var ObjectProphecy<MailerInterface> */ private $mailer; @@ -49,10 +51,11 @@ class MailFactoryTest extends TestCase protected function setUp(): void { - $this->mailer = $this->prophesize(\Swift_Mailer::class); + $this->mailer = $this->prophesize(MailerInterface::class); $this->twig = $this->prophesize(Environment::class); $this->translator = $this->prophesize(Translator::class); $this->translator->getLocale()->willReturn('en'); + $this->translator->trans('testcase')->willReturn('Test case'); $this->user = $this->prophesize(User::class); $this->user->getEmail()->willReturn('test@example.com'); $this->user->getLocale()->willReturn('de'); @@ -70,22 +73,18 @@ public function testSendEmails(): void $this->twig->render('admin-template', Argument::any())->willReturn('Admin-Template'); $this->mailer->send( - Argument::that( - function (\Swift_Message $message) { - return 'User-Template' === $message->getBody() - && $message->getFrom() === ['test@sulu.io' => null] - && $message->getTo() === ['test@example.com' => null]; - } - ) + (new Email()) + ->subject('Test case') + ->from('test@sulu.io') + ->to('test@example.com') + ->html('User-Template') )->shouldBeCalledTimes(1); $this->mailer->send( - Argument::that( - function (\Swift_Message $message) { - return 'Admin-Template' === $message->getBody() - && $message->getFrom() === ['test@sulu.io' => null] - && $message->getTo() === ['user@sulu.io' => null]; - } - ) + (new Email()) + ->subject('Test case') + ->from('test@sulu.io') + ->to('user@sulu.io') + ->html('Admin-Template') )->shouldBeCalledTimes(1); $mail = new Mail('test@sulu.io', 'user@sulu.io', 'testcase', 'user-template', 'admin-template'); @@ -100,22 +99,18 @@ public function testSendEmailsNoAdminTemplate(): void $this->twig->render('admin-template', Argument::any())->willReturn('Admin-Template'); $this->mailer->send( - Argument::that( - function (\Swift_Message $message) { - return 'User-Template' === $message->getBody() - && $message->getFrom() === ['test@sulu.io' => null] - && $message->getTo() === ['test@example.com' => null]; - } - ) + (new Email()) + ->subject('Test case') + ->from('test@sulu.io') + ->to('test@example.com') + ->html('User-Template') )->shouldBeCalledTimes(1); $this->mailer->send( - Argument::that( - function (\Swift_Message $message) { - return 'Admin-Template' === $message->getBody() - && $message->getFrom() === ['test@sulu.io' => null] - && $message->getTo() === ['user@sulu.io' => null]; - } - ) + (new Email()) + ->subject('Test case') + ->from('test@sulu.io') + ->to('user@sulu.io') + ->html('Admin-Template') )->shouldNotBeCalled(); $mail = new Mail('test@sulu.io', 'user@sulu.io', 'testcase', 'user-template', null); @@ -130,22 +125,18 @@ public function testSendEmailsNoUserTemplate(): void $this->twig->render('admin-template', Argument::any())->willReturn('Admin-Template'); $this->mailer->send( - Argument::that( - function (\Swift_Message $message) { - return 'User-Template' === $message->getBody() - && $message->getFrom() === ['test@sulu.io' => null] - && $message->getTo() === ['test@example.com' => null]; - } - ) + (new Email()) + ->subject('Test case') + ->from('test@sulu.io') + ->to('test@example.com') + ->html('User-Template') )->shouldNotBeCalled(); $this->mailer->send( - Argument::that( - function (\Swift_Message $message) { - return 'Admin-Template' === $message->getBody() - && $message->getFrom() === ['test@sulu.io' => null] - && $message->getTo() === ['user@sulu.io' => null]; - } - ) + (new Email()) + ->subject('Test case') + ->from('test@sulu.io') + ->to('user@sulu.io') + ->html('Admin-Template') )->shouldBeCalledTimes(1); $mail = new Mail('test@sulu.io', 'user@sulu.io', 'testcase', null, 'admin-template'); diff --git a/Tests/phpstan/object-manager.php b/Tests/phpstan/object-manager.php index 8a0eff1..596d140 100644 --- a/Tests/phpstan/object-manager.php +++ b/Tests/phpstan/object-manager.php @@ -34,7 +34,7 @@ // this is a workaround for the following phpstan issue: https://github.com/phpstan/phpstan-doctrine/issues/98 $resolveTargetEntityListener = \current(\array_filter( $objectManager->getEventManager()->getListeners('loadClassMetadata'), - static function ($listener) { + static function($listener) { return $listener instanceof ResolveTargetEntityListener; } )); diff --git a/composer.json b/composer.json index 0d6bbec..24ad0f8 100644 --- a/composer.json +++ b/composer.json @@ -8,44 +8,50 @@ "beberlei/doctrineextensions": "^1.0", "doctrine/doctrine-bundle": "^1.10 || ^2.0", "doctrine/orm": "^2.5.3", - "doctrine/persistence": "^1.3 || ^2.0", + "doctrine/persistence": "^1.3 || ^2.0 || ^3.0", + "doctrine/phpcr-bundle": "^2 || ^3.0", "jms/serializer-bundle": "^3.3 || ^4.0", "massive/build-bundle": "^0.3 || ^0.4 || ^0.5", - "sulu/sulu": "^2.0.6 || ^2.5@dev", - "symfony/config": "^4.4 || ^5.0", - "symfony/console": "^4.4 || ^5.0", - "symfony/dependency-injection": "^4.4 || ^5.0", - "symfony/event-dispatcher": "^4.4 || ^5.0", - "symfony/form": "^4.4 || ^5.0", - "symfony/framework-bundle": "^4.4 || ^5.0", - "symfony/http-foundation": "^4.4 || ^5.0", - "symfony/http-kernel": "^4.4 || ^5.0", - "symfony/intl": "^4.4 || ^5.0", - "symfony/routing": "^4.4 || ^5.0", - "symfony/security-bundle": "^4.4 || ^5.0", - "symfony/swiftmailer-bundle": "^3.1.4" + "sulu/sulu": "^2.4.0 || ^2.6@dev", + "symfony/config": "^5.4 || ^6.2", + "symfony/console": "^5.4 || ^6.2", + "symfony/dependency-injection": "^5.4 || ^6.2", + "symfony/event-dispatcher": "^5.4 || ^6.2", + "symfony/form": "^5.4 || ^6.2", + "symfony/framework-bundle": "^5.4 || ^6.2", + "symfony/http-foundation": "^5.4 || ^6.2", + "symfony/http-kernel": "^5.4 || ^6.2", + "symfony/intl": "^5.4 || ^6.2", + "symfony/mailer": "^5.4 || ^6.2", + "symfony/routing": "^5.4 || ^6.2", + "symfony/security-bundle": "^5.4 || ^6.2" }, "require-dev": { "doctrine/data-fixtures": "^1.3.3", + "friendsofsymfony/jsrouting-bundle": "^2.6 || ^3.0", "handcraftedinthealps/zendsearch": "^2.0", "jackalope/jackalope-doctrine-dbal": "^1.3.4", "jangregor/phpstan-prophecy": "^1.0", "massive/search-bundle": "^2.0", "php-cs-fixer/shim": "^3.9", + "phpspec/prophecy": "^1.16", "phpstan/phpstan": "1.0", "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^8.2", - "symfony/browser-kit": "^4.4 || ^5.0", - "symfony/css-selector": "^4.4 || ^5.0", - "symfony/dotenv": "^4.4 || ^5.0", + "symfony/browser-kit": "^5.4 || ^6.2", + "symfony/css-selector": "^5.4 || ^6.2", + "symfony/dotenv": "^5.4 || ^6.2", "symfony/monolog-bundle": "^3.1", - "symfony/phpunit-bridge": "^4.4 || ^5.0", - "symfony/stopwatch": "^4.4 || ^5.0", - "symfony/var-dumper": "^4.4 || ^5.0", + "symfony/phpunit-bridge": "^5.4 || ^6.2", + "symfony/stopwatch": "^5.4 || ^6.2", + "symfony/var-dumper": "^5.4 || ^6.2", "thecodingmachine/phpstan-strict-rules": "^1.0" }, + "conflict": { + "dantleech/phpcr-migrations-bundle": "<1.2.0" + }, "keywords": [ "registration", "login", @@ -111,6 +117,9 @@ ] }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": true + } } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3c960b4..f35cf76 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,25 @@ parameters: ignoreErrors: + - + message: "#^Else branch is unreachable because previous condition is always true\\.$#" + count: 1 + path: Command/InitCommand.php + + - + message: "#^Call to method encodePassword\\(\\) on an unknown class Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\UserPasswordEncoderInterface\\.$#" + count: 1 + path: Controller/AbstractController.php + + - + message: "#^Method Sulu\\\\Bundle\\\\CommunityBundle\\\\Controller\\\\AbstractController\\:\\:getSubscribedServices\\(\\) should return array\\<int\\|string, string\\> but returns array\\<string\\|Symfony\\\\Contracts\\\\Service\\\\Attribute\\\\SubscribedService\\>\\.$#" + count: 1 + path: Controller/AbstractController.php + + - + message: "#^PHPDoc tag @var for variable \\$encoder contains unknown class Symfony\\\\Component\\\\Security\\\\Core\\\\Encoder\\\\UserPasswordEncoderInterface\\.$#" + count: 1 + path: Controller/AbstractController.php + - message: "#^Strict comparison using \\=\\=\\= between true and array\\{from\\: array\\<string\\>\\|string, to\\: array\\<string\\>\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} will always evaluate to false\\.$#" count: 1 @@ -250,6 +270,31 @@ parameters: count: 1 path: EventListener/MailListener.php + - + message: "#^Call to method createMessage\\(\\) on an unknown class Swift_Mailer\\.$#" + count: 1 + path: Mail/MailFactory.php + + - + message: "#^Call to method send\\(\\) on an unknown class Swift_Mailer\\.$#" + count: 1 + path: Mail/MailFactory.php + + - + message: "#^Class Swift_Mailer not found\\.$#" + count: 1 + path: Mail/MailFactory.php + + - + message: "#^Method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\MailFactory\\:\\:__construct\\(\\) has parameter \\$mailer with no type specified\\.$#" + count: 1 + path: Mail/MailFactory.php + + - + message: "#^Property Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\MailFactory\\:\\:\\$mailer has unknown class Swift_Mailer as its type\\.$#" + count: 1 + path: Mail/MailFactory.php + - message: "#^Method Sulu\\\\Bundle\\\\CommunityBundle\\\\Manager\\\\CommunityManager\\:\\:getConfigProperty\\(\\) should return array\\{from\\: array\\<string\\>\\|string, to\\: array\\<string\\>\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} but returns array\\<array\\|bool\\|string\\|null\\>\\|string\\.$#" count: 1 @@ -275,6 +320,11 @@ parameters: count: 1 path: Manager/CommunityManager.php + - + message: "#^Parameter \\#2 \\$firewallName of class Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\UsernamePasswordToken constructor expects string, array\\<string, array\\<array\\|bool\\|string\\|null\\>\\|string\\> given\\.$#" + count: 1 + path: Manager/CommunityManager.php + - message: "#^Parameter \\#2 \\$to of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\<string\\>\\|string, array\\<string, array\\<array\\|bool\\|string\\|null\\>\\|string\\> given\\.$#" count: 1 @@ -291,7 +341,17 @@ parameters: path: Manager/CommunityManager.php - - message: "#^Parameter \\#3 \\$roles of class Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\UsernamePasswordToken constructor expects array\\<string\\>, array\\<string, array\\<array\\|bool\\|string\\|null\\>\\|string\\> given\\.$#" + message: "#^If condition is always true\\.$#" count: 1 - path: Manager/CommunityManager.php + path: Tests/Application/config/config.php + + - + message: "#^Cannot call method getHtmlBody\\(\\) on Symfony\\\\Component\\\\Mime\\\\RawMessage\\|null\\.$#" + count: 3 + path: Tests/Functional/Controller/RegistrationTest.php + + - + message: "#^Cannot call method getTo\\(\\) on Symfony\\\\Component\\\\Mime\\\\RawMessage\\|null\\.$#" + count: 3 + path: Tests/Functional/Controller/RegistrationTest.php From d95bfd8f27dea7c2f589858c6f825be34ecbcd14 Mon Sep 17 00:00:00 2001 From: Paul Kepinski <paul.kepinski@orange.fr> Date: Thu, 25 Apr 2024 18:21:59 +0200 Subject: [PATCH 3/4] Return HTTP 422 code when form is invalid (#168) --- Controller/AbstractController.php | 18 +++++++++++++- Controller/CompletionController.php | 2 +- Controller/PasswordController.php | 4 ++-- Controller/ProfileController.php | 2 +- Controller/RegistrationController.php | 2 +- .../Controller/ProfileControllerTest.php | 13 ++++++++++ .../Controller/RegistrationTest.php | 24 ++++++++++++++++++- 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 148a1b1..6940907 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -120,9 +120,25 @@ protected function renderTemplate(string $type, array $data = []): Response Configuration::TEMPLATE ); + $response = new Response(); + + // Reuse logic from Symfony AbstractController. + // See: https://github.com/symfony/symfony/blob/6.3/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php#L239-L243 + // See: https://github.com/symfony/symfony/blob/6.3/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php#L260-L265 + foreach ($data as $k => $v) { + if ($v instanceof FormInterface) { + if ($v->isSubmitted() && !$v->isValid()) { + $response->setStatusCode(422); + } + + $data[$k] = $v->createView(); + } + } + return $this->render( $template, - $data + $data, + $response ); } diff --git a/Controller/CompletionController.php b/Controller/CompletionController.php index 72a4f70..20ed474 100644 --- a/Controller/CompletionController.php +++ b/Controller/CompletionController.php @@ -81,7 +81,7 @@ public function indexAction(Request $request): Response return $this->renderTemplate( self::TYPE, [ - 'form' => $form->createView(), + 'form' => $form, 'success' => $success, ] ); diff --git a/Controller/PasswordController.php b/Controller/PasswordController.php index 16890e0..e931172 100644 --- a/Controller/PasswordController.php +++ b/Controller/PasswordController.php @@ -67,7 +67,7 @@ public function forgetAction(Request $request): Response return $this->renderTemplate( Configuration::TYPE_PASSWORD_FORGET, [ - 'form' => $form->createView(), + 'form' => $form, 'success' => $success, ] ); @@ -138,7 +138,7 @@ public function resetAction(Request $request, string $token): Response return $this->renderTemplate( Configuration::TYPE_PASSWORD_RESET, [ - 'form' => $form->createView(), + 'form' => $form, 'success' => $success, ] ); diff --git a/Controller/ProfileController.php b/Controller/ProfileController.php index 96c45ed..f4436f0 100644 --- a/Controller/ProfileController.php +++ b/Controller/ProfileController.php @@ -73,7 +73,7 @@ public function indexAction(Request $request): Response return $this->renderTemplate( self::TYPE, [ - 'form' => $form->createView(), + 'form' => $form, 'success' => $success, ] ); diff --git a/Controller/RegistrationController.php b/Controller/RegistrationController.php index 47dafe3..4cb8451 100644 --- a/Controller/RegistrationController.php +++ b/Controller/RegistrationController.php @@ -78,7 +78,7 @@ public function indexAction(Request $request): Response return $this->renderTemplate( self::TYPE, [ - 'form' => $form->createView(), + 'form' => $form, 'success' => $success, ] ); diff --git a/Tests/Functional/Controller/ProfileControllerTest.php b/Tests/Functional/Controller/ProfileControllerTest.php index 5818682..4c36eb4 100644 --- a/Tests/Functional/Controller/ProfileControllerTest.php +++ b/Tests/Functional/Controller/ProfileControllerTest.php @@ -172,6 +172,19 @@ public function testProfileWithoutNote(): void $this->assertNull($user->getContact()->getNote()); } + public function testProfileInvalid(): void + { + $crawler = $this->client->request('GET', '/profile'); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + + $form = $crawler->selectButton('profile[submit]')->form([ + 'profile[firstName]' => null, + ]); + + $this->client->submit($form); + $this->assertHttpStatusCode(422, $this->client->getResponse()); + } + /** * @return array{ * 'sulu.context': SuluKernel::CONTEXT_WEBSITE, diff --git a/Tests/Functional/Controller/RegistrationTest.php b/Tests/Functional/Controller/RegistrationTest.php index b57ac46..32ee79d 100644 --- a/Tests/Functional/Controller/RegistrationTest.php +++ b/Tests/Functional/Controller/RegistrationTest.php @@ -92,6 +92,17 @@ public function testRegister(): void $this->assertHttpStatusCode(302, $this->client->getResponse()); } + public function testRegisterInvalid(): void + { + $crawler = $this->client->request('GET', '/registration'); + + $form = $crawler->selectButton('registration[submit]')->form([ + 'registration[username]' => null, + ]); + $this->client->submit($form); + $this->assertHttpStatusCode(422, $this->client->getResponse()); + } + public function testConfirmation(): User { $this->testRegister(); @@ -180,7 +191,7 @@ public function testRegistrationBlacklistedBlocked(): void ] ); $this->client->submit($form); - $this->assertHttpStatusCode(200, $this->client->getResponse()); + $this->assertHttpStatusCode(422, $this->client->getResponse()); $content = $this->client->getResponse()->getContent(); $this->assertIsString($content); @@ -344,6 +355,17 @@ public function testPasswordForget(): void $this->assertStringStartsWith('my-new-password', $password); } + public function testPasswordForgetInvalid(): void + { + $crawler = $this->client->request('GET', '/password-forget'); + + $form = $crawler->selectButton('password_forget[submit]')->form([ + 'password_forget[email_username]' => 'hikaru@sulu.io', + ]); + $this->client->submit($form); + $this->assertHttpStatusCode(422, $this->client->getResponse()); + } + /** * Find user by username. */ From d576ea6c702aead93c03e1aa91513ee1aadfb490 Mon Sep 17 00:00:00 2001 From: Oliver Kossin <thecadiens@gmail.com> Date: Wed, 24 Aug 2022 09:52:16 +0200 Subject: [PATCH 4/4] [146][WIP] Rename Blacklist to Registration Rule --- Admin/CommunityAdmin.php | 64 ++++---- .../BlacklistConfirmationController.php | 144 ------------------ ...RegistrationRuleConfirmationController.php | 144 ++++++++++++++++++ ...php => RegistrationRuleItemController.php} | 46 +++--- DependencyInjection/Configuration.php | 54 +++---- .../SuluCommunityExtension.php | 6 +- ...klistItem.php => RegistrationRuleItem.php} | 4 +- ...php => RegistrationRuleItemRepository.php} | 10 +- ...klistUser.php => RegistrationRuleUser.php} | 2 +- ...php => RegistrationRuleUserRepository.php} | 4 +- ...tener.php => RegistrationRuleListener.php} | 30 ++-- Manager/BlacklistItemManagerInterface.php | 37 ----- ...er.php => RegistrationRuleItemManager.php} | 20 +-- .../RegistrationRuleItemManagerInterface.php | 37 +++++ README.md | 2 +- ...m.orm.xml => RegistrationRuleItem.orm.xml} | 4 +- ...r.orm.xml => RegistrationRuleUser.orm.xml} | 4 +- ...xml => registration_rule_item_details.xml} | 2 +- ..._items.xml => registration_rule_items.xml} | 8 +- Resources/config/routing_api.yaml | 4 +- Resources/config/routing_website.yaml | 4 +- ...klistItem.xml => RegistrationRuleItem.xml} | 2 +- Resources/config/services.xml | 36 ++--- Resources/config/validator.xml | 2 +- ...lacklisting.md => 12-registration-rule.md} | 16 +- Resources/doc/3-customization.md | 14 +- Resources/doc/index.md | 2 +- Resources/translations/admin.de.json | 2 +- Resources/translations/admin.en.json | 2 +- Resources/translations/admin.fr.json | 2 +- ... => registration-rule-confirmed.html.twig} | 0 ...wig => registration-rule-denied.html.twig} | 0 ...twig => registration-rule-email.html.twig} | 0 SuluCommunityBundle.php | 8 +- Tests/Application/.env | 2 +- ...=> RegistrationRuleItemControllerTest.php} | 48 +++--- .../Controller/RegistrationTest.php | 22 +-- ...=> RegistrationRuleItemRepositoryTest.php} | 20 +-- ...rait.php => RegistrationRuleItemTrait.php} | 16 +- ...mTest.php => RegistrationRuleItemTest.php} | 28 ++-- ...t.php => RegistrationRuleListenerTest.php} | 24 +-- ...hp => RegistrationRuleItemManagerTest.php} | 30 ++-- Tests/Unit/Validator/BlockedValidatorTest.php | 16 +- UPGRADE.md | 8 +- Validator/Constraints/BlockedValidator.php | 16 +- phpstan-baseline.neon | 12 +- 46 files changed, 479 insertions(+), 479 deletions(-) delete mode 100644 Controller/BlacklistConfirmationController.php create mode 100644 Controller/RegistrationRuleConfirmationController.php rename Controller/{BlacklistItemController.php => RegistrationRuleItemController.php} (82%) rename Entity/{BlacklistItem.php => RegistrationRuleItem.php} (95%) rename Entity/{BlacklistItemRepository.php => RegistrationRuleItemRepository.php} (74%) rename Entity/{BlacklistUser.php => RegistrationRuleUser.php} (98%) rename Entity/{BlacklistUserRepository.php => RegistrationRuleUserRepository.php} (87%) rename EventListener/{BlacklistListener.php => RegistrationRuleListener.php} (73%) delete mode 100644 Manager/BlacklistItemManagerInterface.php rename Manager/{BlacklistItemManager.php => RegistrationRuleItemManager.php} (67%) create mode 100644 Manager/RegistrationRuleItemManagerInterface.php rename Resources/config/doctrine/{BlacklistItem.orm.xml => RegistrationRuleItem.orm.xml} (85%) rename Resources/config/doctrine/{BlacklistUser.orm.xml => RegistrationRuleUser.orm.xml} (88%) rename Resources/config/forms/{blacklist_item_details.xml => registration_rule_item_details.xml} (96%) rename Resources/config/lists/{blacklist_items.xml => registration_rule_items.xml} (73%) rename Resources/config/serializer/{BlacklistItem.xml => RegistrationRuleItem.xml} (72%) rename Resources/doc/{12-blacklisting.md => 12-registration-rule.md} (81%) rename Resources/views/{blacklist-confirmed.html.twig => registration-rule-confirmed.html.twig} (100%) rename Resources/views/{blacklist-denied.html.twig => registration-rule-denied.html.twig} (100%) rename Resources/views/{blacklist-email.html.twig => registration-rule-email.html.twig} (100%) rename Tests/Functional/Controller/{BlacklistItemControllerTest.php => RegistrationRuleItemControllerTest.php} (70%) rename Tests/Functional/Entity/{BlacklistItemRepositoryTest.php => RegistrationRuleItemRepositoryTest.php} (61%) rename Tests/Functional/Traits/{BlacklistItemTrait.php => RegistrationRuleItemTrait.php} (63%) rename Tests/Unit/Entity/{BlacklistItemTest.php => RegistrationRuleItemTest.php} (63%) rename Tests/Unit/Listener/{BlacklistListenerTest.php => RegistrationRuleListenerTest.php} (81%) rename Tests/Unit/Manager/{BlacklistItemManagerTest.php => RegistrationRuleItemManagerTest.php} (67%) diff --git a/Admin/CommunityAdmin.php b/Admin/CommunityAdmin.php index b760d1a..4fe9201 100644 --- a/Admin/CommunityAdmin.php +++ b/Admin/CommunityAdmin.php @@ -27,10 +27,10 @@ */ class CommunityAdmin extends Admin { - public const BLACKLIST_ITEM_SECURITY_CONTEXT = 'sulu.community.blacklist_items'; - public const BLACKLIST_ITEM_LIST_VIEW = 'sulu_community.blacklist_item'; - public const BLACKLIST_ITEM_ADD_FORM_VIEW = 'sulu_community.blacklist_item.add_form'; - public const BLACKLIST_ITEM_EDIT_FORM_VIEW = 'sulu_community.blacklist_item.edit_form'; + public const REGISTRATION_RULE_ITEM_SECURITY_CONTEXT = 'sulu.community.registration_rule_items'; + public const REGISTRATION_RULE_ITEM_LIST_VIEW = 'sulu_community.registration_rule_item'; + public const REGISTRATION_RULE_ITEM_ADD_FORM_VIEW = 'sulu_community.registration_rule_item.add_form'; + public const REGISTRATION_RULE_ITEM_EDIT_FORM_VIEW = 'sulu_community.registration_rule_item.edit_form'; /** * @var SecurityCheckerInterface @@ -69,10 +69,10 @@ public function __construct( public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void { - if ($this->securityChecker->hasPermission(static::BLACKLIST_ITEM_SECURITY_CONTEXT, PermissionTypes::VIEW)) { - $tags = new NavigationItem('sulu_community.blacklist'); + if ($this->securityChecker->hasPermission(static::REGISTRATION_RULE_ITEM_SECURITY_CONTEXT, PermissionTypes::VIEW)) { + $tags = new NavigationItem('sulu_community.registration_rule'); $tags->setPosition(40); - $tags->setView(static::BLACKLIST_ITEM_LIST_VIEW); + $tags->setView(static::REGISTRATION_RULE_ITEM_LIST_VIEW); $navigationItemCollection->get(Admin::SETTINGS_NAVIGATION_ITEM)->addChild($tags); } @@ -83,61 +83,61 @@ public function configureViews(ViewCollection $viewCollection): void $formToolbarActions = []; $listToolbarActions = []; - if ($this->securityChecker->hasPermission(static::BLACKLIST_ITEM_SECURITY_CONTEXT, PermissionTypes::ADD)) { + if ($this->securityChecker->hasPermission(static::REGISTRATION_RULE_ITEM_SECURITY_CONTEXT, PermissionTypes::ADD)) { $listToolbarActions[] = new ToolbarAction('sulu_admin.add'); } - if ($this->securityChecker->hasPermission(static::BLACKLIST_ITEM_SECURITY_CONTEXT, PermissionTypes::EDIT)) { + if ($this->securityChecker->hasPermission(static::REGISTRATION_RULE_ITEM_SECURITY_CONTEXT, PermissionTypes::EDIT)) { $formToolbarActions[] = new ToolbarAction('sulu_admin.save'); } - if ($this->securityChecker->hasPermission(static::BLACKLIST_ITEM_SECURITY_CONTEXT, PermissionTypes::DELETE)) { + if ($this->securityChecker->hasPermission(static::REGISTRATION_RULE_ITEM_SECURITY_CONTEXT, PermissionTypes::DELETE)) { $formToolbarActions[] = new ToolbarAction('sulu_admin.delete'); $listToolbarActions[] = new ToolbarAction('sulu_admin.delete'); } - if ($this->securityChecker->hasPermission(static::BLACKLIST_ITEM_SECURITY_CONTEXT, PermissionTypes::VIEW)) { + if ($this->securityChecker->hasPermission(static::REGISTRATION_RULE_ITEM_SECURITY_CONTEXT, PermissionTypes::VIEW)) { $listToolbarActions[] = new ToolbarAction('sulu_admin.export'); } - if ($this->securityChecker->hasPermission(static::BLACKLIST_ITEM_SECURITY_CONTEXT, PermissionTypes::EDIT)) { + if ($this->securityChecker->hasPermission(static::REGISTRATION_RULE_ITEM_SECURITY_CONTEXT, PermissionTypes::EDIT)) { $viewCollection->add( - $this->viewBuilderFactory->createListViewBuilder(static::BLACKLIST_ITEM_LIST_VIEW, '/blacklist') - ->setResourceKey('blacklist_items') - ->setListKey('blacklist_items') + $this->viewBuilderFactory->createListViewBuilder(static::REGISTRATION_RULE_ITEM_LIST_VIEW, '/blacklist') + ->setResourceKey('registration_rule_items') + ->setListKey('registration_rule_items') ->setTitle('sulu_community.blacklist') ->addListAdapters(['table']) - ->setAddView(static::BLACKLIST_ITEM_ADD_FORM_VIEW) - ->setEditView(static::BLACKLIST_ITEM_EDIT_FORM_VIEW) + ->setAddView(static::REGISTRATION_RULE_ITEM_ADD_FORM_VIEW) + ->setEditView(static::REGISTRATION_RULE_ITEM_EDIT_FORM_VIEW) ->addToolbarActions($listToolbarActions) ); $viewCollection->add( - $this->viewBuilderFactory->createResourceTabViewBuilder(static::BLACKLIST_ITEM_ADD_FORM_VIEW, '/blacklist/add') - ->setResourceKey('blacklist_items') - ->setBackView(static::BLACKLIST_ITEM_LIST_VIEW) + $this->viewBuilderFactory->createResourceTabViewBuilder(static::REGISTRATION_RULE_ITEM_ADD_FORM_VIEW, '/blacklist/add') + ->setResourceKey('registration_rule_items') + ->setBackView(static::REGISTRATION_RULE_ITEM_LIST_VIEW) ); $viewCollection->add( - $this->viewBuilderFactory->createFormViewBuilder(static::BLACKLIST_ITEM_ADD_FORM_VIEW . '.details', '/details') - ->setResourceKey('blacklist_items') - ->setFormKey('blacklist_item_details') + $this->viewBuilderFactory->createFormViewBuilder(static::REGISTRATION_RULE_ITEM_ADD_FORM_VIEW . '.details', '/details') + ->setResourceKey('registration_rule_items') + ->setFormKey('registration_rule_item_details') ->setTabTitle('sulu_admin.details') - ->setEditView(static::BLACKLIST_ITEM_EDIT_FORM_VIEW) + ->setEditView(static::REGISTRATION_RULE_ITEM_EDIT_FORM_VIEW) ->addToolbarActions($formToolbarActions) - ->setParent(static::BLACKLIST_ITEM_ADD_FORM_VIEW) + ->setParent(static::REGISTRATION_RULE_ITEM_ADD_FORM_VIEW) ); $viewCollection->add( - $this->viewBuilderFactory->createResourceTabViewBuilder(static::BLACKLIST_ITEM_EDIT_FORM_VIEW, '/blacklist/:id') - ->setResourceKey('blacklist_items') - ->setBackView(static::BLACKLIST_ITEM_LIST_VIEW) + $this->viewBuilderFactory->createResourceTabViewBuilder(static::REGISTRATION_RULE_ITEM_EDIT_FORM_VIEW, '/blacklist/:id') + ->setResourceKey('registration-rule-items') + ->setBackView(static::REGISTRATION_RULE_ITEM_LIST_VIEW) ->setTitleProperty('name') ); $viewCollection->add( - $this->viewBuilderFactory->createFormViewBuilder(static::BLACKLIST_ITEM_EDIT_FORM_VIEW . '.details', '/details') - ->setResourceKey('blacklist_items') + $this->viewBuilderFactory->createFormViewBuilder(static::REGISTRATION_RULE_ITEM_EDIT_FORM_VIEW . '.details', '/details') + ->setResourceKey('registration-rule-items') ->setFormKey('blacklist_item_details') ->setTabTitle('sulu_admin.details') ->addToolbarActions($formToolbarActions) - ->setParent(static::BLACKLIST_ITEM_EDIT_FORM_VIEW) + ->setParent(static::REGISTRATION_RULE_ITEM_EDIT_FORM_VIEW) ); } } @@ -173,7 +173,7 @@ public function getSecurityContexts() [ 'Sulu' => [ 'Settings' => [ - self::BLACKLIST_ITEM_SECURITY_CONTEXT => [ + self::REGISTRATION_RULE_ITEM_SECURITY_CONTEXT => [ PermissionTypes::VIEW, PermissionTypes::ADD, PermissionTypes::EDIT, diff --git a/Controller/BlacklistConfirmationController.php b/Controller/BlacklistConfirmationController.php deleted file mode 100644 index 450ce94..0000000 --- a/Controller/BlacklistConfirmationController.php +++ /dev/null @@ -1,144 +0,0 @@ -<?php - -/* - * This file is part of Sulu. - * - * (c) Sulu GmbH - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Sulu\Bundle\CommunityBundle\Controller; - -use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistUser; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistUserRepository; -use Sulu\Bundle\CommunityBundle\Manager\BlacklistItemManager; -use Sulu\Bundle\CommunityBundle\Manager\BlacklistItemManagerInterface; -use Sulu\Bundle\SecurityBundle\Entity\User; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; - -/** - * Handles user confirmations for administrators. - */ -class BlacklistConfirmationController extends AbstractController -{ - /** - * Confirms user with given token. - */ - public function confirmAction(Request $request): Response - { - /** @var string $token */ - $token = $request->get('token'); - - /** @var BlacklistUser|null $blacklistUser */ - $blacklistUser = $this->getBlacklistUserRepository()->findByToken($token); - - if (null === $blacklistUser) { - throw new NotFoundHttpException(); - } - - $blacklistUser->confirm(); - $this->getEntityManager()->flush(); - - $communityManager = $this->getCommunityManager($blacklistUser->getWebspaceKey()); - - /** @var User $user */ - $user = $blacklistUser->getUser(); - $communityManager->sendEmails(Configuration::TYPE_BLACKLIST_CONFIRMED, $user); - - return $this->renderTemplate( - Configuration::TYPE_BLACKLIST_CONFIRMED, - ['user' => $blacklistUser->getUser()] - ); - } - - /** - * Denies user with given token. - */ - public function denyAction(Request $request): Response - { - $entityManager = $this->getEntityManager(); - - /** @var string $token */ - $token = $request->get('token'); - - /** @var BlacklistUser|null $blacklistUser */ - $blacklistUser = $this->getBlacklistUserRepository()->findByToken($token); - - if (null === $blacklistUser) { - throw new NotFoundHttpException(); - } - - /** @var User $user */ - $user = $blacklistUser->getUser(); - $blacklistUser->deny(); - - $communityManager = $this->getCommunityManager($blacklistUser->getWebspaceKey()); - if (true === $communityManager->getConfigTypeProperty( - Configuration::TYPE_BLACKLIST_DENIED, - Configuration::DELETE_USER - ) - ) { - $entityManager->remove($user->getContact()); - $entityManager->remove($user); - $entityManager->remove($blacklistUser); - } - - /** @var BlacklistItem|null $item */ - $item = $this->getBlacklistItemRepository()->findOneBy(['pattern' => $user->getEmail()]); - - if (!$item) { - $item = $this->getBlacklistItemManager()->create(); - } - - /** @var string $email */ - $email = $user->getEmail(); - - $item->setType(BlacklistItem::TYPE_BLOCK) - ->setPattern($email); - - $entityManager->flush(); - - $communityManager->sendEmails(Configuration::TYPE_BLACKLIST_DENIED, $user); - - return $this->renderTemplate( - Configuration::TYPE_BLACKLIST_DENIED, - ['user' => $blacklistUser->getUser()] - ); - } - - protected function getBlacklistUserRepository(): BlacklistUserRepository - { - return $this->container->get('sulu_community.blacklisting.user_repository'); - } - - protected function getBlacklistItemRepository(): BlacklistItemRepository - { - return $this->container->get('sulu_community.blacklisting.item_repository'); - } - - protected function getBlacklistItemManager(): BlacklistItemManager - { - return $this->container->get('sulu_community.blacklisting.item_manager'); - } - - /** - * @return array<string|int, string> - */ - public static function getSubscribedServices(): array - { - $subscribedServices = parent::getSubscribedServices(); - - $subscribedServices['sulu_community.blacklisting.user_repository'] = BlacklistUserRepository::class; - $subscribedServices['sulu_community.blacklisting.item_repository'] = BlacklistItemRepository::class; - $subscribedServices['sulu_community.blacklisting.item_manager'] = BlacklistItemManagerInterface::class; - - return $subscribedServices; - } -} diff --git a/Controller/RegistrationRuleConfirmationController.php b/Controller/RegistrationRuleConfirmationController.php new file mode 100644 index 0000000..224ac2d --- /dev/null +++ b/Controller/RegistrationRuleConfirmationController.php @@ -0,0 +1,144 @@ +<?php + +/* + * This file is part of Sulu. + * + * (c) Sulu GmbH + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sulu\Bundle\CommunityBundle\Controller; + +use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUser; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUserRepository; +use Sulu\Bundle\CommunityBundle\Manager\RegistrationRuleItemManager; +use Sulu\Bundle\CommunityBundle\Manager\RegistrationRuleItemManagerInterface; +use Sulu\Bundle\SecurityBundle\Entity\User; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; + +/** + * Handles user confirmations for administrators. + */ +class RegistrationRuleConfirmationController extends AbstractController +{ + /** + * Confirms user with given token. + */ + public function confirmAction(Request $request): Response + { + /** @var string $token */ + $token = $request->get('token'); + + /** @var RegistrationRuleUser|null $registrationRuleUser */ + $registrationRuleUser = $this->getRegistrationRuleUserRepository()->findByToken($token); + + if (null === $registrationRuleUser) { + throw new NotFoundHttpException(); + } + + $registrationRuleUser->confirm(); + $this->getEntityManager()->flush(); + + $communityManager = $this->getCommunityManager($registrationRuleUser->getWebspaceKey()); + + /** @var User $user */ + $user = $registrationRuleUser->getUser(); + $communityManager->sendEmails(Configuration::TYPE_REGISTRATION_RULE_CONFIRMED, $user); + + return $this->renderTemplate( + Configuration::TYPE_REGISTRATION_RULE_CONFIRMED, + ['user' => $registrationRuleUser->getUser()] + ); + } + + /** + * Denies user with given token. + */ + public function denyAction(Request $request): Response + { + $entityManager = $this->getEntityManager(); + + /** @var string $token */ + $token = $request->get('token'); + + /** @var RegistrationRuleUser|null $registrationRuleUser */ + $registrationRuleUser = $this->getRegistrationRuleUserRepository()->findByToken($token); + + if (null === $registrationRuleUser) { + throw new NotFoundHttpException(); + } + + /** @var User $user */ + $user = $registrationRuleUser->getUser(); + $registrationRuleUser->deny(); + + $communityManager = $this->getCommunityManager($registrationRuleUser->getWebspaceKey()); + if (true === $communityManager->getConfigTypeProperty( + Configuration::TYPE_REGISTRATION_RULE_DENIED, + Configuration::DELETE_USER + ) + ) { + $entityManager->remove($user->getContact()); + $entityManager->remove($user); + $entityManager->remove($registrationRuleUser); + } + + /** @var RegistrationRuleItem|null $item */ + $item = $this->getRegistrationRuleItemRepository()->findOneBy(['pattern' => $user->getEmail()]); + + if (!$item) { + $item = $this->getRegistrationRuleItemManager()->create(); + } + + /** @var string $email */ + $email = $user->getEmail(); + + $item->setType(RegistrationRuleItem::TYPE_BLOCK) + ->setPattern($email); + + $entityManager->flush(); + + $communityManager->sendEmails(Configuration::TYPE_REGISTRATION_RULE_DENIED, $user); + + return $this->renderTemplate( + Configuration::TYPE_REGISTRATION_RULE_DENIED, + ['user' => $registrationRuleUser->getUser()] + ); + } + + protected function getRegistrationRuleUserRepository(): RegistrationRuleUserRepository + { + return $this->container->get('sulu_community.registration_rule.user_repository'); + } + + protected function getRegistrationRuleItemRepository(): RegistrationRuleItemRepository + { + return $this->container->get('sulu_community.registration_rule.item_repository'); + } + + protected function getRegistrationRuleItemManager(): RegistrationRuleItemManager + { + return $this->container->get('sulu_community.registration_rule.item_manager'); + } + + /** + * @return array<string|int, string> + */ + public static function getSubscribedServices(): array + { + $subscribedServices = parent::getSubscribedServices(); + + $subscribedServices['sulu_community.registration_rule.user_repository'] = RegistrationRuleUserRepository::class; + $subscribedServices['sulu_community.registration_rule.item_repository'] = RegistrationRuleItemRepository::class; + $subscribedServices['sulu_community.registration_rule.item_manager'] = RegistrationRuleItemManagerInterface::class; + + return $subscribedServices; + } +} diff --git a/Controller/BlacklistItemController.php b/Controller/RegistrationRuleItemController.php similarity index 82% rename from Controller/BlacklistItemController.php rename to Controller/RegistrationRuleItemController.php index 75c628b..660c2fe 100644 --- a/Controller/BlacklistItemController.php +++ b/Controller/RegistrationRuleItemController.php @@ -16,8 +16,8 @@ use FOS\RestBundle\Controller\Annotations\RouteResource; use FOS\RestBundle\Routing\ClassResourceInterface; use FOS\RestBundle\View\ViewHandlerInterface; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Manager\BlacklistItemManagerInterface; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Manager\RegistrationRuleItemManagerInterface; use Sulu\Component\Rest\AbstractRestController; use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilderFactoryInterface; use Sulu\Component\Rest\ListBuilder\Doctrine\FieldDescriptor\DoctrineFieldDescriptor; @@ -31,13 +31,13 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; /** - * Provides admin-api for blacklist-items. + * Provides admin-api for registration-rule-items. * * @NamePrefix("sulu_community.") - * - * @RouteResource("blacklist-item") - */ -class BlacklistItemController extends AbstractRestController implements ClassResourceInterface + + * @RouteResource("registration-rule-item") +*/ +class RegistrationRuleItemController extends AbstractRestController implements ClassResourceInterface { use RequestParametersTrait; @@ -57,22 +57,22 @@ class BlacklistItemController extends AbstractRestController implements ClassRes protected $listBuilderFactory; /** - * @var BlacklistItemManagerInterface + * @var RegistrationRuleItemManagerInterface */ - protected $blacklistItemManager; + protected $registrationRuleItemManager; public function __construct( EntityManagerInterface $entityManager, RestHelperInterface $restHelper, DoctrineListBuilderFactoryInterface $listBuilderFactory, - BlacklistItemManagerInterface $blacklistItemManager, + RegistrationRuleItemManagerInterface $registrationRuleItemManager, ViewHandlerInterface $viewHandler, ?TokenStorageInterface $tokenStorage = null ) { $this->entityManager = $entityManager; $this->restHelper = $restHelper; $this->listBuilderFactory = $listBuilderFactory; - $this->blacklistItemManager = $blacklistItemManager; + $this->registrationRuleItemManager = $registrationRuleItemManager; parent::__construct($viewHandler, $tokenStorage); } @@ -91,7 +91,7 @@ public function fieldsAction(): Response public function cgetAction(Request $request): Response { $fieldDescriptors = $this->getFieldDescriptors(); - $listBuilder = $this->listBuilderFactory->create(BlacklistItem::class); + $listBuilder = $this->listBuilderFactory->create(RegistrationRuleItem::class); $this->restHelper->initializeListBuilder($listBuilder, $fieldDescriptors); $listResponse = $this->prepareListResponse($request, $listBuilder, $fieldDescriptors); @@ -100,8 +100,8 @@ public function cgetAction(Request $request): Response $this->view( new ListRepresentation( $listResponse, - 'blacklist_items', - 'sulu_community.get_blacklist-items', + 'registration_rule_items', + 'sulu_community.get_registration_rule-items', $request->query->all(), $listBuilder->getCurrentPage(), $listBuilder->getLimit(), @@ -116,7 +116,7 @@ public function cgetAction(Request $request): Response */ public function getAction(int $id): Response { - return $this->handleView($this->view($this->blacklistItemManager->find($id))); + return $this->handleView($this->view($this->registrationRuleItemManager->find($id))); } /** @@ -124,7 +124,7 @@ public function getAction(int $id): Response */ public function postAction(Request $request): Response { - $item = $this->blacklistItemManager->create() + $item = $this->registrationRuleItemManager->create() ->setPattern($this->getRequestParameter($request, 'pattern', true)) ->setType($this->getRequestParameter($request, 'type', true)); @@ -138,7 +138,7 @@ public function postAction(Request $request): Response */ public function deleteAction(int $id): Response { - $this->blacklistItemManager->delete($id); + $this->registrationRuleItemManager->delete($id); $this->entityManager->flush(); return $this->handleView($this->view(null)); @@ -153,7 +153,7 @@ public function cdeleteAction(Request $request): Response return (int) $id; }, \array_filter(\explode(',', (string) $request->query->get('ids', '')))); - $this->blacklistItemManager->delete($ids); + $this->registrationRuleItemManager->delete($ids); $this->entityManager->flush(); return $this->handleView($this->view(null)); @@ -164,7 +164,7 @@ public function cdeleteAction(Request $request): Response */ public function putAction(int $id, Request $request): Response { - $item = $this->blacklistItemManager->find($id) + $item = $this->registrationRuleItemManager->find($id) ->setPattern($this->getRequestParameter($request, 'pattern', true)) ->setType($this->getRequestParameter($request, 'type', true)); @@ -174,7 +174,7 @@ public function putAction(int $id, Request $request): Response } /** - * Creates the field-descriptors for blacklist-items. + * Creates the field-descriptors for registration_rule-items. * * @return DoctrineFieldDescriptor[] */ @@ -184,7 +184,7 @@ private function getFieldDescriptors(): array 'id' => new DoctrineFieldDescriptor( 'id', 'id', - BlacklistItem::class, + RegistrationRuleItem::class, 'public.id', [], FieldDescriptorInterface::VISIBILITY_NO @@ -192,7 +192,7 @@ private function getFieldDescriptors(): array 'pattern' => new DoctrineFieldDescriptor( 'pattern', 'pattern', - BlacklistItem::class, + RegistrationRuleItem::class, 'community.blacklist.pattern', [], FieldDescriptorInterface::VISIBILITY_ALWAYS, @@ -203,7 +203,7 @@ private function getFieldDescriptors(): array 'type' => new DoctrineFieldDescriptor( 'type', 'type', - BlacklistItem::class, + RegistrationRuleItem::class, 'public.type', [], FieldDescriptorInterface::VISIBILITY_ALWAYS, diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index cc9cdcb..edc2cfa 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -11,10 +11,10 @@ namespace Sulu\Bundle\CommunityBundle\DependencyInjection; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistUser; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistUserRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUser; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUserRepository; use Sulu\Bundle\CommunityBundle\Form\Type\CompletionType; use Sulu\Bundle\CommunityBundle\Form\Type\PasswordForgetType; use Sulu\Bundle\CommunityBundle\Form\Type\PasswordResetType; @@ -51,9 +51,9 @@ class Configuration implements ConfigurationInterface public const TYPE_CONFIRMATION = 'confirmation'; public const TYPE_PASSWORD_FORGET = 'password_forget'; public const TYPE_PASSWORD_RESET = 'password_reset'; - public const TYPE_BLACKLISTED = 'blacklisted'; - public const TYPE_BLACKLIST_CONFIRMED = 'blacklist_confirmed'; - public const TYPE_BLACKLIST_DENIED = 'blacklist_denied'; + public const TYPE_REGISTRATION_RULEED = 'blacklisted'; + public const TYPE_REGISTRATION_RULE_CONFIRMED = 'blacklist_confirmed'; + public const TYPE_REGISTRATION_RULE_DENIED = 'blacklist_denied'; public const TYPE_PROFILE = 'profile'; public const TYPE_EMAIL_CONFIRMATION = 'email_confirmation'; @@ -64,9 +64,9 @@ class Configuration implements ConfigurationInterface self::TYPE_REGISTRATION, self::TYPE_PASSWORD_FORGET, self::TYPE_PASSWORD_RESET, - self::TYPE_BLACKLISTED, - self::TYPE_BLACKLIST_CONFIRMED, - self::TYPE_BLACKLIST_DENIED, + self::TYPE_REGISTRATION_RULEED, + self::TYPE_REGISTRATION_RULE_CONFIRMED, + self::TYPE_REGISTRATION_RULE_DENIED, self::TYPE_PROFILE, self::TYPE_EMAIL_CONFIRMATION, ]; @@ -101,18 +101,18 @@ public function getConfigTreeBuilder() ->arrayNode('objects') ->addDefaultsIfNotSet() ->children() - ->arrayNode('blacklist_item') + ->arrayNode('registration_rule_item') ->addDefaultsIfNotSet() ->children() - ->scalarNode('model')->defaultValue(BlacklistItem::class)->end() - ->scalarNode('repository')->defaultValue(BlacklistItemRepository::class)->end() + ->scalarNode('model')->defaultValue(RegistrationRuleItem::class)->end() + ->scalarNode('repository')->defaultValue(RegistrationRuleItemRepository::class)->end() ->end() ->end() - ->arrayNode('blacklist_user') + ->arrayNode('registration_rule_user') ->addDefaultsIfNotSet() ->children() - ->scalarNode('model')->defaultValue(BlacklistUser::class)->end() - ->scalarNode('repository')->defaultValue(BlacklistUserRepository::class)->end() + ->scalarNode('model')->defaultValue(RegistrationRuleUser::class)->end() + ->scalarNode('repository')->defaultValue(RegistrationRuleUserRepository::class)->end() ->end() ->end() ->end() @@ -256,27 +256,27 @@ public function getConfigTreeBuilder() ->end() ->end() ->end() - // Blacklisted - ->arrayNode(self::TYPE_BLACKLISTED) + // RegistrationRuleed + ->arrayNode(self::TYPE_REGISTRATION_RULEED) ->addDefaultsIfNotSet() ->children() - // Blacklisted configuration + // RegistrationRuleed configuration ->arrayNode(self::EMAIL) ->addDefaultsIfNotSet() ->children() - ->scalarNode(self::EMAIL_SUBJECT)->defaultValue('Blacklisted')->end() - ->scalarNode(self::EMAIL_ADMIN_TEMPLATE)->defaultValue('@SuluCommunity/blacklist-email.html.twig')->end() + ->scalarNode(self::EMAIL_SUBJECT)->defaultValue('RegistrationRuleed')->end() + ->scalarNode(self::EMAIL_ADMIN_TEMPLATE)->defaultValue('@SuluCommunity/registration-rule-email.html.twig')->end() ->scalarNode(self::EMAIL_USER_TEMPLATE)->defaultValue(null)->end() ->end() ->end() ->end() ->end() - // Blacklist denied - ->arrayNode(self::TYPE_BLACKLIST_DENIED) + // RegistrationRule denied + ->arrayNode(self::TYPE_REGISTRATION_RULE_DENIED) ->addDefaultsIfNotSet() ->children() // Denied configuration - ->scalarNode(self::TEMPLATE)->defaultValue('@SuluCommunity/blacklist-denied.html.twig')->end() + ->scalarNode(self::TEMPLATE)->defaultValue('@SuluCommunity/registration-rule-denied.html.twig')->end() ->scalarNode(self::DELETE_USER)->defaultTrue()->end() ->arrayNode(self::EMAIL) ->addDefaultsIfNotSet() @@ -288,12 +288,12 @@ public function getConfigTreeBuilder() ->end() ->end() ->end() - // Blacklist confirmed - ->arrayNode(self::TYPE_BLACKLIST_CONFIRMED) + // RegistrationRule confirmed + ->arrayNode(self::TYPE_REGISTRATION_RULE_CONFIRMED) ->addDefaultsIfNotSet() ->children() // Confirmed configuration - ->scalarNode(self::TEMPLATE)->defaultValue('@SuluCommunity/blacklist-confirmed.html.twig')->end() + ->scalarNode(self::TEMPLATE)->defaultValue('@SuluCommunity/registration-rule-confirmed.html.twig')->end() ->arrayNode(self::EMAIL) ->addDefaultsIfNotSet() ->children() diff --git a/DependencyInjection/SuluCommunityExtension.php b/DependencyInjection/SuluCommunityExtension.php index a219ffe..5434177 100644 --- a/DependencyInjection/SuluCommunityExtension.php +++ b/DependencyInjection/SuluCommunityExtension.php @@ -71,10 +71,10 @@ public function prepend(ContainerBuilder $container): void ], ], 'resources' => [ - 'blacklist_items' => [ + 'registration-rule-items' => [ 'routes' => [ - 'list' => 'sulu_community.get_blacklist-items', - 'detail' => 'sulu_community.get_blacklist-item', + 'list' => 'sulu_community.get_registration-rule-items', + 'detail' => 'sulu_community.get_registration-rule-item', ], ], ], diff --git a/Entity/BlacklistItem.php b/Entity/RegistrationRuleItem.php similarity index 95% rename from Entity/BlacklistItem.php rename to Entity/RegistrationRuleItem.php index d8d85cc..8eb6d64 100644 --- a/Entity/BlacklistItem.php +++ b/Entity/RegistrationRuleItem.php @@ -12,9 +12,9 @@ namespace Sulu\Bundle\CommunityBundle\Entity; /** - * Represents a single item in the blacklist. + * Represents a single item in the registration rule. */ -class BlacklistItem +class RegistrationRuleItem { public const TYPE_REQUEST = 'request'; public const TYPE_BLOCK = 'block'; diff --git a/Entity/BlacklistItemRepository.php b/Entity/RegistrationRuleItemRepository.php similarity index 74% rename from Entity/BlacklistItemRepository.php rename to Entity/RegistrationRuleItemRepository.php index 7bc842a..44365c0 100644 --- a/Entity/BlacklistItemRepository.php +++ b/Entity/RegistrationRuleItemRepository.php @@ -14,18 +14,18 @@ use Sulu\Component\Persistence\Repository\ORM\EntityRepository; /** - * Entity-Repository for blacklist-items. + * Entity-Repository for registration-rule-items. * - * @method BlacklistItem createNew() + * @method RegistrationRuleItem createNew() */ -class BlacklistItemRepository extends EntityRepository +class RegistrationRuleItemRepository extends EntityRepository { /** * Returns items which matches given email. * * @param string $email * - * @return BlacklistItem[] + * @return RegistrationRuleItem[] */ public function findBySender($email) { @@ -33,7 +33,7 @@ public function findBySender($email) ->where('REGEXP(:email, entity.regexp) = true') ->setParameter('email', $email); - /** @var BlacklistItem[] */ + /** @var RegistrationRuleItem[] */ return $queryBuilder->getQuery()->getResult(); } } diff --git a/Entity/BlacklistUser.php b/Entity/RegistrationRuleUser.php similarity index 98% rename from Entity/BlacklistUser.php rename to Entity/RegistrationRuleUser.php index 52d38a1..91e3074 100644 --- a/Entity/BlacklistUser.php +++ b/Entity/RegistrationRuleUser.php @@ -16,7 +16,7 @@ /** * Represents a requested user which has to be confirmed. */ -class BlacklistUser +class RegistrationRuleUser { public const TYPE_NEW = 0; public const TYPE_CONFIRMED = 1; diff --git a/Entity/BlacklistUserRepository.php b/Entity/RegistrationRuleUserRepository.php similarity index 87% rename from Entity/BlacklistUserRepository.php rename to Entity/RegistrationRuleUserRepository.php index 99bc8ed..6da93ea 100644 --- a/Entity/BlacklistUserRepository.php +++ b/Entity/RegistrationRuleUserRepository.php @@ -15,14 +15,14 @@ use Doctrine\ORM\NoResultException; use Sulu\Component\Persistence\Repository\ORM\EntityRepository; -class BlacklistUserRepository extends EntityRepository +class RegistrationRuleUserRepository extends EntityRepository { /** * Return blacklist-user for given token. * * @param string $token * - * @return BlacklistUser|object|null + * @return RegistrationRuleUser|object|null */ public function findByToken($token) { diff --git a/EventListener/BlacklistListener.php b/EventListener/RegistrationRuleListener.php similarity index 73% rename from EventListener/BlacklistListener.php rename to EventListener/RegistrationRuleListener.php index b248842..2aed744 100644 --- a/EventListener/BlacklistListener.php +++ b/EventListener/RegistrationRuleListener.php @@ -13,9 +13,9 @@ use Doctrine\Persistence\ObjectManager; use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistUser; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUser; use Sulu\Bundle\CommunityBundle\Event\UserRegisteredEvent; use Sulu\Bundle\CommunityBundle\Mail\Mail; use Sulu\Bundle\CommunityBundle\Mail\MailFactoryInterface; @@ -25,12 +25,12 @@ /** * Interrupts registration to avoid register request-type emails. */ -class BlacklistListener implements EventSubscriberInterface +class RegistrationRuleListener implements EventSubscriberInterface { /** - * @var BlacklistItemRepository + * @var RegistrationRuleItemRepository */ - private $blacklistItemRepository; + private $registrationRuleRepository; /** * @var ObjectManager @@ -48,12 +48,12 @@ class BlacklistListener implements EventSubscriberInterface private $mailFactory; public function __construct( - BlacklistItemRepository $blacklistItemRepository, + RegistrationRuleItemRepository $registrationRuleRepository, ObjectManager $objectManager, TokenGeneratorInterface $tokenGenerator, MailFactoryInterface $mailFactory ) { - $this->blacklistItemRepository = $blacklistItemRepository; + $this->registrationRuleRepository = $registrationRuleRepository; $this->objectManager = $objectManager; $this->tokenGenerator = $tokenGenerator; $this->mailFactory = $mailFactory; @@ -74,11 +74,11 @@ public static function getSubscribedEvents() */ public function validateEmail(UserRegisteredEvent $event): void { - if (BlacklistItem::TYPE_REQUEST !== $this->getType((string) $event->getUser()->getEmail())) { + if (RegistrationRuleItem::TYPE_REQUEST !== $this->getType((string) $event->getUser()->getEmail())) { return; } - $blacklistUser = new BlacklistUser( + $blacklistUser = new RegistrationRuleUser( $this->tokenGenerator->generateToken(), $event->getConfigProperty(Configuration::WEBSPACE_KEY), $event->getUser() @@ -90,7 +90,7 @@ public function validateEmail(UserRegisteredEvent $event): void Mail::create( $event->getConfigProperty(Configuration::EMAIL_FROM), $event->getConfigProperty(Configuration::EMAIL_TO), - $event->getConfigTypeProperty(Configuration::TYPE_BLACKLISTED, Configuration::EMAIL) + $event->getConfigTypeProperty(Configuration::TYPE_REGISTRATION_RULEED, Configuration::EMAIL) ), $event->getUser(), ['token' => $blacklistUser->getToken()] @@ -104,18 +104,18 @@ public function validateEmail(UserRegisteredEvent $event): void */ private function getType(string $email): ?string { - $items = $this->blacklistItemRepository->findBySender($email); + $items = $this->registrationRuleRepository->findBySender($email); if (0 === \count($items)) { return null; } foreach ($items as $item) { - if (BlacklistItem::TYPE_BLOCK === $item->getType()) { - return BlacklistItem::TYPE_BLOCK; + if (RegistrationRuleItem::TYPE_BLOCK === $item->getType()) { + return RegistrationRuleItem::TYPE_BLOCK; } } - return BlacklistItem::TYPE_REQUEST; + return RegistrationRuleItem::TYPE_REQUEST; } } diff --git a/Manager/BlacklistItemManagerInterface.php b/Manager/BlacklistItemManagerInterface.php deleted file mode 100644 index 3027872..0000000 --- a/Manager/BlacklistItemManagerInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -/* - * This file is part of Sulu. - * - * (c) Sulu GmbH - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Sulu\Bundle\CommunityBundle\Manager; - -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; - -/** - * Interface for blacklist-item manager. - */ -interface BlacklistItemManagerInterface -{ - /** - * Returns blacklist-item. - */ - public function find(int $id): BlacklistItem; - - /** - * Return new blacklist-item. - */ - public function create(): BlacklistItem; - - /** - * Deletes given blacklist-item. - * - * @param int|int[] $ids - */ - public function delete($ids): void; -} diff --git a/Manager/BlacklistItemManager.php b/Manager/RegistrationRuleItemManager.php similarity index 67% rename from Manager/BlacklistItemManager.php rename to Manager/RegistrationRuleItemManager.php index 6f3b0b4..971d38b 100644 --- a/Manager/BlacklistItemManager.php +++ b/Manager/RegistrationRuleItemManager.php @@ -12,13 +12,13 @@ namespace Sulu\Bundle\CommunityBundle\Manager; use Doctrine\ORM\EntityManagerInterface; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; /** - * Manages blacklist-items. + * Manages registration-rule-items. */ -class BlacklistItemManager implements BlacklistItemManagerInterface +class RegistrationRuleItemManager implements RegistrationRuleItemManagerInterface { /** * @var EntityManagerInterface @@ -26,25 +26,25 @@ class BlacklistItemManager implements BlacklistItemManagerInterface private $entityManager; /** - * @var BlacklistItemRepository + * @var RegistrationRuleItemRepository */ private $blacklistItemRepository; - public function __construct(EntityManagerInterface $entityManager, BlacklistItemRepository $blacklistItemRepository) + public function __construct(EntityManagerInterface $entityManager, RegistrationRuleItemRepository $blacklistItemRepository) { $this->entityManager = $entityManager; $this->blacklistItemRepository = $blacklistItemRepository; } - public function find(int $id): BlacklistItem + public function find(int $id): RegistrationRuleItem { - /** @var BlacklistItem $blacklistItem */ + /** @var RegistrationRuleItem $blacklistItem */ $blacklistItem = $this->blacklistItemRepository->find($id); return $blacklistItem; } - public function create(): BlacklistItem + public function create(): RegistrationRuleItem { $item = $this->blacklistItemRepository->createNew(); @@ -60,7 +60,7 @@ public function delete($ids): void } foreach ($ids as $id) { - /** @var BlacklistItem $object */ + /** @var RegistrationRuleItem $object */ $object = $this->entityManager->getReference($this->blacklistItemRepository->getClassName(), $id); $this->entityManager->remove($object); diff --git a/Manager/RegistrationRuleItemManagerInterface.php b/Manager/RegistrationRuleItemManagerInterface.php new file mode 100644 index 0000000..a43d86c --- /dev/null +++ b/Manager/RegistrationRuleItemManagerInterface.php @@ -0,0 +1,37 @@ +<?php + +/* + * This file is part of Sulu. + * + * (c) Sulu GmbH + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sulu\Bundle\CommunityBundle\Manager; + +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; + +/** + * Interface for registration-rule-item manager. + */ +interface RegistrationRuleItemManagerInterface +{ + /** + * Returns registration-rule-item. + */ + public function find(int $id): RegistrationRuleItem; + + /** + * Return new registration-rule-item. + */ + public function create(): RegistrationRuleItem; + + /** + * Deletes given registration-rule-item. + * + * @param int|int[] $ids + */ + public function delete($ids): void; +} diff --git a/README.md b/README.md index 78b402c..af92952 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The SuluCommunityBundle adds following features to a webspace: - Registration - Password Forget/Reset - Profile - - Blacklisting + - RegistrationRuleing ## Documentation diff --git a/Resources/config/doctrine/BlacklistItem.orm.xml b/Resources/config/doctrine/RegistrationRuleItem.orm.xml similarity index 85% rename from Resources/config/doctrine/BlacklistItem.orm.xml rename to Resources/config/doctrine/RegistrationRuleItem.orm.xml index f0b6c76..70d633c 100644 --- a/Resources/config/doctrine/BlacklistItem.orm.xml +++ b/Resources/config/doctrine/RegistrationRuleItem.orm.xml @@ -2,8 +2,8 @@ <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - <entity name="Sulu\Bundle\CommunityBundle\Entity\BlacklistItem" table="com_blacklist_item" - repository-class="Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository"> + <entity name="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem" table="com_registration_rule_item" + repository-class="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository"> <indexes> <index columns="regexpPattern"/> </indexes> diff --git a/Resources/config/doctrine/BlacklistUser.orm.xml b/Resources/config/doctrine/RegistrationRuleUser.orm.xml similarity index 88% rename from Resources/config/doctrine/BlacklistUser.orm.xml rename to Resources/config/doctrine/RegistrationRuleUser.orm.xml index 2205e52..8d457b3 100644 --- a/Resources/config/doctrine/BlacklistUser.orm.xml +++ b/Resources/config/doctrine/RegistrationRuleUser.orm.xml @@ -2,8 +2,8 @@ <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - <entity name="Sulu\Bundle\CommunityBundle\Entity\BlacklistUser" table="com_blacklist_user" - repository-class="Sulu\Bundle\CommunityBundle\Entity\BlacklistUserRepository"> + <entity name="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUser" table="com_registration_rule_user" + repository-class="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUserRepository"> <indexes> <index columns="token"/> </indexes> diff --git a/Resources/config/forms/blacklist_item_details.xml b/Resources/config/forms/registration_rule_item_details.xml similarity index 96% rename from Resources/config/forms/blacklist_item_details.xml rename to Resources/config/forms/registration_rule_item_details.xml index 5512229..163cd14 100644 --- a/Resources/config/forms/blacklist_item_details.xml +++ b/Resources/config/forms/registration_rule_item_details.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd" > - <key>blacklist_item_details</key> + <key>registration_rule_item_details</key> <properties> <property name="pattern" type="text_line" mandatory="true"> diff --git a/Resources/config/lists/blacklist_items.xml b/Resources/config/lists/registration_rule_items.xml similarity index 73% rename from Resources/config/lists/blacklist_items.xml rename to Resources/config/lists/registration_rule_items.xml index 06123c0..7412519 100644 --- a/Resources/config/lists/blacklist_items.xml +++ b/Resources/config/lists/registration_rule_items.xml @@ -1,6 +1,6 @@ <?xml version="1.0" ?> <list xmlns="http://schemas.sulu.io/list-builder/list"> - <key>blacklist_items</key> + <key>registration_rule_items</key> <properties> <property @@ -10,7 +10,7 @@ translation="sulu_admin.id" > <field-name>id</field-name> - <entity-name>%sulu.model.blacklist_item.class%</entity-name> + <entity-name>%sulu.model.registration_rule_item.class%</entity-name> </property> <property @@ -20,7 +20,7 @@ translation="sulu_community.pattern" > <field-name>pattern</field-name> - <entity-name>%sulu.model.blacklist_item.class%</entity-name> + <entity-name>%sulu.model.registration_rule_item.class%</entity-name> </property> <property @@ -30,7 +30,7 @@ translation="sulu_community.type" > <field-name>type</field-name> - <entity-name>%sulu.model.blacklist_item.class%</entity-name> + <entity-name>%sulu.model.registration_rule_item.class%</entity-name> </property> </properties> </list> diff --git a/Resources/config/routing_api.yaml b/Resources/config/routing_api.yaml index 81ebccd..58eba8a 100644 --- a/Resources/config/routing_api.yaml +++ b/Resources/config/routing_api.yaml @@ -1,3 +1,3 @@ -sulu_community.blacklist_item: +sulu_community.registration_rule_item: type: rest - resource: sulu_community.controller.blacklist_item + resource: sulu_community.controller.registration_rule_item diff --git a/Resources/config/routing_website.yaml b/Resources/config/routing_website.yaml index 50a059e..fdfb2bd 100644 --- a/Resources/config/routing_website.yaml +++ b/Resources/config/routing_website.yaml @@ -35,8 +35,8 @@ sulu_community.logout: sulu_community.user_confirm: path: /_community/confirm - controller: Sulu\Bundle\CommunityBundle\Controller\BlacklistConfirmationController::confirmAction + controller: Sulu\Bundle\CommunityBundle\Controller\RegistrationRuleConfirmationController::confirmAction sulu_community.user_deny: path: /_community/deny - controller: Sulu\Bundle\CommunityBundle\Controller\BlacklistConfirmationController::denyAction + controller: Sulu\Bundle\CommunityBundle\Controller\RegistrationRuleConfirmationController::denyAction diff --git a/Resources/config/serializer/BlacklistItem.xml b/Resources/config/serializer/RegistrationRuleItem.xml similarity index 72% rename from Resources/config/serializer/BlacklistItem.xml rename to Resources/config/serializer/RegistrationRuleItem.xml index 2481194..3657f2e 100644 --- a/Resources/config/serializer/BlacklistItem.xml +++ b/Resources/config/serializer/RegistrationRuleItem.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <serializer> - <class name="Sulu\Bundle\CommunityBundle\Entity\BlacklistItem" exclusion-policy="ALL"> + <class name="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem" exclusion-policy="ALL"> <property name="id" type="integer" expose="true"/> <property name="pattern" type="string" expose="true"/> <property name="type" type="string" expose="true"/> diff --git a/Resources/config/services.xml b/Resources/config/services.xml index fff3c33..baafe33 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -57,8 +57,8 @@ </service> <!-- black-listener --> - <service id="sulu_community.black_listener" class="Sulu\Bundle\CommunityBundle\EventListener\BlacklistListener"> - <argument type="service" id="sulu.repository.blacklist_item"/> + <service id="sulu_community.registration_rule_listener" class="Sulu\Bundle\CommunityBundle\EventListener\RegistrationRuleListener"> + <argument type="service" id="sulu.repository.registration_rule_item"/> <argument type="service" id="doctrine.orm.entity_manager"/> <argument type="service" id="sulu_security.token_generator"/> <argument type="service" id="sulu_community.mail_factory"/> @@ -96,32 +96,32 @@ <tag name="massive_build.builder"/> </service> - <!-- blacklisting --> - <service id="sulu_community.blacklisting.item_manager" - class="Sulu\Bundle\CommunityBundle\Manager\BlacklistItemManager" + <!-- registration_rule --> + <service id="sulu_community.registration_rule.item_manager" + class="Sulu\Bundle\CommunityBundle\Manager\RegistrationRuleItemManager" public="true"> <argument type="service" id="doctrine.orm.entity_manager"/> - <argument type="service" id="sulu.repository.blacklist_item"/> + <argument type="service" id="sulu.repository.registration_rule_item"/> </service> - <service id="Sulu\Bundle\CommunityBundle\Manager\BlacklistItemManagerInterface" alias="sulu_community.blacklisting.item_manager"/> + <service id="Sulu\Bundle\CommunityBundle\Manager\RegistrationRuleItemManagerInterface" alias="sulu_community.registration_rule.item_manager"/> - <service id="sulu_community.blacklisting.item_repository" - class="Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository" + <service id="sulu_community.registration_rule.item_repository" + class="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository" public="true"> <factory service="doctrine.orm.entity_manager" method="getRepository"/> - <argument type="string">Sulu\Bundle\CommunityBundle\Entity\BlacklistItem</argument> + <argument type="string">Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem</argument> </service> - <service id="Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository" alias="sulu_community.blacklisting.item_repository"/> + <service id="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository" alias="sulu_community.registration_rule.item_repository"/> - <service id="sulu_community.blacklisting.user_repository" - class="Sulu\Bundle\CommunityBundle\Entity\BlacklistUserRepository" + <service id="sulu_community.registration_rule.user_repository" + class="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUserRepository" public="true"> <factory service="doctrine.orm.entity_manager" method="getRepository"/> - <argument type="string">Sulu\Bundle\CommunityBundle\Entity\BlacklistUser</argument> + <argument type="string">Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUser</argument> </service> - <service id="Sulu\Bundle\CommunityBundle\Entity\BlacklistUserRepository" alias="sulu_community.blacklisting.user_repository"/> + <service id="Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUserRepository" alias="sulu_community.registration_rule.user_repository"/> <!-- email-confirmation --> <service id="sulu_community.email_confirmation.listener" @@ -152,11 +152,11 @@ <service id="Sulu\Bundle\CommunityBundle\Mail\MailFactoryInterface" alias="sulu_community.mail_factory"/> <!-- Controller --> - <service id="sulu_community.controller.blacklist_item" class="Sulu\Bundle\CommunityBundle\Controller\BlacklistItemController" public="true"> + <service id="sulu_community.controller.registration_rule_item" class="Sulu\Bundle\CommunityBundle\Controller\RegistrationRuleItemController" public="true"> <argument type="service" id="doctrine.orm.entity_manager"/> <argument type="service" id="sulu_core.doctrine_rest_helper"/> <argument type="service" id="sulu_core.doctrine_list_builder_factory"/> - <argument type="service" id="sulu_community.blacklisting.item_manager"/> + <argument type="service" id="sulu_community.registration_rule.item_manager"/> <argument type="service" id="fos_rest.view_handler.default"/> <argument type="service" id="security.token_storage"/> </service> @@ -171,7 +171,7 @@ </call> </service> - <service id="Sulu\Bundle\CommunityBundle\Controller\BlacklistConfirmationController" class="Sulu\Bundle\CommunityBundle\Controller\BlacklistConfirmationController" public="true"> + <service id="Sulu\Bundle\CommunityBundle\Controller\RegistrationRuleConfirmationController" class="Sulu\Bundle\CommunityBundle\Controller\RegistrationRuleConfirmationController" public="true"> <tag name="container.service_subscriber" /> <tag name="controller.service_arguments" /> <tag name="sulu.context" context="website" /> diff --git a/Resources/config/validator.xml b/Resources/config/validator.xml index b0295b6..370703e 100644 --- a/Resources/config/validator.xml +++ b/Resources/config/validator.xml @@ -12,7 +12,7 @@ <!-- Blocked Validator --> <service id="sulu_community.validator.blocked" class="Sulu\Bundle\CommunityBundle\Validator\Constraints\BlockedValidator"> - <argument type="service" id="sulu.repository.blacklist_item"/> + <argument type="service" id="sulu.repository.registration_rule_item"/> <tag name="validator.constraint_validator" alias="blocked_validator"/> </service> diff --git a/Resources/doc/12-blacklisting.md b/Resources/doc/12-registration-rule.md similarity index 81% rename from Resources/doc/12-blacklisting.md rename to Resources/doc/12-registration-rule.md index eea3b98..e16b2a9 100644 --- a/Resources/doc/12-blacklisting.md +++ b/Resources/doc/12-registration-rule.md @@ -1,4 +1,4 @@ -# Blacklisting +# RegistrationRuleing ## Config @@ -10,21 +10,21 @@ sulu_community: <webspace_key>: # Replace <webspace_key> with the key of your webspace blacklisted: email: - subject: Blacklisted - admin_template: community/blacklist-email.html.twig + subject: RegistrationRuleed + admin_template: community/registration-rule-email.html.twig user_template: ~ blacklist_denied: email: subject: Denied admin_template: ~ user_template: ~ - template: community/blacklist-denied.html.twig + template: community/registration-rule-denied.html.twig blacklist_confirmed: email: subject: Registration admin_template: ~ user_template: community/registration-email.html.twig - template: community/blacklist-confirmed.html.twig + template: community/registration-rule-confirmed.html.twig ``` ## Backend Config @@ -32,7 +32,7 @@ sulu_community: To enable the blacklisting feature add the permissions for blacklisting to your role. For this go to `Settings -> Roles -> YourRole` in the sulu backend and add the permissions. -When you successfully enabled it email addresses can be set to `block` or on `request` under `Settings -> Blacklist`. +When you successfully enabled it email addresses can be set to `block` or on `request` under `Settings -> RegistrationRule`. It is possible to use wildcards e.g. `*@test.com` to set the state for a whole domain. ## blacklist.email @@ -42,7 +42,7 @@ The admin of the page will receive the blacklisted email when a user email addre **Example Template**: ```twig -{# community/blacklist-email.html.twig #} +{# community/registration-rule-email.html.twig #} {% extends 'base-email.html.twig' %} @@ -64,7 +64,7 @@ When the admin clicks on the link a template is rendered which can show specific **Example Template**: ```twig -{# community/blacklist-denied.html.twig / community/blacklist-confirmed.html.twig #} +{# community/registration-rule-denied.html.twig / community/registration-rule-confirmed.html.twig #} {% extends 'base.html.twig' %} diff --git a/Resources/doc/3-customization.md b/Resources/doc/3-customization.md index c7f592e..9438963 100644 --- a/Resources/doc/3-customization.md +++ b/Resources/doc/3-customization.md @@ -104,24 +104,24 @@ sulu_community: admin_template: ~ template: community/email-confirmation-success.html.twig - # Blacklist + # RegistrationRule blacklisted: email: - subject: Blacklisted - admin_template: community/blacklist-email.html.twig + subject: RegistrationRuleed + admin_template: community/registration-rule-email.html.twig user_template: ~ blacklist_denied: email: subject: Denied admin_template: ~ user_template: ~ - template: community/blacklist-denied.html.twig + template: community/registration-rule-denied.html.twig blacklist_confirmed: email: subject: Registration admin_template: ~ user_template: community/registration-email.html.twig - template: community/blacklist-confirmed.html.twig + template: community/registration-rule-confirmed.html.twig ``` ### Basic Options @@ -199,7 +199,7 @@ The subject of the emails. #### email.admin_template Type: `string` -Example: community/blacklist-email.html.twig +Example: community/registration-rule-email.html.twig The template used to render the admin email, set to null to deactivate it. @@ -249,5 +249,5 @@ The form type which is used to build the form. - [Profile](9-profile.md) - [Email Confirmation](10-email-confirmation.md) - [Completion](11-completion.md) - - [Blacklisting](12-blacklisting.md) + - [RegistrationRuleing](12-registration-rule.md) - [Maintenance](13-maintenance.md) diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 9e4f93e..fe7ed77 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -24,4 +24,4 @@ 6. [Profile](9-profile.md) 7. [Email Confirmation](10-email-confirmation.md) 8. [Completion](11-completion.md) -9. [Blacklisting](12-blacklisting.md) +9. [RegistrationRuleing](12-registration-rule.md) diff --git a/Resources/translations/admin.de.json b/Resources/translations/admin.de.json index 6a6b2bf..f6263dc 100644 --- a/Resources/translations/admin.de.json +++ b/Resources/translations/admin.de.json @@ -1,5 +1,5 @@ { - "sulu_community.blacklist": "Blacklist", + "sulu_community.blacklist": "RegistrationRule", "sulu_community.pattern": "Absender", "sulu_community.type": "Typ", "sulu_community.request": "Bestätigen", diff --git a/Resources/translations/admin.en.json b/Resources/translations/admin.en.json index 0495c2d..2381cd8 100644 --- a/Resources/translations/admin.en.json +++ b/Resources/translations/admin.en.json @@ -1,5 +1,5 @@ { - "sulu_community.blacklist": "Blacklist", + "sulu_community.blacklist": "RegistrationRule", "sulu_community.pattern": "Sender", "sulu_community.type": "Type", "sulu_community.request": "Confirmation", diff --git a/Resources/translations/admin.fr.json b/Resources/translations/admin.fr.json index f21dc28..50940a3 100644 --- a/Resources/translations/admin.fr.json +++ b/Resources/translations/admin.fr.json @@ -1,5 +1,5 @@ { - "sulu_community.blacklist": "Blacklist", + "sulu_community.blacklist": "RegistrationRule", "sulu_community.pattern": "Expéditeur", "sulu_community.type": "Type", "sulu_community.request": "Confirmer", diff --git a/Resources/views/blacklist-confirmed.html.twig b/Resources/views/registration-rule-confirmed.html.twig similarity index 100% rename from Resources/views/blacklist-confirmed.html.twig rename to Resources/views/registration-rule-confirmed.html.twig diff --git a/Resources/views/blacklist-denied.html.twig b/Resources/views/registration-rule-denied.html.twig similarity index 100% rename from Resources/views/blacklist-denied.html.twig rename to Resources/views/registration-rule-denied.html.twig diff --git a/Resources/views/blacklist-email.html.twig b/Resources/views/registration-rule-email.html.twig similarity index 100% rename from Resources/views/blacklist-email.html.twig rename to Resources/views/registration-rule-email.html.twig diff --git a/SuluCommunityBundle.php b/SuluCommunityBundle.php index 9d72133..e5b9e28 100644 --- a/SuluCommunityBundle.php +++ b/SuluCommunityBundle.php @@ -13,8 +13,8 @@ use Sulu\Bundle\CommunityBundle\DependencyInjection\CompilerPass\CommunityManagerCompilerPass; use Sulu\Bundle\CommunityBundle\DependencyInjection\CompilerPass\CommunityValidatorCompilerPass; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistUser; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUser; use Sulu\Bundle\PersistenceBundle\PersistenceBundleTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -30,8 +30,8 @@ public function build(ContainerBuilder $container): void { $this->buildPersistence( [ - BlacklistItem::class => 'sulu.model.blacklist_item.class', - BlacklistUser::class => 'sulu.model.blacklist_user.class', + RegistrationRuleItem::class => 'sulu.model.registration_rule_item.class', + RegistrationRuleUser::class => 'sulu.model.registration_rule_user.class', ], $container ); diff --git a/Tests/Application/.env b/Tests/Application/.env index 2026b5c..59daa2b 100644 --- a/Tests/Application/.env +++ b/Tests/Application/.env @@ -1,4 +1,4 @@ APP_ENV=test -DATABASE_URL=mysql://root:@127.0.0.1:3306/su_community_test?serverVersion=8.0 +DATABASE_URL="mysql://root:ChangeMe@127.0.0.1:3306/sulu_community?serverVersion=8.0.27&charset=utf8mb4" DATABASE_CHARSET=utf8mb4 DATABASE_COLLATE=utf8mb4_unicode_ci diff --git a/Tests/Functional/Controller/BlacklistItemControllerTest.php b/Tests/Functional/Controller/RegistrationRuleItemControllerTest.php similarity index 70% rename from Tests/Functional/Controller/BlacklistItemControllerTest.php rename to Tests/Functional/Controller/RegistrationRuleItemControllerTest.php index ecdc480..cadf6aa 100644 --- a/Tests/Functional/Controller/BlacklistItemControllerTest.php +++ b/Tests/Functional/Controller/RegistrationRuleItemControllerTest.php @@ -11,11 +11,11 @@ namespace Sulu\Bundle\CommunityBundle\Tests\Functional\Controller; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; use Symfony\Bundle\FrameworkBundle\KernelBrowser; -class BlacklistItemControllerTest extends SuluTestCase +class RegistrationRuleItemControllerTest extends SuluTestCase { /** * @var KernelBrowser @@ -31,7 +31,7 @@ protected function setUp(): void public function testCgetEmpty(): void { - $this->client->request('GET', '/admin/api/blacklist-items'); + $this->client->request('GET', '/admin/api/registration-rule-items'); $this->assertHttpStatusCode(200, $this->client->getResponse()); /** @var string $content */ @@ -40,7 +40,7 @@ public function testCgetEmpty(): void $this->assertIsArray($result); $this->assertSame(0, $result['total']); - $this->assertCount(0, $result['_embedded']['blacklist_items']); + $this->assertCount(0, $result['_embedded']['registration_rule_items']); } /** @@ -50,8 +50,8 @@ public function testPost(string $pattern = '*@sulu.io'): array { $this->client->request( 'POST', - '/admin/api/blacklist-items', - ['pattern' => $pattern, 'type' => BlacklistItem::TYPE_REQUEST] + '/admin/api/registration-rule-items', + ['pattern' => $pattern, 'type' => RegistrationRuleItem::TYPE_REQUEST] ); $this->assertHttpStatusCode(200, $this->client->getResponse()); @@ -61,7 +61,7 @@ public function testPost(string $pattern = '*@sulu.io'): array $this->assertIsArray($result); $this->assertSame($pattern, $result['pattern']); - $this->assertSame(BlacklistItem::TYPE_REQUEST, $result['type']); + $this->assertSame(RegistrationRuleItem::TYPE_REQUEST, $result['type']); return $result; } @@ -73,7 +73,7 @@ public function testGet(): array { $item = $this->testPost(); - $this->client->request('GET', '/admin/api/blacklist-items/' . $item['id']); + $this->client->request('GET', '/admin/api/registration-rule-items/' . $item['id']); $this->assertHttpStatusCode(200, $this->client->getResponse()); /** @var string $content */ @@ -92,7 +92,7 @@ public function testCget(): void { $item = $this->testPost(); - $this->client->request('GET', '/admin/api/blacklist-items'); + $this->client->request('GET', '/admin/api/registration-rule-items'); $this->assertHttpStatusCode(200, $this->client->getResponse()); /** @var string $content */ @@ -101,20 +101,20 @@ public function testCget(): void $this->assertIsArray($result); $this->assertSame(1, $result['total']); - $this->assertCount(1, $result['_embedded']['blacklist_items']); - $this->assertSame($item['id'], $result['_embedded']['blacklist_items'][0]['id']); - $this->assertSame($item['pattern'], $result['_embedded']['blacklist_items'][0]['pattern']); - $this->assertSame($item['type'], $result['_embedded']['blacklist_items'][0]['type']); + $this->assertCount(1, $result['_embedded']['registration_rule_items']); + $this->assertSame($item['id'], $result['_embedded']['registration_rule_items'][0]['id']); + $this->assertSame($item['pattern'], $result['_embedded']['registration_rule_items'][0]['pattern']); + $this->assertSame($item['type'], $result['_embedded']['registration_rule_items'][0]['type']); } public function testDelete(): void { $item = $this->testPost(); - $this->client->request('DELETE', '/admin/api/blacklist-items/' . $item['id']); + $this->client->request('DELETE', '/admin/api/registration-rule-items/' . $item['id']); $this->assertHttpStatusCode(204, $this->client->getResponse()); - $this->client->request('GET', '/admin/api/blacklist-items'); + $this->client->request('GET', '/admin/api/registration-rule-items'); $this->assertHttpStatusCode(200, $this->client->getResponse()); /** @var string $content */ @@ -123,7 +123,7 @@ public function testDelete(): void $this->assertIsArray($result); $this->assertSame(0, $result['total']); - $this->assertCount(0, $result['_embedded']['blacklist_items']); + $this->assertCount(0, $result['_embedded']['registration_rule_items']); } public function testCDelete(): void @@ -131,10 +131,10 @@ public function testCDelete(): void $item1 = $this->testPost(); $item2 = $this->testPost('test@sulu.io'); - $this->client->request('DELETE', '/admin/api/blacklist-items?ids=' . \implode(',', [$item1['id'], $item2['id']])); + $this->client->request('DELETE', '/admin/api/registration-rule-items?ids=' . \implode(',', [$item1['id'], $item2['id']])); $this->assertHttpStatusCode(204, $this->client->getResponse()); - $this->client->request('GET', '/admin/api/blacklist-items'); + $this->client->request('GET', '/admin/api/registration-rule-items'); $this->assertHttpStatusCode(200, $this->client->getResponse()); /** @var string $content */ @@ -143,14 +143,14 @@ public function testCDelete(): void $this->assertIsArray($result); $this->assertSame(0, $result['total']); - $this->assertCount(0, $result['_embedded']['blacklist_items']); + $this->assertCount(0, $result['_embedded']['registration_rule_items']); } public function testPostInvalidType(): void { $this->client->request( 'POST', - '/admin/api/blacklist-items', + '/admin/api/registration-rule-items', ['pattern' => '*@sulu.io', 'type' => 'test'] ); $this->assertHttpStatusCode(409, $this->client->getResponse()); @@ -162,8 +162,8 @@ public function testPut(): void $this->client->request( 'PUT', - '/admin/api/blacklist-items/' . $item['id'], - ['pattern' => 'test@sulu.io', 'type' => BlacklistItem::TYPE_BLOCK] + '/admin/api/registration-rule-items/' . $item['id'], + ['pattern' => 'test@sulu.io', 'type' => RegistrationRuleItem::TYPE_BLOCK] ); $this->assertHttpStatusCode(200, $this->client->getResponse()); @@ -173,7 +173,7 @@ public function testPut(): void $this->assertIsArray($result); $this->assertSame('test@sulu.io', $result['pattern']); - $this->assertSame(BlacklistItem::TYPE_BLOCK, $result['type']); + $this->assertSame(RegistrationRuleItem::TYPE_BLOCK, $result['type']); } public function testPutInvalidType(): void @@ -182,7 +182,7 @@ public function testPutInvalidType(): void $this->client->request( 'PUT', - '/admin/api/blacklist-items/' . $item['id'], + '/admin/api/registration-rule-items/' . $item['id'], ['pattern' => 'test@sulu.io', 'type' => 'test'] ); $this->assertHttpStatusCode(409, $this->client->getResponse()); diff --git a/Tests/Functional/Controller/RegistrationTest.php b/Tests/Functional/Controller/RegistrationTest.php index 32ee79d..7633369 100644 --- a/Tests/Functional/Controller/RegistrationTest.php +++ b/Tests/Functional/Controller/RegistrationTest.php @@ -14,8 +14,8 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\NoResultException; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Tests\Functional\Traits\BlacklistItemTrait; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Tests\Functional\Traits\RegistrationRuleItemTrait; use Sulu\Bundle\ContactBundle\Entity\EmailType; use Sulu\Bundle\SecurityBundle\Entity\Role; use Sulu\Bundle\SecurityBundle\Entity\User; @@ -32,7 +32,7 @@ */ class RegistrationTest extends SuluTestCase { - use BlacklistItemTrait; + use RegistrationRuleItemTrait; /** * @var KernelBrowser @@ -174,9 +174,9 @@ public function testLoginWrongPassword(): void $this->assertSame('http://localhost/login', $this->client->getResponse()->getTargetUrl()); } - public function testRegistrationBlacklistedBlocked(): void + public function testRegistrationRegistrationRuleedBlocked(): void { - $this->createBlacklistItem($this->getEntityManager(), '*@sulu.io', BlacklistItem::TYPE_BLOCK); + $this->createRegistrationRuleItem($this->getEntityManager(), '*@sulu.io', RegistrationRuleItem::TYPE_BLOCK); $crawler = $this->client->request('GET', '/registration'); $form = $crawler->selectButton('registration[submit]')->form( @@ -199,13 +199,13 @@ public function testRegistrationBlacklistedBlocked(): void $this->assertNull($this->findUser()); } - public function testRegistrationBlacklistedRequested(): ?RawMessage + public function testRegistrationRegistrationRuleRequested(): ?RawMessage { if (\class_exists(\Swift_Mailer::class)) { $this->markTestSkipped('Skip test for swift mailer.'); } - $this->createBlacklistItem($this->getEntityManager(), '*@sulu.io', BlacklistItem::TYPE_REQUEST); + $this->createBlacklistItem($this->getEntityManager(), '*@sulu.io', RegistrationRule::TYPE_REQUEST); $crawler = $this->client->request('GET', '/registration'); $this->assertHttpStatusCode(200, $this->client->getResponse()); @@ -239,9 +239,9 @@ public function testRegistrationBlacklistedRequested(): ?RawMessage return $message; } - public function testBlacklistConfirm(): void + public function testRegistrationRuleConfirm(): void { - $message = $this->testRegistrationBlacklistedRequested(); + $message = $this->testRegistrationRegistrationRuleedRequested(); $emailCrawler = new Crawler(); $emailCrawler->addContent($message->getHtmlBody()); @@ -268,9 +268,9 @@ public function testBlacklistConfirm(): void $this->assertSame('hikaru@sulu.io', $message->getTo()[0]->getAddress()); } - public function testBlacklistBlocked(): void + public function testRegistrationRuleBlocked(): void { - $message = $this->testRegistrationBlacklistedRequested(); + $message = $this->testRegistrationRegistrationRuleedRequested(); $emailCrawler = new Crawler(); $emailCrawler->addContent($message->getHtmlBody()); diff --git a/Tests/Functional/Entity/BlacklistItemRepositoryTest.php b/Tests/Functional/Entity/RegistrationRuleItemRepositoryTest.php similarity index 61% rename from Tests/Functional/Entity/BlacklistItemRepositoryTest.php rename to Tests/Functional/Entity/RegistrationRuleItemRepositoryTest.php index 2bd84c9..2630b22 100644 --- a/Tests/Functional/Entity/BlacklistItemRepositoryTest.php +++ b/Tests/Functional/Entity/RegistrationRuleItemRepositoryTest.php @@ -12,11 +12,11 @@ namespace Sulu\Bundle\CommunityBundle\Tests\Functional\Entity; use Doctrine\ORM\EntityManagerInterface; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; -class BlacklistItemRepositoryTest extends SuluTestCase +class RegistrationRuleItemRepositoryTest extends SuluTestCase { protected function setUp(): void { @@ -25,13 +25,13 @@ protected function setUp(): void public function testFindBySender(): void { - $item1 = new BlacklistItem('*@sulu.io', BlacklistItem::TYPE_BLOCK); - $item2 = new BlacklistItem('test@sulu.io', BlacklistItem::TYPE_REQUEST); + $item1 = new RegistrationRuleItem('*@sulu.io', RegistrationRuleItem::TYPE_BLOCK); + $item2 = new RegistrationRuleItem('test@sulu.io', RegistrationRuleItem::TYPE_REQUEST); /** @var EntityManagerInterface $entityManager */ $entityManager = $this->getEntityManager(); - /** @var BlacklistItemRepository $repository */ - $repository = $entityManager->getRepository(BlacklistItem::class); + /** @var RegistrationRuleItemRepository $repository */ + $repository = $entityManager->getRepository(RegistrationRuleItem::class); $entityManager->persist($item1); $entityManager->persist($item2); @@ -39,13 +39,13 @@ public function testFindBySender(): void $entityManager->clear(); $items = \array_map( - function(BlacklistItem $item) { + function (RegistrationRuleItem $item) { return ['pattern' => $item->getPattern(), 'type' => $item->getType()]; }, $repository->findBySender('test@sulu.io') ); - $this->assertContains(['pattern' => '*@sulu.io', 'type' => BlacklistItem::TYPE_BLOCK], $items); - $this->assertContains(['pattern' => 'test@sulu.io', 'type' => BlacklistItem::TYPE_REQUEST], $items); + $this->assertContains(['pattern' => '*@sulu.io', 'type' => RegistrationRuleItem::TYPE_BLOCK], $items); + $this->assertContains(['pattern' => 'test@sulu.io', 'type' => RegistrationRuleItem::TYPE_REQUEST], $items); } } diff --git a/Tests/Functional/Traits/BlacklistItemTrait.php b/Tests/Functional/Traits/RegistrationRuleItemTrait.php similarity index 63% rename from Tests/Functional/Traits/BlacklistItemTrait.php rename to Tests/Functional/Traits/RegistrationRuleItemTrait.php index 8c4b3ae..bddf99a 100644 --- a/Tests/Functional/Traits/BlacklistItemTrait.php +++ b/Tests/Functional/Traits/RegistrationRuleItemTrait.php @@ -12,20 +12,20 @@ namespace Sulu\Bundle\CommunityBundle\Tests\Functional\Traits; use Doctrine\ORM\EntityManagerInterface; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; -trait BlacklistItemTrait +trait RegistrationRuleItemTrait { - private function createBlacklistItem( + private function createRegistrationRuleItem( EntityManagerInterface $entityManager, string $pattern, string $type - ): BlacklistItem { - /** @var BlacklistItemRepository $blackListItemRepository */ - $blackListItemRepository = $entityManager->getRepository(BlacklistItem::class); + ): RegistrationRuleItem { + /** @var RegistrationRuleItemRepository $blackListItemRepository */ + $blackListItemRepository = $entityManager->getRepository(RegistrationRuleItem::class); - /** @var BlacklistItem $blackListItem */ + /** @var RegistrationRuleItem $blackListItem */ $blackListItem = $blackListItemRepository->createNew(); $blackListItem->setPattern($pattern) ->setType($type); diff --git a/Tests/Unit/Entity/BlacklistItemTest.php b/Tests/Unit/Entity/RegistrationRuleItemTest.php similarity index 63% rename from Tests/Unit/Entity/BlacklistItemTest.php rename to Tests/Unit/Entity/RegistrationRuleItemTest.php index dfa173c..f695857 100644 --- a/Tests/Unit/Entity/BlacklistItemTest.php +++ b/Tests/Unit/Entity/RegistrationRuleItemTest.php @@ -12,22 +12,22 @@ namespace Sulu\Bundle\CommunityBundle\Tests\Unit\Entity; use PHPUnit\Framework\TestCase; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; use Sulu\Bundle\CommunityBundle\Entity\InvalidTypeException; -class BlacklistItemTest extends TestCase +class RegistrationRuleItemTest extends TestCase { public function testConstructor(): void { - $item = new BlacklistItem('*@sulu.io', BlacklistItem::TYPE_REQUEST); + $item = new RegistrationRuleItem('*@sulu.io', RegistrationRuleItem::TYPE_REQUEST); $this->assertSame('*@sulu.io', $item->getPattern()); $this->assertSame('[^@]*@sulu\.io', $item->getRegexp()); - $this->assertSame(BlacklistItem::TYPE_REQUEST, $item->getType()); + $this->assertSame(RegistrationRuleItem::TYPE_REQUEST, $item->getType()); } public function testEmptyConstructor(): void { - $item = new BlacklistItem(); + $item = new RegistrationRuleItem(); $this->assertNull($item->getPattern()); $this->assertNull($item->getRegexp()); $this->assertNull($item->getType()); @@ -35,7 +35,7 @@ public function testEmptyConstructor(): void public function testSetPattern(): void { - $item = new BlacklistItem(); + $item = new RegistrationRuleItem(); $item->setPattern('*@sulu.io'); $this->assertSame('*@sulu.io', $item->getPattern()); @@ -44,7 +44,7 @@ public function testSetPattern(): void public function testSetPatternNoWildcard(): void { - $item = new BlacklistItem(); + $item = new RegistrationRuleItem(); $item->setPattern('test@sulu.io'); $this->assertSame('test@sulu.io', $item->getPattern()); @@ -53,25 +53,25 @@ public function testSetPatternNoWildcard(): void public function testSetTypeRequest(): void { - $item = new BlacklistItem(); - $item->setType(BlacklistItem::TYPE_REQUEST); + $item = new RegistrationRuleItem(); + $item->setType(RegistrationRuleItem::TYPE_REQUEST); - $this->assertSame(BlacklistItem::TYPE_REQUEST, $item->getType()); + $this->assertSame(RegistrationRuleItem::TYPE_REQUEST, $item->getType()); } public function testSetTypeBlock(): void { - $item = new BlacklistItem(); - $item->setType(BlacklistItem::TYPE_BLOCK); + $item = new RegistrationRuleItem(); + $item->setType(RegistrationRuleItem::TYPE_BLOCK); - $this->assertSame(BlacklistItem::TYPE_BLOCK, $item->getType()); + $this->assertSame(RegistrationRuleItem::TYPE_BLOCK, $item->getType()); } public function testSetTypeBlockInvalid(): void { $this->expectException(InvalidTypeException::class); - $item = new BlacklistItem(); + $item = new RegistrationRuleItem(); $item->setType('test'); } } diff --git a/Tests/Unit/Listener/BlacklistListenerTest.php b/Tests/Unit/Listener/RegistrationRuleListenerTest.php similarity index 81% rename from Tests/Unit/Listener/BlacklistListenerTest.php rename to Tests/Unit/Listener/RegistrationRuleListenerTest.php index b36e934..7baeb11 100644 --- a/Tests/Unit/Listener/BlacklistListenerTest.php +++ b/Tests/Unit/Listener/RegistrationRuleListenerTest.php @@ -16,20 +16,20 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistUser; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUser; use Sulu\Bundle\CommunityBundle\Event\UserRegisteredEvent; -use Sulu\Bundle\CommunityBundle\EventListener\BlacklistListener; +use Sulu\Bundle\CommunityBundle\EventListener\RegistrationRuleListener; use Sulu\Bundle\CommunityBundle\Mail\Mail; use Sulu\Bundle\CommunityBundle\Mail\MailFactoryInterface; use Sulu\Bundle\SecurityBundle\Entity\User; use Sulu\Bundle\SecurityBundle\Util\TokenGeneratorInterface; -class BlacklistListenerTest extends TestCase +class RegistrationRuleListenerTest extends TestCase { /** - * @var ObjectProphecy<BlacklistItemRepository> + * @var ObjectProphecy<RegistrationRuleItemRepository> */ private $repository; @@ -49,18 +49,18 @@ class BlacklistListenerTest extends TestCase private $mailFactory; /** - * @var BlacklistListener + * @var RegistrationRuleListener */ private $listener; protected function setUp(): void { - $this->repository = $this->prophesize(BlacklistItemRepository::class); + $this->repository = $this->prophesize(RegistrationRuleItemRepository::class); $this->entityManager = $this->prophesize(EntityManagerInterface::class); $this->tokenGenerator = $this->prophesize(TokenGeneratorInterface::class); $this->mailFactory = $this->prophesize(MailFactoryInterface::class); - $this->listener = new BlacklistListener( + $this->listener = new RegistrationRuleListener( $this->repository->reveal(), $this->entityManager->reveal(), $this->tokenGenerator->reveal(), @@ -71,7 +71,7 @@ protected function setUp(): void public function testValidateEmail(): void { $this->repository->findBySender('test@sulu.io') - ->willReturn([new BlacklistItem('*@sulu.io', BlacklistItem::TYPE_REQUEST)]); + ->willReturn([new RegistrationRuleItem('*@sulu.io', RegistrationRuleItem::TYPE_REQUEST)]); $this->tokenGenerator->generateToken()->willReturn('123-123-123'); $user = $this->prophesize(User::class); @@ -81,7 +81,7 @@ public function testValidateEmail(): void $event->getConfigProperty(Configuration::WEBSPACE_KEY)->willReturn('sulu-io'); $event->getConfigProperty(Configuration::EMAIL_TO)->willReturn(['admin@sulu.io' => 'admin@sulu.io']); $event->getConfigProperty(Configuration::EMAIL_FROM)->willReturn(['from@sulu.io' => 'from@sulu.io']); - $event->getConfigTypeProperty(Configuration::TYPE_BLACKLISTED, Configuration::EMAIL)->willReturn( + $event->getConfigTypeProperty(Configuration::TYPE_REGISTRATION_RULEED, Configuration::EMAIL)->willReturn( [ Configuration::EMAIL_SUBJECT => 'subject', Configuration::EMAIL_USER_TEMPLATE => 'user_template', @@ -92,7 +92,7 @@ public function testValidateEmail(): void $this->entityManager->persist( Argument::that( - function(BlacklistUser $item) use ($user) { + function(RegistrationRuleUser $item) use ($user) { return '123-123-123' === $item->getToken() && 'sulu-io' === $item->getWebspaceKey() && $item->getUser() === $user->reveal(); diff --git a/Tests/Unit/Manager/BlacklistItemManagerTest.php b/Tests/Unit/Manager/RegistrationRuleItemManagerTest.php similarity index 67% rename from Tests/Unit/Manager/BlacklistItemManagerTest.php rename to Tests/Unit/Manager/RegistrationRuleItemManagerTest.php index 5bbdbc7..2ae907a 100644 --- a/Tests/Unit/Manager/BlacklistItemManagerTest.php +++ b/Tests/Unit/Manager/RegistrationRuleItemManagerTest.php @@ -14,14 +14,14 @@ use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; -use Sulu\Bundle\CommunityBundle\Manager\BlacklistItemManager; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; +use Sulu\Bundle\CommunityBundle\Manager\RegistrationRuleItemManager; -class BlacklistItemManagerTest extends TestCase +class RegistrationRuleItemManagerTest extends TestCase { /** - * @var ObjectProphecy<BlacklistItemRepository> + * @var ObjectProphecy<RegistrationRuleItemRepository> */ private $repository; @@ -31,21 +31,21 @@ class BlacklistItemManagerTest extends TestCase private $entityManager; /** - * @var BlacklistItemManager + * @var RegistrationRuleItemManager */ private $manager; protected function setUp(): void { - $this->repository = $this->prophesize(BlacklistItemRepository::class); + $this->repository = $this->prophesize(RegistrationRuleItemRepository::class); $this->entityManager = $this->prophesize(EntityManagerInterface::class); - $this->manager = new BlacklistItemManager($this->entityManager->reveal(), $this->repository->reveal()); + $this->manager = new RegistrationRuleItemManager($this->entityManager->reveal(), $this->repository->reveal()); } public function testCreate(): void { - $entity = new BlacklistItem(); + $entity = new RegistrationRuleItem(); $this->repository->createNew()->willReturn($entity)->shouldBeCalled(); $this->entityManager->persist($entity)->shouldBeCalled(); @@ -55,7 +55,7 @@ public function testCreate(): void public function testFind(): void { - $entity = new BlacklistItem(); + $entity = new RegistrationRuleItem(); $this->repository->find(1)->willReturn($entity)->shouldBeCalled(); $this->assertSame($entity, $this->manager->find(1)); @@ -63,10 +63,10 @@ public function testFind(): void public function testDeleteSingle(): void { - $className = BlacklistItem::class; + $className = RegistrationRuleItem::class; $this->repository->getClassName()->willReturn($className); - $entity = new BlacklistItem(); + $entity = new RegistrationRuleItem(); $this->entityManager->getReference($className, 1)->willReturn($entity); $this->entityManager->remove($entity)->shouldBeCalled(); @@ -75,11 +75,11 @@ public function testDeleteSingle(): void public function testDeleteList(): void { - $className = BlacklistItem::class; + $className = RegistrationRuleItem::class; $this->repository->getClassName()->willReturn($className); - $entity1 = new BlacklistItem(); - $entity2 = new BlacklistItem(); + $entity1 = new RegistrationRuleItem(); + $entity2 = new RegistrationRuleItem(); $this->entityManager->getReference($className, 1)->willReturn($entity1); $this->entityManager->getReference($className, 2)->willReturn($entity2); $this->entityManager->remove($entity1)->shouldBeCalled(); diff --git a/Tests/Unit/Validator/BlockedValidatorTest.php b/Tests/Unit/Validator/BlockedValidatorTest.php index 93fe203..318a179 100644 --- a/Tests/Unit/Validator/BlockedValidatorTest.php +++ b/Tests/Unit/Validator/BlockedValidatorTest.php @@ -12,8 +12,8 @@ namespace Sulu\Bundle\CommunityBundle\Tests\Unit\Validator; use PHPUnit\Framework\TestCase; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; use Sulu\Bundle\CommunityBundle\Validator\Constraints\Blocked; use Sulu\Bundle\CommunityBundle\Validator\Constraints\BlockedValidator; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -23,15 +23,15 @@ class BlockedValidatorTest extends TestCase public function testValidate(): void { $context = $this->prophesize(ExecutionContextInterface::class); - $repository = $this->prophesize(BlacklistItemRepository::class); + $repository = $this->prophesize(RegistrationRuleItemRepository::class); $validator = new BlockedValidator($repository->reveal()); $validator->initialize($context->reveal()); $repository->findBySender('test@sulu.io') ->willReturn( [ - new BlacklistItem('*@sulu.io', BlacklistItem::TYPE_REQUEST), - new BlacklistItem('test@sulu.io', BlacklistItem::TYPE_BLOCK), + new RegistrationRuleItem('*@sulu.io', RegistrationRuleItem::TYPE_REQUEST), + new RegistrationRuleItem('test@sulu.io', RegistrationRuleItem::TYPE_BLOCK), ] ); @@ -43,12 +43,12 @@ public function testValidate(): void public function testValidateNoBlocking(): void { $context = $this->prophesize(ExecutionContextInterface::class); - $repository = $this->prophesize(BlacklistItemRepository::class); + $repository = $this->prophesize(RegistrationRuleItemRepository::class); $validator = new BlockedValidator($repository->reveal()); $validator->initialize($context->reveal()); $repository->findBySender('test@sulu.io') - ->willReturn([new BlacklistItem('*@sulu.io', BlacklistItem::TYPE_REQUEST)]); + ->willReturn([new RegistrationRuleItem('*@sulu.io', RegistrationRuleItem::TYPE_REQUEST)]); $validator->validate('test@sulu.io', new Blocked()); @@ -58,7 +58,7 @@ public function testValidateNoBlocking(): void public function testValidateNoMatch(): void { $context = $this->prophesize(ExecutionContextInterface::class); - $repository = $this->prophesize(BlacklistItemRepository::class); + $repository = $this->prophesize(RegistrationRuleItemRepository::class); $validator = new BlockedValidator($repository->reveal()); $validator->initialize($context->reveal()); diff --git a/UPGRADE.md b/UPGRADE.md index 058b3cb..a6672ea 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -4,13 +4,13 @@ ### ListRepresentation relation name changed -The name of the relation inside of the `_embedded` field has been changed from `items` to `blacklist_items`. +The name of the relation inside of the `_embedded` field has been changed from `items` to `registration_rule_items`. -### BlacklistUser and BlacklistItem repository service identification changed +### RegistrationRuleUser and RegistrationRuleItem repository service identification changed - - BlacklistUserRepository has been changed from `sulu_community.blacklisting.user_repository` to `sulu.repository.blacklist_user`. + - RegistrationRuleUserRepository has been changed from `sulu_community.registration_rule.user_repository` to `sulu.repository.blacklist_user`. - - BlacklistItemRepository has been changed from `sulu_community.blacklisting.item_repository` to `sulu.repository.blacklist_item`. + - RegistrationRuleItemRepository has been changed from `sulu_community.registration_rule.item_repository` to `sulu.repository.blacklist_item`. ### Typehints added to the codebase diff --git a/Validator/Constraints/BlockedValidator.php b/Validator/Constraints/BlockedValidator.php index dbe55e4..923d77c 100644 --- a/Validator/Constraints/BlockedValidator.php +++ b/Validator/Constraints/BlockedValidator.php @@ -11,8 +11,8 @@ namespace Sulu\Bundle\CommunityBundle\Validator\Constraints; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; -use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem; +use Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItemRepository; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; @@ -22,13 +22,13 @@ class BlockedValidator extends ConstraintValidator { /** - * @var BlacklistItemRepository + * @var RegistrationRuleItemRepository */ - protected $blacklistItemRepository; + protected $registrationRuleItemRepository; - public function __construct(BlacklistItemRepository $blacklistItemRepository) + public function __construct(RegistrationRuleItemRepository $registrationRuleItemRepository) { - $this->blacklistItemRepository = $blacklistItemRepository; + $this->registrationRuleItemRepository = $registrationRuleItemRepository; } /** @@ -40,10 +40,10 @@ public function validate($value, Constraint $constraint): void return; } - $items = $this->blacklistItemRepository->findBySender($value); + $items = $this->registrationRuleItemRepository->findBySender($value); foreach ($items as $item) { - if (BlacklistItem::TYPE_BLOCK === $item->getType()) { + if (RegistrationRuleItem::TYPE_BLOCK === $item->getType()) { $this->context->addViolation($constraint->message, ['%email%' => $value]); break; } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f35cf76..a83d140 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -23,7 +23,7 @@ parameters: - message: "#^Strict comparison using \\=\\=\\= between true and array\\{from\\: array\\<string\\>\\|string, to\\: array\\<string\\>\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} will always evaluate to false\\.$#" count: 1 - path: Controller/BlacklistConfirmationController.php + path: Controller/RegistrationRuleConfirmationController.php - message: "#^If condition is always true\\.$#" @@ -228,22 +228,22 @@ parameters: - message: "#^Parameter \\#1 \\$from of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\<string\\>\\|string, array\\<string, array\\<array\\|bool\\|string\\|null\\>\\|string\\> given\\.$#" count: 1 - path: EventListener/BlacklistListener.php + path: EventListener/RegistrationRuleListener.php - message: "#^Parameter \\#2 \\$to of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\<string\\>\\|string, array\\<string, array\\<array\\|bool\\|string\\|null\\>\\|string\\> given\\.$#" count: 1 - path: EventListener/BlacklistListener.php + path: EventListener/RegistrationRuleListener.php - - message: "#^Parameter \\#2 \\$webspaceKey of class Sulu\\\\Bundle\\\\CommunityBundle\\\\Entity\\\\BlacklistUser constructor expects string, array\\<string, array\\<array\\|bool\\|string\\|null\\>\\|string\\> given\\.$#" + message: "#^Parameter \\#2 \\$webspaceKey of class Sulu\\\\Bundle\\\\CommunityBundle\\\\Entity\\\\RegistrationRuleUser constructor expects string, array\\<string, array\\<array\\|bool\\|string\\|null\\>\\|string\\> given\\.$#" count: 1 - path: EventListener/BlacklistListener.php + path: EventListener/RegistrationRuleListener.php - message: "#^Parameter \\#3 \\$config of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\{subject\\: string, user_template\\: string\\|null, admin_template\\: string\\|null\\}, array\\{from\\: array\\<string\\>\\|string, to\\: array\\<string\\>\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} given\\.$#" count: 1 - path: EventListener/BlacklistListener.php + path: EventListener/RegistrationRuleListener.php - message: "#^Parameter \\#1 \\$from of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\<string\\>\\|string, array\\<string, array\\<array\\|bool\\|string\\|null\\>\\|string\\> given\\.$#"