support custom fields for timesheets, customers, projects and activities (#871)

This commit is contained in:
Kevin Papst
2019-06-26 00:39:05 +02:00
committed by GitHub
parent 994c671fd8
commit d8621f0b7a
103 changed files with 2567 additions and 238 deletions

View File

@@ -12,7 +12,8 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\Activity;
use App\Form\ActivityEditForm;
use App\Event\ActivityMetaDefinitionEvent;
use App\Form\API\ActivityApiEditForm;
use App\Repository\ActivityRepository;
use App\Repository\Query\ActivityQuery;
use FOS\RestBundle\Controller\Annotations as Rest;
@@ -22,6 +23,7 @@ use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Swagger\Annotations as SWG;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -37,20 +39,20 @@ class ActivityController extends BaseApiController
* @var ActivityRepository
*/
protected $repository;
/**
* @var ViewHandlerInterface
*/
protected $viewHandler;
/**
* @param ViewHandlerInterface $viewHandler
* @param ActivityRepository $repository
* @var EventDispatcherInterface
*/
public function __construct(ViewHandlerInterface $viewHandler, ActivityRepository $repository)
protected $dispatcher;
public function __construct(ViewHandlerInterface $viewHandler, ActivityRepository $repository, EventDispatcherInterface $dispatcher)
{
$this->viewHandler = $viewHandler;
$this->repository = $repository;
$this->dispatcher = $dispatcher;
}
/**
@@ -133,12 +135,18 @@ class ActivityController extends BaseApiController
*/
public function getAction($id)
{
/** @var Activity $data */
$data = $this->repository->find($id);
if (null === $data) {
throw new NotFoundException();
}
// make sure the fields are properly setup and we know, which meta fields
// should be exposed and which not
$event = new ActivityMetaDefinitionEvent($data);
$this->dispatcher->dispatch(ActivityMetaDefinitionEvent::class, $event);
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Activity']);
@@ -177,9 +185,7 @@ class ActivityController extends BaseApiController
$activity = new Activity();
$form = $this->createForm(ActivityEditForm::class, $activity, [
'csrf_protection' => false,
]);
$form = $this->createForm(ActivityApiEditForm::class, $activity);
$form->submit($request->request->all());
@@ -241,9 +247,7 @@ class ActivityController extends BaseApiController
throw new AccessDeniedHttpException('User cannot update activity');
}
$form = $this->createForm(ActivityEditForm::class, $activity, [
'csrf_protection' => false,
]);
$form = $this->createForm(ActivityApiEditForm::class, $activity);
$form->setData($activity);
$form->submit($request->request->all(), false);