Merge pull request #1683 from wallabag/v2-demo

Demonstration mode to prevent password changes
This commit is contained in:
Nicolas Lœuillet 2016-02-22 14:18:34 +01:00
commit 2aadeea8cd
7 changed files with 64 additions and 6 deletions

View file

@ -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"

View file

@ -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"

View file

@ -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) {

View file

@ -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');
}

View file

@ -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) {

View file

@ -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'

View file

@ -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');
}
}