From: Kevin Decherf Date: Sun, 26 Apr 2020 13:39:57 +0000 (+0200) Subject: Merge pull request #4026 from wallabag/3760-ignorelist-db X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=0e8a0f77d0b643a884e6687bd9c463267852a970;hp=8a8a78a64c116caf81aaa4339906298bdc0e32e0;p=github%2Fwallabag%2Fwallabag.git Merge pull request #4026 from wallabag/3760-ignorelist-db Move Ignore Origin rules to database --- diff --git a/app/DoctrineMigrations/Version20190826204730.php b/app/DoctrineMigrations/Version20190826204730.php new file mode 100644 index 00000000..ee1ba6bf --- /dev/null +++ b/app/DoctrineMigrations/Version20190826204730.php @@ -0,0 +1,64 @@ +hasTable($this->getTable('ignore_origin_user_rule'))) { + $userTable = $schema->createTable($this->getTable('ignore_origin_user_rule', true)); + $userTable->addColumn('id', 'integer', ['autoincrement' => true]); + $userTable->addColumn('config_id', 'integer'); + $userTable->addColumn('rule', 'string', ['length' => 255]); + $userTable->addIndex(['config_id'], 'idx_config'); + $userTable->setPrimaryKey(['id']); + $userTable->addForeignKeyConstraint($this->getTable('config'), ['config_id'], ['id'], [], 'fk_config'); + + if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) { + $schema->dropSequence('ignore_origin_user_rule_id_seq'); + $schema->createSequence('ignore_origin_user_rule_id_seq'); + } + } + + if (false === $schema->hasTable($this->getTable('ignore_origin_instance_rule'))) { + $instanceTable = $schema->createTable($this->getTable('ignore_origin_instance_rule', true)); + $instanceTable->addColumn('id', 'integer', ['autoincrement' => true]); + $instanceTable->addColumn('rule', 'string', ['length' => 255]); + $instanceTable->setPrimaryKey(['id']); + + if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) { + $schema->dropSequence('ignore_origin_instance_rule_id_seq'); + $schema->createSequence('ignore_origin_instance_rule_id_seq'); + } + } + } + + public function postUp(Schema $schema): void + { + foreach ($this->container->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $entity) { + $previous_rule = $this->container + ->get('doctrine.orm.default_entity_manager') + ->getConnection() + ->fetchArray('SELECT * FROM ' . $this->getTable('ignore_origin_instance_rule') . " WHERE rule = '" . $entity['rule'] . "'"); + + if (false === $previous_rule) { + $this->addSql('INSERT INTO ' . $this->getTable('ignore_origin_instance_rule') . " (rule) VALUES ('" . $entity['rule'] . "');"); + } + } + } + + public function down(Schema $schema): void + { + $schema->dropTable($this->getTable('ignore_origin_user_rule')); + $schema->dropTable($this->getTable('ignore_origin_instance_rule')); + } +} diff --git a/app/config/security.yml b/app/config/security.yml index 760b2550..5a73440b 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -79,4 +79,5 @@ security: - { path: ^/annotations, roles: ROLE_USER } - { path: ^/2fa, role: IS_AUTHENTICATED_2FA_IN_PROGRESS } - { path: ^/users, roles: ROLE_SUPER_ADMIN } + - { path: ^/ignore-origin-instance-rules, roles: ROLE_SUPER_ADMIN } - { path: ^/, roles: ROLE_USER } diff --git a/app/config/wallabag.yml b/app/config/wallabag.yml index eaa92507..4dad9200 100644 --- a/app/config/wallabag.yml +++ b/app/config/wallabag.yml @@ -165,6 +165,14 @@ wallabag_core: value: 0 section: entry + default_ignore_origin_instance_rules: + - + rule: host = "feedproxy.google.com" + - + rule: host = "feeds.reuters.com" + - + rule: _all ~ "https?://www\.lemonde\.fr/tiny.*" + wallabag_user: registration_enabled: "%fosuser_registration%" diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 3aa332f1..8d08187a 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; +use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule; use Wallabag\CoreBundle\Entity\InternalSetting; class InstallCommand extends ContainerAwareCommand @@ -277,6 +278,7 @@ class InstallCommand extends ContainerAwareCommand // cleanup before insert new stuff $em->createQuery('DELETE FROM WallabagCoreBundle:InternalSetting')->execute(); + $em->createQuery('DELETE FROM WallabagCoreBundle:IgnoreOriginInstanceRule')->execute(); foreach ($this->getContainer()->getParameter('wallabag_core.default_internal_settings') as $setting) { $newSetting = new InternalSetting(); @@ -286,6 +288,12 @@ class InstallCommand extends ContainerAwareCommand $em->persist($newSetting); } + foreach ($this->getContainer()->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $ignore_origin_instance_rule) { + $newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule(); + $newIgnoreOriginInstanceRule->setRule($ignore_origin_instance_rule['rule']); + $em->persist($newIgnoreOriginInstanceRule); + } + $em->flush(); $this->io->text('Config successfully setup.'); diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 56efe82b..3efc7bb3 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -14,10 +14,13 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint; use Wallabag\CoreBundle\Entity\Config; +use Wallabag\CoreBundle\Entity\IgnoreOriginUserRule; +use Wallabag\CoreBundle\Entity\RuleInterface; use Wallabag\CoreBundle\Entity\TaggingRule; use Wallabag\CoreBundle\Form\Type\ChangePasswordType; use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\FeedType; +use Wallabag\CoreBundle\Form\Type\IgnoreOriginUserRuleType; use Wallabag\CoreBundle\Form\Type\TaggingRuleImportType; use Wallabag\CoreBundle\Form\Type\TaggingRuleType; use Wallabag\CoreBundle\Form\Type\UserInformationType; @@ -173,6 +176,40 @@ class ConfigController extends Controller return $this->redirect($this->generateUrl('config') . '#set5'); } + // handle ignore origin rules + $ignoreOriginUserRule = new IgnoreOriginUserRule(); + $action = $this->generateUrl('config') . '#set6'; + + if ($request->query->has('ignore-origin-user-rule')) { + $ignoreOriginUserRule = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule') + ->find($request->query->get('ignore-origin-user-rule')); + + if ($this->getUser()->getId() !== $ignoreOriginUserRule->getConfig()->getUser()->getId()) { + return $this->redirect($action); + } + + $action = $this->generateUrl('config', [ + 'ignore-origin-user-rule' => $ignoreOriginUserRule->getId(), + ]) . '#set6'; + } + + $newIgnoreOriginUserRule = $this->createForm(IgnoreOriginUserRuleType::class, $ignoreOriginUserRule, ['action' => $action]); + $newIgnoreOriginUserRule->handleRequest($request); + + if ($newIgnoreOriginUserRule->isSubmitted() && $newIgnoreOriginUserRule->isValid()) { + $ignoreOriginUserRule->setConfig($config); + $em->persist($ignoreOriginUserRule); + $em->flush(); + + $this->addFlash( + 'notice', + 'flashes.config.notice.ignore_origin_rules_updated' + ); + + return $this->redirect($this->generateUrl('config') . '#set6'); + } + return $this->render('WallabagCoreBundle:Config:index.html.twig', [ 'form' => [ 'config' => $configForm->createView(), @@ -181,6 +218,7 @@ class ConfigController extends Controller 'user' => $userForm->createView(), 'new_tagging_rule' => $newTaggingRule->createView(), 'import_tagging_rule' => $taggingRulesImportform->createView(), + 'new_ignore_origin_user_rule' => $newIgnoreOriginUserRule->createView(), ], 'feed' => [ 'username' => $user->getUsername(), @@ -447,6 +485,43 @@ class ConfigController extends Controller return $this->redirect($this->generateUrl('config') . '?tagging-rule=' . $rule->getId() . '#set5'); } + /** + * Deletes an ignore origin rule and redirect to the config homepage. + * + * @Route("/ignore-origin-user-rule/delete/{id}", requirements={"id" = "\d+"}, name="delete_ignore_origin_rule") + * + * @return RedirectResponse + */ + public function deleteIgnoreOriginRuleAction(IgnoreOriginUserRule $rule) + { + $this->validateRuleAction($rule); + + $em = $this->getDoctrine()->getManager(); + $em->remove($rule); + $em->flush(); + + $this->addFlash( + 'notice', + 'flashes.config.notice.ignore_origin_rules_deleted' + ); + + return $this->redirect($this->generateUrl('config') . '#set6'); + } + + /** + * Edit an ignore origin rule. + * + * @Route("/ignore-origin-user-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_ignore_origin_rule") + * + * @return RedirectResponse + */ + public function editIgnoreOriginRuleAction(IgnoreOriginUserRule $rule) + { + $this->validateRuleAction($rule); + + return $this->redirect($this->generateUrl('config') . '?ignore-origin-user-rule=' . $rule->getId() . '#set6'); + } + /** * Remove all annotations OR tags OR entries for the current user. * @@ -659,10 +734,10 @@ class ConfigController extends Controller /** * Validate that a rule can be edited/deleted by the current user. */ - private function validateRuleAction(TaggingRule $rule) + private function validateRuleAction(RuleInterface $rule) { if ($this->getUser()->getId() !== $rule->getConfig()->getUser()->getId()) { - throw $this->createAccessDeniedException('You can not access this tagging rule.'); + throw $this->createAccessDeniedException('You can not access this rule.'); } } diff --git a/src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php b/src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php new file mode 100644 index 00000000..ef1f0ed7 --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php @@ -0,0 +1,138 @@ +get('wallabag_core.ignore_origin_instance_rule_repository')->findAll(); + + return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:index.html.twig', [ + 'rules' => $rules, + ]); + } + + /** + * Creates a new ignore origin instance rule entity. + * + * @Route("/new", name="ignore_origin_instance_rules_new", methods={"GET", "POST"}) + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function newAction(Request $request) + { + $ignoreOriginInstanceRule = new IgnoreOriginInstanceRule(); + + $form = $this->createForm('Wallabag\CoreBundle\Form\Type\IgnoreOriginInstanceRuleType', $ignoreOriginInstanceRule); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($ignoreOriginInstanceRule); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.added') + ); + + return $this->redirectToRoute('ignore_origin_instance_rules_index'); + } + + return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:new.html.twig', [ + 'rule' => $ignoreOriginInstanceRule, + 'form' => $form->createView(), + ]); + } + + /** + * Displays a form to edit an existing ignore origin instance rule entity. + * + * @Route("/{id}/edit", name="ignore_origin_instance_rules_edit", methods={"GET", "POST"}) + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function editAction(Request $request, IgnoreOriginInstanceRule $ignoreOriginInstanceRule) + { + $deleteForm = $this->createDeleteForm($ignoreOriginInstanceRule); + $editForm = $this->createForm('Wallabag\CoreBundle\Form\Type\IgnoreOriginInstanceRuleType', $ignoreOriginInstanceRule); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($ignoreOriginInstanceRule); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.updated') + ); + + return $this->redirectToRoute('ignore_origin_instance_rules_index'); + } + + return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:edit.html.twig', [ + 'rule' => $ignoreOriginInstanceRule, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + ]); + } + + /** + * Deletes a site credential entity. + * + * @Route("/{id}", name="ignore_origin_instance_rules_delete", methods={"DELETE"}) + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function deleteAction(Request $request, IgnoreOriginInstanceRule $ignoreOriginInstanceRule) + { + $form = $this->createDeleteForm($ignoreOriginInstanceRule); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.deleted') + ); + + $em = $this->getDoctrine()->getManager(); + $em->remove($ignoreOriginInstanceRule); + $em->flush(); + } + + return $this->redirectToRoute('ignore_origin_instance_rules_index'); + } + + /** + * Creates a form to delete a ignore origin instance rule entity. + * + * @param IgnoreOriginInstanceRule $ignoreOriginInstanceRule The ignore origin instance rule entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(IgnoreOriginInstanceRule $ignoreOriginInstanceRule) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('ignore_origin_instance_rules_delete', ['id' => $ignoreOriginInstanceRule->getId()])) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php new file mode 100644 index 00000000..8a0a06ed --- /dev/null +++ b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php @@ -0,0 +1,36 @@ +container = $container; + } + + /** + * {@inheritdoc} + */ + public function load(ObjectManager $manager) + { + foreach ($this->container->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $ignore_origin_instance_rule) { + $newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule(); + $newIgnoreOriginInstanceRule->setRule($ignore_origin_instance_rule['rule']); + $manager->persist($newIgnoreOriginInstanceRule); + } + + $manager->flush(); + } +} diff --git a/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginUserRuleFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginUserRuleFixtures.php new file mode 100644 index 00000000..679eff7d --- /dev/null +++ b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginUserRuleFixtures.php @@ -0,0 +1,36 @@ +setRule('host = "example.fr"'); + $rule->setConfig($this->getReference('admin-user')->getConfig()); + + $manager->persist($rule); + + $manager->flush(); + } + + /** + * {@inheritdoc} + */ + public function getDependencies() + { + return [ + UserFixtures::class, + ]; + } +} diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index 7ae73371..85747256 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php @@ -65,6 +65,13 @@ class Configuration implements ConfigurationInterface ->end() ->scalarNode('encryption_key_path') ->end() + ->arrayNode('default_ignore_origin_instance_rules') + ->prototype('array') + ->children() + ->scalarNode('rule')->end() + ->end() + ->end() + ->end() ->end() ; diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index e9a1e9e0..af91e588 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php @@ -30,6 +30,7 @@ class WallabagCoreExtension extends Extension $container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']); $container->setParameter('wallabag_core.default_internal_settings', $config['default_internal_settings']); $container->setParameter('wallabag_core.site_credentials.encryption_key_path', $config['encryption_key_path']); + $container->setParameter('wallabag_core.default_ignore_origin_instance_rules', $config['default_ignore_origin_instance_rules']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index fe7942ee..1bed4513 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -119,6 +119,12 @@ class Config */ private $taggingRules; + /** + * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\IgnoreOriginUserRule", mappedBy="config", cascade={"remove"}) + * @ORM\OrderBy({"id" = "ASC"}) + */ + private $ignoreOriginRules; + /* * @param User $user */ @@ -126,6 +132,7 @@ class Config { $this->user = $user; $this->taggingRules = new ArrayCollection(); + $this->ignoreOriginRules = new ArrayCollection(); } /** @@ -387,4 +394,22 @@ class Config { return $this->taggingRules; } + + /** + * @return Config + */ + public function addIgnoreOriginRule(IgnoreOriginUserRule $rule) + { + $this->ignoreOriginRules[] = $rule; + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getIgnoreOriginRules() + { + return $this->ignoreOriginRules; + } } diff --git a/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php b/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php new file mode 100644 index 00000000..ce3b6e7d --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php @@ -0,0 +1,70 @@ +id; + } + + /** + * Set rule. + * + * @return IgnoreOriginRuleInterface + */ + public function setRule(string $rule) + { + $this->rule = $rule; + + return $this; + } + + /** + * Get rule. + * + * @return string + */ + public function getRule() + { + return $this->rule; + } +} diff --git a/src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php b/src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php new file mode 100644 index 00000000..eb865a3a --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php @@ -0,0 +1,12 @@ +id; + } + + /** + * Set rule. + * + * @return IgnoreOriginRuleInterface + */ + public function setRule(string $rule) + { + $this->rule = $rule; + + return $this; + } + + /** + * Get rule. + * + * @return string + */ + public function getRule() + { + return $this->rule; + } + + /** + * Set config. + * + * @return IgnoreOriginUserRule + */ + public function setConfig(Config $config) + { + $this->config = $config; + + return $this; + } + + /** + * Get config. + * + * @return Config + */ + public function getConfig() + { + return $this->config; + } +} diff --git a/src/Wallabag/CoreBundle/Entity/RuleInterface.php b/src/Wallabag/CoreBundle/Entity/RuleInterface.php new file mode 100644 index 00000000..8e9b5c45 --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/RuleInterface.php @@ -0,0 +1,7 @@ +add('rule', TextType::class, [ + 'required' => true, + 'label' => 'config.form_rules.rule_label', + ]) + ->add('save', SubmitType::class, [ + 'label' => 'config.form.save', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => 'Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule', + ]); + } + + public function getBlockPrefix() + { + return 'ignore_origin_instance_rule'; + } +} diff --git a/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginUserRuleType.php b/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginUserRuleType.php new file mode 100644 index 00000000..b9110f17 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginUserRuleType.php @@ -0,0 +1,37 @@ +add('rule', TextType::class, [ + 'required' => true, + 'label' => 'config.form_rules.rule_label', + ]) + ->add('save', SubmitType::class, [ + 'label' => 'config.form.save', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => 'Wallabag\CoreBundle\Entity\IgnoreOriginUserRule', + ]); + } + + public function getBlockPrefix() + { + return 'ignore_origin_user_rule'; + } +} diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 9c6fa8db..7e93249d 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -19,6 +19,7 @@ class ContentProxy { protected $graby; protected $tagger; + protected $ignoreOriginProcessor; protected $validator; protected $logger; protected $mimeGuesser; @@ -26,10 +27,11 @@ class ContentProxy protected $eventDispatcher; protected $storeArticleHeaders; - public function __construct(Graby $graby, RuleBasedTagger $tagger, ValidatorInterface $validator, LoggerInterface $logger, $fetchingErrorMessage, $storeArticleHeaders = false) + public function __construct(Graby $graby, RuleBasedTagger $tagger, RuleBasedIgnoreOriginProcessor $ignoreOriginProcessor, ValidatorInterface $validator, LoggerInterface $logger, $fetchingErrorMessage, $storeArticleHeaders = false) { $this->graby = $graby; $this->tagger = $tagger; + $this->ignoreOriginProcessor = $ignoreOriginProcessor; $this->validator = $validator; $this->logger = $logger; $this->mimeGuesser = new MimeTypeExtensionGuesser(); @@ -356,7 +358,7 @@ class ContentProxy $diff_keys = array_keys($diff); sort($diff_keys); - if ($this->ignoreUrl($entry->getUrl())) { + if ($this->ignoreOriginProcessor->process($entry)) { $entry->setUrl($url); return false; @@ -395,41 +397,6 @@ class ContentProxy } } - /** - * Check entry url against an ignore list to replace with content url. - * - * XXX: move the ignore list in the database to let users handle it - * - * @param string $url url to test - * - * @return bool true if url matches ignore list otherwise false - */ - private function ignoreUrl($url) - { - $ignored_hosts = ['feedproxy.google.com', 'feeds.reuters.com']; - $ignored_patterns = ['https?://www\.lemonde\.fr/tiny.*']; - - $parsed_url = parse_url($url); - - $filtered = array_filter($ignored_hosts, function ($var) use ($parsed_url) { - return $var === $parsed_url['host']; - }); - - if ([] !== $filtered) { - return true; - } - - $filtered = array_filter($ignored_patterns, function ($var) use ($url) { - return preg_match("`$var`i", $url); - }); - - if ([] !== $filtered) { - return true; - } - - return false; - } - /** * Validate that the given content has at least a title, an html and a url. * diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessor.php b/src/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessor.php new file mode 100644 index 00000000..333e5b0a --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessor.php @@ -0,0 +1,50 @@ +rulerz = $rulerz; + $this->logger = $logger; + $this->ignoreOriginInstanceRuleRepository = $ignoreOriginInstanceRuleRepository; + } + + /** + * @param Entry $entry Entry to process + * + * @return bool + */ + public function process(Entry $entry) + { + $url = $entry->getUrl(); + $userRules = $entry->getUser()->getConfig()->getIgnoreOriginRules()->toArray(); + $rules = array_merge($this->ignoreOriginInstanceRuleRepository->findAll(), $userRules); + + $parsed_url = parse_url($url); + // We add the former url as a new key _all for pattern matching + $parsed_url['_all'] = $url; + + foreach ($rules as $rule) { + if ($this->rulerz->satisfies($parsed_url, $rule->getRule())) { + $this->logger->info('Origin url matching ignore rule.', [ + 'rule' => $rule->getRule(), + ]); + + return true; + } + } + + return false; + } +} diff --git a/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php b/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php new file mode 100644 index 00000000..532e2bb3 --- /dev/null +++ b/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php @@ -0,0 +1,23 @@ + 0; + } +} diff --git a/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php b/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php new file mode 100644 index 00000000..708a0ede --- /dev/null +++ b/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php @@ -0,0 +1,9 @@ +subject matches a search (case-insensitive).
Example: title matches "football"' # notmatches: 'Tests that a subject doesn''t match match a search (case-insensitive).
Example: title notmatches "football"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -617,6 +637,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: # entry_already_saved: 'Entry already saved on %date%' @@ -658,3 +680,8 @@ flashes: # added: 'Site credential for "%host%" added' # updated: 'Site credential for "%host%" updated' # deleted: 'Site credential for "%host%" deleted' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index cd70c99f..549704d0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Zurück zu ungelesenen Artikeln' users_management: 'Benutzerverwaltung' site_credentials: 'Zugangsdaten' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Schnelleinstieg" top: add_new_entry: 'Neuen Artikel hinzufügen' @@ -59,6 +60,7 @@ config: user_info: 'Benutzerinformation' password: 'Kennwort' rules: 'Tagging-Regeln' + # ignore_origin: 'Ignore origin rules' new_user: 'Benutzer hinzufügen' reset: 'Zurücksetzen' form: @@ -177,6 +179,24 @@ config: and: 'Eine Regel UND eine andere' matches: 'Testet, ob eine Variable auf eine Suche zutrifft (Groß- und Kleinschreibung wird nicht berücksichtigt).
Beispiel: title matches "Fußball"' notmatches: 'Testet, ob ein Titel nicht auf eine Suche zutrifft (Groß- und Kleinschreibung wird nicht berücksichtigt).
Beispiel: title notmatches "Fußball"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -617,6 +637,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'Eintrag bereits am %date% gespeichert' @@ -658,3 +680,8 @@ flashes: added: 'Zugangsdaten für "%host%" hinzugefügt' updated: 'Zugangsdaten für "%host%" aktualisiert' deleted: 'Zugangsdaten für "%host%" gelöscht' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 1bc32423..a68a7d7d 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Back to unread articles' users_management: 'Users management' site_credentials: 'Site credentials' + ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Quickstart" top: add_new_entry: 'Add a new entry' @@ -59,6 +60,7 @@ config: user_info: 'User information' password: 'Password' rules: 'Tagging rules' + ignore_origin: 'Ignore origin rules' new_user: 'Add a user' reset: 'Reset area' form: @@ -177,6 +179,24 @@ config: and: 'One rule AND another' matches: 'Tests that a subject matches a search (case-insensitive).
Example: title matches "football"' notmatches: 'Tests that a subject doesn''t match match a search (case-insensitive).
Example: title notmatches "football"' + form_ignore_origin_rules: + faq: + title: 'FAQ' + ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + how_to_use_them_title: 'How do I use them?' + how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + variables_available_title: 'Which variables and operators can I use to write rules?' + variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + meaning: 'Meaning' + variable_description: + label: 'Variable' + host: 'Host of the address' + _all: 'Full address, mainly for pattern matching' + operator_description: + label: 'Operator' + equal_to: 'Equal to…' + matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: page_title: Two-factor authentication app: @@ -594,6 +614,24 @@ site_credential: delete_confirm: Are you sure? back_to_list: Back to list +ignore_origin_instance_rule: + page_title: Global ignore origin rules + new_ignore_origin_instance_rule: Create a global ignore origin rule + edit_ignore_origin_instance_rule: Edit an existing ignore origin rule + description: "Here you can manage the global ignore origin rules used to ignore some patterns of origin url." + list: + actions: Actions + edit_action: Edit + yes: Yes + no: No + create_new_one: Create a new global ignore origin rule + form: + rule_label: Rule + save: Save + delete: Delete + delete_confirm: Are you sure? + back_to_list: Back to list + error: page_title: An error occurred @@ -617,6 +655,8 @@ flashes: otp_disabled: Two-factor authentication disabled tagging_rules_imported: Tagging rules imported tagging_rules_not_imported: Error while importing tagging rules + ignore_origin_rules_deleted: 'Ignore origin rule deleted' + ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'Entry already saved on %date%' @@ -658,3 +698,8 @@ flashes: added: 'Site credential for "%host%" added' updated: 'Site credential for "%host%" updated' deleted: 'Site credential for "%host%" deleted' + ignore_origin_instance_rule: + notice: + added: 'Global ignore origin rule added' + updated: 'Global ignore origin rule updated' + deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index bced72e9..c3e3ba81 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Volver a los artículos sin leer' users_management: 'Configuración de usuarios' site_credentials: 'Credenciales del sitio' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Inicio rápido" top: add_new_entry: 'Añadir un nuevo artículo' @@ -59,6 +60,7 @@ config: user_info: 'Información de usuario' password: 'Contraseña' rules: 'Reglas de etiquetado automáticas' + # ignore_origin: 'Ignore origin rules' new_user: 'Añadir un usuario' reset: 'Reiniciar mi cuenta' form: @@ -177,6 +179,24 @@ config: and: 'Una regla Y la otra' matches: 'Prueba si un sujeto corresponde a una búsqueda (insensible a mayúsculas).
Ejemplo : title matches "fútbol"' notmatches: 'Prueba si subject no corresponde a una búsqueda (insensible a mayúsculas).
Example: title notmatches "fútbol"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: page_title: Autenticación de dos pasos app: @@ -617,6 +637,8 @@ flashes: # otp_disabled: Two-factor authentication disabled tagging_rules_imported: Reglas de etiquetado importadas tagging_rules_not_imported: Un error se ha producico en la importación de las reglas de etiquetado + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'Artículo ya guardado el %fecha%' @@ -658,3 +680,8 @@ flashes: added: 'Credenciales del sitio añadidas para "%host%"' updated: 'Credenciales del sitio actualizadas para "%host%"' deleted: 'Credenciales del sitio eliminadas para "%host%"' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 0704204a..4a52a208 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'بازگشت به خوانده‌نشده‌ها' # users_management: 'Users management' # site_credentials: 'Site credentials' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Quickstart" top: add_new_entry: 'افزودن مقالهٔ تازه' @@ -59,6 +60,7 @@ config: user_info: 'اطلاعات کاربر' password: 'رمز' rules: 'برچسب‌گذاری خودکار' + # ignore_origin: 'Ignore origin rules' new_user: 'افزودن کاربر' # reset: 'Reset area' form: @@ -177,6 +179,24 @@ config: # and: 'One rule AND another' # matches: 'Tests that a subject matches a search (case-insensitive).
Example: title matches "football"' # notmatches: 'Tests that a subject doesn''t match match a search (case-insensitive).
Example: title notmatches "football"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -617,6 +637,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'این مقاله در تاریخ %date% ذخیره شده بود' @@ -658,3 +680,8 @@ flashes: # added: 'Site credential for "%host%" added' # updated: 'Site credential for "%host%" updated' # deleted: 'Site credential for "%host%" deleted' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 5d5878eb..2cfab8cf 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -33,6 +33,7 @@ menu: back_to_unread: "Retour aux articles non lus" users_management: "Gestion des utilisateurs" site_credentials: 'Accès aux sites' + ignore_origin_instance_rules: "Règles globales d'omission d'origine" quickstart: "Pour bien débuter" top: add_new_entry: "Sauvegarder un nouvel article" @@ -59,6 +60,7 @@ config: user_info: "Mon compte" password: "Mot de passe" rules: "Règles de tag automatiques" + ignore_origin: "Règles d'omission d'origine" new_user: "Créer un compte" reset: "Réinitialisation" form: @@ -177,6 +179,24 @@ config: and: "Une règle ET l’autre" matches: "Teste si un sujet correspond à une recherche (non sensible à la casse).
Exemple : title matches \"football\"" notmatches: "Teste si un sujet ne correspond pas à une recherche (non sensible à la casse).
Exemple : title notmatches \"football\"" + form_ignore_origin_rules: + faq: + title: "FAQ" + ignore_origin_rules_definition_title: "Que signifient les règles d'omission d'origine ?" + ignore_origin_rules_definition_description: "Ce sont des règles utilisées par wallabag pour omettre automatiquement l'adresse d'origine après une redirection.
Si une redirection intervient pendant la récupération d'un nouvel article, toutes les règles d'omission (règles utilisateur et instance) seront utilisées afin d'ignorer ou non l'adresse d'origine." + how_to_use_them_title: "Comment les utiliser ?" + how_to_use_them_description: "Imaginons que vous vouliez omettre l'origine d'un article provenant de « rss.example.com » (sachant qu'après la redirection, l'adresse réelle est example.com).
Dans ce cas, vous devriez mettre « host = \"rss.example.com\" » dans le champ Règle." + variables_available_title: "Quelles variables et opérateurs puis-je utiliser pour écrire des règles ?" + variables_available_description: "Les variables et opérateurs suivants peuvent être utilisés pour écrire des règles d'omission d'origine :" + meaning: "Signification" + variable_description: + label: "Variable" + host: "Hôte" + _all: "Adresse complète, utile pour les expressions régulières" + operator_description: + label: "Opérateur" + equal_to: "Égal à…" + matches: "Teste si un sujet correspond à une recherche (non sensible à la casse).
Exemple : _all ~ \"https?://rss.example.com/foobar/.*\"" otp: page_title: Authentification double-facteur app: @@ -618,6 +638,8 @@ flashes: otp_disabled: "Authentification à double-facteur désactivée" tagging_rules_imported: Règles bien importées tagging_rules_not_imported: Impossible d'importer les règles + ignore_origin_rules_deleted: "Règle d'omission d'origine supprimée" + ignore_origin_rules_updated: "Règle d'omission d'origine mise à jour" entry: notice: entry_already_saved: "Article déjà sauvegardé le %date%" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 23e72f20..af1c1fe7 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Torna ai contenuti non letti' users_management: 'Gestione utenti' site_credentials: 'Credenziali sito' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Introduzione" top: add_new_entry: 'Aggiungi un nuovo contenuto' @@ -59,6 +60,7 @@ config: user_info: 'Informazioni utente' password: 'Password' rules: 'Regole di etichettatura' + # ignore_origin: 'Ignore origin rules' new_user: 'Aggiungi utente' reset: 'Area di reset' form: @@ -177,6 +179,24 @@ config: and: "Una regola E un'altra" matches: 'Verifica che un oggetto risulti in una ricerca (case-insensitive).
Esempio: titolo contiene "football"' # notmatches: 'Tests that a subject doesn''t match match a search (case-insensitive).
Example: title notmatches "football"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -617,6 +637,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'Contenuto già salvato in data %date%' @@ -658,3 +680,8 @@ flashes: # added: 'Site credential for "%host%" added' # updated: 'Site credential for "%host%" updated' # deleted: 'Site credential for "%host%" deleted' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 6ddff6ea..59dd9b22 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Tornar als articles pas legits' users_management: 'Gestion dels utilizaires' site_credentials: 'Identificants del site' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Per ben començar" top: add_new_entry: 'Enregistrar un novèl article' @@ -59,6 +60,7 @@ config: user_info: 'Mon compte' password: 'Senhal' rules: "Règlas d'etiquetas automaticas" + # ignore_origin: 'Ignore origin rules' new_user: 'Crear un compte' reset: 'Zòna de reïnicializacion' form: @@ -177,6 +179,24 @@ config: and: "Una règla E l'autra" matches: 'Teste se un subjècte correspond a una recèrca (non sensibla a la cassa).
Exemple : title matches \"football\"' notmatches: 'Teste se subjècte correspond pas a una recèrca (sensibla a la cassa).
Example : title notmatches "football"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: page_title: Autentificacion en dos temps app: @@ -617,6 +637,8 @@ flashes: # otp_disabled: Two-factor authentication disabled tagging_rules_imported: Règlas d’etiquetatge importadas tagging_rules_not_imported: Error en important las règlas d’etiquetatge + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'Article ja salvagardat lo %date%' @@ -658,3 +680,8 @@ flashes: added: 'Identificant per "%host%" ajustat' updated: 'Identificant per "%host%" mes a jorn' deleted: 'Identificant per "%host%" suprimit' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 770477c9..c09ef47a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Powrót do nieprzeczytanych artykułów' users_management: 'Zarządzanie użytkownikami' site_credentials: 'Poświadczenia strony' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Szybki start" top: add_new_entry: 'Dodaj nowy wpis' @@ -59,6 +60,7 @@ config: user_info: 'Informacje o użytkowniku' password: 'Hasło' rules: 'Zasady tagowania' + # ignore_origin: 'Ignore origin rules' new_user: 'Dodaj użytkownika' reset: 'Reset' form: @@ -177,6 +179,24 @@ config: and: 'Jedna reguła I inna' matches: 'Sprawdź czy temat pasuje szukaj (duże lub małe litery).
Przykład: tytuł zawiera "piłka nożna"' notmatches: 'Sprawdź czy temat nie zawiera szukaj (duże lub małe litery).
Przykład: tytuł nie zawiera "piłka nożna"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -617,6 +637,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'Wpis już został dodany %date%' @@ -658,3 +680,8 @@ flashes: added: 'Poświadczenie dla "%host%" dodane' updated: 'Poświadczenie dla "%host%" zaktualizowane' deleted: 'Poświadczenie dla "%host%" usuniętę' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index d993cb05..293a4e44 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Voltar para os artigos não lidos' users_management: 'Gestão de Usuários' site_credentials: 'Credenciais do site' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Começo Rápido" top: add_new_entry: 'Adicionar um novo artigo' @@ -59,6 +60,7 @@ config: user_info: 'Informação do Usuário' password: 'Senha' rules: 'Regras de tags' + # ignore_origin: 'Ignore origin rules' new_user: 'Adicionar um usuário' reset: 'Reiniciar minha conta' form: @@ -177,6 +179,24 @@ config: and: 'Uma regra E outra' matches: 'Testa que um assunto corresponde a uma pesquisa (maiúscula ou minúscula).
Exemplo: title matches "futebol"' notmatches: 'Testa que um assunto não corresponde a uma search (maiúscula ou minúscula).
Exemplo: title notmatches "futebol"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: page_title: Autenticação de dois fatores app: @@ -657,3 +677,8 @@ flashes: added: 'Credencial do site para "%host%" foi adicionada' updated: 'Credencial do site pa "%host%" atualizada' deleted: 'Credencial do site pa "%host%" removida' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index bc8b72e0..3c605709 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Înapoi la articolele necitite' # users_management: 'Users management' # site_credentials: 'Site credentials' + # ignore_origin_instance_rules: 'Global ignore origin rules' # quickstart: "Quickstart" top: add_new_entry: 'Introdu un nou articol' @@ -59,6 +60,7 @@ config: user_info: 'Informații despre utilizator' password: 'Parolă' # rules: 'Tagging rules' + # ignore_origin: 'Ignore origin rules' new_user: 'Crează un utilizator' # reset: 'Reset area' form: @@ -177,6 +179,24 @@ config: # and: 'One rule AND another' # matches: 'Tests that a subject matches a search (case-insensitive).
Example: title matches "football"' # notmatches: 'Tests that a subject doesn''t match match a search (case-insensitive).
Example: title notmatches "football"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -616,6 +636,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: # entry_already_saved: 'Entry already saved on %date%' @@ -657,3 +679,8 @@ flashes: # added: 'Site credential for "%host%" added' # updated: 'Site credential for "%host%" updated' # deleted: 'Site credential for "%host%" deleted' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml index 2f7f55e5..eead4ec6 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Назад к непрочитанным записям' users_management: 'Управление пользователями' site_credentials: 'Site credentials' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Быстрый старт" top: add_new_entry: 'Добавить новую запись' @@ -59,6 +60,7 @@ config: user_info: 'Информация о пользователе' password: 'Пароль' rules: 'Правила настройки простановки тегов' + # ignore_origin: 'Ignore origin rules' new_user: 'Добавить пользователя' reset: 'Сброс данных' form: @@ -177,6 +179,24 @@ config: and: 'Одно правило И другое' matches: 'Тесты, в которых тема соответствует поиску (без учета регистра). Пример: title matches "футбол" ' # notmatches: 'Tests that a subject doesn''t match match a search (case-insensitive).
Example: title notmatches "football"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -616,6 +636,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'Запись была сохранена ранее %date%' @@ -657,3 +679,8 @@ flashes: # added: 'Site credential for "%host%" added' # updated: 'Site credential for "%host%" updated' # deleted: 'Site credential for "%host%" deleted' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml index 48e1c34a..8d2b05f3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'กลับไปยังรายการที่ไม่ได้อ่าน' users_management: 'การจัดการผู้ใช้' site_credentials: 'การรับรองไซต์' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "เริ่มแบบด่วน" top: add_new_entry: 'เพิ่มรายการใหม่' @@ -59,6 +60,7 @@ config: user_info: 'ข้อมูลผู้ใช้' password: 'รหัสผ่าน' rules: 'การแท็กข้อบังคับ' + # ignore_origin: 'Ignore origin rules' new_user: 'เพิ่มผู้ใช้' reset: 'รีเซ็ตพื้นที่ ' form: @@ -177,6 +179,24 @@ config: and: 'หนึ่งข้อบังคับและอื่นๆ' matches: 'ทดสอบว่า เรื่อง นี้ตรงกับ การต้นหา (กรณีไม่ทราบ).
ตัวอย่าง: หัวข้อที่ตรงกับ "football"' notmatches: 'ทดสอบว่า เรื่อง นี้ไม่ตรงกับ การต้นหา (กรณีไม่ทราบ).
ตัวอย่าง: หัวข้อทีไม่ตรงกับ "football"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -616,6 +636,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'รายการพร้อมบันทึกที่ %date%' @@ -657,3 +679,8 @@ flashes: added: 'ไซต์ข้อมูลประจำตัวสำหรับ "%host%" ที่ทำการเพิ่ม' updated: 'ไซต์ข้อมูลประจำตัวสำหรับ "%host%" ที่ทำการอัปเดต' deleted: 'ไซต์ข้อมูลประจำตัวสำหรับ "%host%" ที่ทำการลบ' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 19029c0b..dfbc3010 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Okunmayan makalelere geri dön' # users_management: 'Users management' # site_credentials: 'Site credentials' + # ignore_origin_instance_rules: 'Global ignore origin rules' quickstart: "Hızlı başlangıç" top: add_new_entry: 'Yeni bir makale ekle' @@ -59,6 +60,7 @@ config: user_info: 'Kullanıcı bilgileri' password: 'Şifre' rules: 'Etiketleme kuralları' + # ignore_origin: 'Ignore origin rules' new_user: 'Bir kullanıcı ekle' # reset: 'Reset area' form: @@ -177,6 +179,24 @@ config: and: 'Bir kural ve diğeri' # matches: 'Tests that a subject matches a search (case-insensitive).
Example: title matches "football"' # notmatches: 'Tests that a subject doesn''t match match a search (case-insensitive).
Example: title notmatches "football"' + form_ignore_origin_rules: + # faq: + # title: 'FAQ' + # ignore_origin_rules_definition_title: 'What does « ignore origin rules » mean?' + # ignore_origin_rules_definition_description: 'They are used by wallabag to automatically ignore an origin address after a redirect.
If a redirect occurs while fetching a new entry, all the ignore origin rules (user defined and instance defined) will be used to ignore the origin address.' + # how_to_use_them_title: 'How do I use them?' + # how_to_use_them_description: 'Let us assume you want to ignore the origin of an entry coming from « rss.example.com » (knowing that after a redirect, the actual address is example.com).
In that case, you should put « host = "rss.example.com" » in the Rule field.' + # variables_available_title: 'Which variables and operators can I use to write rules?' + # variables_available_description: 'The following variables and operators can be used to create ignore origin rules:' + # meaning: 'Meaning' + # variable_description: + # label: 'Variable' + # host: 'Host of the address' + # _all: 'Full address, mainly for pattern matching' + # operator_description: + # label: 'Operator' + # equal_to: 'Equal to…' + # matches: 'Tests that a subject matches a search (case-insensitive).
Example: _all ~ "https?://rss.example.com/foobar/.*"' otp: # page_title: Two-factor authentication # app: @@ -616,6 +636,8 @@ flashes: # otp_disabled: Two-factor authentication disabled # tagging_rules_imported: Tagging rules imported # tagging_rules_not_imported: Error while importing tagging rules + # ignore_origin_rules_deleted: 'Ignore origin rule deleted' + # ignore_origin_rules_updated: 'Ignore origin rule updated' entry: notice: entry_already_saved: 'Entry already saved on %date%' @@ -657,3 +679,8 @@ flashes: # added: 'Site credential for "%host%" added' # updated: 'Site credential for "%host%" updated' # deleted: 'Site credential for "%host%" deleted' + ignore_origin_instance_rule: + notice: + # added: 'Global ignore origin rule added' + # updated: 'Global ignore origin rule updated' + # deleted: 'Global ignore origin rule deleted' diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig index eb395eac..b6edce39 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig @@ -404,6 +404,76 @@ +

{{ 'config.tab_menu.ignore_origin'|trans }}

+ + + + {{ form_start(form.new_ignore_origin_user_rule) }} + {{ form_errors(form.new_ignore_origin_user_rule) }} + +
+
+ {{ form_label(form.new_ignore_origin_user_rule.rule) }} + {{ form_errors(form.new_ignore_origin_user_rule.rule) }} + {{ form_widget(form.new_ignore_origin_user_rule.rule) }} +
+
+ + {{ form_rest(form.new_ignore_origin_user_rule) }} + + +
+
+

{{ 'config.form_ignore_origin_rules.faq.title'|trans }}

+ +
{{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_title'|trans }}
+

{{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_description'|trans|raw }}

+ +
{{ 'config.form_ignore_origin_rules.faq.how_to_use_them_title'|trans }}
+

{{ 'config.form_ignore_origin_rules.faq.how_to_use_them_description'|trans|raw }}

+ +
{{ 'config.form_ignore_origin_rules.faq.variables_available_title'|trans }}
+

+ {{ 'config.form_ignore_origin_rules.faq.variables_available_description'|trans }} +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
{{ 'config.form_ignore_origin_rules.faq.variable_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}{{ 'config.form_ignore_origin_rules.faq.operator_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}
host{{ 'config.form_ignore_origin_rules.faq.variable_description.host'|trans }}={{ 'config.form_ignore_origin_rules.faq.operator_description.equal_to'|trans }}
_all{{ 'config.form_ignore_origin_rules.faq.variable_description._all'|trans }}~{{ 'config.form_ignore_origin_rules.faq.operator_description.matches'|trans|raw }}
+
+
+

{{ 'config.reset.title'|trans }}

{{ 'config.reset.description'|trans }}

diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/edit.html.twig new file mode 100644 index 00000000..30c2a520 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/edit.html.twig @@ -0,0 +1,87 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'ignore_origin_instance_rule.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

{{ 'ignore_origin_instance_rule.edit_ignore_origin_instance_rule'|trans }}

+ +
+ {{ form_start(edit_form) }} + {{ form_errors(edit_form) }} + +
+
+ {{ form_label(edit_form.rule) }} + {{ form_errors(edit_form.rule) }} + {{ form_widget(edit_form.rule) }} +
+
+ +
+ + {{ form_widget(edit_form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_widget(edit_form._token) }} + +

+ {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +

+

{{ 'ignore_origin_instance_rule.form.back_to_list'|trans }}

+
+
+
+ +
+
+

{{ 'config.form_ignore_origin_rules.faq.title'|trans }}

+ +
{{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_title'|trans }}
+

{{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_description'|trans|raw }}

+ +
{{ 'config.form_ignore_origin_rules.faq.how_to_use_them_title'|trans }}
+

{{ 'config.form_ignore_origin_rules.faq.how_to_use_them_description'|trans|raw }}

+ +
{{ 'config.form_ignore_origin_rules.faq.variables_available_title'|trans }}
+

+ {{ 'config.form_ignore_origin_rules.faq.variables_available_description'|trans }} +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
{{ 'config.form_ignore_origin_rules.faq.variable_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}{{ 'config.form_ignore_origin_rules.faq.operator_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}
host{{ 'config.form_ignore_origin_rules.faq.variable_description.host'|trans }}={{ 'config.form_ignore_origin_rules.faq.operator_description.equal_to'|trans }}
_all{{ 'config.form_ignore_origin_rules.faq.variable_description._all'|trans }}~{{ 'config.form_ignore_origin_rules.faq.operator_description.matches'|trans|raw }}
+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/index.html.twig new file mode 100644 index 00000000..2de7cf0a --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/index.html.twig @@ -0,0 +1,42 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'ignore_origin_instance_rule.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

{{ 'ignore_origin_instance_rule.description'|trans|raw }}

+ + + + + + + + + + {% for rule in rules %} + + + + + {% endfor %} + +
{{ 'ignore_origin_instance_rule.form.rule_label'|trans }}{{ 'ignore_origin_instance_rule.list.actions'|trans }}
{{ rule.rule }} + {{ 'ignore_origin_instance_rule.list.edit_action'|trans }} +
+
+

+ {{ 'ignore_origin_instance_rule.list.create_new_one'|trans }} +

+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig new file mode 100644 index 00000000..cb052ff0 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig @@ -0,0 +1,80 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'ignore_origin_instance_rule.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

{{ 'ignore_origin_instance_rule.new_ignore_origin_instance_rule'|trans }}

+ +
+ {{ form_start(form) }} + {{ form_errors(form) }} + +
+
+ {{ form_label(form.rule) }} + {{ form_errors(form.rule) }} + {{ form_widget(form.rule) }} +
+
+ + {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_rest(form) }} + +

{{ 'ignore_origin_instance_rule.form.back_to_list'|trans }}

+
+
+
+ +
+
+

{{ 'config.form_ignore_origin_rules.faq.title'|trans }}

+ +
{{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_title'|trans }}
+

{{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_description'|trans|raw }}

+ +
{{ 'config.form_ignore_origin_rules.faq.how_to_use_them_title'|trans }}
+

{{ 'config.form_ignore_origin_rules.faq.how_to_use_them_description'|trans|raw }}

+ +
{{ 'config.form_ignore_origin_rules.faq.variables_available_title'|trans }}
+

+ {{ 'config.form_ignore_origin_rules.faq.variables_available_description'|trans }} +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
{{ 'config.form_ignore_origin_rules.faq.variable_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}{{ 'config.form_ignore_origin_rules.faq.operator_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}
host{{ 'config.form_ignore_origin_rules.faq.variable_description.host'|trans }}={{ 'config.form_ignore_origin_rules.faq.operator_description.equal_to'|trans }}
_all{{ 'config.form_ignore_origin_rules.faq.variable_description._all'|trans }}~{{ 'config.form_ignore_origin_rules.faq.operator_description.matches'|trans|raw }}
+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig index 6b1e2bd7..e1446ff7 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig @@ -45,6 +45,7 @@ {% if is_granted('ROLE_SUPER_ADMIN') %} + {% endif %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index c2e92ad1..22b38a1b 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -16,7 +16,8 @@
  • {{ 'config.tab_menu.user_info'|trans }}
  • {{ 'config.tab_menu.password'|trans }}
  • {{ 'config.tab_menu.rules'|trans }}
  • -
  • {{ 'config.tab_menu.reset'|trans }}
  • +
  • {{ 'config.tab_menu.ignore_origin'|trans }}
  • +
  • {{ 'config.tab_menu.reset'|trans }}
  • @@ -294,11 +295,11 @@ « {{ tagging_rule.rule }} » {{ 'config.form_rules.then_tag_as_label'|trans }} « {{ tagging_rule.tags|join(', ') }} » - - mode_edit + + mode_edit - - delete + + delete {% endfor %} @@ -466,6 +467,89 @@
    + {% if app.user.config.ignoreOriginRules is not empty %} +
    +
    +
      + {% for ignore_origin_rule in app.user.config.ignoreOriginRules %} +
    • + {{ 'config.form_rules.if_label'|trans }} + « {{ ignore_origin_rule.rule }} » + + mode_edit + + + delete + +
    • + {% endfor %} +
    +
    +
    + {% endif %} + + {{ form_start(form.new_ignore_origin_user_rule) }} + {{ form_errors(form.new_ignore_origin_user_rule) }} + +
    +
    + {{ form_label(form.new_ignore_origin_user_rule.rule) }} + {{ form_errors(form.new_ignore_origin_user_rule.rule) }} + {{ form_widget(form.new_ignore_origin_user_rule.rule) }} +
    +
    + + {{ form_widget(form.new_ignore_origin_user_rule.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_rest(form.new_ignore_origin_user_rule) }} + + + + +
    +
    +

    {{ 'config.form_ignore_origin_rules.faq.title'|trans }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_title'|trans }}
    +

    {{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_description'|trans|raw }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.how_to_use_them_title'|trans }}
    +

    {{ 'config.form_ignore_origin_rules.faq.how_to_use_them_description'|trans|raw }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.variables_available_title'|trans }}
    +

    + {{ 'config.form_ignore_origin_rules.faq.variables_available_description'|trans }} +

    + + + + + + + + + + + + + + + + + + + + + + + + + +
    {{ 'config.form_ignore_origin_rules.faq.variable_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}{{ 'config.form_ignore_origin_rules.faq.operator_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}
    host{{ 'config.form_ignore_origin_rules.faq.variable_description.host'|trans }}={{ 'config.form_ignore_origin_rules.faq.operator_description.equal_to'|trans }}
    _all{{ 'config.form_ignore_origin_rules.faq.variable_description._all'|trans }}~{{ 'config.form_ignore_origin_rules.faq.operator_description.matches'|trans|raw }}
    +
    +
    +
    + +
    {{ 'config.reset.title'|trans }}

    {{ 'config.reset.description'|trans }}

    diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig new file mode 100644 index 00000000..30c2a520 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig @@ -0,0 +1,87 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'ignore_origin_instance_rule.page_title'|trans }}{% endblock %} + +{% block content %} + +
    +
    +
    +
    +
    +

    {{ 'ignore_origin_instance_rule.edit_ignore_origin_instance_rule'|trans }}

    + +
    + {{ form_start(edit_form) }} + {{ form_errors(edit_form) }} + +
    +
    + {{ form_label(edit_form.rule) }} + {{ form_errors(edit_form.rule) }} + {{ form_widget(edit_form.rule) }} +
    +
    + +
    + + {{ form_widget(edit_form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_widget(edit_form._token) }} + +

    + {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +

    +

    {{ 'ignore_origin_instance_rule.form.back_to_list'|trans }}

    +
    +
    +
    + +
    +
    +

    {{ 'config.form_ignore_origin_rules.faq.title'|trans }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_title'|trans }}
    +

    {{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_description'|trans|raw }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.how_to_use_them_title'|trans }}
    +

    {{ 'config.form_ignore_origin_rules.faq.how_to_use_them_description'|trans|raw }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.variables_available_title'|trans }}
    +

    + {{ 'config.form_ignore_origin_rules.faq.variables_available_description'|trans }} +

    + + + + + + + + + + + + + + + + + + + + + + + + + +
    {{ 'config.form_ignore_origin_rules.faq.variable_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}{{ 'config.form_ignore_origin_rules.faq.operator_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}
    host{{ 'config.form_ignore_origin_rules.faq.variable_description.host'|trans }}={{ 'config.form_ignore_origin_rules.faq.operator_description.equal_to'|trans }}
    _all{{ 'config.form_ignore_origin_rules.faq.variable_description._all'|trans }}~{{ 'config.form_ignore_origin_rules.faq.operator_description.matches'|trans|raw }}
    +
    +
    +
    +
    +
    + +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/index.html.twig new file mode 100644 index 00000000..2de7cf0a --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/index.html.twig @@ -0,0 +1,42 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'ignore_origin_instance_rule.page_title'|trans }}{% endblock %} + +{% block content %} + +
    +
    +
    +
    +
    +

    {{ 'ignore_origin_instance_rule.description'|trans|raw }}

    + + + + + + + + + + {% for rule in rules %} + + + + + {% endfor %} + +
    {{ 'ignore_origin_instance_rule.form.rule_label'|trans }}{{ 'ignore_origin_instance_rule.list.actions'|trans }}
    {{ rule.rule }} + {{ 'ignore_origin_instance_rule.list.edit_action'|trans }} +
    +
    +

    + {{ 'ignore_origin_instance_rule.list.create_new_one'|trans }} +

    +
    +
    +
    +
    +
    + +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig new file mode 100644 index 00000000..cb052ff0 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig @@ -0,0 +1,80 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'ignore_origin_instance_rule.page_title'|trans }}{% endblock %} + +{% block content %} + +
    +
    +
    +
    +
    +

    {{ 'ignore_origin_instance_rule.new_ignore_origin_instance_rule'|trans }}

    + +
    + {{ form_start(form) }} + {{ form_errors(form) }} + +
    +
    + {{ form_label(form.rule) }} + {{ form_errors(form.rule) }} + {{ form_widget(form.rule) }} +
    +
    + + {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + {{ form_rest(form) }} + +

    {{ 'ignore_origin_instance_rule.form.back_to_list'|trans }}

    +
    +
    +
    + +
    +
    +

    {{ 'config.form_ignore_origin_rules.faq.title'|trans }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_title'|trans }}
    +

    {{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_description'|trans|raw }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.how_to_use_them_title'|trans }}
    +

    {{ 'config.form_ignore_origin_rules.faq.how_to_use_them_description'|trans|raw }}

    + +
    {{ 'config.form_ignore_origin_rules.faq.variables_available_title'|trans }}
    +

    + {{ 'config.form_ignore_origin_rules.faq.variables_available_description'|trans }} +

    + + + + + + + + + + + + + + + + + + + + + + + + + +
    {{ 'config.form_ignore_origin_rules.faq.variable_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}{{ 'config.form_ignore_origin_rules.faq.operator_description.label'|trans }}{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}
    host{{ 'config.form_ignore_origin_rules.faq.variable_description.host'|trans }}={{ 'config.form_ignore_origin_rules.faq.operator_description.equal_to'|trans }}
    _all{{ 'config.form_ignore_origin_rules.faq.variable_description._all'|trans }}~{{ 'config.form_ignore_origin_rules.faq.operator_description.matches'|trans|raw }}
    +
    +
    +
    +
    +
    + +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig index c51d07fc..d9b6d190 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig @@ -78,9 +78,13 @@ {{ 'menu.left.users_management'|trans }} -
  • +
  • {{ 'menu.left.internal_settings'|trans }}
  • + +
  • + {{ 'menu.left.ignore_origin_instance_rules'|trans }} +
  • {% endif %}
  • {{ 'menu.left.import'|trans }} diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php index c4bd6dac..a0e2939c 100644 --- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php @@ -45,6 +45,9 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase $this->getEntityManager()->flush(); } + /** + * @group NetworkCalls + */ public function testRunReloadEntryCommand() { $application = new Application($this->getClient()->getKernel()); @@ -70,6 +73,9 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase $this->assertContains('Done', $tester->getDisplay()); } + /** + * @group NetworkCalls + */ public function testRunReloadEntryWithUsernameCommand() { $application = new Application($this->getClient()->getKernel()); diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index b3b3a19a..92d22267 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -435,7 +435,6 @@ class ConfigControllerTest extends WallabagCoreTestCase public function testTaggingRuleCreation() { $this->logInAs('admin'); - $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/config'); @@ -457,7 +456,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); - $editLink = $crawler->filter('.mode_edit')->last()->link(); + $editLink = $crawler->filter('div[id=set5] a.mode_edit')->last()->link(); $crawler = $client->click($editLink); $this->assertSame(302, $client->getResponse()->getStatusCode()); @@ -482,7 +481,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); - $deleteLink = $crawler->filter('.delete')->last()->link(); + $deleteLink = $crawler->filter('div[id=set5] a.delete')->last()->link(); $crawler = $client->click($deleteLink); $this->assertSame(302, $client->getResponse()->getStatusCode()); @@ -574,11 +573,11 @@ class ConfigControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:TaggingRule') ->findAll()[0]; - $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); + $crawler = $client->request('GET', '/tagging-rule/delete/' . $rule->getId()); $this->assertSame(403, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('You can not access this tagging rule', $body[0]); + $this->assertContains('You can not access this rule', $body[0]); } public function testEditingTaggingRuleFromAnOtherUser() @@ -594,7 +593,144 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertSame(403, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('You can not access this tagging rule', $body[0]); + $this->assertContains('You can not access this rule', $body[0]); + } + + public function testIgnoreOriginRuleCreation() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form(); + + $data = [ + 'ignore_origin_user_rule[rule]' => 'host = "example.com"', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); + + $editLink = $crawler->filter('div[id=set6] a.mode_edit')->last()->link(); + + $crawler = $client->click($editLink); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertContains('?ignore-origin-user-rule=', $client->getResponse()->headers->get('location')); + + $crawler = $client->followRedirect(); + + $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form(); + + $data = [ + 'ignore_origin_user_rule[rule]' => 'host = "example.org"', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); + + $this->assertContains('host = "example.org"', $crawler->filter('body')->extract(['_text'])[0]); + + $deleteLink = $crawler->filter('div[id=set6] a.delete')->last()->link(); + + $crawler = $client->click($deleteLink); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + $this->assertContains('flashes.config.notice.ignore_origin_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); + } + + public function dataForIgnoreOriginRuleCreationFail() + { + return [ + [ + [ + 'ignore_origin_user_rule[rule]' => 'foo = "bar"', + ], + [ + 'The variable', + 'does not exist.', + ], + ], + [ + [ + 'ignore_origin_user_rule[rule]' => '_all != "none"', + ], + [ + 'The operator', + 'does not exist.', + ], + ], + ]; + } + + /** + * @dataProvider dataForIgnoreOriginRuleCreationFail + */ + public function testIgnoreOriginRuleCreationFail($data, $messages) + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form(); + + $crawler = $client->submit($form, $data); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + + foreach ($messages as $message) { + $this->assertContains($message, $body[0]); + } + } + + public function testDeletingIgnoreOriginRuleFromAnOtherUser() + { + $this->logInAs('bob'); + $client = $this->getClient(); + + $rule = $client->getContainer()->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule') + ->findAll()[0]; + + $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId()); + + $this->assertSame(403, $client->getResponse()->getStatusCode()); + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('You can not access this rule', $body[0]); + } + + public function testEditingIgnoreOriginRuleFromAnOtherUser() + { + $this->logInAs('bob'); + $client = $this->getClient(); + + $rule = $client->getContainer()->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule') + ->findAll()[0]; + + $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId()); + + $this->assertSame(403, $client->getResponse()->getStatusCode()); + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('You can not access this rule', $body[0]); } public function testDemoMode() @@ -676,6 +812,9 @@ class ConfigControllerTest extends WallabagCoreTestCase $em->flush(); } + /** + * @group NetworkCalls + */ public function testDeleteAccount() { $client = $this->getClient(); diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 5b806830..0aa562d8 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -40,6 +40,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('login', $client->getResponse()->headers->get('location')); } + /** + * @group NetworkCalls + */ public function testQuickstart() { $this->logInAs('empty'); @@ -87,6 +90,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('form[name=entry]')); } + /** + * @group NetworkCalls + */ public function testPostNewViaBookmarklet() { $this->logInAs('admin'); @@ -131,7 +137,7 @@ class EntryControllerTest extends WallabagCoreTestCase } /** - * This test will require an internet connection. + * @group NetworkCalls */ public function testPostNewOk() { @@ -169,6 +175,9 @@ class EntryControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('store_article_headers', 0); } + /** + * @group NetworkCalls + */ public function testPostWithMultipleAuthors() { $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; @@ -229,6 +238,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); } + /** + * @group NetworkCalls + */ public function testPostNewOkUrlExistWithAccent() { $this->logInAs('admin'); @@ -265,7 +277,7 @@ class EntryControllerTest extends WallabagCoreTestCase } /** - * This test will require an internet connection. + * @group NetworkCalls */ public function testPostNewOkUrlExistWithRedirection() { @@ -303,7 +315,7 @@ class EntryControllerTest extends WallabagCoreTestCase } /** - * This test will require an internet connection. + * @group NetworkCalls */ public function testPostNewThatWillBeTagged() { @@ -430,7 +442,7 @@ class EntryControllerTest extends WallabagCoreTestCase } /** - * This test will require an internet connection. + * @group NetworkCalls */ public function testReload() { @@ -1056,6 +1068,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertSame(404, $client->getResponse()->getStatusCode()); } + /** + * @group NetworkCalls + */ public function testNewEntryWithDownloadImagesEnabled() { $this->downloadImagesEnabled = true; @@ -1383,6 +1398,7 @@ class EntryControllerTest extends WallabagCoreTestCase /** * @dataProvider dataForLanguage + * @group NetworkCalls */ public function testLanguageValidation($url, $expectedLanguage) { @@ -1414,7 +1430,7 @@ class EntryControllerTest extends WallabagCoreTestCase } /** - * This test will require an internet connection. + * @group NetworkCalls */ public function testRestrictedArticle() { diff --git a/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php new file mode 100644 index 00000000..9783cd25 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php @@ -0,0 +1,148 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/ignore-origin-instance-rules/'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('ignore_origin_instance_rule.description', $body); + $this->assertContains('ignore_origin_instance_rule.list.create_new_one', $body); + } + + public function testIgnoreOriginInstanceRuleCreationEditionDeletion() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + // Creation + $crawler = $client->request('GET', '/ignore-origin-instance-rules/new'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('ignore_origin_instance_rule.new_ignore_origin_instance_rule', $body); + $this->assertContains('ignore_origin_instance_rule.form.back_to_list', $body); + + $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form(); + + $data = [ + 'ignore_origin_instance_rule[rule]' => 'host = "foo.example.com"', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.ignore_origin_instance_rule.notice.added', $crawler->filter('body')->extract(['_text'])[0]); + + // Edition + $editLink = $crawler->filter('div[id=content] table a')->last()->link(); + + $crawler = $client->click($editLink); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->assertContains('foo.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('ignore_origin_instance_rule.edit_ignore_origin_instance_rule', $body); + $this->assertContains('ignore_origin_instance_rule.form.back_to_list', $body); + + $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form(); + + $data = [ + 'ignore_origin_instance_rule[rule]' => 'host = "bar.example.com"', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.ignore_origin_instance_rule.notice.updated', $crawler->filter('body')->extract(['_text'])[0]); + + $editLink = $crawler->filter('div[id=content] table a')->last()->link(); + + $crawler = $client->click($editLink); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->assertContains('bar.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]); + + $deleteForm = $crawler->filter('body')->selectButton('ignore_origin_instance_rule.form.delete')->form(); + + $client->submit($deleteForm, []); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.ignore_origin_instance_rule.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); + } + + public function dataForIgnoreOriginInstanceRuleCreationFail() + { + return [ + [ + [ + 'ignore_origin_instance_rule[rule]' => 'foo = "bar"', + ], + [ + 'The variable', + 'does not exist.', + ], + ], + [ + [ + 'ignore_origin_instance_rule[rule]' => '_all != "none"', + ], + [ + 'The operator', + 'does not exist.', + ], + ], + ]; + } + + /** + * @dataProvider dataForIgnoreOriginInstanceRuleCreationFail + */ + public function testIgnoreOriginInstanceRuleCreationFail($data, $messages) + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/ignore-origin-instance-rules/new'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form(); + + $crawler = $client->submit($form, $data); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + + foreach ($messages as $message) { + $this->assertContains($message, $body[0]); + } + } +} diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 9ce72c79..a65ac17c 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -12,6 +12,7 @@ use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Validator\RecursiveValidator; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Helper\ContentProxy; +use Wallabag\CoreBundle\Helper\RuleBasedIgnoreOriginProcessor; use Wallabag\CoreBundle\Helper\RuleBasedTagger; use Wallabag\UserBundle\Entity\User; @@ -25,6 +26,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -42,7 +45,7 @@ class ContentProxyTest extends TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://user@:80'); @@ -62,6 +65,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -79,7 +84,7 @@ class ContentProxyTest extends TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -99,6 +104,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -118,7 +125,7 @@ class ContentProxyTest extends TestCase 'description' => 'desc', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://domain.io'); @@ -139,6 +146,10 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $ruleBasedIgnoreOriginProcessor->expects($this->once()) + ->method('process'); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -159,7 +170,7 @@ class ContentProxyTest extends TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -180,6 +191,10 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $ruleBasedIgnoreOriginProcessor->expects($this->once()) + ->method('process'); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -200,7 +215,7 @@ class ContentProxyTest extends TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -221,6 +236,10 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $ruleBasedIgnoreOriginProcessor->expects($this->once()) + ->method('process'); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -240,7 +259,7 @@ class ContentProxyTest extends TestCase 'image' => null, ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -261,6 +280,10 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $ruleBasedIgnoreOriginProcessor->expects($this->once()) + ->method('process'); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -280,7 +303,7 @@ class ContentProxyTest extends TestCase 'image' => 'http://3.3.3.3/cover.jpg', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -301,6 +324,10 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $ruleBasedIgnoreOriginProcessor->expects($this->once()) + ->method('process'); + $validator = $this->getValidator(false); $validator->expects($this->once()) ->method('validate') @@ -324,7 +351,7 @@ class ContentProxyTest extends TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $validator, $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -344,6 +371,10 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $ruleBasedIgnoreOriginProcessor->expects($this->once()) + ->method('process'); + $validator = $this->getValidator(false); $validator->expects($this->exactly(2)) ->method('validate') @@ -372,7 +403,7 @@ class ContentProxyTest extends TestCase 'image' => 'https://', ]); - $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $validator, $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -393,7 +424,11 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $ruleBasedIgnoreOriginProcessor->expects($this->once()) + ->method('process'); + + $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -433,10 +468,12 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $logger, $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -469,11 +506,13 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $logger = new Logger('foo'); $handler = new TestHandler(); $logger->pushHandler($handler); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $logger, $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -512,7 +551,9 @@ class ContentProxyTest extends TestCase ->method('tag') ->will($this->throwException(new \Exception())); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + + $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -554,7 +595,9 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + + $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -590,6 +633,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -607,7 +652,7 @@ class ContentProxyTest extends TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -631,6 +676,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -648,7 +695,7 @@ class ContentProxyTest extends TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -668,6 +715,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -685,7 +734,7 @@ class ContentProxyTest extends TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -704,6 +753,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -721,7 +772,7 @@ class ContentProxyTest extends TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -740,6 +791,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -757,7 +810,7 @@ class ContentProxyTest extends TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -776,6 +829,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -793,7 +848,7 @@ class ContentProxyTest extends TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -813,6 +868,8 @@ class ContentProxyTest extends TestCase $tagger->expects($this->once()) ->method('tag'); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) ->disableOriginalConstructor() @@ -830,7 +887,7 @@ class ContentProxyTest extends TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -850,6 +907,7 @@ class ContentProxyTest extends TestCase * $expected_entry_url * $expected_origin_url * $expected_domain + * $processor_result */ public function dataForChangedUrl() { @@ -861,6 +919,7 @@ class ContentProxyTest extends TestCase 'http://1.1.1.1', 'http://0.0.0.0', '1.1.1.1', + false, ], 'origin already set' => [ 'http://0.0.0.0', @@ -869,6 +928,7 @@ class ContentProxyTest extends TestCase 'http://1.1.1.1', 'http://hello', '1.1.1.1', + false, ], 'trailing slash' => [ 'https://example.com/hello-world', @@ -877,6 +937,7 @@ class ContentProxyTest extends TestCase 'https://example.com/hello-world/', null, 'example.com', + false, ], 'query string in fetched content' => [ 'https://example.org/hello', @@ -885,6 +946,7 @@ class ContentProxyTest extends TestCase 'https://example.org/hello?world=1', 'https://example.org/hello', 'example.org', + false, ], 'fragment in fetched content' => [ 'https://example.org/hello', @@ -893,6 +955,7 @@ class ContentProxyTest extends TestCase 'https://example.org/hello', null, 'example.org', + false, ], 'fragment and query string in fetched content' => [ 'https://example.org/hello', @@ -901,6 +964,7 @@ class ContentProxyTest extends TestCase 'https://example.org/hello?foo#world', 'https://example.org/hello', 'example.org', + false, ], 'different path and query string in fetch content' => [ 'https://example.org/hello', @@ -909,6 +973,7 @@ class ContentProxyTest extends TestCase 'https://example.org/world?foo', 'https://example.org/hello', 'example.org', + false, ], 'feedproxy ignore list test' => [ 'http://feedproxy.google.com/~r/Wallabag/~3/helloworld', @@ -917,6 +982,7 @@ class ContentProxyTest extends TestCase 'https://example.org/hello-wallabag', null, 'example.org', + true, ], 'feedproxy ignore list test with origin url already set' => [ 'http://feedproxy.google.com/~r/Wallabag/~3/helloworld', @@ -925,6 +991,7 @@ class ContentProxyTest extends TestCase 'https://example.org/hello-wallabag', 'https://example.org/this-is-source', 'example.org', + true, ], 'lemonde ignore pattern test' => [ 'http://www.lemonde.fr/tiny/url', @@ -933,6 +1000,7 @@ class ContentProxyTest extends TestCase 'http://example.com/hello-world', null, 'example.com', + true, ], ]; } @@ -940,13 +1008,18 @@ class ContentProxyTest extends TestCase /** * @dataProvider dataForChangedUrl */ - public function testWithChangedUrl($entry_url, $origin_url, $content_url, $expected_entry_url, $expected_origin_url, $expected_domain) + public function testWithChangedUrl($entry_url, $origin_url, $content_url, $expected_entry_url, $expected_origin_url, $expected_domain, $processor_result) { $tagger = $this->getTaggerMock(); $tagger->expects($this->once()) ->method('tag'); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true); + $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock(); + $ruleBasedIgnoreOriginProcessor->expects($this->once()) + ->method('process') + ->willReturn($processor_result); + + $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true); $entry = new Entry(new User()); $entry->setOriginUrl($origin_url); $proxy->updateEntry( @@ -1015,6 +1088,14 @@ class ContentProxyTest extends TestCase ->getMock(); } + private function getRuleBasedIgnoreOriginProcessorMock() + { + return $this->getMockBuilder(RuleBasedIgnoreOriginProcessor::class) + ->setMethods(['process']) + ->disableOriginalConstructor() + ->getMock(); + } + private function getLogger() { return new NullLogger(); diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php new file mode 100644 index 00000000..9e39bc81 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php @@ -0,0 +1,212 @@ +rulerz = $this->getRulerZMock(); + $this->logger = $this->getLogger(); + $this->ignoreOriginInstanceRuleRepository = $this->getIgnoreOriginInstanceRuleRepositoryMock(); + $this->handler = new TestHandler(); + $this->logger->pushHandler($this->handler); + + $this->processor = new RuleBasedIgnoreOriginProcessor($this->rulerz, $this->logger, $this->ignoreOriginInstanceRuleRepository); + } + + public function testProcessWithNoRule() + { + $user = $this->getUser(); + $entry = new Entry($user); + $entry->setUrl('http://example.com/hello-world'); + + $this->ignoreOriginInstanceRuleRepository + ->expects($this->once()) + ->method('findAll') + ->willReturn([]); + + $this->rulerz + ->expects($this->never()) + ->method('satisfies'); + + $result = $this->processor->process($entry); + + $this->assertFalse($result); + } + + public function testProcessWithNoMatchingRule() + { + $userRule = $this->getIgnoreOriginUserRule('rule as string'); + $user = $this->getUser([$userRule]); + $entry = new Entry($user); + $entry->setUrl('http://example.com/hello-world'); + + $this->ignoreOriginInstanceRuleRepository + ->expects($this->once()) + ->method('findAll') + ->willReturn([]); + + $this->rulerz + ->expects($this->once()) + ->method('satisfies') + ->willReturn(false); + + $result = $this->processor->process($entry); + + $this->assertFalse($result); + } + + public function testProcessWithAMatchingRule() + { + $userRule = $this->getIgnoreOriginUserRule('rule as string'); + $user = $this->getUser([$userRule]); + $entry = new Entry($user); + $entry->setUrl('http://example.com/hello-world'); + + $this->ignoreOriginInstanceRuleRepository + ->expects($this->once()) + ->method('findAll') + ->willReturn([]); + + $this->rulerz + ->expects($this->once()) + ->method('satisfies') + ->willReturn(true); + + $result = $this->processor->process($entry); + + $this->assertTrue($result); + } + + public function testProcessWithAMixOfMatchingRules() + { + $userRule = $this->getIgnoreOriginUserRule('rule as string'); + $anotherUserRule = $this->getIgnoreOriginUserRule('another rule as string'); + $user = $this->getUser([$userRule, $anotherUserRule]); + $entry = new Entry($user); + $entry->setUrl('http://example.com/hello-world'); + + $this->ignoreOriginInstanceRuleRepository + ->expects($this->once()) + ->method('findAll') + ->willReturn([]); + + $this->rulerz + ->method('satisfies') + ->will($this->onConsecutiveCalls(false, true)); + + $result = $this->processor->process($entry); + + $this->assertTrue($result); + } + + public function testProcessWithInstanceRules() + { + $user = $this->getUser(); + $entry = new Entry($user); + $entry->setUrl('http://example.com/hello-world'); + + $instanceRule = $this->getIgnoreOriginInstanceRule('rule as string'); + $this->ignoreOriginInstanceRuleRepository + ->expects($this->once()) + ->method('findAll') + ->willReturn([$instanceRule]); + + $this->rulerz + ->expects($this->once()) + ->method('satisfies') + ->willReturn(true); + + $result = $this->processor->process($entry); + + $this->assertTrue($result); + } + + public function testProcessWithMixedRules() + { + $userRule = $this->getIgnoreOriginUserRule('rule as string'); + $user = $this->getUser([$userRule]); + $entry = new Entry($user); + $entry->setUrl('http://example.com/hello-world'); + + $instanceRule = $this->getIgnoreOriginInstanceRule('rule as string'); + $this->ignoreOriginInstanceRuleRepository + ->expects($this->once()) + ->method('findAll') + ->willReturn([$instanceRule]); + + $this->rulerz + ->method('satisfies') + ->will($this->onConsecutiveCalls(false, true)); + + $result = $this->processor->process($entry); + + $this->assertTrue($result); + } + + private function getUser(array $ignoreOriginRules = []) + { + $user = new User(); + $config = new Config($user); + + $user->setConfig($config); + + foreach ($ignoreOriginRules as $rule) { + $config->addIgnoreOriginRule($rule); + } + + return $user; + } + + private function getIgnoreOriginUserRule($rule) + { + $ignoreOriginUserRule = new IgnoreOriginUserRule(); + $ignoreOriginUserRule->setRule($rule); + + return $ignoreOriginUserRule; + } + + private function getIgnoreOriginInstanceRule($rule) + { + $ignoreOriginInstanceRule = new IgnoreOriginInstanceRule(); + $ignoreOriginInstanceRule->setRule($rule); + + return $ignoreOriginInstanceRule; + } + + private function getRulerZMock() + { + return $this->getMockBuilder('RulerZ\RulerZ') + ->disableOriginalConstructor() + ->getMock(); + } + + private function getIgnoreOriginInstanceRuleRepositoryMock() + { + return $this->getMockBuilder('Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository') + ->disableOriginalConstructor() + ->getMock(); + } + + private function getLogger() + { + return new Logger('foo'); + } +}