Add new Ignore Origin rules tab, update ConfigController

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
This commit is contained in:
Kevin Decherf 2019-06-23 22:13:44 +02:00
parent c675bd11c6
commit 24230a5130
20 changed files with 406 additions and 13 deletions

View file

@ -14,10 +14,13 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint; use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint;
use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Config;
use Wallabag\CoreBundle\Entity\IgnoreOriginUserRule;
use Wallabag\CoreBundle\Entity\RuleInterface;
use Wallabag\CoreBundle\Entity\TaggingRule; use Wallabag\CoreBundle\Entity\TaggingRule;
use Wallabag\CoreBundle\Form\Type\ChangePasswordType; use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\ConfigType;
use Wallabag\CoreBundle\Form\Type\FeedType; use Wallabag\CoreBundle\Form\Type\FeedType;
use Wallabag\CoreBundle\Form\Type\IgnoreOriginUserRuleType;
use Wallabag\CoreBundle\Form\Type\TaggingRuleImportType; use Wallabag\CoreBundle\Form\Type\TaggingRuleImportType;
use Wallabag\CoreBundle\Form\Type\TaggingRuleType; use Wallabag\CoreBundle\Form\Type\TaggingRuleType;
use Wallabag\CoreBundle\Form\Type\UserInformationType; use Wallabag\CoreBundle\Form\Type\UserInformationType;
@ -173,6 +176,40 @@ class ConfigController extends Controller
return $this->redirect($this->generateUrl('config') . '#set5'); return $this->redirect($this->generateUrl('config') . '#set5');
} }
// handle ignore origin rules
$ignoreOriginUserRule = new IgnoreOriginUserRule();
$action = $this->generateUrl('config') . '#set6';
if ($request->query->has('ignore-origin-user-rule')) {
$ignoreOriginUserRule = $this->getDoctrine()
->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
->find($request->query->get('ignore-origin-user-rule'));
if ($this->getUser()->getId() !== $ignoreOriginUserRule->getConfig()->getUser()->getId()) {
return $this->redirect($action);
}
$action = $this->generateUrl('config', [
'ignore-origin-user-rule' => $ignoreOriginUserRule->getId(),
]) . '#set6';
}
$newIgnoreOriginUserRule = $this->createForm(IgnoreOriginUserRuleType::class, $ignoreOriginUserRule, ['action' => $action]);
$newIgnoreOriginUserRule->handleRequest($request);
if ($newIgnoreOriginUserRule->isSubmitted() && $newIgnoreOriginUserRule->isValid()) {
$ignoreOriginUserRule->setConfig($config);
$em->persist($ignoreOriginUserRule);
$em->flush();
$this->addFlash(
'notice',
'flashes.config.notice.ignore_origin_rules_updated'
);
return $this->redirect($this->generateUrl('config') . '#set6');
}
return $this->render('WallabagCoreBundle:Config:index.html.twig', [ return $this->render('WallabagCoreBundle:Config:index.html.twig', [
'form' => [ 'form' => [
'config' => $configForm->createView(), 'config' => $configForm->createView(),
@ -181,6 +218,7 @@ class ConfigController extends Controller
'user' => $userForm->createView(), 'user' => $userForm->createView(),
'new_tagging_rule' => $newTaggingRule->createView(), 'new_tagging_rule' => $newTaggingRule->createView(),
'import_tagging_rule' => $taggingRulesImportform->createView(), 'import_tagging_rule' => $taggingRulesImportform->createView(),
'new_ignore_origin_user_rule' => $newIgnoreOriginUserRule->createView(),
], ],
'feed' => [ 'feed' => [
'username' => $user->getUsername(), 'username' => $user->getUsername(),
@ -447,6 +485,43 @@ class ConfigController extends Controller
return $this->redirect($this->generateUrl('config') . '?tagging-rule=' . $rule->getId() . '#set5'); return $this->redirect($this->generateUrl('config') . '?tagging-rule=' . $rule->getId() . '#set5');
} }
/**
* Deletes an ignore origin rule and redirect to the config homepage.
*
* @Route("/ignore-origin-user-rule/delete/{id}", requirements={"id" = "\d+"}, name="delete_ignore_origin_rule")
*
* @return RedirectResponse
*/
public function deleteIgnoreOriginRuleAction(IgnoreOriginUserRule $rule)
{
$this->validateRuleAction($rule);
$em = $this->getDoctrine()->getManager();
$em->remove($rule);
$em->flush();
$this->addFlash(
'notice',
'flashes.config.notice.ignore_origin_rules_deleted'
);
return $this->redirect($this->generateUrl('config') . '#set6');
}
/**
* Edit an ignore origin rule.
*
* @Route("/ignore-origin-user-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_ignore_origin_rule")
*
* @return RedirectResponse
*/
public function editIgnoreOriginRuleAction(IgnoreOriginUserRule $rule)
{
$this->validateRuleAction($rule);
return $this->redirect($this->generateUrl('config') . '?ignore-origin-user-rule=' . $rule->getId() . '#set6');
}
/** /**
* Remove all annotations OR tags OR entries for the current user. * Remove all annotations OR tags OR entries for the current user.
* *
@ -659,10 +734,10 @@ class ConfigController extends Controller
/** /**
* Validate that a rule can be edited/deleted by the current user. * Validate that a rule can be edited/deleted by the current user.
*/ */
private function validateRuleAction(TaggingRule $rule) private function validateRuleAction(RuleInterface $rule)
{ {
if ($this->getUser()->getId() !== $rule->getConfig()->getUser()->getId()) { if ($this->getUser()->getId() !== $rule->getConfig()->getUser()->getId()) {
throw $this->createAccessDeniedException('You can not access this tagging rule.'); throw $this->createAccessDeniedException('You can not access this rule.');
} }
} }

View file

@ -0,0 +1,36 @@
<?php
namespace Wallabag\CoreBundle\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Wallabag\CoreBundle\Entity\IgnoreOriginUserRule;
use Wallabag\UserBundle\DataFixtures\UserFixtures;
class IgnoreOriginUserRuleFixtures extends Fixture implements DependentFixtureInterface
{
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$rule = new IgnoreOriginUserRule();
$rule->setRule('host = "example.fr"');
$rule->setConfig($this->getReference('admin-user')->getConfig());
$manager->persist($rule);
$manager->flush();
}
/**
* {@inheritdoc}
*/
public function getDependencies()
{
return [
UserFixtures::class,
];
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Wallabag\CoreBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class IgnoreOriginUserRuleType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->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\IgnoreOriginUserRule',
]);
}
public function getBlockPrefix()
{
return 'ignore_origin_user_rule';
}
}

View file

@ -59,6 +59,7 @@ config:
user_info: 'Brugeroplysninger' user_info: 'Brugeroplysninger'
password: 'Adgangskode' password: 'Adgangskode'
# rules: 'Tagging rules' # rules: 'Tagging rules'
# ignore_origin: 'Ignore origin rules'
new_user: 'Tilføj bruger' new_user: 'Tilføj bruger'
# reset: 'Reset area' # reset: 'Reset area'
form: form:
@ -617,6 +618,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
# entry_already_saved: 'Entry already saved on %date%' # entry_already_saved: 'Entry already saved on %date%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'Benutzerinformation' user_info: 'Benutzerinformation'
password: 'Kennwort' password: 'Kennwort'
rules: 'Tagging-Regeln' rules: 'Tagging-Regeln'
# ignore_origin: 'Ignore origin rules'
new_user: 'Benutzer hinzufügen' new_user: 'Benutzer hinzufügen'
reset: 'Zurücksetzen' reset: 'Zurücksetzen'
form: form:
@ -617,6 +618,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'Eintrag bereits am %date% gespeichert' entry_already_saved: 'Eintrag bereits am %date% gespeichert'

View file

@ -59,6 +59,7 @@ config:
user_info: 'User information' user_info: 'User information'
password: 'Password' password: 'Password'
rules: 'Tagging rules' rules: 'Tagging rules'
ignore_origin: 'Ignore origin rules'
new_user: 'Add a user' new_user: 'Add a user'
reset: 'Reset area' reset: 'Reset area'
form: form:
@ -617,6 +618,8 @@ flashes:
otp_disabled: Two-factor authentication disabled otp_disabled: Two-factor authentication disabled
tagging_rules_imported: Tagging rules imported tagging_rules_imported: Tagging rules imported
tagging_rules_not_imported: Error while importing tagging rules tagging_rules_not_imported: Error while importing tagging rules
ignore_origin_rules_deleted: 'Ignore origin rule deleted'
ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'Entry already saved on %date%' entry_already_saved: 'Entry already saved on %date%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'Información de usuario' user_info: 'Información de usuario'
password: 'Contraseña' password: 'Contraseña'
rules: 'Reglas de etiquetado automáticas' rules: 'Reglas de etiquetado automáticas'
# ignore_origin: 'Ignore origin rules'
new_user: 'Añadir un usuario' new_user: 'Añadir un usuario'
reset: 'Reiniciar mi cuenta' reset: 'Reiniciar mi cuenta'
form: form:
@ -617,6 +618,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
tagging_rules_imported: Reglas de etiquetado importadas tagging_rules_imported: Reglas de etiquetado importadas
tagging_rules_not_imported: Un error se ha producico en la importación de las reglas de etiquetado tagging_rules_not_imported: Un error se ha producico en la importación de las reglas de etiquetado
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'Artículo ya guardado el %fecha%' entry_already_saved: 'Artículo ya guardado el %fecha%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'اطلاعات کاربر' user_info: 'اطلاعات کاربر'
password: 'رمز' password: 'رمز'
rules: 'برچسب‌گذاری خودکار' rules: 'برچسب‌گذاری خودکار'
# ignore_origin: 'Ignore origin rules'
new_user: 'افزودن کاربر' new_user: 'افزودن کاربر'
# reset: 'Reset area' # reset: 'Reset area'
form: form:
@ -617,6 +618,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'این مقاله در تاریخ %date% ذخیره شده بود' entry_already_saved: 'این مقاله در تاریخ %date% ذخیره شده بود'

View file

@ -59,6 +59,7 @@ config:
user_info: "Mon compte" user_info: "Mon compte"
password: "Mot de passe" password: "Mot de passe"
rules: "Règles de tag automatiques" rules: "Règles de tag automatiques"
ignore_origin: "Règles d'omission d'origine"
new_user: "Créer un compte" new_user: "Créer un compte"
reset: "Réinitialisation" reset: "Réinitialisation"
form: form:
@ -618,6 +619,11 @@ flashes:
otp_disabled: "Authentification à double-facteur désactivée" otp_disabled: "Authentification à double-facteur désactivée"
tagging_rules_imported: Règles bien importées tagging_rules_imported: Règles bien importées
tagging_rules_not_imported: Impossible d'importer les règles 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: entry:
notice: notice:
entry_already_saved: "Article déjà sauvegardé le %date%" entry_already_saved: "Article déjà sauvegardé le %date%"

View file

@ -59,6 +59,7 @@ config:
user_info: 'Informazioni utente' user_info: 'Informazioni utente'
password: 'Password' password: 'Password'
rules: 'Regole di etichettatura' rules: 'Regole di etichettatura'
# ignore_origin: 'Ignore origin rules'
new_user: 'Aggiungi utente' new_user: 'Aggiungi utente'
reset: 'Area di reset' reset: 'Area di reset'
form: form:
@ -617,6 +618,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'Contenuto già salvato in data %date%' entry_already_saved: 'Contenuto già salvato in data %date%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'Mon compte' user_info: 'Mon compte'
password: 'Senhal' password: 'Senhal'
rules: "Règlas d'etiquetas automaticas" rules: "Règlas d'etiquetas automaticas"
# ignore_origin: 'Ignore origin rules'
new_user: 'Crear un compte' new_user: 'Crear un compte'
reset: 'Zòna de reïnicializacion' reset: 'Zòna de reïnicializacion'
form: form:
@ -617,6 +618,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
tagging_rules_imported: Règlas detiquetatge importadas tagging_rules_imported: Règlas detiquetatge importadas
tagging_rules_not_imported: Error en important las règlas detiquetatge tagging_rules_not_imported: Error en important las règlas detiquetatge
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'Article ja salvagardat lo %date%' entry_already_saved: 'Article ja salvagardat lo %date%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'Informacje o użytkowniku' user_info: 'Informacje o użytkowniku'
password: 'Hasło' password: 'Hasło'
rules: 'Zasady tagowania' rules: 'Zasady tagowania'
# ignore_origin: 'Ignore origin rules'
new_user: 'Dodaj użytkownika' new_user: 'Dodaj użytkownika'
reset: 'Reset' reset: 'Reset'
form: form:
@ -617,6 +618,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'Wpis już został dodany %date%' entry_already_saved: 'Wpis już został dodany %date%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'Informação do Usuário' user_info: 'Informação do Usuário'
password: 'Senha' password: 'Senha'
rules: 'Regras de tags' rules: 'Regras de tags'
# ignore_origin: 'Ignore origin rules'
new_user: 'Adicionar um usuário' new_user: 'Adicionar um usuário'
reset: 'Reiniciar minha conta' reset: 'Reiniciar minha conta'
form: form:

View file

@ -59,6 +59,7 @@ config:
user_info: 'Informații despre utilizator' user_info: 'Informații despre utilizator'
password: 'Parolă' password: 'Parolă'
# rules: 'Tagging rules' # rules: 'Tagging rules'
# ignore_origin: 'Ignore origin rules'
new_user: 'Crează un utilizator' new_user: 'Crează un utilizator'
# reset: 'Reset area' # reset: 'Reset area'
form: form:
@ -616,6 +617,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
# entry_already_saved: 'Entry already saved on %date%' # entry_already_saved: 'Entry already saved on %date%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'Информация о пользователе' user_info: 'Информация о пользователе'
password: 'Пароль' password: 'Пароль'
rules: 'Правила настройки простановки тегов' rules: 'Правила настройки простановки тегов'
# ignore_origin: 'Ignore origin rules'
new_user: 'Добавить пользователя' new_user: 'Добавить пользователя'
reset: 'Сброс данных' reset: 'Сброс данных'
form: form:
@ -616,6 +617,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'Запись была сохранена ранее %date%' entry_already_saved: 'Запись была сохранена ранее %date%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'ข้อมูลผู้ใช้' user_info: 'ข้อมูลผู้ใช้'
password: 'รหัสผ่าน' password: 'รหัสผ่าน'
rules: 'การแท็กข้อบังคับ' rules: 'การแท็กข้อบังคับ'
# ignore_origin: 'Ignore origin rules'
new_user: 'เพิ่มผู้ใช้' new_user: 'เพิ่มผู้ใช้'
reset: 'รีเซ็ตพื้นที่ ' reset: 'รีเซ็ตพื้นที่ '
form: form:
@ -616,6 +617,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'รายการพร้อมบันทึกที่ %date%' entry_already_saved: 'รายการพร้อมบันทึกที่ %date%'

View file

@ -59,6 +59,7 @@ config:
user_info: 'Kullanıcı bilgileri' user_info: 'Kullanıcı bilgileri'
password: 'Şifre' password: 'Şifre'
rules: 'Etiketleme kuralları' rules: 'Etiketleme kuralları'
# ignore_origin: 'Ignore origin rules'
new_user: 'Bir kullanıcı ekle' new_user: 'Bir kullanıcı ekle'
# reset: 'Reset area' # reset: 'Reset area'
form: form:
@ -616,6 +617,8 @@ flashes:
# otp_disabled: Two-factor authentication disabled # otp_disabled: Two-factor authentication disabled
# tagging_rules_imported: Tagging rules imported # tagging_rules_imported: Tagging rules imported
# tagging_rules_not_imported: Error while importing tagging rules # tagging_rules_not_imported: Error while importing tagging rules
# ignore_origin_rules_deleted: 'Ignore origin rule deleted'
# ignore_origin_rules_updated: 'Ignore origin rule updated'
entry: entry:
notice: notice:
entry_already_saved: 'Entry already saved on %date%' entry_already_saved: 'Entry already saved on %date%'

View file

@ -404,6 +404,33 @@
</div> </div>
</div> </div>
<h2>{{ 'config.tab_menu.ignore_origin'|trans }}</h2>
<ul>
{% for ignore_origin_rule in app.user.config.ignoreOriginRules %}
<li>
{{ 'config.form_rules.if_label'|trans }}
« {{ ignore_origin_rule.rule }} »
<a href="{{ path('edit_ignore_origin_rule', {id: ignore_origin_rule.id}) }}" title="{{ 'config.form_rules.edit_rule_label'|trans }}" class="tool mode_edit">✎</a>
<a href="{{ path('delete_ignore_origin_rule', {id: ignore_origin_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}" class="tool delete icon-trash icon"></a>
</li>
{% endfor %}
</ul>
{{ form_start(form.new_ignore_origin_user_rule) }}
{{ form_errors(form.new_ignore_origin_user_rule) }}
<fieldset class="w500p inline">
<div class="row">
{{ form_label(form.new_ignore_origin_user_rule.rule) }}
{{ form_errors(form.new_ignore_origin_user_rule.rule) }}
{{ form_widget(form.new_ignore_origin_user_rule.rule) }}
</div>
</fieldset>
{{ form_rest(form.new_ignore_origin_user_rule) }}
</form>
<h2>{{ 'config.reset.title'|trans }}</h2> <h2>{{ 'config.reset.title'|trans }}</h2>
<fieldset class="w500p inline"> <fieldset class="w500p inline">
<p>{{ 'config.reset.description'|trans }}</p> <p>{{ 'config.reset.description'|trans }}</p>

View file

@ -16,7 +16,8 @@
<li class="tab col s12 m6 l3"><a href="#set3">{{ 'config.tab_menu.user_info'|trans }}</a></li> <li class="tab col s12 m6 l3"><a href="#set3">{{ 'config.tab_menu.user_info'|trans }}</a></li>
<li class="tab col s12 m6 l3"><a href="#set4">{{ 'config.tab_menu.password'|trans }}</a></li> <li class="tab col s12 m6 l3"><a href="#set4">{{ 'config.tab_menu.password'|trans }}</a></li>
<li class="tab col s12 m6 l3"><a href="#set5">{{ 'config.tab_menu.rules'|trans }}</a></li> <li class="tab col s12 m6 l3"><a href="#set5">{{ 'config.tab_menu.rules'|trans }}</a></li>
<li class="tab col s12 m6 l3"><a href="#set6">{{ 'config.tab_menu.reset'|trans }}</a></li> <li class="tab col s12 m6 l3"><a href="#set6">{{ 'config.tab_menu.ignore_origin'|trans }}</a></li>
<li class="tab col s12 m6 l3"><a href="#set7">{{ 'config.tab_menu.reset'|trans }}</a></li>
</ul> </ul>
</div> </div>
@ -294,11 +295,11 @@
« {{ tagging_rule.rule }} » « {{ tagging_rule.rule }} »
{{ 'config.form_rules.then_tag_as_label'|trans }} {{ 'config.form_rules.then_tag_as_label'|trans }}
« {{ tagging_rule.tags|join(', ') }} » « {{ tagging_rule.tags|join(', ') }} »
<a href="{{ path('edit_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.edit_rule_label'|trans }}"> <a href="{{ path('edit_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.edit_rule_label'|trans }}" class="mode_edit">
<i class="tool grey-text mode_edit material-icons">mode_edit</i> <i class="tool grey-text material-icons">mode_edit</i>
</a> </a>
<a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}"> <a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}" class="delete">
<i class="tool grey-text delete material-icons">delete</i> <i class="tool grey-text material-icons">delete</i>
</a> </a>
</li> </li>
{% endfor %} {% endfor %}
@ -466,6 +467,44 @@
</div> </div>
<div id="set6" class="col s12"> <div id="set6" class="col s12">
{% if app.user.config.ignoreOriginRules is not empty %}
<div class="row">
<div class="input-field col s12">
<ul>
{% for ignore_origin_rule in app.user.config.ignoreOriginRules %}
<li>
{{ 'config.form_rules.if_label'|trans }}
« {{ ignore_origin_rule.rule }} »
<a href="{{ path('edit_ignore_origin_rule', {id: ignore_origin_rule.id}) }}" title="{{ 'config.form_rules.edit_rule_label'|trans }}" class="mode_edit">
<i class="tool grey-text material-icons">mode_edit</i>
</a>
<a href="{{ path('delete_ignore_origin_rule', {id: ignore_origin_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}" class="delete">
<i class="tool grey-text material-icons">delete</i>
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
{{ form_start(form.new_ignore_origin_user_rule) }}
{{ form_errors(form.new_ignore_origin_user_rule) }}
<div class="row">
<div class="input-field col s12">
{{ form_label(form.new_ignore_origin_user_rule.rule) }}
{{ form_errors(form.new_ignore_origin_user_rule.rule) }}
{{ form_widget(form.new_ignore_origin_user_rule.rule) }}
</div>
</div>
{{ form_widget(form.new_ignore_origin_user_rule.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
{{ form_rest(form.new_ignore_origin_user_rule) }}
</form>
</div>
<div id="set7" class="col s12">
<div class="row"> <div class="row">
<h5>{{ 'config.reset.title'|trans }}</h5> <h5>{{ 'config.reset.title'|trans }}</h5>
<p>{{ 'config.reset.description'|trans }}</p> <p>{{ 'config.reset.description'|trans }}</p>

View file

@ -435,7 +435,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
public function testTaggingRuleCreation() public function testTaggingRuleCreation()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/config'); $crawler = $client->request('GET', '/config');
@ -457,7 +456,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
$this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
$editLink = $crawler->filter('.mode_edit')->last()->link(); $editLink = $crawler->filter('div[id=set5] a.mode_edit')->last()->link();
$crawler = $client->click($editLink); $crawler = $client->click($editLink);
$this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertSame(302, $client->getResponse()->getStatusCode());
@ -482,7 +481,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
$this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
$deleteLink = $crawler->filter('.delete')->last()->link(); $deleteLink = $crawler->filter('div[id=set5] a.delete')->last()->link();
$crawler = $client->click($deleteLink); $crawler = $client->click($deleteLink);
$this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertSame(302, $client->getResponse()->getStatusCode());
@ -574,11 +573,11 @@ class ConfigControllerTest extends WallabagCoreTestCase
->getRepository('WallabagCoreBundle:TaggingRule') ->getRepository('WallabagCoreBundle:TaggingRule')
->findAll()[0]; ->findAll()[0];
$crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); $crawler = $client->request('GET', '/tagging-rule/delete/' . $rule->getId());
$this->assertSame(403, $client->getResponse()->getStatusCode()); $this->assertSame(403, $client->getResponse()->getStatusCode());
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
$this->assertContains('You can not access this tagging rule', $body[0]); $this->assertContains('You can not access this rule', $body[0]);
} }
public function testEditingTaggingRuleFromAnOtherUser() public function testEditingTaggingRuleFromAnOtherUser()
@ -594,7 +593,144 @@ class ConfigControllerTest extends WallabagCoreTestCase
$this->assertSame(403, $client->getResponse()->getStatusCode()); $this->assertSame(403, $client->getResponse()->getStatusCode());
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
$this->assertContains('You can not access this tagging rule', $body[0]); $this->assertContains('You can not access this rule', $body[0]);
}
public function testIgnoreOriginRuleCreation()
{
$this->logInAs('admin');
$client = $this->getClient();
$crawler = $client->request('GET', '/config');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
$data = [
'ignore_origin_user_rule[rule]' => 'host = "example.com"',
];
$client->submit($form, $data);
$this->assertSame(302, $client->getResponse()->getStatusCode());
$crawler = $client->followRedirect();
$this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
$editLink = $crawler->filter('div[id=set6] a.mode_edit')->last()->link();
$crawler = $client->click($editLink);
$this->assertSame(302, $client->getResponse()->getStatusCode());
$this->assertContains('?ignore-origin-user-rule=', $client->getResponse()->headers->get('location'));
$crawler = $client->followRedirect();
$form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
$data = [
'ignore_origin_user_rule[rule]' => 'host = "example.org"',
];
$client->submit($form, $data);
$this->assertSame(302, $client->getResponse()->getStatusCode());
$crawler = $client->followRedirect();
$this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
$this->assertContains('host = "example.org"', $crawler->filter('body')->extract(['_text'])[0]);
$deleteLink = $crawler->filter('div[id=set6] a.delete')->last()->link();
$crawler = $client->click($deleteLink);
$this->assertSame(302, $client->getResponse()->getStatusCode());
$crawler = $client->followRedirect();
$this->assertContains('flashes.config.notice.ignore_origin_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
}
public function dataForIgnoreOriginRuleCreationFail()
{
return [
[
[
'ignore_origin_user_rule[rule]' => 'foo = "bar"',
],
[
'The variable',
'does not exist.',
],
],
[
[
'ignore_origin_user_rule[rule]' => '_all != "none"',
],
[
'The operator',
'does not exist.',
],
],
];
}
/**
* @dataProvider dataForIgnoreOriginRuleCreationFail
*/
public function testIgnoreOriginRuleCreationFail($data, $messages)
{
$this->logInAs('admin');
$client = $this->getClient();
$crawler = $client->request('GET', '/config');
$this->assertSame(200, $client->getResponse()->getStatusCode());
$form = $crawler->filter('button[id=ignore_origin_user_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]);
}
}
public function testDeletingIgnoreOriginRuleFromAnOtherUser()
{
$this->logInAs('bob');
$client = $this->getClient();
$rule = $client->getContainer()->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
->findAll()[0];
$crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId());
$this->assertSame(403, $client->getResponse()->getStatusCode());
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
$this->assertContains('You can not access this rule', $body[0]);
}
public function testEditingIgnoreOriginRuleFromAnOtherUser()
{
$this->logInAs('bob');
$client = $this->getClient();
$rule = $client->getContainer()->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
->findAll()[0];
$crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId());
$this->assertSame(403, $client->getResponse()->getStatusCode());
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
$this->assertContains('You can not access this rule', $body[0]);
} }
public function testDemoMode() public function testDemoMode()