From 7408a6cb687959eac6bc7a2ed370695bbf88b6d6 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Tue, 27 Aug 2019 00:03:30 +0200 Subject: [PATCH] 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 760b2550..5a73440b 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -79,4 +79,5 @@ security: - { path: ^/annotations, roles: ROLE_USER } - { path: ^/2fa, role: IS_AUTHENTICATED_2FA_IN_PROGRESS } - { path: ^/users, roles: ROLE_SUPER_ADMIN } + - { path: ^/ignore-origin-instance-rules, roles: ROLE_SUPER_ADMIN } - { path: ^/, roles: ROLE_USER } diff --git a/src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php b/src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php new file mode 100644 index 00000000..ef1f0ed7 --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php @@ -0,0 +1,138 @@ +get('wallabag_core.ignore_origin_instance_rule_repository')->findAll(); + + return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:index.html.twig', [ + 'rules' => $rules, + ]); + } + + /** + * Creates a new ignore origin instance rule entity. + * + * @Route("/new", name="ignore_origin_instance_rules_new", methods={"GET", "POST"}) + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function newAction(Request $request) + { + $ignoreOriginInstanceRule = new IgnoreOriginInstanceRule(); + + $form = $this->createForm('Wallabag\CoreBundle\Form\Type\IgnoreOriginInstanceRuleType', $ignoreOriginInstanceRule); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($ignoreOriginInstanceRule); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.added') + ); + + return $this->redirectToRoute('ignore_origin_instance_rules_index'); + } + + return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:new.html.twig', [ + 'rule' => $ignoreOriginInstanceRule, + 'form' => $form->createView(), + ]); + } + + /** + * Displays a form to edit an existing ignore origin instance rule entity. + * + * @Route("/{id}/edit", name="ignore_origin_instance_rules_edit", methods={"GET", "POST"}) + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function editAction(Request $request, IgnoreOriginInstanceRule $ignoreOriginInstanceRule) + { + $deleteForm = $this->createDeleteForm($ignoreOriginInstanceRule); + $editForm = $this->createForm('Wallabag\CoreBundle\Form\Type\IgnoreOriginInstanceRuleType', $ignoreOriginInstanceRule); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($ignoreOriginInstanceRule); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.updated') + ); + + return $this->redirectToRoute('ignore_origin_instance_rules_index'); + } + + return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:edit.html.twig', [ + 'rule' => $ignoreOriginInstanceRule, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + ]); + } + + /** + * Deletes a site credential entity. + * + * @Route("/{id}", name="ignore_origin_instance_rules_delete", methods={"DELETE"}) + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function deleteAction(Request $request, IgnoreOriginInstanceRule $ignoreOriginInstanceRule) + { + $form = $this->createDeleteForm($ignoreOriginInstanceRule); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->get('session')->getFlashBag()->add( + 'notice', + $this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.deleted') + ); + + $em = $this->getDoctrine()->getManager(); + $em->remove($ignoreOriginInstanceRule); + $em->flush(); + } + + return $this->redirectToRoute('ignore_origin_instance_rules_index'); + } + + /** + * Creates a form to delete a ignore origin instance rule entity. + * + * @param IgnoreOriginInstanceRule $ignoreOriginInstanceRule The ignore origin instance rule entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(IgnoreOriginInstanceRule $ignoreOriginInstanceRule) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('ignore_origin_instance_rules_delete', ['id' => $ignoreOriginInstanceRule->getId()])) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginInstanceRuleType.php b/src/Wallabag/CoreBundle/Form/Type/IgnoreOriginInstanceRuleType.php new file mode 100644 index 00000000..d2e414fb --- /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 92440c92..05ee0b10 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 7a9382cb..908be26e 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 b16662c3..d831a2aa 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 3e77afd6..4de4dcb5 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 38c252f7..32dcdb3c 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 b12dd9ca..dfdf2083 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 eb44318b..42a50ca5 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 165186b1..df3553c8 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 fbf64f30..41977ede 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 93910d4b..78918e15 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 5984d229..5400187a 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 a138ee5d..ce803ecd 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 b786a73d..7c887781 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 a317c2f5..f2ce40d9 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 00000000..ebb07d07 --- /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 00000000..2de7cf0a --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/index.html.twig @@ -0,0 +1,42 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'ignore_origin_instance_rule.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

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

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

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

+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/IgnoreOriginInstanceRule/new.html.twig new file mode 100644 index 00000000..fbe1f795 --- /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 6b1e2bd7..e1446ff7 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig @@ -45,6 +45,7 @@ {% if is_granted('ROLE_SUPER_ADMIN') %} + {% endif %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/edit.html.twig new file mode 100644 index 00000000..ebb07d07 --- /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 00000000..2de7cf0a --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/index.html.twig @@ -0,0 +1,42 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'ignore_origin_instance_rule.page_title'|trans }}{% endblock %} + +{% block content %} + +
+
+
+
+
+

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

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

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

+
+
+
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/IgnoreOriginInstanceRule/new.html.twig new file mode 100644 index 00000000..fbe1f795 --- /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 c51d07fc..d9b6d190 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig @@ -78,9 +78,13 @@ {{ 'menu.left.users_management'|trans }} -
  • +
  • {{ 'menu.left.internal_settings'|trans }}
  • + +
  • + {{ 'menu.left.ignore_origin_instance_rules'|trans }} +
  • {% endif %}
  • {{ 'menu.left.import'|trans }} diff --git a/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php new file mode 100644 index 00000000..9783cd25 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php @@ -0,0 +1,148 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/ignore-origin-instance-rules/'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('ignore_origin_instance_rule.description', $body); + $this->assertContains('ignore_origin_instance_rule.list.create_new_one', $body); + } + + public function testIgnoreOriginInstanceRuleCreationEditionDeletion() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + // Creation + $crawler = $client->request('GET', '/ignore-origin-instance-rules/new'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('ignore_origin_instance_rule.new_ignore_origin_instance_rule', $body); + $this->assertContains('ignore_origin_instance_rule.form.back_to_list', $body); + + $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form(); + + $data = [ + 'ignore_origin_instance_rule[rule]' => 'host = "foo.example.com"', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.ignore_origin_instance_rule.notice.added', $crawler->filter('body')->extract(['_text'])[0]); + + // Edition + $editLink = $crawler->filter('div[id=content] table a')->last()->link(); + + $crawler = $client->click($editLink); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->assertContains('foo.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('ignore_origin_instance_rule.edit_ignore_origin_instance_rule', $body); + $this->assertContains('ignore_origin_instance_rule.form.back_to_list', $body); + + $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form(); + + $data = [ + 'ignore_origin_instance_rule[rule]' => 'host = "bar.example.com"', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.ignore_origin_instance_rule.notice.updated', $crawler->filter('body')->extract(['_text'])[0]); + + $editLink = $crawler->filter('div[id=content] table a')->last()->link(); + + $crawler = $client->click($editLink); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->assertContains('bar.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]); + + $deleteForm = $crawler->filter('body')->selectButton('ignore_origin_instance_rule.form.delete')->form(); + + $client->submit($deleteForm, []); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.ignore_origin_instance_rule.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); + } + + public function dataForIgnoreOriginInstanceRuleCreationFail() + { + return [ + [ + [ + 'ignore_origin_instance_rule[rule]' => 'foo = "bar"', + ], + [ + 'The variable', + 'does not exist.', + ], + ], + [ + [ + 'ignore_origin_instance_rule[rule]' => '_all != "none"', + ], + [ + 'The operator', + 'does not exist.', + ], + ], + ]; + } + + /** + * @dataProvider dataForIgnoreOriginInstanceRuleCreationFail + */ + public function testIgnoreOriginInstanceRuleCreationFail($data, $messages) + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/ignore-origin-instance-rules/new'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form(); + + $crawler = $client->submit($form, $data); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + + foreach ($messages as $message) { + $this->assertContains($message, $body[0]); + } + } +} -- 2.41.0