From d576ea6c702aead93c03e1aa91513ee1aadfb490 Mon Sep 17 00:00:00 2001 From: Oliver Kossin Date: Wed, 24 Aug 2022 09:52:16 +0200 Subject: [PATCH] [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 b760d1ac..4fe9201e 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 450ce94e..00000000 --- a/Controller/BlacklistConfirmationController.php +++ /dev/null @@ -1,144 +0,0 @@ -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 - */ - 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 00000000..224ac2df --- /dev/null +++ b/Controller/RegistrationRuleConfirmationController.php @@ -0,0 +1,144 @@ +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 + */ + 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 75c628b5..660c2fe8 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 cc9cdcb3..edc2cfa4 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 a219ffe1..54341774 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 d8d85ccf..8eb6d649 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 7bc842a9..44365c0d 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 52d38a16..91e30744 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 99bc8edd..6da93ea1 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 b248842a..2aed744d 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 30278729..00000000 --- a/Manager/BlacklistItemManagerInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -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 00000000..a43d86cc --- /dev/null +++ b/Manager/RegistrationRuleItemManagerInterface.php @@ -0,0 +1,37 @@ + - + 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 2205e528..8d457b3a 100644 --- a/Resources/config/doctrine/BlacklistUser.orm.xml +++ b/Resources/config/doctrine/RegistrationRuleUser.orm.xml @@ -2,8 +2,8 @@ - + 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 55122292..163cd144 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" > - blacklist_item_details + registration_rule_item_details 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 06123c0b..7412519b 100644 --- a/Resources/config/lists/blacklist_items.xml +++ b/Resources/config/lists/registration_rule_items.xml @@ -1,6 +1,6 @@ - blacklist_items + registration_rule_items id - %sulu.model.blacklist_item.class% + %sulu.model.registration_rule_item.class% pattern - %sulu.model.blacklist_item.class% + %sulu.model.registration_rule_item.class% type - %sulu.model.blacklist_item.class% + %sulu.model.registration_rule_item.class% diff --git a/Resources/config/routing_api.yaml b/Resources/config/routing_api.yaml index 81ebccdd..58eba8a4 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 50a059e5..fdfb2bd8 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 24811946..3657f2e0 100644 --- a/Resources/config/serializer/BlacklistItem.xml +++ b/Resources/config/serializer/RegistrationRuleItem.xml @@ -1,6 +1,6 @@ - + diff --git a/Resources/config/services.xml b/Resources/config/services.xml index fff3c33b..baafe33f 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -57,8 +57,8 @@ - - + + @@ -96,32 +96,32 @@ - - + - + - + - - Sulu\Bundle\CommunityBundle\Entity\BlacklistItem + Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleItem - + - - Sulu\Bundle\CommunityBundle\Entity\BlacklistUser + Sulu\Bundle\CommunityBundle\Entity\RegistrationRuleUser - + - + - + @@ -171,7 +171,7 @@ - + diff --git a/Resources/config/validator.xml b/Resources/config/validator.xml index b0295b6a..370703e7 100644 --- a/Resources/config/validator.xml +++ b/Resources/config/validator.xml @@ -12,7 +12,7 @@ - + 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 eea3b986..e16b2a97 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: : # Replace 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 c7f592e2..94389630 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 9e4f93e0..fe7ed777 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 6a6b2bfe..f6263dc4 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 0495c2dd..2381cd87 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 f21dc28a..50940a39 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 9d72133a..e5b9e282 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 2026b5cd..59daa2b3 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 ecdc480b..cadf6aa7 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 32ee79dc..76333692 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 2bd84c90..2630b224 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 8c4b3aea..bddf99a6 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 dfa173c1..f695857e 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 b36e9349..7baeb116 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 + * @var ObjectProphecy */ 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 5bbdbc7e..2ae907ab 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 + * @var ObjectProphecy */ 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 93fe203f..318a1796 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 058b3cb5..a6672ea3 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 dbe55e4c..923d77cb 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 f35cf768..a83d140c 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, to\\: array\\\\|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, array\\\\|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, array\\\\|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\\> given\\.$#" + message: "#^Parameter \\#2 \\$webspaceKey of class Sulu\\\\Bundle\\\\CommunityBundle\\\\Entity\\\\RegistrationRuleUser constructor expects string, array\\\\|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, to\\: array\\\\|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, array\\\\|string\\> given\\.$#"