Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -10,30 +10,7 @@
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\Form\ActivityEditForm;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ActivityApiEditForm extends ActivityEditForm
|
||||
final class ActivityApiEditForm extends ActivityEditForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
$builder->remove('metaFields');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,7 @@
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\Form\ActivityRateForm;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ActivityRateApiForm extends ActivityRateForm
|
||||
final class ActivityRateApiForm extends ActivityRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,30 +10,7 @@
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\Form\CustomerEditForm;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CustomerApiEditForm extends CustomerEditForm
|
||||
final class CustomerApiEditForm extends CustomerEditForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
$builder->remove('metaFields');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,7 @@
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\Form\CustomerRateForm;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CustomerRateApiForm extends CustomerRateForm
|
||||
final class CustomerRateApiForm extends CustomerRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
37
src/Form/API/DateTimeApiType.php
Normal file
37
src/Form/API/DateTimeApiType.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\API\BaseApiController;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class DateTimeApiType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'documentation' => [
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'example' => (new \DateTime())->format(BaseApiController::DATE_FORMAT_PHP),
|
||||
],
|
||||
'widget' => 'single_text',
|
||||
'html5' => true, // for the correct format
|
||||
'with_seconds' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return DateTimeType::class;
|
||||
}
|
||||
}
|
||||
@@ -10,36 +10,7 @@
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\Form\ProjectEditForm;
|
||||
use App\Form\Type\APITrueFalseType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ProjectApiEditForm extends ProjectEditForm
|
||||
final class ProjectApiEditForm extends ProjectEditForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
$builder->remove('metaFields');
|
||||
$builder->remove('globalActivities');
|
||||
$builder->add('globalActivities', APITrueFalseType::class, [
|
||||
'label' => 'label.globalActivities',
|
||||
'empty_data' => '1',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,7 @@
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\Form\ProjectRateForm;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ProjectRateApiForm extends ProjectRateForm
|
||||
final class ProjectRateApiForm extends ProjectRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,7 @@
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\Form\TagEditForm;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TagApiEditForm extends TagEditForm
|
||||
final class TagApiEditForm extends TagEditForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,25 +11,12 @@ namespace App\Form\API;
|
||||
|
||||
use App\Form\TeamEditForm;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TeamApiEditForm extends TeamEditForm
|
||||
final class TeamApiEditForm extends TeamEditForm
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
parent::buildForm($builder, $options);
|
||||
$builder->remove('users');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,25 +19,27 @@ use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TimesheetApiEditForm extends TimesheetEditForm
|
||||
final class TimesheetApiEditForm extends TimesheetEditForm
|
||||
{
|
||||
protected function addBillable(FormBuilderInterface $builder, array $options)
|
||||
protected function addBillable(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
if (!$options['include_billable']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->add('billable', BillableType::class, []);
|
||||
$builder->add('billable', BillableType::class);
|
||||
|
||||
$builder->addEventListener(
|
||||
FormEvents::PRE_SUBMIT,
|
||||
function (FormEvent $event) {
|
||||
$data = $event->getData();
|
||||
if (\array_key_exists('billable', $data)) {
|
||||
$data['billableMode'] = Timesheet::BILLABLE_AUTOMATIC;
|
||||
$event->getForm()->add('billableMode', TimesheetBillableType::class, []);
|
||||
if ($data['billable'] === true) {
|
||||
$billable = $data['billable'] === null ? false : (bool) $data['billable'];
|
||||
if ($billable === true) {
|
||||
$data['billableMode'] = Timesheet::BILLABLE_YES;
|
||||
} elseif ($data['billable'] === false) {
|
||||
} elseif ($billable === false) {
|
||||
$data['billableMode'] = Timesheet::BILLABLE_NO;
|
||||
}
|
||||
}
|
||||
@@ -46,14 +48,13 @@ class TimesheetApiEditForm extends TimesheetEditForm
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
$builder->remove('metaFields');
|
||||
if ($builder->has('metaFields')) {
|
||||
$builder->remove('metaFields');
|
||||
}
|
||||
|
||||
if ($builder->has('duration')) {
|
||||
$builder->remove('duration');
|
||||
@@ -63,6 +64,11 @@ class TimesheetApiEditForm extends TimesheetEditForm
|
||||
$builder->get('user')->setRequired(false);
|
||||
}
|
||||
|
||||
// TODO this is only a quick fix, see bugs reports
|
||||
if ($builder->has('duration')) {
|
||||
$builder->remove('duration');
|
||||
}
|
||||
|
||||
if ($builder->has('tags')) {
|
||||
$builder->remove('tags');
|
||||
// @deprecated for BC reasons here, arrays will be supported in 2.0
|
||||
@@ -72,7 +78,22 @@ class TimesheetApiEditForm extends TimesheetEditForm
|
||||
}
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
protected function addBegin(FormBuilderInterface $builder, array $dateTimeOptions, array $options = []): void
|
||||
{
|
||||
$builder->add('begin', DateTimeApiType::class, array_merge($dateTimeOptions, [
|
||||
'label' => 'begin',
|
||||
]));
|
||||
}
|
||||
|
||||
protected function addEnd(FormBuilderInterface $builder, array $dateTimeOptions, array $options = []): void
|
||||
{
|
||||
$builder->add('end', DateTimeApiType::class, array_merge($dateTimeOptions, [
|
||||
'label' => 'end',
|
||||
'required' => false,
|
||||
]));
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
|
||||
@@ -15,12 +15,9 @@ use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class UserApiCreateForm extends UserCreateType
|
||||
final class UserApiCreateForm extends UserCreateType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
@@ -30,7 +27,7 @@ class UserApiCreateForm extends UserCreateType
|
||||
|
||||
$builder->add('plainPassword', PasswordType::class, [
|
||||
'required' => true,
|
||||
'label' => 'label.password',
|
||||
'label' => 'password',
|
||||
'documentation' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Plain text password',
|
||||
@@ -43,7 +40,7 @@ class UserApiCreateForm extends UserCreateType
|
||||
|
||||
$builder->add('plainApiToken', PasswordType::class, [
|
||||
'required' => false,
|
||||
'label' => 'label.api_token',
|
||||
'label' => 'api_token',
|
||||
'documentation' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Plain API token',
|
||||
@@ -52,7 +49,7 @@ class UserApiCreateForm extends UserCreateType
|
||||
|
||||
if ($options['include_roles']) {
|
||||
$builder->add('roles', UserRoleType::class, [
|
||||
'label' => 'label.roles',
|
||||
'label' => 'roles',
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
@@ -60,14 +57,13 @@ class UserApiCreateForm extends UserCreateType
|
||||
}
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
'include_roles' => true,
|
||||
'include_add_more' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,18 +14,15 @@ use App\Form\UserEditType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class UserApiEditForm extends UserEditType
|
||||
final class UserApiEditForm extends UserEditType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
if ($options['include_roles']) {
|
||||
$builder->add('roles', UserRoleType::class, [
|
||||
'label' => 'label.roles',
|
||||
'label' => 'roles',
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
@@ -33,7 +30,7 @@ class UserApiEditForm extends UserEditType
|
||||
}
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user