From c65850050d1e3ba2cf08264cf3b328dc02ac775e Mon Sep 17 00:00:00 2001 From: Kevin Jiang Date: Sun, 7 Jul 2024 01:04:28 +1200 Subject: [PATCH 1/2] Implement tagging rules reset Adding tagging rule reset to templates Adding messages to tagging rule reset Adding translation for Traditional and Simplified Chinese --- src/Controller/ConfigController.php | 7 +++++-- src/Repository/TaggingRuleRepository.php | 14 ++++++++++++++ templates/Config/index.html.twig | 9 +++++++++ translations/messages.en.yml | 2 ++ translations/messages.zh.yml | 2 ++ translations/messages.zh_Hant.yml | 2 ++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php index 83aa720df..1ce402ba6 100644 --- a/src/Controller/ConfigController.php +++ b/src/Controller/ConfigController.php @@ -561,11 +561,11 @@ class ConfigController extends AbstractController /** * Remove all annotations OR tags OR entries for the current user. * - * @Route("/reset/{type}", requirements={"id" = "annotations|tags|entries"}, name="config_reset", methods={"POST"}) + * @Route("/reset/{type}", requirements={"id" = "annotations|tags|entries|tagging_rules"}, name="config_reset", methods={"POST"}) * * @return RedirectResponse */ - public function resetAction(Request $request, string $type, AnnotationRepository $annotationRepository, EntryRepository $entryRepository) + public function resetAction(Request $request, string $type, AnnotationRepository $annotationRepository, EntryRepository $entryRepository, TaggingRuleRepository $taggingRuleRepository) { if (!$this->isCsrfTokenValid('reset-area', $request->request->get('token'))) { throw $this->createAccessDeniedException('Bad CSRF token.'); @@ -575,6 +575,9 @@ class ConfigController extends AbstractController case 'annotations': $annotationRepository->removeAllByUserId($this->getUser()->getId()); break; + case 'tagging_rules': + $taggingRuleRepository->removeAllTaggingRules($this->getConfig()->getId()); + break; case 'tags': $this->removeAllTagsByUserId($this->getUser()->getId()); break; diff --git a/src/Repository/TaggingRuleRepository.php b/src/Repository/TaggingRuleRepository.php index 8c0fb7920..8b03a6c4e 100644 --- a/src/Repository/TaggingRuleRepository.php +++ b/src/Repository/TaggingRuleRepository.php @@ -12,4 +12,18 @@ class TaggingRuleRepository extends ServiceEntityRepository { parent::__construct($registry, TaggingRule::class); } + + /** + * Remove all tagging rule for a config. + * Used when a user wants to reset. + * + * @param int $configId + */ + public function removeAllTaggingRules($configId) + { + $this->getEntityManager() + ->createQuery('DELETE FROM Wallabag\Entity\TaggingRule tr WHERE tr.config = :configId') + ->setParameter(':configId', $configId) + ->execute(); + } } diff --git a/templates/Config/index.html.twig b/templates/Config/index.html.twig index e152ce690..20e78e785 100644 --- a/templates/Config/index.html.twig +++ b/templates/Config/index.html.twig @@ -640,6 +640,15 @@
{{ 'config.reset.title'|trans }}

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

+ {% if app.user.config.taggingRules is not empty %} +

+

+ + + +
+

+ {% endif %}

diff --git a/translations/messages.en.yml b/translations/messages.en.yml index a774ac1c4..8ac2732d6 100644 --- a/translations/messages.en.yml +++ b/translations/messages.en.yml @@ -138,6 +138,7 @@ config: description: By hitting buttons below you'll have ability to remove some information from your account. Be aware that these actions are IRREVERSIBLE. annotations: Remove ALL annotations tags: Remove ALL tags + tagging_rules: Remove ALL tagging rules entries: Remove ALL entries archived: Remove ALL archived entries confirm: Are you really sure? (THIS CAN'T BE UNDONE) @@ -676,6 +677,7 @@ flashes: feed_token_revoked: 'Feed token revoked' annotations_reset: Annotations reset tags_reset: Tags reset + tagging_rules_reset: Tagging rules reset entries_reset: Entries reset archived_reset: Archived entries deleted otp_enabled: Two-factor authentication enabled diff --git a/translations/messages.zh.yml b/translations/messages.zh.yml index 9295d4408..37c1bb4d8 100644 --- a/translations/messages.zh.yml +++ b/translations/messages.zh.yml @@ -140,6 +140,7 @@ config: title: '重置区(危险区域)' description: '一旦你点击这个按钮,你就可以移除你账号中的某些信息。请注意这些操作是不可撤销的。' annotations: "删除所有标注" + tagging_rules: "删除所有标签规则" tags: "删除所有标签" entries: "删除所有项目" archived: "删除所有已存档项目" @@ -678,6 +679,7 @@ flashes: feed_token_revoked: '订阅源令牌已作废' annotations_reset: 标注已重置 tags_reset: 标签已重置 + tagging_rules_reset: 标签规则已重置 entries_reset: 项目列表已重置 archived_reset: 所有存档项目已删除 otp_enabled: 两步验证已启用 diff --git a/translations/messages.zh_Hant.yml b/translations/messages.zh_Hant.yml index d918693cc..fa6453f61 100644 --- a/translations/messages.zh_Hant.yml +++ b/translations/messages.zh_Hant.yml @@ -139,6 +139,7 @@ config: page_title: 雙重驗證 reset: tags: 移除所有標籤 + tagging_rules: 移除所有標籤規則 title: 重設區域(危險地帶) entries: 移除所有條目 archived: 移除所有已封存條目 @@ -671,6 +672,7 @@ flashes: entries_reset: 已重設條目 archived_reset: 完成刪除已封存條目 tags_reset: 已重設標籤 + tagging_rules_reset: 已重設標籤規則 annotations_reset: 已重設註釋 tagging_rules_updated: 已更新標籤規則 tagging_rules_deleted: 已刪除標籤規則 From 897aa1d309ffd89a34dbb524c31e9a29eb80038c Mon Sep 17 00:00:00 2001 From: Kevin Jiang Date: Sun, 7 Jul 2024 01:06:22 +1200 Subject: [PATCH 2/2] Adding tests for tagging rules reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix test: associate tagging rule with user config Update src/Repository/TaggingRuleRepository.php Co-authored-by: Jérémy Benoist Update src/Controller/ConfigController.php Co-authored-by: Jérémy Benoist Update src/Repository/TaggingRuleRepository.php Co-authored-by: Jérémy Benoist --- src/Controller/ConfigController.php | 2 +- src/Repository/TaggingRuleRepository.php | 4 ++-- tests/Controller/ConfigControllerTest.php | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php index 1ce402ba6..80ab75095 100644 --- a/src/Controller/ConfigController.php +++ b/src/Controller/ConfigController.php @@ -576,7 +576,7 @@ class ConfigController extends AbstractController $annotationRepository->removeAllByUserId($this->getUser()->getId()); break; case 'tagging_rules': - $taggingRuleRepository->removeAllTaggingRules($this->getConfig()->getId()); + $taggingRuleRepository->removeAllByConfigId($this->getConfig()->getId()); break; case 'tags': $this->removeAllTagsByUserId($this->getUser()->getId()); diff --git a/src/Repository/TaggingRuleRepository.php b/src/Repository/TaggingRuleRepository.php index 8b03a6c4e..3d068c273 100644 --- a/src/Repository/TaggingRuleRepository.php +++ b/src/Repository/TaggingRuleRepository.php @@ -14,12 +14,12 @@ class TaggingRuleRepository extends ServiceEntityRepository } /** - * Remove all tagging rule for a config. + * Remove all tagging rules for a config. * Used when a user wants to reset. * * @param int $configId */ - public function removeAllTaggingRules($configId) + public function removeAllByConfigId($configId) { $this->getEntityManager() ->createQuery('DELETE FROM Wallabag\Entity\TaggingRule tr WHERE tr.config = :configId') diff --git a/tests/Controller/ConfigControllerTest.php b/tests/Controller/ConfigControllerTest.php index 997378ba5..922f8b28c 100644 --- a/tests/Controller/ConfigControllerTest.php +++ b/tests/Controller/ConfigControllerTest.php @@ -870,6 +870,12 @@ class ConfigControllerTest extends WallabagTestCase $tag->setLabel('super'); $em->persist($tag); + $taggingRule = new TaggingRule(); + $taggingRule->setConfig($user->getConfig()); + $taggingRule->setRule('readingTime <= 30'); + $taggingRule->setTags(['aTestTag']); + $em->persist($taggingRule); + $entry = new Entry($user); $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); $entry->setContent('Youhou'); @@ -910,6 +916,23 @@ class ConfigControllerTest extends WallabagTestCase $this->assertEmpty($annotationsReset, 'Annotations were reset'); + // reset taggingRules + $crawler = $client->request('GET', '/config#set3'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=reset-tagging-rules]')->form(); + $client->submit($form); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertStringContainsString('flashes.config.notice.tagging_rules_reset', $client->getContainer()->get(SessionInterface::class)->getFlashBag()->get('notice')[0]); + + $taggingRuleReset = $em + ->getRepository(TaggingRule::class) + ->count(['config' => $user->getConfig()]); + + $this->assertSame(0, $taggingRuleReset, 'Tagging rules were reset'); + // reset tags $crawler = $client->request('GET', '/config#set3');