aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas@loeuillet.org>2016-02-22 14:18:34 +0100
committerNicolas Lœuillet <nicolas@loeuillet.org>2016-02-22 14:18:34 +0100
commit2aadeea8cd968a2e32631b166097748611a520f6 (patch)
tree2a167eaae0edea08060abfd132aec3c4a7239207
parent2b71f68c95acd20b9ee5e6dc4d67a1ec649fc440 (diff)
parentb6c00b0b807108cd54ab32fa73f9c196f4f12d97 (diff)
downloadwallabag-2aadeea8cd968a2e32631b166097748611a520f6.tar.gz
wallabag-2aadeea8cd968a2e32631b166097748611a520f6.tar.zst
wallabag-2aadeea8cd968a2e32631b166097748611a520f6.zip
Merge pull request #1683 from wallabag/v2-demo
Demonstration mode to prevent password changes
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml2
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml2
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php10
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php15
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php10
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml1
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php30
7 files changed, 64 insertions, 6 deletions
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml
index 719e51ea..b627376e 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml
@@ -25,3 +25,5 @@ modify_settings: "apply"
25piwik_host: Host of your website in Piwik 25piwik_host: Host of your website in Piwik
26piwik_site_id: ID of your website in Piwik 26piwik_site_id: ID of your website in Piwik
27piwik_enabled: Enable Piwik 27piwik_enabled: Enable Piwik
28demo_mode_enabled: "Enable demo mode ? (only used for the wallabag public demo)"
29demo_mode_username: "Demo user"
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml
index ab5dfc72..084eb6df 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml
@@ -25,3 +25,5 @@ modify_settings: "appliquer"
25piwik_host: URL de votre site dans Piwik 25piwik_host: URL de votre site dans Piwik
26piwik_site_id: ID de votre site dans Piwik 26piwik_site_id: ID de votre site dans Piwik
27piwik_enabled: Activer Piwik 27piwik_enabled: Activer Piwik
28demo_mode_enabled: "Activer le mode démo ? (utiliser uniquement pour la démo publique de wallabag)"
29demo_mode_username: "Utilisateur de la démo"
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 93520f9a..2e241757 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -327,6 +327,16 @@ class InstallCommand extends ContainerAwareCommand
327 'value' => '1', 327 'value' => '1',
328 'section' => 'analytics', 328 'section' => 'analytics',
329 ], 329 ],
330 [
331 'name' => 'demo_mode_enabled',
332 'value' => '0',
333 'section' => 'misc',
334 ],
335 [
336 'name' => 'demo_mode_username',
337 'value' => 'wallabag',
338 'section' => 'misc',
339 ],
330 ]; 340 ];
331 341
332 foreach ($settings as $setting) { 342 foreach ($settings as $setting) {
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 6eb621d8..1791eac2 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -57,13 +57,16 @@ class ConfigController extends Controller
57 $pwdForm->handleRequest($request); 57 $pwdForm->handleRequest($request);
58 58
59 if ($pwdForm->isValid()) { 59 if ($pwdForm->isValid()) {
60 $user->setPlainPassword($pwdForm->get('new_password')->getData()); 60 if ($this->get('craue_config')->get('demo_mode_enabled') && $this->get('craue_config')->get('demo_mode_username') === $user->getUsername()) {
61 $userManager->updateUser($user, true); 61 $message = 'In demonstration mode, you can\'t change password for this user.';
62 } else {
63 $message = 'Password updated';
62 64
63 $this->get('session')->getFlashBag()->add( 65 $user->setPlainPassword($pwdForm->get('new_password')->getData());
64 'notice', 66 $userManager->updateUser($user, true);
65 'Password updated' 67 }
66 ); 68
69 $this->get('session')->getFlashBag()->add('notice', $message);
67 70
68 return $this->redirect($this->generateUrl('config').'#set4'); 71 return $this->redirect($this->generateUrl('config').'#set4');
69 } 72 }
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
index 10b60f30..1f4cafdf 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
@@ -125,6 +125,16 @@ class LoadSettingData extends AbstractFixture implements OrderedFixtureInterface
125 'value' => '1', 125 'value' => '1',
126 'section' => 'analytics', 126 'section' => 'analytics',
127 ], 127 ],
128 [
129 'name' => 'demo_mode_enabled',
130 'value' => '0',
131 'section' => 'misc',
132 ],
133 [
134 'name' => 'demo_mode_username',
135 'value' => 'wallabag',
136 'section' => 'misc',
137 ],
128 ]; 138 ];
129 139
130 foreach ($settings as $setting) { 140 foreach ($settings as $setting) {
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index 54161646..65280ebc 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -175,6 +175,7 @@ Entry deleted: "Article supprimé"
175Tagging rule deleted: "Règle supprimée" 175Tagging rule deleted: "Règle supprimée"
176Tagging rules updated: "Règles mises à jour" 176Tagging rules updated: "Règles mises à jour"
177User "%username%" added: 'Utilisateur "%username%" ajouté' 177User "%username%" added: 'Utilisateur "%username%" ajouté'
178In demonstration mode, you can't change password for this user.: 'En démo, vous ne pouvez pas changer le mot de passe de cet utilisateur.'
178 179
179# Entry 180# Entry
180Mark as read: 'Marquer comme lu' 181Mark as read: 'Marquer comme lu'
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
index 6c370a2d..2af93ffe 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
@@ -577,4 +577,34 @@ class ConfigControllerTest extends WallabagCoreTestCase
577 $this->assertEquals(403, $client->getResponse()->getStatusCode()); 577 $this->assertEquals(403, $client->getResponse()->getStatusCode());
578 $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent()); 578 $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent());
579 } 579 }
580
581 public function testDemoMode()
582 {
583 $this->logInAs('admin');
584 $client = $this->getClient();
585
586 $config = $client->getContainer()->get('craue_config');
587 $config->set('demo_mode_enabled', 1);
588 $config->set('demo_mode_username', 'admin');
589
590 $crawler = $client->request('GET', '/config');
591
592 $this->assertEquals(200, $client->getResponse()->getStatusCode());
593
594 $form = $crawler->filter('button[id=change_passwd_save]')->form();
595
596 $data = array(
597 'change_passwd[old_password]' => 'mypassword',
598 'change_passwd[new_password][first]' => 'mypassword',
599 'change_passwd[new_password][second]' => 'mypassword',
600 );
601
602 $client->submit($form, $data);
603
604 $this->assertEquals(302, $client->getResponse()->getStatusCode());
605 $this->assertContains('In demonstration mode, you can\'t change password for this user.', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
606
607 $config->set('demo_mode_enabled', 0);
608 $config->set('demo_mode_username', 'wallabag');
609 }
580} 610}