2019-04-28 14:18:11 +02:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2020-02-22 18:14:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-04-28 14:18:11 +02:00
|
|
|
namespace App\Form;
|
|
|
|
|
2020-02-01 19:48:07 +01:00
|
|
|
use App\Entity\Base\AbstractNamedDBElement;
|
|
|
|
use App\Entity\Base\AbstractStructuralDBElement;
|
2019-11-09 00:47:20 +01:00
|
|
|
use App\Entity\UserSystem\Group;
|
2019-10-13 17:48:18 +02:00
|
|
|
use App\Entity\UserSystem\User;
|
2019-09-10 17:12:56 +02:00
|
|
|
use App\Form\Permissions\PermissionsType;
|
2019-09-19 12:12:12 +02:00
|
|
|
use App\Form\Type\CurrencyEntityType;
|
2023-01-23 23:58:11 +01:00
|
|
|
use App\Form\Type\MasterPictureAttachmentType;
|
2019-08-13 23:04:06 +02:00
|
|
|
use App\Form\Type\StructuralEntityType;
|
2023-02-01 23:15:02 +01:00
|
|
|
use App\Form\Type\ThemeChoiceType;
|
2019-04-28 14:18:11 +02:00
|
|
|
use Symfony\Component\Form\AbstractType;
|
2019-09-19 12:35:28 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
2019-09-19 12:12:12 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
2019-09-24 18:28:35 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
2019-09-19 12:12:12 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
|
2019-09-19 12:35:28 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
2019-04-28 14:18:11 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ResetType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
2019-09-19 12:12:12 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
|
2019-04-28 14:18:11 +02:00
|
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
2019-09-24 18:28:35 +02:00
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
2019-04-28 14:18:11 +02:00
|
|
|
use Symfony\Component\Security\Core\Security;
|
2019-09-19 12:35:28 +02:00
|
|
|
use Symfony\Component\Validator\Constraints\Length;
|
2019-04-28 14:18:11 +02:00
|
|
|
|
|
|
|
class UserAdminForm extends AbstractType
|
|
|
|
{
|
2022-09-18 22:59:31 +02:00
|
|
|
protected Security $security;
|
2019-04-28 14:18:11 +02:00
|
|
|
|
2019-12-26 14:53:13 +01:00
|
|
|
public function __construct(Security $security)
|
2019-04-28 14:18:11 +02:00
|
|
|
{
|
|
|
|
$this->security = $security;
|
|
|
|
}
|
|
|
|
|
2020-01-05 15:46:58 +01:00
|
|
|
public function configureOptions(OptionsResolver $resolver): void
|
2019-09-24 18:28:35 +02:00
|
|
|
{
|
|
|
|
parent::configureOptions($resolver); // TODO: Change the autogenerated stub
|
|
|
|
$resolver->setRequired('attachment_class');
|
2020-03-24 21:49:09 +01:00
|
|
|
$resolver->setDefault('parameter_class', false);
|
2019-09-24 18:28:35 +02:00
|
|
|
}
|
2019-04-28 14:18:11 +02:00
|
|
|
|
2020-01-05 15:46:58 +01:00
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
2019-04-28 14:18:11 +02:00
|
|
|
{
|
2020-02-01 19:48:07 +01:00
|
|
|
/** @var AbstractStructuralDBElement $entity */
|
2019-04-28 14:18:11 +02:00
|
|
|
$entity = $options['data'];
|
2019-11-09 00:47:20 +01:00
|
|
|
$is_new = null === $entity->getID();
|
2019-04-28 14:18:11 +02:00
|
|
|
|
|
|
|
$builder
|
2019-09-04 15:53:18 +02:00
|
|
|
->add('name', TextType::class, [
|
|
|
|
'empty_data' => '',
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.username.label',
|
2020-01-05 22:49:00 +01:00
|
|
|
'attr' => [
|
|
|
|
'placeholder' => 'user.username.placeholder',
|
|
|
|
],
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('edit_username', $entity),
|
2019-09-04 15:53:18 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
->add('group', StructuralEntityType::class, [
|
|
|
|
'class' => Group::class,
|
|
|
|
'required' => false,
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'group.label',
|
2019-09-04 15:53:18 +02:00
|
|
|
'disable_not_selectable' => true,
|
2022-11-14 22:42:12 +01:00
|
|
|
'disabled' => !$this->security->isGranted('edit_permissions', $entity),
|
2020-01-05 22:49:00 +01:00
|
|
|
])
|
2019-04-28 14:18:11 +02:00
|
|
|
|
2019-09-04 15:53:18 +02:00
|
|
|
->add('first_name', TextType::class, [
|
|
|
|
'empty_data' => '',
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.firstName.label',
|
2020-01-05 22:49:00 +01:00
|
|
|
'attr' => [
|
|
|
|
'placeholder' => 'user.firstName.placeholder',
|
|
|
|
],
|
|
|
|
'required' => false,
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity),
|
2019-09-04 15:53:18 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
->add('last_name', TextType::class, [
|
|
|
|
'empty_data' => '',
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.lastName.label',
|
2020-01-05 22:49:00 +01:00
|
|
|
'attr' => [
|
|
|
|
'placeholder' => 'user.lastName.placeholder',
|
|
|
|
],
|
2019-09-04 15:53:18 +02:00
|
|
|
'required' => false,
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity),
|
2019-09-04 15:53:18 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
->add('email', TextType::class, [
|
|
|
|
'empty_data' => '',
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.email.label',
|
2020-01-05 22:49:00 +01:00
|
|
|
'attr' => [
|
|
|
|
'placeholder' => 'user.email.placeholder',
|
|
|
|
],
|
2019-09-04 15:53:18 +02:00
|
|
|
'required' => false,
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity),
|
2020-01-05 22:49:00 +01:00
|
|
|
])
|
2019-04-28 14:18:11 +02:00
|
|
|
|
2019-09-04 15:53:18 +02:00
|
|
|
->add('department', TextType::class, [
|
|
|
|
'empty_data' => '',
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.department.label',
|
2020-01-05 22:49:00 +01:00
|
|
|
'attr' => [
|
|
|
|
'placeholder' => 'user.department.placeholder',
|
|
|
|
],
|
2019-09-04 15:53:18 +02:00
|
|
|
'required' => false,
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity),
|
2019-09-04 15:53:18 +02:00
|
|
|
])
|
2019-04-28 14:18:11 +02:00
|
|
|
|
2019-09-19 12:12:12 +02:00
|
|
|
//Config section
|
|
|
|
->add('language', LanguageType::class, [
|
|
|
|
'required' => false,
|
2019-12-26 14:53:13 +01:00
|
|
|
'placeholder' => 'user_settings.language.placeholder',
|
|
|
|
'label' => 'user.language_select',
|
2019-09-19 12:12:12 +02:00
|
|
|
'preferred_choices' => ['en', 'de'],
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
|
2019-09-19 12:12:12 +02:00
|
|
|
])
|
|
|
|
->add('timezone', TimezoneType::class, [
|
|
|
|
'required' => false,
|
2019-12-26 14:53:13 +01:00
|
|
|
'placeholder' => 'user_settings.timezone.placeholder',
|
|
|
|
'label' => 'user.timezone.label',
|
2019-09-19 12:12:12 +02:00
|
|
|
'preferred_choices' => ['Europe/Berlin'],
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
|
2019-09-19 12:12:12 +02:00
|
|
|
])
|
2023-02-01 23:15:02 +01:00
|
|
|
->add('theme', ThemeChoiceType::class, [
|
2019-09-19 12:12:12 +02:00
|
|
|
'required' => false,
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.theme.label',
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
|
2019-09-19 12:12:12 +02:00
|
|
|
])
|
|
|
|
->add('currency', CurrencyEntityType::class, [
|
|
|
|
'required' => false,
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.currency.label',
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
|
2019-09-19 12:12:12 +02:00
|
|
|
])
|
|
|
|
|
2019-09-19 12:35:28 +02:00
|
|
|
->add('new_password', RepeatedType::class, [
|
|
|
|
'type' => PasswordType::class,
|
2020-01-05 22:49:00 +01:00
|
|
|
'first_options' => [
|
|
|
|
'label' => 'user.settings.pw_new.label',
|
|
|
|
],
|
|
|
|
'second_options' => [
|
|
|
|
'label' => 'user.settings.pw_confirm.label',
|
|
|
|
],
|
2019-09-19 12:35:28 +02:00
|
|
|
'invalid_message' => 'password_must_match',
|
|
|
|
'required' => false,
|
|
|
|
'mapped' => false,
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('set_password', $entity),
|
2019-09-19 12:35:28 +02:00
|
|
|
'constraints' => [new Length([
|
|
|
|
'min' => 6,
|
|
|
|
'max' => 128,
|
2019-11-09 00:47:20 +01:00
|
|
|
])],
|
2019-09-19 12:35:28 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
->add('need_pw_change', CheckboxType::class, [
|
|
|
|
'required' => false,
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.edit.needs_pw_change',
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('set_password', $entity),
|
2019-10-26 23:22:27 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
->add('disabled', CheckboxType::class, [
|
|
|
|
'required' => false,
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'user.edit.user_disabled',
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('set_password', $entity)
|
2019-11-09 00:47:20 +01:00
|
|
|
|| $entity === $this->security->getUser(),
|
2019-09-19 12:35:28 +02:00
|
|
|
])
|
|
|
|
|
2019-09-19 12:12:12 +02:00
|
|
|
//Permission section
|
2019-09-10 17:12:56 +02:00
|
|
|
->add('permissions', PermissionsType::class, [
|
|
|
|
'mapped' => false,
|
|
|
|
'data' => $builder->getData(),
|
2020-08-21 21:36:22 +02:00
|
|
|
'disabled' => !$this->security->isGranted('edit_permissions', $entity),
|
2022-11-14 00:02:37 +01:00
|
|
|
'show_presets' => $this->security->isGranted('edit_permissions', $entity) && !$is_new,
|
2019-09-10 17:12:56 +02:00
|
|
|
])
|
2019-04-28 14:18:11 +02:00
|
|
|
;
|
|
|
|
/*->add('comment', CKEditorType::class, ['required' => false,
|
|
|
|
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
|
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); */
|
|
|
|
|
|
|
|
$this->additionalFormElements($builder, $options, $entity);
|
|
|
|
|
2019-09-24 18:28:35 +02:00
|
|
|
//Attachment section
|
|
|
|
$builder->add('attachments', CollectionType::class, [
|
|
|
|
'entry_type' => AttachmentFormType::class,
|
|
|
|
'allow_add' => true,
|
|
|
|
'allow_delete' => true,
|
|
|
|
'label' => false,
|
2020-04-01 15:10:06 +02:00
|
|
|
'reindex_enable' => true,
|
2019-09-24 18:28:35 +02:00
|
|
|
'entry_options' => [
|
|
|
|
'data_class' => $options['attachment_class'],
|
|
|
|
],
|
2019-09-24 18:41:53 +02:00
|
|
|
'by_reference' => false,
|
2023-01-23 23:58:11 +01:00
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit_infos', $entity),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [
|
|
|
|
'required' => false,
|
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit_infos', $entity),
|
|
|
|
'label' => 'part.edit.master_attachment',
|
|
|
|
'entity' => $entity,
|
2019-09-24 18:28:35 +02:00
|
|
|
]);
|
|
|
|
|
2020-03-04 21:54:03 +01:00
|
|
|
$builder->add('log_comment', TextType::class, [
|
|
|
|
'label' => 'edit.log_comment',
|
|
|
|
'mapped' => false,
|
|
|
|
'required' => false,
|
|
|
|
'empty_data' => null,
|
|
|
|
]);
|
|
|
|
|
2019-04-28 14:18:11 +02:00
|
|
|
//Buttons
|
2019-09-04 15:53:18 +02:00
|
|
|
$builder->add('save', SubmitType::class, [
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => $is_new ? 'user.create' : 'user.edit.save',
|
2020-01-05 22:49:00 +01:00
|
|
|
'attr' => [
|
|
|
|
'class' => $is_new ? 'btn-success' : '',
|
|
|
|
],
|
2019-09-04 15:53:18 +02:00
|
|
|
])
|
|
|
|
->add('reset', ResetType::class, [
|
2019-12-26 14:53:13 +01:00
|
|
|
'label' => 'entity.edit.reset',
|
2019-09-04 15:53:18 +02:00
|
|
|
]);
|
2019-04-28 14:18:11 +02:00
|
|
|
}
|
|
|
|
|
2020-02-01 19:48:07 +01:00
|
|
|
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void
|
2019-04-28 14:18:11 +02:00
|
|
|
{
|
|
|
|
//Empty for Base
|
|
|
|
}
|
2019-11-09 00:47:20 +01:00
|
|
|
}
|