diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-01 16:47:48 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-01 16:52:05 +0200 |
commit | bf3dc999e7b25888460faff2251f75e4a79491c4 (patch) | |
tree | e529f9a322f7359141254ed6f05cc2c15ba845c3 | |
parent | c4bf7af96f52aaafd13049e74f27b368eec79bf8 (diff) | |
download | wallabag-bf3dc999e7b25888460faff2251f75e4a79491c4.tar.gz wallabag-bf3dc999e7b25888460faff2251f75e4a79491c4.tar.zst wallabag-bf3dc999e7b25888460faff2251f75e4a79491c4.zip |
Add ability to edit a tagging rule
14 files changed, 95 insertions, 14 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 75a9af0b..28e33998 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -108,7 +108,21 @@ class ConfigController extends Controller | |||
108 | 108 | ||
109 | // handle tagging rule | 109 | // handle tagging rule |
110 | $taggingRule = new TaggingRule(); | 110 | $taggingRule = new TaggingRule(); |
111 | $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $this->generateUrl('config').'#set5']); | 111 | $action = $this->generateUrl('config').'#set5'; |
112 | |||
113 | if ($request->query->has('tagging-rule')) { | ||
114 | $taggingRule = $this->getDoctrine() | ||
115 | ->getRepository('WallabagCoreBundle:TaggingRule') | ||
116 | ->find($request->query->get('tagging-rule')); | ||
117 | |||
118 | if ($this->getUser()->getId() !== $taggingRule->getConfig()->getUser()->getId()) { | ||
119 | return $this->redirect($action); | ||
120 | } | ||
121 | |||
122 | $action = $this->generateUrl('config').'?tagging-rule='.$taggingRule->getId().'#set5'; | ||
123 | } | ||
124 | |||
125 | $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]); | ||
112 | $newTaggingRule->handleRequest($request); | 126 | $newTaggingRule->handleRequest($request); |
113 | 127 | ||
114 | if ($newTaggingRule->isValid()) { | 128 | if ($newTaggingRule->isValid()) { |
@@ -222,6 +236,24 @@ class ConfigController extends Controller | |||
222 | } | 236 | } |
223 | 237 | ||
224 | /** | 238 | /** |
239 | * Edit a tagging rule. | ||
240 | * | ||
241 | * @param TaggingRule $rule | ||
242 | * | ||
243 | * @Route("/tagging-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_tagging_rule") | ||
244 | * | ||
245 | * @return RedirectResponse | ||
246 | */ | ||
247 | public function editTaggingRuleAction(TaggingRule $rule) | ||
248 | { | ||
249 | if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { | ||
250 | throw $this->createAccessDeniedException('You can not access this tagging rule.'); | ||
251 | } | ||
252 | |||
253 | return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5'); | ||
254 | } | ||
255 | |||
256 | /** | ||
225 | * Retrieve config for the current user. | 257 | * Retrieve config for the current user. |
226 | * If no config were found, create a new one. | 258 | * If no config were found, create a new one. |
227 | * | 259 | * |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 7ad5c100..98ccfb1d 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | # if_label: 'if' | 94 | # if_label: 'if' |
95 | # then_tag_as_label: 'then tag as' | 95 | # then_tag_as_label: 'then tag as' |
96 | # delete_rule_label: 'delete' | 96 | # delete_rule_label: 'delete' |
97 | # edit_rule_label: 'edit' | ||
97 | # rule_label: 'Rule' | 98 | # rule_label: 'Rule' |
98 | # tags_label: 'Tags' | 99 | # tags_label: 'Tags' |
99 | # faq: | 100 | # faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 650e4761..1dcd7dbe 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | if_label: 'Wenn' | 94 | if_label: 'Wenn' |
95 | then_tag_as_label: 'dann tagge als' | 95 | then_tag_as_label: 'dann tagge als' |
96 | delete_rule_label: 'löschen' | 96 | delete_rule_label: 'löschen' |
97 | # edit_rule_label: 'edit' | ||
97 | rule_label: 'Regel' | 98 | rule_label: 'Regel' |
98 | tags_label: 'Tags' | 99 | tags_label: 'Tags' |
99 | faq: | 100 | faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index d5842cc5..e75166bf 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | if_label: 'if' | 94 | if_label: 'if' |
95 | then_tag_as_label: 'then tag as' | 95 | then_tag_as_label: 'then tag as' |
96 | delete_rule_label: 'delete' | 96 | delete_rule_label: 'delete' |
97 | edit_rule_label: 'edit' | ||
97 | rule_label: 'Rule' | 98 | rule_label: 'Rule' |
98 | tags_label: 'Tags' | 99 | tags_label: 'Tags' |
99 | faq: | 100 | faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index bd691c1c..0884e9e6 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | if_label: 'si' | 94 | if_label: 'si' |
95 | then_tag_as_label: 'Etiquete como' | 95 | then_tag_as_label: 'Etiquete como' |
96 | delete_rule_label: 'Borre' | 96 | delete_rule_label: 'Borre' |
97 | # edit_rule_label: 'edit' | ||
97 | rule_label: 'Regla' | 98 | rule_label: 'Regla' |
98 | tags_label: 'Etiquetas' | 99 | tags_label: 'Etiquetas' |
99 | faq: | 100 | faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index a9989a83..1d30d5b2 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | if_label: 'اگر' | 94 | if_label: 'اگر' |
95 | then_tag_as_label: 'این برچسب را بزن' | 95 | then_tag_as_label: 'این برچسب را بزن' |
96 | delete_rule_label: 'پاک کن' | 96 | delete_rule_label: 'پاک کن' |
97 | # edit_rule_label: 'edit' | ||
97 | rule_label: 'قانون' | 98 | rule_label: 'قانون' |
98 | tags_label: 'برچسبها' | 99 | tags_label: 'برچسبها' |
99 | faq: | 100 | faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index b70ca64d..c3647731 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | if_label: 'si' | 94 | if_label: 'si' |
95 | then_tag_as_label: 'alors attribuer les tags' | 95 | then_tag_as_label: 'alors attribuer les tags' |
96 | delete_rule_label: 'supprimer' | 96 | delete_rule_label: 'supprimer' |
97 | edit_rule_label: 'éditer' | ||
97 | rule_label: 'Règle' | 98 | rule_label: 'Règle' |
98 | tags_label: 'Tags' | 99 | tags_label: 'Tags' |
99 | faq: | 100 | faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 118098fe..2c99e9a8 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | if_label: 'se' | 94 | if_label: 'se' |
95 | then_tag_as_label: 'allora tagga come' | 95 | then_tag_as_label: 'allora tagga come' |
96 | delete_rule_label: 'elimina' | 96 | delete_rule_label: 'elimina' |
97 | # edit_rule_label: 'edit' | ||
97 | rule_label: 'Regola' | 98 | rule_label: 'Regola' |
98 | tags_label: 'Tag' | 99 | tags_label: 'Tag' |
99 | faq: | 100 | faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 93467dac..ebebcbc0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | if_label: 'se' | 94 | if_label: 'se' |
95 | then_tag_as_label: 'alara atribuir las etiquetas' | 95 | then_tag_as_label: 'alara atribuir las etiquetas' |
96 | delete_rule_label: 'suprimir' | 96 | delete_rule_label: 'suprimir' |
97 | # edit_rule_label: 'edit' | ||
97 | rule_label: 'Règla' | 98 | rule_label: 'Règla' |
98 | tags_label: 'Etiquetas' | 99 | tags_label: 'Etiquetas' |
99 | faq: | 100 | faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 27507a81..0a76b673 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | if_label: 'jeżeli' | 94 | if_label: 'jeżeli' |
95 | then_tag_as_label: 'wtedy otaguj jako' | 95 | then_tag_as_label: 'wtedy otaguj jako' |
96 | delete_rule_label: 'usuń' | 96 | delete_rule_label: 'usuń' |
97 | # edit_rule_label: 'edit' | ||
97 | rule_label: 'Reguła' | 98 | rule_label: 'Reguła' |
98 | tags_label: 'Tagi' | 99 | tags_label: 'Tagi' |
99 | faq: | 100 | faq: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 7c77ffb7..d107a96e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml | |||
@@ -94,6 +94,7 @@ config: | |||
94 | # if_label: 'if' | 94 | # if_label: 'if' |
95 | # then_tag_as_label: 'then tag as' | 95 | # then_tag_as_label: 'then tag as' |
96 | # delete_rule_label: 'delete' | 96 | # delete_rule_label: 'delete' |
97 | # edit_rule_label: 'edit' | ||
97 | # rule_label: 'Rule' | 98 | # rule_label: 'Rule' |
98 | # tags_label: 'Tags' | 99 | # tags_label: 'Tags' |
99 | # faq: | 100 | # faq: |
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 6446cf2c..dd4f7b00 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 | |||
@@ -191,6 +191,7 @@ | |||
191 | « {{ tagging_rule.rule }} » | 191 | « {{ tagging_rule.rule }} » |
192 | {{ 'config.form_rules.then_tag_as_label'|trans }} | 192 | {{ 'config.form_rules.then_tag_as_label'|trans }} |
193 | « {{ tagging_rule.tags|join(', ') }} » | 193 | « {{ tagging_rule.tags|join(', ') }} » |
194 | <a href="{{ path('edit_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.edit_rule_label'|trans }}" class="tool mode_edit">✎</a> | ||
194 | <a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}" class="tool delete icon-trash icon"></a> | 195 | <a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}" class="tool delete icon-trash icon"></a> |
195 | </li> | 196 | </li> |
196 | {% endfor %} | 197 | {% endfor %} |
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 5330c353..650a3ae2 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 | |||
@@ -218,6 +218,9 @@ | |||
218 | « {{ tagging_rule.rule }} » | 218 | « {{ tagging_rule.rule }} » |
219 | {{ 'config.form_rules.then_tag_as_label'|trans }} | 219 | {{ 'config.form_rules.then_tag_as_label'|trans }} |
220 | « {{ tagging_rule.tags|join(', ') }} » | 220 | « {{ tagging_rule.tags|join(', ') }} » |
221 | <a href="{{ path('edit_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.edit_rule_label'|trans }}"> | ||
222 | <i class="tool grey-text mode_edit material-icons">mode_edit</i> | ||
223 | </a> | ||
221 | <a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}"> | 224 | <a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}"> |
222 | <i class="tool grey-text delete material-icons">delete</i> | 225 | <i class="tool grey-text delete material-icons">delete</i> |
223 | </a> | 226 | </a> |
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 7193f9b0..bb3ea9e2 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -56,8 +56,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
56 | 56 | ||
57 | $crawler = $client->followRedirect(); | 57 | $crawler = $client->followRedirect(); |
58 | 58 | ||
59 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 59 | $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]); |
60 | $this->assertContains('flashes.config.notice.config_saved', $alert[0]); | ||
61 | } | 60 | } |
62 | 61 | ||
63 | public function testChangeReadingSpeed() | 62 | public function testChangeReadingSpeed() |
@@ -213,8 +212,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
213 | 212 | ||
214 | $crawler = $client->followRedirect(); | 213 | $crawler = $client->followRedirect(); |
215 | 214 | ||
216 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 215 | $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]); |
217 | $this->assertContains('flashes.config.notice.password_updated', $alert[0]); | ||
218 | } | 216 | } |
219 | 217 | ||
220 | public function dataForUserFailed() | 218 | public function dataForUserFailed() |
@@ -382,8 +380,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
382 | 380 | ||
383 | $crawler = $client->followRedirect(); | 381 | $crawler = $client->followRedirect(); |
384 | 382 | ||
385 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 383 | $this->assertContains('flashes.config.notice.user_added', $crawler->filter('body')->extract(['_text'])[0]); |
386 | $this->assertContains('flashes.config.notice.user_added', $alert[0]); | ||
387 | 384 | ||
388 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 385 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
389 | $user = $em | 386 | $user = $em |
@@ -474,8 +471,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
474 | 471 | ||
475 | $crawler = $client->followRedirect(); | 472 | $crawler = $client->followRedirect(); |
476 | 473 | ||
477 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 474 | $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); |
478 | $this->assertContains('flashes.config.notice.rss_updated', $alert[0]); | ||
479 | } | 475 | } |
480 | 476 | ||
481 | public function dataForRssFailed() | 477 | public function dataForRssFailed() |
@@ -540,8 +536,32 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
540 | 536 | ||
541 | $crawler = $client->followRedirect(); | 537 | $crawler = $client->followRedirect(); |
542 | 538 | ||
543 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 539 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); |
544 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $alert[0]); | 540 | |
541 | $editLink = $crawler->filter('.mode_edit')->last()->link(); | ||
542 | |||
543 | $crawler = $client->click($editLink); | ||
544 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
545 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); | ||
546 | |||
547 | $crawler = $client->followRedirect(); | ||
548 | |||
549 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | ||
550 | |||
551 | $data = [ | ||
552 | 'tagging_rule[rule]' => 'readingTime <= 30', | ||
553 | 'tagging_rule[tags]' => 'short reading', | ||
554 | ]; | ||
555 | |||
556 | $client->submit($form, $data); | ||
557 | |||
558 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
559 | |||
560 | $crawler = $client->followRedirect(); | ||
561 | |||
562 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | ||
563 | |||
564 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); | ||
545 | 565 | ||
546 | $deleteLink = $crawler->filter('.delete')->last()->link(); | 566 | $deleteLink = $crawler->filter('.delete')->last()->link(); |
547 | 567 | ||
@@ -549,8 +569,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
549 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 569 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
550 | 570 | ||
551 | $crawler = $client->followRedirect(); | 571 | $crawler = $client->followRedirect(); |
552 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 572 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); |
553 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $alert[0]); | ||
554 | } | 573 | } |
555 | 574 | ||
556 | public function dataForTaggingRuleFailed() | 575 | public function dataForTaggingRuleFailed() |
@@ -613,7 +632,23 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
613 | ->getRepository('WallabagCoreBundle:TaggingRule') | 632 | ->getRepository('WallabagCoreBundle:TaggingRule') |
614 | ->findAll()[0]; | 633 | ->findAll()[0]; |
615 | 634 | ||
616 | $crawler = $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); | 635 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); |
636 | |||
637 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
638 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
639 | $this->assertContains('You can not access this tagging rule', $body[0]); | ||
640 | } | ||
641 | |||
642 | public function testEditingTaggingRuleFromAnOtherUser() | ||
643 | { | ||
644 | $this->logInAs('bob'); | ||
645 | $client = $this->getClient(); | ||
646 | |||
647 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | ||
648 | ->getRepository('WallabagCoreBundle:TaggingRule') | ||
649 | ->findAll()[0]; | ||
650 | |||
651 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); | ||
617 | 652 | ||
618 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 653 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); |
619 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 654 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |