From 24230a5130005e274e1d8d3fe8eaca13cb978b9c Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 23 Jun 2019 22:13:44 +0200 Subject: [PATCH] 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 56efe82b..3efc7bb3 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -14,10 +14,13 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint; use Wallabag\CoreBundle\Entity\Config; +use Wallabag\CoreBundle\Entity\IgnoreOriginUserRule; +use Wallabag\CoreBundle\Entity\RuleInterface; use Wallabag\CoreBundle\Entity\TaggingRule; use Wallabag\CoreBundle\Form\Type\ChangePasswordType; use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\FeedType; +use Wallabag\CoreBundle\Form\Type\IgnoreOriginUserRuleType; use Wallabag\CoreBundle\Form\Type\TaggingRuleImportType; use Wallabag\CoreBundle\Form\Type\TaggingRuleType; use Wallabag\CoreBundle\Form\Type\UserInformationType; @@ -173,6 +176,40 @@ class ConfigController extends Controller return $this->redirect($this->generateUrl('config') . '#set5'); } + // handle ignore origin rules + $ignoreOriginUserRule = new IgnoreOriginUserRule(); + $action = $this->generateUrl('config') . '#set6'; + + if ($request->query->has('ignore-origin-user-rule')) { + $ignoreOriginUserRule = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule') + ->find($request->query->get('ignore-origin-user-rule')); + + if ($this->getUser()->getId() !== $ignoreOriginUserRule->getConfig()->getUser()->getId()) { + return $this->redirect($action); + } + + $action = $this->generateUrl('config', [ + 'ignore-origin-user-rule' => $ignoreOriginUserRule->getId(), + ]) . '#set6'; + } + + $newIgnoreOriginUserRule = $this->createForm(IgnoreOriginUserRuleType::class, $ignoreOriginUserRule, ['action' => $action]); + $newIgnoreOriginUserRule->handleRequest($request); + + if ($newIgnoreOriginUserRule->isSubmitted() && $newIgnoreOriginUserRule->isValid()) { + $ignoreOriginUserRule->setConfig($config); + $em->persist($ignoreOriginUserRule); + $em->flush(); + + $this->addFlash( + 'notice', + 'flashes.config.notice.ignore_origin_rules_updated' + ); + + return $this->redirect($this->generateUrl('config') . '#set6'); + } + return $this->render('WallabagCoreBundle:Config:index.html.twig', [ 'form' => [ 'config' => $configForm->createView(), @@ -181,6 +218,7 @@ class ConfigController extends Controller 'user' => $userForm->createView(), 'new_tagging_rule' => $newTaggingRule->createView(), 'import_tagging_rule' => $taggingRulesImportform->createView(), + 'new_ignore_origin_user_rule' => $newIgnoreOriginUserRule->createView(), ], 'feed' => [ 'username' => $user->getUsername(), @@ -447,6 +485,43 @@ class ConfigController extends Controller return $this->redirect($this->generateUrl('config') . '?tagging-rule=' . $rule->getId() . '#set5'); } + /** + * Deletes an ignore origin rule and redirect to the config homepage. + * + * @Route("/ignore-origin-user-rule/delete/{id}", requirements={"id" = "\d+"}, name="delete_ignore_origin_rule") + * + * @return RedirectResponse + */ + public function deleteIgnoreOriginRuleAction(IgnoreOriginUserRule $rule) + { + $this->validateRuleAction($rule); + + $em = $this->getDoctrine()->getManager(); + $em->remove($rule); + $em->flush(); + + $this->addFlash( + 'notice', + 'flashes.config.notice.ignore_origin_rules_deleted' + ); + + return $this->redirect($this->generateUrl('config') . '#set6'); + } + + /** + * Edit an ignore origin rule. + * + * @Route("/ignore-origin-user-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_ignore_origin_rule") + * + * @return RedirectResponse + */ + public function editIgnoreOriginRuleAction(IgnoreOriginUserRule $rule) + { + $this->validateRuleAction($rule); + + return $this->redirect($this->generateUrl('config') . '?ignore-origin-user-rule=' . $rule->getId() . '#set6'); + } + /** * Remove all annotations OR tags OR entries for the current user. * @@ -659,10 +734,10 @@ class ConfigController extends Controller /** * Validate that a rule can be edited/deleted by the current user. */ - private function validateRuleAction(TaggingRule $rule) + private function validateRuleAction(RuleInterface $rule) { if ($this->getUser()->getId() !== $rule->getConfig()->getUser()->getId()) { - throw $this->createAccessDeniedException('You can not access this tagging rule.'); + throw $this->createAccessDeniedException('You can not access this rule.'); } } diff --git a/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginUserRuleFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginUserRuleFixtures.php new file mode 100644 index 00000000..679eff7d --- /dev/null +++ b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginUserRuleFixtures.php @@ -0,0 +1,36 @@ +setRule('host = "example.fr"'); + $rule->setConfig($this->getReference('admin-user')->getConfig()); + + $manager->persist($rule); + + $manager->flush(); + } + + /** + * {@inheritdoc} + */ + public function getDependencies() + { + return [ + UserFixtures::class, + ]; + } +} diff --git a/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginUserRuleType.php b/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginUserRuleType.php new file mode 100644 index 00000000..b9110f17 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginUserRuleType.php @@ -0,0 +1,37 @@ +add('rule', TextType::class, [ + 'required' => true, + 'label' => 'config.form_rules.rule_label', + ]) + ->add('save', SubmitType::class, [ + 'label' => 'config.form.save', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => 'Wallabag\CoreBundle\Entity\IgnoreOriginUserRule', + ]); + } + + public function getBlockPrefix() + { + return 'ignore_origin_user_rule'; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 4d525979..92440c92 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 cd70c99f..7a9382cb 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 1bc32423..b16662c3 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 bced72e9..3e77afd6 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 0704204a..38c252f7 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 5d5878eb..b12dd9ca 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 23e72f20..eb44318b 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 6ddff6ea..165186b1 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 770477c9..fbf64f30 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 d993cb05..93910d4b 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 bc8b72e0..5984d229 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 2f7f55e5..a138ee5d 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 48e1c34a..b786a73d 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 19029c0b..a317c2f5 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 eb395eac..f182fda4 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 }}

+ + + + {{ 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 c2e92ad1..faf9a424 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 b3b3a19a..40a1aa97 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() -- 2.41.0