From c675bd11c66e60a1976dfd66484448dcc9d80f0f Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 23 Jun 2019 22:13:06 +0200 Subject: [PATCH 1/8] Add IgnoreOriginRule-related entities, db migration, update config Add IgnoreOriginUserRule for user-defined rules and IgnoreOriginInstanceRule for system-wide rules. Add an interface for these two new entities. Signed-off-by: Kevin Decherf --- .../Version20190826204730.php | 64 ++++++++++++ src/Wallabag/CoreBundle/Entity/Config.php | 25 +++++ .../Entity/IgnoreOriginInstanceRule.php | 71 ++++++++++++++ .../Entity/IgnoreOriginRuleInterface.php | 12 +++ .../Entity/IgnoreOriginUserRule.php | 98 +++++++++++++++++++ .../CoreBundle/Entity/RuleInterface.php | 7 ++ .../CoreBundle/Entity/TaggingRule.php | 2 +- .../IgnoreOriginInstanceRuleRepository.php | 9 ++ .../IgnoreOriginUserRuleRepository.php | 9 ++ .../CoreBundle/Resources/config/services.yml | 6 ++ 10 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 app/DoctrineMigrations/Version20190826204730.php create mode 100644 src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php create mode 100644 src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php create mode 100644 src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php create mode 100644 src/Wallabag/CoreBundle/Entity/RuleInterface.php create mode 100644 src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php create mode 100644 src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php diff --git a/app/DoctrineMigrations/Version20190826204730.php b/app/DoctrineMigrations/Version20190826204730.php new file mode 100644 index 000000000..ee1ba6bf1 --- /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/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index fe7942ee2..1bed45138 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 000000000..34aed50c6 --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php @@ -0,0 +1,71 @@ +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 000000000..eb865a3a0 --- /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 000000000..8e9b5c454 --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/RuleInterface.php @@ -0,0 +1,7 @@ + Date: Sun, 23 Jun 2019 22:13:44 +0200 Subject: [PATCH 2/8] Add new Ignore Origin rules tab, update ConfigController Signed-off-by: Kevin Decherf --- .../Controller/ConfigController.php | 79 +++++++++- .../IgnoreOriginUserRuleFixtures.php | 36 +++++ .../Form/Type/IgnoreOriginUserRuleType.php | 37 +++++ .../Resources/translations/messages.da.yml | 3 + .../Resources/translations/messages.de.yml | 3 + .../Resources/translations/messages.en.yml | 3 + .../Resources/translations/messages.es.yml | 3 + .../Resources/translations/messages.fa.yml | 3 + .../Resources/translations/messages.fr.yml | 6 + .../Resources/translations/messages.it.yml | 3 + .../Resources/translations/messages.oc.yml | 3 + .../Resources/translations/messages.pl.yml | 3 + .../Resources/translations/messages.pt.yml | 1 + .../Resources/translations/messages.ro.yml | 3 + .../Resources/translations/messages.ru.yml | 3 + .../Resources/translations/messages.th.yml | 3 + .../Resources/translations/messages.tr.yml | 3 + .../views/themes/baggy/Config/index.html.twig | 27 ++++ .../themes/material/Config/index.html.twig | 49 +++++- .../Controller/ConfigControllerTest.php | 148 +++++++++++++++++- 20 files changed, 406 insertions(+), 13 deletions(-) create mode 100644 src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginUserRuleFixtures.php create mode 100644 src/Wallabag/CoreBundle/Form/Type/IgnoreOriginUserRuleType.php diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 56efe82bb..3efc7bb32 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/DataFixtures/IgnoreOriginUserRuleFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginUserRuleFixtures.php new file mode 100644 index 000000000..679eff7de --- /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/Form/Type/IgnoreOriginUserRuleType.php b/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginUserRuleType.php new file mode 100644 index 000000000..b9110f17b --- /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/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 4d5259797..92440c92c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -59,6 +59,7 @@ config: user_info: 'Brugeroplysninger' password: 'Adgangskode' # rules: 'Tagging rules' + # ignore_origin: 'Ignore origin rules' new_user: 'Tilføj bruger' # reset: 'Reset area' form: @@ -617,6 +618,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index cd70c99ff..7a9382cb3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -59,6 +59,7 @@ config: user_info: 'Benutzerinformation' password: 'Kennwort' rules: 'Tagging-Regeln' + # ignore_origin: 'Ignore origin rules' new_user: 'Benutzer hinzufügen' reset: 'Zurücksetzen' form: @@ -617,6 +618,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' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 1bc32423a..b16662c31 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -59,6 +59,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: @@ -617,6 +618,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index bced72e95..3e77afd6b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -59,6 +59,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: @@ -617,6 +618,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 0704204aa..38c252f73 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -59,6 +59,7 @@ config: user_info: 'اطلاعات کاربر' password: 'رمز' rules: 'برچسب‌گذاری خودکار' + # ignore_origin: 'Ignore origin rules' new_user: 'افزودن کاربر' # reset: 'Reset area' form: @@ -617,6 +618,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% ذخیره شده بود' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 5d5878eba..b12dd9ca9 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -59,6 +59,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: @@ -618,6 +619,11 @@ 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 +<<<<<<< HEAD +======= + ignore_origin_rules_deleted: "Règle d'omission d'origine supprimée" + ignore_origin_rules_updated: "Règle d'omission d'origine mise à jour" +>>>>>>> 4c595340... fixup! Add new Ignore Origin rules tab, update ConfigController 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 23e72f20a..eb44318b9 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -59,6 +59,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: @@ -617,6 +618,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 6ddff6ea7..165186b1d 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -59,6 +59,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: @@ -617,6 +618,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 770477c96..fbf64f30b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -59,6 +59,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: @@ -617,6 +618,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index d993cb059..93910d4be 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -59,6 +59,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index bc8b72e0b..5984d2298 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -59,6 +59,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: @@ -616,6 +617,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml index 2f7f55e53..a138ee5d3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml @@ -59,6 +59,7 @@ config: user_info: 'Информация о пользователе' password: 'Пароль' rules: 'Правила настройки простановки тегов' + # ignore_origin: 'Ignore origin rules' new_user: 'Добавить пользователя' reset: 'Сброс данных' form: @@ -616,6 +617,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml index 48e1c34ad..b786a73d1 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml @@ -59,6 +59,7 @@ config: user_info: 'ข้อมูลผู้ใช้' password: 'รหัสผ่าน' rules: 'การแท็กข้อบังคับ' + # ignore_origin: 'Ignore origin rules' new_user: 'เพิ่มผู้ใช้' reset: 'รีเซ็ตพื้นที่ ' form: @@ -616,6 +617,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%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 19029c0b1..a317c2f50 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -59,6 +59,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: @@ -616,6 +617,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%' 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 eb395eac4..f182fda40 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,33 @@ +

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

+ +
    + {% for ignore_origin_rule in app.user.config.ignoreOriginRules %} +
  • + {{ 'config.form_rules.if_label'|trans }} + « {{ ignore_origin_rule.rule }} » + + +
  • + {% endfor %} +
+ + {{ 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.reset.title'|trans }}

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

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 c2e92ad10..faf9a4240 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,44 @@
    + {% 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.reset.title'|trans }}

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

    diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index b3b3a19a7..40a1aa978 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() From f39c5a2a702036750b4d7c32d02e7f92955a4eed Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 11 Aug 2019 23:51:55 +0200 Subject: [PATCH 3/8] Add new Helper to process Ignore Origin rules and RulerZ operator This commits adds a new helper like RuleBasedTagger for processing ignore origin rules. It also adds a new custom RulerZ operator for the '~' pattern matching rule. Renames 'pattern' with '_all' in IgnoreOriginRule entity. Signed-off-by: Kevin Decherf --- .../Entity/IgnoreOriginInstanceRule.php | 3 +- .../Entity/IgnoreOriginUserRule.php | 3 +- .../Helper/RuleBasedIgnoreOriginProcessor.php | 50 +++++ .../Operator/PHP/PatternMatches.php | 23 ++ .../CoreBundle/Resources/config/services.yml | 13 ++ .../RuleBasedIgnoreOriginProcessorTest.php | 212 ++++++++++++++++++ 6 files changed, 300 insertions(+), 4 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessor.php create mode 100644 src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php create mode 100644 tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php diff --git a/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php b/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php index 34aed50c6..ce3b6e7d7 100644 --- a/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php +++ b/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php @@ -11,7 +11,6 @@ use Symfony\Component\Validator\Constraints as Assert; * * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository") * @ORM\Table(name="`ignore_origin_instance_rule`") - * @ORM\Entity */ class IgnoreOriginInstanceRule implements IgnoreOriginRuleInterface, RuleInterface { @@ -30,7 +29,7 @@ class IgnoreOriginInstanceRule implements IgnoreOriginRuleInterface, RuleInterfa * @Assert\NotBlank() * @Assert\Length(max=255) * @RulerZAssert\ValidRule( - * allowed_variables={"host","pattern"}, + * allowed_variables={"host","_all"}, * allowed_operators={"=","~"} * ) * @ORM\Column(name="rule", type="string", nullable=false) diff --git a/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php b/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php index befd60905..0b6f318dc 100644 --- a/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php +++ b/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php @@ -11,7 +11,6 @@ use Symfony\Component\Validator\Constraints as Assert; * * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\IgnoreOriginUserRuleRepository") * @ORM\Table(name="`ignore_origin_user_rule`") - * @ORM\Entity */ class IgnoreOriginUserRule implements IgnoreOriginRuleInterface, RuleInterface { @@ -30,7 +29,7 @@ class IgnoreOriginUserRule implements IgnoreOriginRuleInterface, RuleInterface * @Assert\NotBlank() * @Assert\Length(max=255) * @RulerZAssert\ValidRule( - * allowed_variables={"host","pattern"}, + * allowed_variables={"host","_all"}, * allowed_operators={"=","~"} * ) * @ORM\Column(name="rule", type="string", nullable=false) diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessor.php b/src/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessor.php new file mode 100644 index 000000000..333e5b0ae --- /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 000000000..532e2bb39 --- /dev/null +++ b/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php @@ -0,0 +1,23 @@ + 0; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 4ece046a8..8417ac35c 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -92,6 +92,7 @@ services: arguments: - "@wallabag_core.graby" - "@wallabag_core.rule_based_tagger" + - "@wallabag_core.rule_based_ignore_origin_processor" - "@validator" - "@logger" - '%wallabag_core.fetching_error_message%' @@ -110,6 +111,13 @@ services: - "@wallabag_core.entry_repository" - "@logger" + wallabag_core.rule_based_ignore_origin_processor: + class: Wallabag\CoreBundle\Helper\RuleBasedIgnoreOriginProcessor + arguments: + - "@rulerz" + - "@logger" + - "@wallabag_core.ignore_origin_instance_rule_repository" + # repository as a service wallabag_core.entry_repository: class: Wallabag\CoreBundle\Repository\EntryRepository @@ -164,6 +172,11 @@ services: tags: - { name: rulerz.operator, target: doctrine, operator: notmatches, inline: true } + wallabag.operator.array.pattern_matches: + class: Wallabag\CoreBundle\Operator\PHP\PatternMatches + tags: + - { name: rulerz.operator, target: native, operator: "~" } + wallabag_core.helper.redirect: class: Wallabag\CoreBundle\Helper\Redirect arguments: diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php new file mode 100644 index 000000000..9e39bc811 --- /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'); + } +} From 2495b197614d82b99eed6bbec4562078f4429ad7 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 11 Aug 2019 23:55:12 +0200 Subject: [PATCH 4/8] Add default system-wide ignore origin rules with install support Signed-off-by: Kevin Decherf --- app/config/wallabag.yml | 8 +++++ .../CoreBundle/Command/InstallCommand.php | 8 +++++ .../IgnoreOriginInstanceRuleFixtures.php | 36 +++++++++++++++++++ .../DependencyInjection/Configuration.php | 7 ++++ .../WallabagCoreExtension.php | 1 + 5 files changed, 60 insertions(+) create mode 100644 src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php diff --git a/app/config/wallabag.yml b/app/config/wallabag.yml index eaa925072..4dad92001 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 3aa332f13..8d08187a9 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/DataFixtures/IgnoreOriginInstanceRuleFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php new file mode 100644 index 000000000..8a0a06ed9 --- /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/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index 7ae73371c..857472567 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 e9a1e9e05..af91e5886 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'); From b22eb276232b5c15a6fbadc9dd10144e709faec3 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 11 Aug 2019 23:55:52 +0200 Subject: [PATCH 5/8] ContentProxy: replace ignoreUrl with new RuleBasedIgnoreOriginProcessor Signed-off-by: Kevin Decherf --- .../CoreBundle/Helper/ContentProxy.php | 41 +----- .../CoreBundle/Helper/ContentProxyTest.php | 127 ++++++++++++++---- 2 files changed, 108 insertions(+), 60 deletions(-) diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 9c6fa8db1..7e93249dd 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/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 9ce72c79c..a65ac17cf 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(); From 7408a6cb687959eac6bc7a2ed370695bbf88b6d6 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Tue, 27 Aug 2019 00:03:30 +0200 Subject: [PATCH 6/8] Add controller, views and translations for ignore origin instance rules Signed-off-by: Kevin Decherf --- app/config/security.yml | 1 + .../IgnoreOriginInstanceRuleController.php | 138 ++++++++++++++++ .../Type/IgnoreOriginInstanceRuleType.php | 37 +++++ .../Resources/translations/messages.da.yml | 6 + .../Resources/translations/messages.de.yml | 6 + .../Resources/translations/messages.en.yml | 24 +++ .../Resources/translations/messages.es.yml | 6 + .../Resources/translations/messages.fa.yml | 6 + .../Resources/translations/messages.fr.yml | 4 +- .../Resources/translations/messages.it.yml | 6 + .../Resources/translations/messages.oc.yml | 6 + .../Resources/translations/messages.pl.yml | 6 + .../Resources/translations/messages.pt.yml | 6 + .../Resources/translations/messages.ro.yml | 6 + .../Resources/translations/messages.ru.yml | 6 + .../Resources/translations/messages.th.yml | 6 + .../Resources/translations/messages.tr.yml | 6 + .../IgnoreOriginInstanceRule/edit.html.twig | 44 ++++++ .../IgnoreOriginInstanceRule/index.html.twig | 42 +++++ .../IgnoreOriginInstanceRule/new.html.twig | 37 +++++ .../views/themes/baggy/layout.html.twig | 1 + .../IgnoreOriginInstanceRule/edit.html.twig | 44 ++++++ .../IgnoreOriginInstanceRule/index.html.twig | 42 +++++ .../IgnoreOriginInstanceRule/new.html.twig | 37 +++++ .../views/themes/material/layout.html.twig | 6 +- ...IgnoreOriginInstanceRuleControllerTest.php | 148 ++++++++++++++++++ 26 files changed, 673 insertions(+), 4 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php create mode 100644 src/Wallabag/CoreBundle/Form/Type/IgnoreOriginInstanceRuleType.php create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/edit.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/index.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/index.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig create mode 100644 tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php diff --git a/app/config/security.yml b/app/config/security.yml index 760b25503..5a73440b2 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/src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php b/src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php new file mode 100644 index 000000000..ef1f0ed74 --- /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/Form/Type/IgnoreOriginInstanceRuleType.php b/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginInstanceRuleType.php new file mode 100644 index 000000000..d2e414fb7 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginInstanceRuleType.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\IgnoreOriginInstanceRule', + ]); + } + + public function getBlockPrefix() + { + return 'ignore_origin_instance_rule'; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 92440c92c..05ee0b10b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -33,6 +33,7 @@ menu: back_to_unread: 'Tilbage til de ulæste artikler' # users_management: 'Users management' # site_credentials: 'Site credentials' + # ignore_origin_instance_rules: 'Global ignore origin rules' # quickstart: "Quickstart" top: add_new_entry: 'Tilføj ny artikel' @@ -661,3 +662,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 7a9382cb3..908be26e6 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' @@ -661,3 +662,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 b16662c31..d831a2aae 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' @@ -595,6 +596,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 @@ -661,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.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 3e77afd6b..4de4dcb59 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' @@ -661,3 +662,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 38c252f73..32dcdb3c3 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: 'افزودن مقالهٔ تازه' @@ -661,3 +662,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 b12dd9ca9..dfdf20836 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" @@ -619,11 +620,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 -<<<<<<< HEAD -======= ignore_origin_rules_deleted: "Règle d'omission d'origine supprimée" ignore_origin_rules_updated: "Règle d'omission d'origine mise à jour" ->>>>>>> 4c595340... fixup! Add new Ignore Origin rules tab, update ConfigController 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 eb44318b9..42a50ca56 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' @@ -661,3 +662,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 165186b1d..df3553c8e 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' @@ -661,3 +662,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 fbf64f30b..41977edec 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' @@ -661,3 +662,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 93910d4be..78918e15a 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' @@ -658,3 +659,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 5984d2298..5400187ab 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' @@ -660,3 +661,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 a138ee5d3..ce803ecda 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: 'Добавить новую запись' @@ -660,3 +661,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 b786a73d1..7c887781b 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: 'เพิ่มรายการใหม่' @@ -660,3 +661,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 a317c2f50..f2ce40d90 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' @@ -660,3 +661,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/IgnoreOriginInstanceRule/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/edit.html.twig new file mode 100644 index 000000000..ebb07d07e --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/edit.html.twig @@ -0,0 +1,44 @@ +{% 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 }}

    +
    +
    +
    +
    +
    +
    + +{% 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 000000000..2de7cf0a4 --- /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 000000000..fbe1f795c --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig @@ -0,0 +1,37 @@ +{% 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 }}

    +
    +
    +
    +
    +
    +
    + +{% 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 6b1e2bd79..e1446ff7c 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/IgnoreOriginInstanceRule/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig new file mode 100644 index 000000000..ebb07d07e --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig @@ -0,0 +1,44 @@ +{% 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 }}

    +
    +
    +
    +
    +
    +
    + +{% 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 000000000..2de7cf0a4 --- /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 000000000..fbe1f795c --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig @@ -0,0 +1,37 @@ +{% 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 }}

    +
    +
    +
    +
    +
    +
    + +{% 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 c51d07fc2..d9b6d190a 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/Controller/IgnoreOriginInstanceRuleControllerTest.php b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php new file mode 100644 index 000000000..9783cd251 --- /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]); + } + } +} From 25c754f62f2230b76d357d6201432fa141f865f2 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Thu, 19 Sep 2019 23:14:10 +0200 Subject: [PATCH 7/8] views: Add doc and translations on ignore origin rules forms Signed-off-by: Kevin Decherf --- .../Resources/translations/messages.da.yml | 18 ++++++++ .../Resources/translations/messages.de.yml | 18 ++++++++ .../Resources/translations/messages.en.yml | 18 ++++++++ .../Resources/translations/messages.es.yml | 18 ++++++++ .../Resources/translations/messages.fa.yml | 18 ++++++++ .../Resources/translations/messages.fr.yml | 18 ++++++++ .../Resources/translations/messages.it.yml | 18 ++++++++ .../Resources/translations/messages.oc.yml | 18 ++++++++ .../Resources/translations/messages.pl.yml | 18 ++++++++ .../Resources/translations/messages.pt.yml | 18 ++++++++ .../Resources/translations/messages.ro.yml | 18 ++++++++ .../Resources/translations/messages.ru.yml | 18 ++++++++ .../Resources/translations/messages.th.yml | 18 ++++++++ .../Resources/translations/messages.tr.yml | 18 ++++++++ .../views/themes/baggy/Config/index.html.twig | 43 ++++++++++++++++++ .../IgnoreOriginInstanceRule/edit.html.twig | 43 ++++++++++++++++++ .../IgnoreOriginInstanceRule/new.html.twig | 43 ++++++++++++++++++ .../themes/material/Config/index.html.twig | 45 +++++++++++++++++++ .../IgnoreOriginInstanceRule/edit.html.twig | 43 ++++++++++++++++++ .../IgnoreOriginInstanceRule/new.html.twig | 43 ++++++++++++++++++ 20 files changed, 512 insertions(+) diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 05ee0b10b..54df2e649 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 908be26e6..549704d0d 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index d831a2aae..a68a7d7de 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 4de4dcb59..c3e3ba816 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 32dcdb3c3..4a52a2081 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index dfdf20836..2cfab8cf4 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 42a50ca56..af1c1fe74 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index df3553c8e..59dd9b221 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 41977edec..c09ef47ab 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index 78918e15a..293a4e443 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 5400187ab..3c6057093 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml index ce803ecda..eead4ec68 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml index 7c887781b..8d2b05f3f 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml @@ -179,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: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index f2ce40d90..dfbc30108 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -179,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: 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 f182fda40..b6edce39e 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 @@ -431,6 +431,49 @@ {{ 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 index ebb07d07e..30c2a520f 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/edit.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/edit.html.twig @@ -37,6 +37,49 @@
  • + +
    +
    +

    {{ '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 }}
    +
    +
    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 index fbe1f795c..cb052ff05 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig @@ -30,6 +30,49 @@ + +
    +
    +

    {{ '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 }}
    +
    +
    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 faf9a4240..22b38a1b6 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 @@ -502,6 +502,51 @@ {{ 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 }}
    +
    +
    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 index ebb07d07e..30c2a520f 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig @@ -37,6 +37,49 @@
    + +
    +
    +

    {{ '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 }}
    +
    +
    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 index fbe1f795c..cb052ff05 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig @@ -30,6 +30,49 @@ + +
    +
    +

    {{ '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 }}
    +
    +
    From 71f7e58fbd84e1d15c7a405a3c5872adb937dc37 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Tue, 10 Mar 2020 22:22:51 +0100 Subject: [PATCH 8/8] tests: add a NetworkCalls group for tests making network calls Excluding this group can decrease the run time of tests during development. Signed-off-by: Kevin Decherf --- .../Command/ReloadEntryCommandTest.php | 6 +++++ .../Controller/ConfigControllerTest.php | 3 +++ .../Controller/EntryControllerTest.php | 26 +++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php index c4bd6dace..a0e2939cf 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 40a1aa978..92d222679 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -812,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 5b8068307..0aa562d80 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() {