From bb0c78f4a636fcc8f60dd3b42ad733e7f31e0bb4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 8 Sep 2016 14:07:36 +0200 Subject: [PATCH] Added check if there is only one user Added translations and documentation --- docs/en/user/configuration.rst | 2 ++ docs/fr/user/configuration.rst | 2 ++ .../CoreBundle/Controller/ConfigController.php | 14 ++++++++++++++ .../Resources/translations/messages.da.yml | 1 + .../Resources/translations/messages.de.yml | 1 + .../Resources/translations/messages.en.yml | 1 + .../Resources/translations/messages.es.yml | 1 + .../Resources/translations/messages.fa.yml | 1 + .../Resources/translations/messages.fr.yml | 1 + .../Resources/translations/messages.it.yml | 1 + .../Resources/translations/messages.oc.yml | 1 + .../Resources/translations/messages.pl.yml | 1 + .../Resources/translations/messages.ro.yml | 1 + .../Resources/translations/messages.tr.yml | 1 + .../views/themes/baggy/Config/index.html.twig | 3 +++ .../views/themes/material/Config/index.html.twig | 5 ++++- .../UserBundle/Repository/UserRepository.php | 14 ++++++++++++++ 17 files changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/en/user/configuration.rst b/docs/en/user/configuration.rst index f4c55dea..824878dc 100644 --- a/docs/en/user/configuration.rst +++ b/docs/en/user/configuration.rst @@ -50,6 +50,8 @@ User information You can change your name, your email address and enable ``Two factor authentication``. +If the wallabag instance has more than one enabled user, you can delete your account here. **Take care, we delete all your data**. + Two factor authentication ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/fr/user/configuration.rst b/docs/fr/user/configuration.rst index 278f0022..2654e8ad 100644 --- a/docs/fr/user/configuration.rst +++ b/docs/fr/user/configuration.rst @@ -51,6 +51,8 @@ Mon compte Vous pouvez ici modifier votre nom, votre adresse email et activer la ``Double authentification``. +Si l'instance de wallabag compte plus d'un utilisateur actif, vous pouvez supprimer ici votre compte. **Attention, nous supprimons toutes vos données**. + Double authentification (2FA) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 3cafd1bc..70a641f7 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\TaggingRule; use Wallabag\CoreBundle\Form\Type\ConfigType; @@ -148,6 +149,9 @@ class ConfigController extends Controller 'token' => $config->getRssToken(), ], 'twofactor_auth' => $this->getParameter('twofactor_auth'), + 'enabled_users' => $this->getDoctrine() + ->getRepository('WallabagUserBundle:User') + ->getSumEnabledUsers(), ]); } @@ -257,10 +261,20 @@ class ConfigController extends Controller * * @Route("/account/delete", name="delete_account") * + * @throws AccessDeniedHttpException + * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function deleteAccountAction() { + $enabledUsers = $this->getDoctrine() + ->getRepository('WallabagUserBundle:User') + ->getSumEnabledUsers(); + + if ($enabledUsers <= 1) { + throw new AccessDeniedHttpException(); + } + $em = $this->get('fos_user.user_manager'); $em->deleteUser($this->getUser()); diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 69bfe7b3..4c412592 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -88,6 +88,7 @@ config: name_label: 'Navn' email_label: 'Emailadresse' # twoFactorAuthentication_label: 'Two factor authentication' + # delete_account: 'Delete my account' form_password: old_password_label: 'Gammel adgangskode' new_password_label: 'Ny adgangskode' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index f4d13442..99b79bce 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -88,6 +88,7 @@ config: name_label: 'Name' email_label: 'E-Mail-Adresse' twoFactorAuthentication_label: 'Zwei-Faktor-Authentifizierung' + # delete_account: 'Delete my account' form_password: old_password_label: 'Altes Kennwort' new_password_label: 'Neues Kennwort' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 6ddb38a0..94144ed4 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -88,6 +88,7 @@ config: name_label: 'Name' email_label: 'Email' twoFactorAuthentication_label: 'Two factor authentication' + delete_account: 'Delete my account' form_password: old_password_label: 'Current password' new_password_label: 'New password' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 05b03938..a5e8d722 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -88,6 +88,7 @@ config: name_label: 'Nombre' email_label: 'Direccion e-mail' twoFactorAuthentication_label: 'Autentificación de dos factores' + # delete_account: 'Delete my account' form_password: old_password_label: 'Contraseña actual' new_password_label: 'Nueva contraseña' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 3a01a8ed..4b8d9689 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -88,6 +88,7 @@ config: name_label: 'نام' email_label: 'نشانی ایمیل' twoFactorAuthentication_label: 'تأیید ۲مرحله‌ای' + # delete_account: 'Delete my account' form_password: old_password_label: 'رمز قدیمی' new_password_label: 'رمز تازه' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 09445836..67cd5f0e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -88,6 +88,7 @@ config: name_label: 'Nom' email_label: 'Adresse e-mail' twoFactorAuthentication_label: 'Double authentification' + delete_account: 'Supprimer mon compte' form_password: old_password_label: 'Mot de passe actuel' new_password_label: 'Nouveau mot de passe' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 93a11aee..55d961f3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -88,6 +88,7 @@ config: name_label: 'Nome' email_label: 'E-mail' twoFactorAuthentication_label: 'Two factor authentication' + # delete_account: 'Delete my account' form_password: old_password_label: 'Password corrente' new_password_label: 'Nuova password' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 8cadf9a3..5c6b4247 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -88,6 +88,7 @@ config: name_label: 'Nom' email_label: 'Adreça de corrièl' twoFactorAuthentication_label: 'Dobla autentificacion' + # delete_account: 'Delete my account' form_password: old_password_label: 'Senhal actual' new_password_label: 'Senhal novèl' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index d392272f..be966427 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -88,6 +88,7 @@ config: name_label: 'Nazwa' email_label: 'Adres email' twoFactorAuthentication_label: 'Autoryzacja dwuetapowa' + # delete_account: 'Delete my account' form_password: old_password_label: 'Stare hasło' new_password_label: 'Nowe hasło' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index f2bce442..1e52cf0b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -88,6 +88,7 @@ config: name_label: 'Nume' email_label: 'E-mail' # twoFactorAuthentication_label: 'Two factor authentication' + # delete_account: 'Delete my account' form_password: old_password_label: 'Parola veche' new_password_label: 'Parola nouă' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index d2bf0504..ef5477e1 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -88,6 +88,7 @@ config: name_label: 'İsim' email_label: 'E-posta' twoFactorAuthentication_label: 'İki adımlı doğrulama' + # delete_account: 'Delete my account' form_password: old_password_label: 'Eski şifre' new_password_label: 'Yeni şifre' 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 ff7ef73a..29575272 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 @@ -148,6 +148,9 @@ {{ form_widget(form.user._token) }} {{ form_widget(form.user.save) }} + {% if enabled_users > 1 %} + {{ 'config.form_user.delete_account' | trans }} + {% endif %}

{{ 'config.tab_menu.password'|trans }}

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 cebde1ac..5aa3eabe 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 @@ -167,7 +167,10 @@ {{ form_widget(form.user.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} {{ form_widget(form.user._token) }} - {{ 'config.user.delete_account' | trans }} + + {% if enabled_users > 1 %} + {{ 'config.form_user.delete_account' | trans }} + {% endif %}
diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php index 009c4881..178761e6 100644 --- a/src/Wallabag/UserBundle/Repository/UserRepository.php +++ b/src/Wallabag/UserBundle/Repository/UserRepository.php @@ -38,4 +38,18 @@ class UserRepository extends EntityRepository ->getQuery() ->getSingleResult(); } + + /** + * Count how many users are enabled. + * + * @return int + */ + public function getSumEnabledUsers() + { + return $this->createQueryBuilder('u') + ->select('count(u)') + ->andWhere('u.expired = 0') + ->getQuery() + ->getSingleScalarResult(); + } } -- 2.41.0