API: allow to set user for timesheet (#1259)

This commit is contained in:
Kevin Papst
2019-11-23 14:21:46 +01:00
committed by GitHub
parent 04dd6b900f
commit 641c199c8c
3 changed files with 8 additions and 2 deletions

View File

@@ -307,12 +307,13 @@ class TimesheetController extends BaseApiController
$form = $this->createForm(TimesheetApiEditForm::class, $timesheet, [
'include_rate' => $this->isGranted('edit_rate', $timesheet),
'include_exported' => $this->isGranted('edit_export', $timesheet),
'include_user' => $this->isGranted('create_other_timesheet'),
'allow_begin_datetime' => $mode->canUpdateTimesWithAPI(),
'allow_end_datetime' => $mode->canUpdateTimesWithAPI(),
'date_format' => self::DATE_FORMAT,
]);
$form->submit($request->request->all());
$form->submit($request->request->all(), false);
if ($form->isValid()) {
if (null === $timesheet->getEnd()) {
@@ -387,6 +388,7 @@ class TimesheetController extends BaseApiController
$form = $this->createForm(TimesheetApiEditForm::class, $timesheet, [
'include_rate' => $this->isGranted('edit_rate', $timesheet),
'include_exported' => $this->isGranted('edit_export', $timesheet),
'include_user' => $this->isGranted('edit', $timesheet),
'allow_begin_datetime' => $mode->canUpdateTimesWithAPI(),
'allow_end_datetime' => $mode->canUpdateTimesWithAPI(),
'date_format' => self::DATE_FORMAT,

View File

@@ -23,6 +23,10 @@ class TimesheetApiEditForm extends TimesheetEditForm
parent::buildForm($builder, $options);
$builder->remove('metaFields');
if ($builder->has('user')) {
$builder->get('user')->setRequired(false);
}
}
public function configureOptions(OptionsResolver $resolver)

View File

@@ -225,7 +225,7 @@ class TimesheetEditForm extends AbstractType
'group_by' => null,
'query_builder' => function (ProjectRepository $repo) use ($builder, $project, $customer, $isNew) {
// is there a better wa to prevent starting a record with a hidden project ?
if ($isNew && !is_object($project)) {
if ($isNew && !empty($project) && (is_int($project) || is_string($project))) {
/** @var Project $project */
$project = $repo->find($project);
if (null !== $project) {