Merge pull request #7570 from KevinSJ/feature/tagging-rule-reset

This commit is contained in:
Jérémy Benoist 2024-07-17 07:02:48 +02:00 committed by GitHub
commit 4712395b09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 57 additions and 2 deletions

View file

@ -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->removeAllByConfigId($this->getConfig()->getId());
break;
case 'tags':
$this->removeAllTagsByUserId($this->getUser()->getId());
break;

View file

@ -12,4 +12,18 @@ class TaggingRuleRepository extends ServiceEntityRepository
{
parent::__construct($registry, TaggingRule::class);
}
/**
* Remove all tagging rules for a config.
* Used when a user wants to reset.
*
* @param int $configId
*/
public function removeAllByConfigId($configId)
{
$this->getEntityManager()
->createQuery('DELETE FROM Wallabag\Entity\TaggingRule tr WHERE tr.config = :configId')
->setParameter(':configId', $configId)
->execute();
}
}

View file

@ -640,6 +640,15 @@
<div class="row">
<h5>{{ 'config.reset.title'|trans }}</h5>
<p>{{ 'config.reset.description'|trans }}</p>
{% if app.user.config.taggingRules is not empty %}
<p>
<form action="{{ path('config_reset', {type: 'tagging_rules'}) }}" method="post" onsubmit="return confirm('{{ 'config.reset.confirm'|trans|escape('js') }}')" name="reset-tagging-rules">
<input type="hidden" name="token" value="{{ csrf_token('reset-area') }}" />
<button class="waves-effect waves-light btn red" type="submit">{{ 'config.reset.tagging_rules'|trans }}</button>
</form>
</p>
{% endif %}
<p>
<form action="{{ path('config_reset', {type: 'annotations'}) }}" method="post" onsubmit="return confirm('{{ 'config.reset.confirm'|trans|escape('js') }}')" name="reset-annotations">
<input type="hidden" name="token" value="{{ csrf_token('reset-area') }}" />

View file

@ -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');

View file

@ -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

View file

@ -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: 两步验证已启用

View file

@ -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: 已刪除標籤規則