use dialog to duplicate timesheet (#2567)
* fix: display time budget in customer listing if set * updated api methods with annotations * do not require checkboxes for system configurations * open dialog for duplicated timesheets
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\API;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Event\RecentActivityEvent;
|
||||
use App\Event\TimesheetDuplicatePostEvent;
|
||||
@@ -36,7 +37,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Swagger\Annotations as SWG;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
@@ -280,20 +280,13 @@ class TimesheetController extends BaseApiController
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*
|
||||
* @Security("is_granted('view', id)")
|
||||
*/
|
||||
public function getAction(int $id): Response
|
||||
public function getAction(Timesheet $id): Response
|
||||
{
|
||||
$data = $this->repository->find($id);
|
||||
|
||||
if (null === $data) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('view', $data)) {
|
||||
throw new AccessDeniedHttpException('You are not allowed to view this timesheet');
|
||||
}
|
||||
|
||||
$view = new View($data, 200);
|
||||
$timesheet = $id; // cannot be changed due to BC reasons, routes use 'id'
|
||||
$view = new View($timesheet, 200);
|
||||
$view->getContext()->setGroups(self::GROUPS_ENTITY);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
@@ -384,34 +377,27 @@ class TimesheetController extends BaseApiController
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="body",
|
||||
* in="body",
|
||||
* required=true,
|
||||
* @SWG\Schema(ref="#/definitions/TimesheetEditForm")
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="Timesheet record ID to update",
|
||||
* required=true,
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="body",
|
||||
* in="body",
|
||||
* required=true,
|
||||
* @SWG\Schema(ref="#/definitions/TimesheetEditForm")
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*
|
||||
* @Security("is_granted('edit', id)")
|
||||
*/
|
||||
public function patchAction(Request $request, int $id): Response
|
||||
public function patchAction(Request $request, Timesheet $id): Response
|
||||
{
|
||||
$timesheet = $this->repository->find($id);
|
||||
|
||||
if (null === $timesheet) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $timesheet)) {
|
||||
throw new AccessDeniedHttpException('You are not allowed to update this timesheet');
|
||||
}
|
||||
|
||||
$timesheet = $id;
|
||||
$event = new TimesheetMetaDefinitionEvent($timesheet);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
@@ -463,20 +449,12 @@ class TimesheetController extends BaseApiController
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*
|
||||
* @Security("is_granted('delete', id)")
|
||||
*/
|
||||
public function deleteAction(int $id): Response
|
||||
public function deleteAction(Timesheet $id): Response
|
||||
{
|
||||
$timesheet = $this->repository->find($id);
|
||||
|
||||
if (null === $timesheet) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('delete', $timesheet)) {
|
||||
throw $this->createAccessDeniedException('You are not allowed to delete this timesheet');
|
||||
}
|
||||
|
||||
$this->service->deleteTimesheet($timesheet);
|
||||
$this->service->deleteTimesheet($id);
|
||||
|
||||
$view = new View(null, Response::HTTP_NO_CONTENT);
|
||||
|
||||
@@ -585,22 +563,14 @@ class TimesheetController extends BaseApiController
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*
|
||||
* @Security("is_granted('stop', id)")
|
||||
*/
|
||||
public function stopAction(int $id): Response
|
||||
public function stopAction(Timesheet $id): Response
|
||||
{
|
||||
$timesheet = $this->repository->find($id);
|
||||
$this->service->stopTimesheet($id);
|
||||
|
||||
if (null === $timesheet) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('stop', $timesheet)) {
|
||||
throw new AccessDeniedHttpException('You are not allowed to stop this timesheet');
|
||||
}
|
||||
|
||||
$this->service->stopTimesheet($timesheet);
|
||||
|
||||
$view = new View($timesheet, 200);
|
||||
$view = new View($id, 200);
|
||||
$view->getContext()->setGroups(self::GROUPS_ENTITY);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
@@ -627,19 +597,12 @@ class TimesheetController extends BaseApiController
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*
|
||||
* @Security("is_granted('start', id)")
|
||||
*/
|
||||
public function restartAction(int $id, ParamFetcherInterface $paramFetcher): Response
|
||||
public function restartAction(Timesheet $id, ParamFetcherInterface $paramFetcher): Response
|
||||
{
|
||||
$timesheet = $this->repository->find($id);
|
||||
|
||||
if (null === $timesheet) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('start', $timesheet)) {
|
||||
throw new AccessDeniedHttpException('You are not allowed to re-start this timesheet');
|
||||
}
|
||||
|
||||
$timesheet = $id;
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
@@ -714,25 +677,16 @@ class TimesheetController extends BaseApiController
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*
|
||||
* @Security("is_granted('duplicate', id)")
|
||||
*/
|
||||
public function duplicateAction(int $id): Response
|
||||
public function duplicateAction(Timesheet $id): Response
|
||||
{
|
||||
$timesheet = $this->repository->find($id);
|
||||
|
||||
if (null === $timesheet) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('duplicate', $timesheet)) {
|
||||
throw new AccessDeniedHttpException('You are not allowed to duplicate this timesheet');
|
||||
}
|
||||
|
||||
$timesheet = $id;
|
||||
$copyTimesheet = clone $timesheet;
|
||||
|
||||
$this->dispatcher->dispatch(new TimesheetDuplicatePreEvent($copyTimesheet, $timesheet));
|
||||
|
||||
$this->service->saveNewTimesheet($copyTimesheet);
|
||||
|
||||
$this->dispatcher->dispatch(new TimesheetDuplicatePostEvent($copyTimesheet, $timesheet));
|
||||
|
||||
$view = new View($copyTimesheet, 200);
|
||||
@@ -759,21 +713,12 @@ class TimesheetController extends BaseApiController
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*
|
||||
* @Security("is_granted('edit_export', id)")
|
||||
*/
|
||||
public function exportAction(int $id): Response
|
||||
public function exportAction(Timesheet $id): Response
|
||||
{
|
||||
$timesheet = $this->repository->find($id);
|
||||
|
||||
if (null === $timesheet) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit_export', $timesheet)) {
|
||||
throw new AccessDeniedHttpException(
|
||||
sprintf('You are not allowed to %s this timesheet', ($timesheet->isExported() ? 'unlock' : 'lock'))
|
||||
);
|
||||
}
|
||||
|
||||
$timesheet = $id;
|
||||
$timesheet->setExported(!$timesheet->isExported());
|
||||
|
||||
$this->service->updateTimesheet($timesheet);
|
||||
@@ -804,19 +749,12 @@ class TimesheetController extends BaseApiController
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*
|
||||
* @Security("is_granted('edit', id)")
|
||||
*/
|
||||
public function metaAction(int $id, ParamFetcherInterface $paramFetcher): Response
|
||||
public function metaAction(Timesheet $id, ParamFetcherInterface $paramFetcher): Response
|
||||
{
|
||||
$timesheet = $this->repository->find($id);
|
||||
|
||||
if (null === $timesheet) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $timesheet)) {
|
||||
throw new AccessDeniedHttpException('You are not allowed to update this timesheet');
|
||||
}
|
||||
|
||||
$timesheet = $id;
|
||||
$event = new TimesheetMetaDefinitionEvent($timesheet);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user