Added an demo mode option, where the user password change dialog is disabled.

This commit is contained in:
Jan Böhmer 2019-10-20 00:01:06 +02:00
parent c955a3a221
commit 89acf91fe6
4 changed files with 26 additions and 6 deletions

3
.env
View file

@ -47,4 +47,7 @@ NO_URL_REWRITE_AVAILABLE=false
# When this is empty the content of config/banner.md is used as banner
BANNER=""
# In demo mode things it is not possible for a user to change his password and his settings.
DEMO_MODE=0
### End custom vars

View file

@ -17,6 +17,7 @@ parameters:
global_theme: '' # The theme to use globally (see public/build/themes/ for choices). Set to '' for default bootstrap theme
# Allow users to download attachments to server. Warning: This can be dangerous, because via that feature attackers maybe can access ressources on your intranet!
allow_attachments_downloads: false
demo_mode: '%env(bool:DEMO_MODE)%' # If set to true, all potentially dangerous things are disabled (like changing passwords of the own user)
services:
# default configuration for services in *this* file
@ -87,6 +88,9 @@ services:
$allow_attachments_downloads: '%allow_attachments_downloads%'
$mimeTypes: '@mime_types'
App\Form\UserSettingsType:
arguments:
$demo_mode: '%demo_mode%'
App\EventSubscriber\TimezoneListener:
arguments:

View file

@ -197,11 +197,15 @@ class UserController extends AdminPages\BaseAdminController
* Password change form
****************************/
$demo_mode = $this->getParameter('demo_mode');
$pw_form = $this->createFormBuilder()
->add('old_password', PasswordType::class, [
'label' => 'user.settings.pw_old.label',
'disabled' => $demo_mode,
'constraints' => [new UserPassword()], ]) //This constraint checks, if the current user pw was inputted.
->add('new_password', RepeatedType::class, [
'disabled' => $demo_mode,
'type' => PasswordType::class,
'first_options' => ['label' => 'user.settings.pw_new.label'],
'second_options' => ['label' => 'user.settings.pw_confirm.label'],

View file

@ -6,6 +6,8 @@ use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\User;
use App\Form\Type\CurrencyEntityType;
use App\Form\Type\StructuralEntityType;
use Doctrine\ORM\Query\Parameter;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
@ -26,10 +28,13 @@ class UserSettingsType extends AbstractType
protected $trans;
public function __construct(Security $security, TranslatorInterface $trans)
protected $demo_mode;
public function __construct(Security $security, TranslatorInterface $trans, bool $demo_mode)
{
$this->security = $security;
$this->trans = $trans;
$this->demo_mode = $demo_mode;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@ -37,29 +42,30 @@ class UserSettingsType extends AbstractType
$builder
->add('name', TextType::class, [
'label' => $this->trans->trans('user.username.label'),
'disabled' => !$this->security->isGranted('edit_username', $options['data']),
'disabled' => !$this->security->isGranted('edit_username', $options['data']) || $this->demo_mode,
])
->add('first_name', TextType::class, [
'required' => false,
'label' => $this->trans->trans('user.firstName.label'),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']) || $this->demo_mode,
])
->add('last_name', TextType::class, [
'required' => false,
'label' => $this->trans->trans('user.lastName.label'),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']) || $this->demo_mode,
])
->add('department', TextType::class, [
'required' => false,
'label' => $this->trans->trans('user.department.label'),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']) || $this->demo_mode,
])
->add('email', EmailType::class, [
'required' => false,
'label' => $this->trans->trans('user.email.label'),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']),
'disabled' => !$this->security->isGranted('edit_infos', $options['data']) || $this->demo_mode,
])
->add('language', LanguageType::class, [
'disabled' => $this->demo_mode,
'required' => false,
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
'placeholder' => $this->trans->trans('user_settings.language.placeholder'),
@ -67,6 +73,7 @@ class UserSettingsType extends AbstractType
'preferred_choices' => ['en', 'de']
])
->add('timezone', TimezoneType::class, [
'disabled' => $this->demo_mode,
'required' => false,
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
'placeholder' => $this->trans->trans('user_settings.timezone.placeholder'),
@ -74,6 +81,7 @@ class UserSettingsType extends AbstractType
'preferred_choices' => ['Europe/Berlin']
])
->add('theme', ChoiceType::class, [
'disabled' => $this->demo_mode,
'required' => false,
'attr' => ['class' => 'selectpicker'],
'choices' => User::AVAILABLE_THEMES,
@ -84,6 +92,7 @@ class UserSettingsType extends AbstractType
'label' => $this->trans->trans('user.theme.label'),
])
->add('currency', CurrencyEntityType::class, [
'disabled' => $this->demo_mode,
'required' => false,
'label' => $this->trans->trans('user.currency.label')
])