aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/en/user/configuration.rst2
-rw-r--r--docs/fr/user/configuration.rst2
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php4
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php37
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.da.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.de.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.en.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.es.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.it.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml5
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig9
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig12
-rw-r--r--src/Wallabag/UserBundle/Repository/UserRepository.php14
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php120
19 files changed, 253 insertions, 2 deletions
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
50 50
51You can change your name, your email address and enable ``Two factor authentication``. 51You can change your name, your email address and enable ``Two factor authentication``.
52 52
53If the wallabag instance has more than one enabled user, you can delete your account here. **Take care, we delete all your data**.
54
53Two factor authentication 55Two factor authentication
54~~~~~~~~~~~~~~~~~~~~~~~~~ 56~~~~~~~~~~~~~~~~~~~~~~~~~
55 57
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
51 51
52Vous pouvez ici modifier votre nom, votre adresse email et activer la ``Double authentification``. 52Vous pouvez ici modifier votre nom, votre adresse email et activer la ``Double authentification``.
53 53
54Si l'instance de wallabag compte plus d'un utilisateur actif, vous pouvez supprimer ici votre compte. **Attention, nous supprimons toutes vos données**.
55
54Double authentification (2FA) 56Double authentification (2FA)
55~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 57~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56 58
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index cc7c2c94..42982e4a 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -77,7 +77,7 @@ class InstallCommand extends ContainerAwareCommand
77 77
78 // testing if database driver exists 78 // testing if database driver exists
79 $fulfilled = true; 79 $fulfilled = true;
80 $label = '<comment>PDO Driver</comment>'; 80 $label = '<comment>PDO Driver (%s)</comment>';
81 $status = '<info>OK!</info>'; 81 $status = '<info>OK!</info>';
82 $help = ''; 82 $help = '';
83 83
@@ -87,7 +87,7 @@ class InstallCommand extends ContainerAwareCommand
87 $help = 'Database driver "'.$this->getContainer()->getParameter('database_driver').'" is not installed.'; 87 $help = 'Database driver "'.$this->getContainer()->getParameter('database_driver').'" is not installed.';
88 } 88 }
89 89
90 $rows[] = [$label, $status, $help]; 90 $rows[] = [sprintf($label, $this->getContainer()->getParameter('database_driver')), $status, $help];
91 91
92 // testing if connection to the database can be etablished 92 // testing if connection to the database can be etablished
93 $label = '<comment>Database connection</comment>'; 93 $label = '<comment>Database connection</comment>';
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 91cdcae5..abd35c02 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;
7use Symfony\Component\HttpFoundation\JsonResponse; 7use Symfony\Component\HttpFoundation\JsonResponse;
8use Symfony\Component\HttpFoundation\RedirectResponse; 8use Symfony\Component\HttpFoundation\RedirectResponse;
9use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
10use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
10use Wallabag\CoreBundle\Entity\Config; 11use Wallabag\CoreBundle\Entity\Config;
11use Wallabag\CoreBundle\Entity\TaggingRule; 12use Wallabag\CoreBundle\Entity\TaggingRule;
12use Wallabag\CoreBundle\Form\Type\ConfigType; 13use Wallabag\CoreBundle\Form\Type\ConfigType;
@@ -148,6 +149,9 @@ class ConfigController extends Controller
148 'token' => $config->getRssToken(), 149 'token' => $config->getRssToken(),
149 ], 150 ],
150 'twofactor_auth' => $this->getParameter('twofactor_auth'), 151 'twofactor_auth' => $this->getParameter('twofactor_auth'),
152 'enabled_users' => $this->getDoctrine()
153 ->getRepository('WallabagUserBundle:User')
154 ->getSumEnabledUsers(),
151 ]); 155 ]);
152 } 156 }
153 157
@@ -251,4 +255,37 @@ class ConfigController extends Controller
251 255
252 return $config; 256 return $config;
253 } 257 }
258
259 /**
260 * Delete account for current user.
261 *
262 * @Route("/account/delete", name="delete_account")
263 *
264 * @param Request $request
265 *
266 * @throws AccessDeniedHttpException
267 *
268 * @return \Symfony\Component\HttpFoundation\RedirectResponse
269 */
270 public function deleteAccountAction(Request $request)
271 {
272 $enabledUsers = $this->getDoctrine()
273 ->getRepository('WallabagUserBundle:User')
274 ->getSumEnabledUsers();
275
276 if ($enabledUsers <= 1) {
277 throw new AccessDeniedHttpException();
278 }
279
280 $user = $this->getUser();
281
282 // logout current user
283 $this->get('security.token_storage')->setToken(null);
284 $request->getSession()->invalidate();
285
286 $em = $this->get('fos_user.user_manager');
287 $em->deleteUser($user);
288
289 return $this->redirect($this->generateUrl('fos_user_security_login'));
290 }
254} 291}
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
index 2652a102..2de5d7bd 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Navn' 88 name_label: 'Navn'
89 email_label: 'Emailadresse' 89 email_label: 'Emailadresse'
90 # twoFactorAuthentication_label: 'Two factor authentication' 90 # twoFactorAuthentication_label: 'Two factor authentication'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Gammel adgangskode' 97 old_password_label: 'Gammel adgangskode'
93 new_password_label: 'Ny adgangskode' 98 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 e0f29b61..515d43a0 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Name' 88 name_label: 'Name'
89 email_label: 'E-Mail-Adresse' 89 email_label: 'E-Mail-Adresse'
90 twoFactorAuthentication_label: 'Zwei-Faktor-Authentifizierung' 90 twoFactorAuthentication_label: 'Zwei-Faktor-Authentifizierung'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Altes Kennwort' 97 old_password_label: 'Altes Kennwort'
93 new_password_label: 'Neues Kennwort' 98 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 b8e98112..43f5a950 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Name' 88 name_label: 'Name'
89 email_label: 'Email' 89 email_label: 'Email'
90 twoFactorAuthentication_label: 'Two factor authentication' 90 twoFactorAuthentication_label: 'Two factor authentication'
91 delete:
92 title: Delete my account (danger zone !)
93 description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 confirm: Are you really sure? (it can't be UNDONE)
95 button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Current password' 97 old_password_label: 'Current password'
93 new_password_label: 'New password' 98 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 70633bd7..adeab2b0 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Nombre' 88 name_label: 'Nombre'
89 email_label: 'Direccion e-mail' 89 email_label: 'Direccion e-mail'
90 twoFactorAuthentication_label: 'AutentificaciĂ³n de dos factores' 90 twoFactorAuthentication_label: 'AutentificaciĂ³n de dos factores'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Contraseña actual' 97 old_password_label: 'Contraseña actual'
93 new_password_label: 'Nueva contraseña' 98 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 074ab7a8..0751752b 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'نام' 88 name_label: 'نام'
89 email_label: 'نشانی ایمیل' 89 email_label: 'نشانی ایمیل'
90 twoFactorAuthentication_label: 'تأیید ۲مرحله‌ای' 90 twoFactorAuthentication_label: 'تأیید ۲مرحله‌ای'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'رمز قدیمی' 97 old_password_label: 'رمز قدیمی'
93 new_password_label: 'رمز تازه' 98 new_password_label: 'رمز تازه'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index 6d85a5ae..1c32a77c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Nom' 88 name_label: 'Nom'
89 email_label: 'Adresse e-mail' 89 email_label: 'Adresse e-mail'
90 twoFactorAuthentication_label: 'Double authentification' 90 twoFactorAuthentication_label: 'Double authentification'
91 delete:
92 title: Supprimer mon compte (attention danger !)
93 description: Si vous confirmez la suppression de votre compte, TOUS les articles, TOUS les tags, TOUTES les annotations et votre compte seront DÉFINITIVEMENT supprimé (c'est IRRÉVERSIBLE). Vous serez ensuite déconnecté.
94 confirm: Vous Ăªtes vraiment sĂ»r ? (c'est IRRÉVERSIBLE !)
95 button: 'Supprimer mon compte'
91 form_password: 96 form_password:
92 old_password_label: 'Mot de passe actuel' 97 old_password_label: 'Mot de passe actuel'
93 new_password_label: 'Nouveau mot de passe' 98 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 15f7e774..f662bd55 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Nome' 88 name_label: 'Nome'
89 email_label: 'E-mail' 89 email_label: 'E-mail'
90 twoFactorAuthentication_label: 'Two factor authentication' 90 twoFactorAuthentication_label: 'Two factor authentication'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Password corrente' 97 old_password_label: 'Password corrente'
93 new_password_label: 'Nuova password' 98 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 1d10be2a..9e314f73 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Nom' 88 name_label: 'Nom'
89 email_label: 'Adreça de corrièl' 89 email_label: 'Adreça de corrièl'
90 twoFactorAuthentication_label: 'Dobla autentificacion' 90 twoFactorAuthentication_label: 'Dobla autentificacion'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Senhal actual' 97 old_password_label: 'Senhal actual'
93 new_password_label: 'Senhal novèl' 98 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 547e9c8b..9877d59a 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Nazwa' 88 name_label: 'Nazwa'
89 email_label: 'Adres email' 89 email_label: 'Adres email'
90 twoFactorAuthentication_label: 'Autoryzacja dwuetapowa' 90 twoFactorAuthentication_label: 'Autoryzacja dwuetapowa'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Stare hasło' 97 old_password_label: 'Stare hasło'
93 new_password_label: 'Nowe hasło' 98 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 2b1d4f6d..83246ed3 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Nume' 88 name_label: 'Nume'
89 email_label: 'E-mail' 89 email_label: 'E-mail'
90 # twoFactorAuthentication_label: 'Two factor authentication' 90 # twoFactorAuthentication_label: 'Two factor authentication'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Parola veche' 97 old_password_label: 'Parola veche'
93 new_password_label: 'Parola nouă' 98 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 8cfc245a..24dd6ff8 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
@@ -88,6 +88,11 @@ config:
88 name_label: 'Ä°sim' 88 name_label: 'Ä°sim'
89 email_label: 'E-posta' 89 email_label: 'E-posta'
90 twoFactorAuthentication_label: 'İki adımlı doğrulama' 90 twoFactorAuthentication_label: 'İki adımlı doğrulama'
91 delete:
92 # title: Delete my account (danger zone !)
93 # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out.
94 # confirm: Are you really sure? (it can't be UNDONE)
95 # button: Delete my account
91 form_password: 96 form_password:
92 old_password_label: 'Eski ÅŸifre' 97 old_password_label: 'Eski ÅŸifre'
93 new_password_label: 'Yeni ÅŸifre' 98 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..54508b6d 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
@@ -150,6 +150,15 @@
150 {{ form_widget(form.user.save) }} 150 {{ form_widget(form.user.save) }}
151 </form> 151 </form>
152 152
153 {% if enabled_users > 1 %}
154 <h2>{{ 'config.form_user.delete.title'|trans }}</h2>
155
156 <p>{{ 'config.form_user.delete.description'|trans }}</p>
157 <a href="{{ path('delete_account') }}" onclick="return confirm('{{ 'config.form_user.delete.confirm'|trans|escape('js') }}')" class="waves-effect waves-light btn red delete-account">
158 {{ 'config.form_user.delete.button'|trans }}
159 </a>
160 {% endif %}
161
153 <h2>{{ 'config.tab_menu.password'|trans }}</h2> 162 <h2>{{ 'config.tab_menu.password'|trans }}</h2>
154 163
155 {{ form_start(form.pwd) }} 164 {{ form_start(form.pwd) }}
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 270c077f..8434508d 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,6 +167,18 @@
167 {{ form_widget(form.user.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} 167 {{ form_widget(form.user.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
168 {{ form_widget(form.user._token) }} 168 {{ form_widget(form.user._token) }}
169 </form> 169 </form>
170
171 {% if enabled_users > 1 %}
172 <br /><hr /><br />
173
174 <div class="row">
175 <h5>{{ 'config.form_user.delete.title'|trans }}</h5>
176 <p>{{ 'config.form_user.delete.description'|trans }}</p>
177 <a href="{{ path('delete_account') }}" onclick="return confirm('{{ 'config.form_user.delete.confirm'|trans|escape('js') }}')" class="waves-effect waves-light btn red delete-account">
178 {{ 'config.form_user.delete.button'|trans }}
179 </a>
180 </div>
181 {% endif %}
170 </div> 182 </div>
171 183
172 <div id="set4" class="col s12"> 184 <div id="set4" class="col s12">
diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php
index 009c4881..445edb3c 100644
--- a/src/Wallabag/UserBundle/Repository/UserRepository.php
+++ b/src/Wallabag/UserBundle/Repository/UserRepository.php
@@ -38,4 +38,18 @@ class UserRepository extends EntityRepository
38 ->getQuery() 38 ->getQuery()
39 ->getSingleResult(); 39 ->getSingleResult();
40 } 40 }
41
42 /**
43 * Count how many users are enabled.
44 *
45 * @return int
46 */
47 public function getSumEnabledUsers()
48 {
49 return $this->createQueryBuilder('u')
50 ->select('count(u)')
51 ->andWhere('u.expired = false')
52 ->getQuery()
53 ->getSingleScalarResult();
54 }
41} 55}
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 1954c654..5faa0130 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -3,6 +3,8 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\UserBundle\Entity\User;
6 8
7class ConfigControllerTest extends WallabagCoreTestCase 9class ConfigControllerTest extends WallabagCoreTestCase
8{ 10{
@@ -570,4 +572,122 @@ class ConfigControllerTest extends WallabagCoreTestCase
570 $config->set('demo_mode_enabled', 0); 572 $config->set('demo_mode_enabled', 0);
571 $config->set('demo_mode_username', 'wallabag'); 573 $config->set('demo_mode_username', 'wallabag');
572 } 574 }
575
576 public function testDeleteUserButtonVisibility()
577 {
578 $this->logInAs('admin');
579 $client = $this->getClient();
580
581 $crawler = $client->request('GET', '/config');
582
583 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
584 $this->assertContains('config.form_user.delete.button', $body[0]);
585
586 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
587
588 $user = $em
589 ->getRepository('WallabagUserBundle:User')
590 ->findOneByUsername('empty');
591 $user->setExpired(1);
592 $em->persist($user);
593
594 $user = $em
595 ->getRepository('WallabagUserBundle:User')
596 ->findOneByUsername('bob');
597 $user->setExpired(1);
598 $em->persist($user);
599
600 $em->flush();
601
602 $crawler = $client->request('GET', '/config');
603
604 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
605 $this->assertNotContains('config.form_user.delete.button', $body[0]);
606
607 $client->request('GET', '/account/delete');
608 $this->assertEquals(403, $client->getResponse()->getStatusCode());
609
610 $user = $em
611 ->getRepository('WallabagUserBundle:User')
612 ->findOneByUsername('empty');
613 $user->setExpired(0);
614 $em->persist($user);
615
616 $user = $em
617 ->getRepository('WallabagUserBundle:User')
618 ->findOneByUsername('bob');
619 $user->setExpired(0);
620 $em->persist($user);
621
622 $em->flush();
623 }
624
625 public function testDeleteAccount()
626 {
627 $client = $this->getClient();
628 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
629
630 $user = new User();
631 $user->setName('Wallace');
632 $user->setEmail('wallace@wallabag.org');
633 $user->setUsername('wallace');
634 $user->setPlainPassword('wallace');
635 $user->setEnabled(true);
636 $user->addRole('ROLE_SUPER_ADMIN');
637
638 $em->persist($user);
639
640 $config = new Config($user);
641
642 $config->setTheme('material');
643 $config->setItemsPerPage(30);
644 $config->setReadingSpeed(1);
645 $config->setLanguage('en');
646 $config->setPocketConsumerKey('xxxxx');
647
648 $em->persist($config);
649 $em->flush();
650
651 $this->logInAs('wallace');
652 $loggedInUserId = $this->getLoggedInUserId();
653
654 // create entry to check after user deletion
655 // that this entry is also deleted
656 $crawler = $client->request('GET', '/new');
657
658 $this->assertEquals(200, $client->getResponse()->getStatusCode());
659
660 $form = $crawler->filter('form[name=entry]')->form();
661 $data = [
662 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
663 ];
664
665 $client->submit($form, $data);
666 $this->assertEquals(302, $client->getResponse()->getStatusCode());
667
668 $crawler = $client->request('GET', '/config');
669
670 $deleteLink = $crawler->filter('.delete-account')->last()->link();
671
672 $client->click($deleteLink);
673 $this->assertEquals(302, $client->getResponse()->getStatusCode());
674
675 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
676 $user = $em
677 ->getRepository('WallabagUserBundle:User')
678 ->createQueryBuilder('u')
679 ->where('u.username = :username')->setParameter('username', 'wallace')
680 ->getQuery()
681 ->getOneOrNullResult()
682 ;
683
684 $this->assertNull($user);
685
686 $entries = $client->getContainer()
687 ->get('doctrine.orm.entity_manager')
688 ->getRepository('WallabagCoreBundle:Entry')
689 ->findByUser($loggedInUserId);
690
691 $this->assertEmpty($entries);
692 }
573} 693}