aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php48
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.da.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.de.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.en.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.es.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.it.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig1
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig3
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php61
14 files changed, 106 insertions, 17 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 75a9af0b..f1e212d9 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()) {
@@ -205,9 +219,7 @@ class ConfigController extends Controller
205 */ 219 */
206 public function deleteTaggingRuleAction(TaggingRule $rule) 220 public function deleteTaggingRuleAction(TaggingRule $rule)
207 { 221 {
208 if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { 222 $this->validateRuleAction($rule);
209 throw $this->createAccessDeniedException('You can not access this tagging rule.');
210 }
211 223
212 $em = $this->getDoctrine()->getManager(); 224 $em = $this->getDoctrine()->getManager();
213 $em->remove($rule); 225 $em->remove($rule);
@@ -222,6 +234,34 @@ class ConfigController extends Controller
222 } 234 }
223 235
224 /** 236 /**
237 * Edit a tagging rule.
238 *
239 * @param TaggingRule $rule
240 *
241 * @Route("/tagging-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_tagging_rule")
242 *
243 * @return RedirectResponse
244 */
245 public function editTaggingRuleAction(TaggingRule $rule)
246 {
247 $this->validateRuleAction($rule);
248
249 return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5');
250 }
251
252 /**
253 * Validate that a rule can be edited/deleted by the current user.
254 *
255 * @param TaggingRule $rule
256 */
257 private function validateRuleAction(TaggingRule $rule)
258 {
259 if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) {
260 throw $this->createAccessDeniedException('You can not access this tagging rule.');
261 }
262 }
263
264 /**
225 * Retrieve config for the current user. 265 * Retrieve config for the current user.
226 * If no config were found, create a new one. 266 * If no config were found, create a new one.
227 * 267 *
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
index 72374a4a..628cdbdb 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
@@ -95,6 +95,7 @@ config:
95 # if_label: 'if' 95 # if_label: 'if'
96 # then_tag_as_label: 'then tag as' 96 # then_tag_as_label: 'then tag as'
97 # delete_rule_label: 'delete' 97 # delete_rule_label: 'delete'
98 # edit_rule_label: 'edit'
98 # rule_label: 'Rule' 99 # rule_label: 'Rule'
99 # tags_label: 'Tags' 100 # tags_label: 'Tags'
100 # faq: 101 # faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
index 3013e780..2e683b8c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
@@ -95,6 +95,7 @@ config:
95 if_label: 'Wenn' 95 if_label: 'Wenn'
96 then_tag_as_label: 'dann tagge als' 96 then_tag_as_label: 'dann tagge als'
97 delete_rule_label: 'löschen' 97 delete_rule_label: 'löschen'
98 # edit_rule_label: 'edit'
98 rule_label: 'Regel' 99 rule_label: 'Regel'
99 tags_label: 'Tags' 100 tags_label: 'Tags'
100 faq: 101 faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
index 7bd85cd6..d629312c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
@@ -95,6 +95,7 @@ config:
95 if_label: 'if' 95 if_label: 'if'
96 then_tag_as_label: 'then tag as' 96 then_tag_as_label: 'then tag as'
97 delete_rule_label: 'delete' 97 delete_rule_label: 'delete'
98 edit_rule_label: 'edit'
98 rule_label: 'Rule' 99 rule_label: 'Rule'
99 tags_label: 'Tags' 100 tags_label: 'Tags'
100 faq: 101 faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
index cab0f302..860c466f 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
@@ -95,6 +95,7 @@ config:
95 if_label: 'si' 95 if_label: 'si'
96 then_tag_as_label: 'Etiquete como' 96 then_tag_as_label: 'Etiquete como'
97 delete_rule_label: 'Borre' 97 delete_rule_label: 'Borre'
98 # edit_rule_label: 'edit'
98 rule_label: 'Regla' 99 rule_label: 'Regla'
99 tags_label: 'Etiquetas' 100 tags_label: 'Etiquetas'
100 faq: 101 faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
index 202f9d2d..6e02010c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
@@ -95,6 +95,7 @@ config:
95 if_label: 'اگر' 95 if_label: 'اگر'
96 then_tag_as_label: 'این برچسب را بزن' 96 then_tag_as_label: 'این برچسب را بزن'
97 delete_rule_label: 'پاک کن' 97 delete_rule_label: 'پاک کن'
98 # edit_rule_label: 'edit'
98 rule_label: 'قانون' 99 rule_label: 'قانون'
99 tags_label: 'برچسب‌ها' 100 tags_label: 'برچسب‌ها'
100 faq: 101 faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index 591b598b..0eeda011 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -95,6 +95,7 @@ config:
95 if_label: 'si' 95 if_label: 'si'
96 then_tag_as_label: 'alors attribuer les tags' 96 then_tag_as_label: 'alors attribuer les tags'
97 delete_rule_label: 'supprimer' 97 delete_rule_label: 'supprimer'
98 edit_rule_label: 'éditer'
98 rule_label: 'Règle' 99 rule_label: 'Règle'
99 tags_label: 'Tags' 100 tags_label: 'Tags'
100 faq: 101 faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
index b767e580..34f660f7 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
@@ -95,6 +95,7 @@ config:
95 if_label: 'se' 95 if_label: 'se'
96 then_tag_as_label: 'allora tagga come' 96 then_tag_as_label: 'allora tagga come'
97 delete_rule_label: 'elimina' 97 delete_rule_label: 'elimina'
98 # edit_rule_label: 'edit'
98 rule_label: 'Regola' 99 rule_label: 'Regola'
99 tags_label: 'Tag' 100 tags_label: 'Tag'
100 faq: 101 faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
index 39eac642..bcc59b29 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
@@ -95,6 +95,7 @@ config:
95 if_label: 'se' 95 if_label: 'se'
96 then_tag_as_label: 'alara atribuir las etiquetas' 96 then_tag_as_label: 'alara atribuir las etiquetas'
97 delete_rule_label: 'suprimir' 97 delete_rule_label: 'suprimir'
98 # edit_rule_label: 'edit'
98 rule_label: 'Règla' 99 rule_label: 'Règla'
99 tags_label: 'Etiquetas' 100 tags_label: 'Etiquetas'
100 faq: 101 faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
index 50da9ff2..ce5ebab9 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
@@ -95,6 +95,7 @@ config:
95 if_label: 'jeżeli' 95 if_label: 'jeżeli'
96 then_tag_as_label: 'wtedy otaguj jako' 96 then_tag_as_label: 'wtedy otaguj jako'
97 delete_rule_label: 'usuń' 97 delete_rule_label: 'usuń'
98 # edit_rule_label: 'edit'
98 rule_label: 'Reguła' 99 rule_label: 'Reguła'
99 tags_label: 'Tagi' 100 tags_label: 'Tagi'
100 faq: 101 faq:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
index 315d6aa0..a54efb4c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
@@ -95,6 +95,7 @@ config:
95 # if_label: 'if' 95 # if_label: 'if'
96 # then_tag_as_label: 'then tag as' 96 # then_tag_as_label: 'then tag as'
97 # delete_rule_label: 'delete' 97 # delete_rule_label: 'delete'
98 # edit_rule_label: 'edit'
98 # rule_label: 'Rule' 99 # rule_label: 'Rule'
99 # tags_label: 'Tags' 100 # tags_label: 'Tags'
100 # faq: 101 # 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']));