diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml index 719e51eab..b627376ec 100644 --- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml +++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml @@ -25,3 +25,5 @@ modify_settings: "apply" piwik_host: Host of your website in Piwik piwik_site_id: ID of your website in Piwik piwik_enabled: Enable Piwik +demo_mode_enabled: "Enable demo mode ? (only used for the wallabag public demo)" +demo_mode_username: "Demo user" diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml index ab5dfc721..084eb6df1 100644 --- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml +++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml @@ -25,3 +25,5 @@ modify_settings: "appliquer" piwik_host: URL de votre site dans Piwik piwik_site_id: ID de votre site dans Piwik piwik_enabled: Activer Piwik +demo_mode_enabled: "Activer le mode démo ? (utiliser uniquement pour la démo publique de wallabag)" +demo_mode_username: "Utilisateur de la démo" diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 93520f9a8..2e241757d 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -327,6 +327,16 @@ class InstallCommand extends ContainerAwareCommand 'value' => '1', 'section' => 'analytics', ], + [ + 'name' => 'demo_mode_enabled', + 'value' => '0', + 'section' => 'misc', + ], + [ + 'name' => 'demo_mode_username', + 'value' => 'wallabag', + 'section' => 'misc', + ], ]; foreach ($settings as $setting) { diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 6eb621d87..1791eac23 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -57,13 +57,16 @@ class ConfigController extends Controller $pwdForm->handleRequest($request); if ($pwdForm->isValid()) { - $user->setPlainPassword($pwdForm->get('new_password')->getData()); - $userManager->updateUser($user, true); + if ($this->get('craue_config')->get('demo_mode_enabled') && $this->get('craue_config')->get('demo_mode_username') === $user->getUsername()) { + $message = 'In demonstration mode, you can\'t change password for this user.'; + } else { + $message = 'Password updated'; - $this->get('session')->getFlashBag()->add( - 'notice', - 'Password updated' - ); + $user->setPlainPassword($pwdForm->get('new_password')->getData()); + $userManager->updateUser($user, true); + } + + $this->get('session')->getFlashBag()->add('notice', $message); return $this->redirect($this->generateUrl('config').'#set4'); } diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php index 10b60f300..1f4cafdfc 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 'value' => '1', 'section' => 'analytics', ], + [ + 'name' => 'demo_mode_enabled', + 'value' => '0', + 'section' => 'misc', + ], + [ + 'name' => 'demo_mode_username', + 'value' => 'wallabag', + 'section' => 'misc', + ], ]; 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 541616469..65280ebc9 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é" Tagging rule deleted: "Règle supprimée" Tagging rules updated: "Règles mises à jour" User "%username%" added: 'Utilisateur "%username%" ajouté' +In 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.' # Entry Mark as read: 'Marquer comme lu' diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 6c370a2d8..2af93ffec 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 $this->assertEquals(403, $client->getResponse()->getStatusCode()); $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent()); } + + public function testDemoMode() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $config = $client->getContainer()->get('craue_config'); + $config->set('demo_mode_enabled', 1); + $config->set('demo_mode_username', 'admin'); + + $crawler = $client->request('GET', '/config'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[id=change_passwd_save]')->form(); + + $data = array( + 'change_passwd[old_password]' => 'mypassword', + 'change_passwd[new_password][first]' => 'mypassword', + 'change_passwd[new_password][second]' => 'mypassword', + ); + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('In demonstration mode, you can\'t change password for this user.', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); + + $config->set('demo_mode_enabled', 0); + $config->set('demo_mode_username', 'wallabag'); + } }