API: changed date-format, camelCase instead of snake_case, null values, update and create for customer and project (#718)

This commit is contained in:
Kevin Papst
2019-04-24 18:13:33 +02:00
committed by GitHub
parent 215d4fc8bf
commit 460391136f
61 changed files with 2304 additions and 505 deletions

View File

@@ -24,6 +24,7 @@ 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;
/**
* @RouteResource("Activity")
@@ -53,20 +54,22 @@ class ActivityController extends BaseApiController
}
/**
* Returns a collection of activities
*
* @SWG\Response(
* response=200,
* description="Returns the collection of all existing activities",
* description="Returns a collection of activity entities",
* @SWG\Schema(
* type="array",
* @SWG\Items(ref="#/definitions/ActivityEntity")
* @SWG\Items(ref="#/definitions/ActivityCollection")
* )
* )
* @Rest\QueryParam(name="project", requirements="\d+", strict=true, nullable=true, description="Project ID to filter activities. If none is provided, only global activities will be returned.")
* @Rest\QueryParam(name="visible", requirements="\d+", strict=true, nullable=true, description="Visibility status to filter activities (1=visible, 2=hidden, 3=both)")
* @Rest\QueryParam(name="globals", requirements="true", strict=true, nullable=true, description="Pass 'true' as string to fetch only global activities")
* @Rest\QueryParam(name="globalsFirst", requirements="false", strict=true, nullable=true, description="Pass 'false' as string if you don't want the global activities to be listed first")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order (allowed values: 'ASC', 'DESC')")
* @Rest\QueryParam(name="orderBy", requirements="id|name|project", strict=true, nullable=true, description="The field by which results will be ordered (allowed values: 'id', 'name', 'project')")
* @Rest\QueryParam(name="project", requirements="\d+", strict=true, nullable=true, description="Project ID to filter activities. If none is provided, all activities will be returned.")
* @Rest\QueryParam(name="visible", requirements="1|2|3", strict=true, nullable=true, description="Visibility status to filter activities. Allowed values: 1=visible, 2=hidden, 3=all (default: 1)")
* @Rest\QueryParam(name="globals", requirements="true", strict=true, nullable=true, description="Use if you want to fetch only global activities. Allowed values: true (default: false)")
* @Rest\QueryParam(name="globalsFirst", requirements="false", strict=true, nullable=true, description="Use if you don't want global activities to be listed first. Allowed values: false (default: true)")
* @Rest\QueryParam(name="orderBy", requirements="id|name|project", strict=true, nullable=true, description="The field by which results will be ordered. Allowed values: id, name, project (default: name)")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order. Allowed values: ASC, DESC (default: ASC)")
*
* @return Response
*/
@@ -110,11 +113,20 @@ class ActivityController extends BaseApiController
}
/**
* Returns one activity
*
* @SWG\Response(
* response=200,
* description="Returns one activity entity",
* @SWG\Schema(ref="#/definitions/ActivityEntity"),
* )
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="Activity ID to fetch",
* required=true,
* )
*
* @param int $id
* @return Response
@@ -122,9 +134,11 @@ class ActivityController extends BaseApiController
public function getAction($id)
{
$data = $this->repository->find($id);
if (null === $data) {
throw new NotFoundException();
}
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Activity']);
@@ -132,11 +146,13 @@ class ActivityController extends BaseApiController
}
/**
* Creates a new activity
*
* @SWG\Post(
* description="Creates a new activity entry and returns it afterwards",
* description="Creates a new activity and returns it afterwards",
* @SWG\Response(
* response=200,
* description="Returns the new created activity entry",
* description="Returns the new created activity",
* @SWG\Schema(ref="#/definitions/ActivityEntity"),
* )
* )
@@ -156,7 +172,7 @@ class ActivityController extends BaseApiController
public function postAction(Request $request)
{
if (!$this->isGranted('create_activity')) {
throw $this->createAccessDeniedException('User cannot create activities');
throw new AccessDeniedHttpException('User cannot create activities');
}
$activity = new Activity();
@@ -168,10 +184,6 @@ class ActivityController extends BaseApiController
$form->submit($request->request->all());
if ($form->isValid()) {
if (null !== $activity->getId()) {
return new Response('This method does not support updates', Response::HTTP_BAD_REQUEST);
}
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($activity);
$entityManager->flush();
@@ -189,11 +201,13 @@ class ActivityController extends BaseApiController
}
/**
* Update an existing activity
*
* @SWG\Patch(
* description="Update an existing activity entry, you can pass all or just a subset of all attributes",
* description="Update an existing activity, you can pass all or just a subset of all attributes",
* @SWG\Response(
* response=200,
* description="Returns the updated activity entry",
* description="Returns the updated activity",
* @SWG\Schema(ref="#/definitions/ActivityEntity")
* )
* )
@@ -203,6 +217,13 @@ class ActivityController extends BaseApiController
* required=true,
* @SWG\Schema(ref="#/definitions/ActivityEditForm")
* )
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="Activity ID to update",
* required=true,
* )
*
* @param Request $request
* @param string $id
@@ -212,8 +233,12 @@ class ActivityController extends BaseApiController
{
$activity = $this->repository->find($id);
if (null === $activity) {
throw new NotFoundException();
}
if (!$this->isGranted('edit', $activity)) {
throw $this->createAccessDeniedException('User cannot update activity');
throw new AccessDeniedHttpException('User cannot update activity');
}
$form = $this->createForm(ActivityEditForm::class, $activity, [

View File

@@ -12,7 +12,10 @@ declare(strict_types=1);
namespace App\API;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
abstract class BaseApiController extends AbstractController
{
public const DATE_FORMAT = DateTimeType::HTML5_FORMAT;
public const DATE_FORMAT_PHP = 'Y-m-d\TH:m:s';
}

View File

@@ -17,8 +17,12 @@ use App\Entity\User;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Swagger\Annotations as SWG;
/**
* @Security("is_granted('ROLE_USER')")
*/
class ConfigurationController extends BaseApiController
{
/**
@@ -41,7 +45,9 @@ class ConfigurationController extends BaseApiController
}
/**
* @SWG\Response(
* Returns the user specific locale configuration
*
* @SWG\Response(
* response=200,
* description="Returns the locale specific configurations for this user",
* @SWG\Schema(ref="#/definitions/I18nConfig")

View File

@@ -11,6 +11,8 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\Customer;
use App\Form\CustomerEditForm;
use App\Repository\CustomerRepository;
use App\Repository\Query\CustomerQuery;
use FOS\RestBundle\Controller\Annotations as Rest;
@@ -20,7 +22,9 @@ use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
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;
/**
* @RouteResource("Customer")
@@ -50,17 +54,19 @@ class CustomerController extends BaseApiController
}
/**
* Returns a collection of customers
*
* @SWG\Response(
* response=200,
* description="Returns the collection of all existing customer",
* description="Returns a collection of customer entities",
* @SWG\Schema(
* type="array",
* @SWG\Items(ref="#/definitions/CustomerEntity")
* @SWG\Items(ref="#/definitions/CustomerCollection")
* )
* )
* @Rest\QueryParam(name="visible", requirements="\d+", strict=true, nullable=true, description="Visibility status to filter activities (1=visible, 2=hidden, 3=both)")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order (allowed values: 'ASC', 'DESC')")
* @Rest\QueryParam(name="orderBy", requirements="id|name", strict=true, nullable=true, description="The field by which results will be ordered (allowed values: 'id', 'name')")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order. Allowed values: ASC, DESC (default: ASC)")
* @Rest\QueryParam(name="orderBy", requirements="id|name", strict=true, nullable=true, description="The field by which results will be ordered. Allowed values: id, name (default: name)")
*
* @return Response
*/
@@ -92,6 +98,8 @@ class CustomerController extends BaseApiController
}
/**
* Returns one customer
*
* @SWG\Response(
* response=200,
* description="Returns one customer entity",
@@ -104,12 +112,134 @@ class CustomerController extends BaseApiController
public function getAction($id)
{
$data = $this->repository->find($id);
if (null === $data) {
throw new NotFoundException();
}
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Customer']);
return $this->viewHandler->handle($view);
}
/**
* Creates a new customer
*
* @SWG\Post(
* description="Creates a new customer and returns it afterwards",
* @SWG\Response(
* response=200,
* description="Returns the new created customer",
* @SWG\Schema(ref="#/definitions/CustomerEntity"),
* )
* )
* @SWG\Parameter(
* name="body",
* in="body",
* required=true,
* @SWG\Schema(ref="#/definitions/CustomerEditForm")
* )
*
* @param Request $request
* @return Response
* @throws \App\Repository\RepositoryException
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function postAction(Request $request)
{
if (!$this->isGranted('create_customer')) {
throw new AccessDeniedHttpException('User cannot create customers');
}
$customer = new Customer();
$form = $this->createForm(CustomerEditForm::class, $customer, [
'csrf_protection' => false,
]);
$form->submit($request->request->all());
if ($form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($customer);
$entityManager->flush();
$view = new View($customer, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Customer']);
return $this->viewHandler->handle($view);
}
$view = new View($form);
$view->getContext()->setGroups(['Default', 'Entity', 'Customer']);
return $this->viewHandler->handle($view);
}
/**
* Update an existing customer
*
* @SWG\Patch(
* description="Update an existing customer, you can pass all or just a subset of all attributes",
* @SWG\Response(
* response=200,
* description="Returns the updated customer",
* @SWG\Schema(ref="#/definitions/CustomerEntity")
* )
* )
* @SWG\Parameter(
* name="body",
* in="body",
* required=true,
* @SWG\Schema(ref="#/definitions/CustomerEditForm")
* )
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="Customer ID to update",
* required=true,
* )
*
* @param Request $request
* @param string $id
* @return Response
*/
public function patchAction(Request $request, string $id)
{
$customer = $this->repository->find($id);
if (null === $customer) {
throw new NotFoundException();
}
if (!$this->isGranted('edit', $customer)) {
throw new AccessDeniedHttpException('User cannot update customer');
}
$form = $this->createForm(CustomerEditForm::class, $customer, [
'csrf_protection' => false,
]);
$form->setData($customer);
$form->submit($request->request->all(), false);
if (false === $form->isValid()) {
$view = new View($form, Response::HTTP_OK);
$view->getContext()->setGroups(['Default', 'Entity', 'Customer']);
return $this->viewHandler->handle($view);
}
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($customer);
$entityManager->flush();
$view = new View($customer, Response::HTTP_OK);
$view->getContext()->setGroups(['Default', 'Entity', 'Customer']);
return $this->viewHandler->handle($view);
}
}

View File

@@ -14,13 +14,13 @@ namespace App\API\Model;
class I18n
{
/**
* Format used for 'begin' and 'end' in TimesheetEditForm: POST, PATCH
* Format used for 'begin' and 'end'
*
* @var string
*/
protected $formDateTime = '';
/**
* Format used for Timesheet queries in: GET
* Format used for toolbar queries
*
* @var string
*/

38
src/API/Model/Version.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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\API\Model;
use App\Constants;
class Version
{
/**
* @var string
*/
protected $version = Constants::VERSION;
/**
* @var string
*/
protected $candidate = Constants::STATUS;
/**
* @var string
*/
protected $semver = Constants::VERSION . '-' . Constants::STATUS;
/**
* @var string
*/
protected $name = Constants::NAME;
/**
* @var string
*/
protected $copyright = Constants::SOFTWARE . ' - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.';
}

View File

@@ -11,6 +11,8 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\Project;
use App\Form\ProjectEditForm;
use App\Repository\ProjectRepository;
use App\Repository\Query\ProjectQuery;
use FOS\RestBundle\Controller\Annotations as Rest;
@@ -20,7 +22,9 @@ use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
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;
/**
* @RouteResource("Project")
@@ -50,18 +54,20 @@ class ProjectController extends BaseApiController
}
/**
* Returns a collection of projects
*
* @SWG\Response(
* response=200,
* description="Returns the collection of all existing projects",
* description="Returns a collection of project entities",
* @SWG\Schema(
* type="array",
* @SWG\Items(ref="#/definitions/ProjectEntity")
* @SWG\Items(ref="#/definitions/ProjectCollection")
* )
* )
* @Rest\QueryParam(name="customer", requirements="\d+", strict=true, nullable=true, description="Customer ID to filter projects")
* @Rest\QueryParam(name="visible", requirements="\d+", strict=true, nullable=true, description="Visibility status to filter projects (1=visible, 2=hidden, 3=both)")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order (allowed values: 'ASC', 'DESC')")
* @Rest\QueryParam(name="orderBy", requirements="id|name", strict=true, nullable=true, description="The field by which results will be ordered (allowed values: 'id', 'name')")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order. Allowed values: ASC, DESC (default: ASC)")
* @Rest\QueryParam(name="orderBy", requirements="id|name|customer", strict=true, nullable=true, description="The field by which results will be ordered. Allowed values: id, name, customer (default: name)")
*
* @param ParamFetcherInterface $paramFetcher
* @return Response
@@ -98,6 +104,8 @@ class ProjectController extends BaseApiController
}
/**
* Returns one project
*
* @SWG\Response(
* response=200,
* description="Returns one project entity",
@@ -118,4 +126,124 @@ class ProjectController extends BaseApiController
return $this->viewHandler->handle($view);
}
/**
* Creates a new project
*
* @SWG\Post(
* description="Creates a new project and returns it afterwards",
* @SWG\Response(
* response=200,
* description="Returns the new created project",
* @SWG\Schema(ref="#/definitions/ProjectEntity"),
* )
* )
* @SWG\Parameter(
* name="body",
* in="body",
* required=true,
* @SWG\Schema(ref="#/definitions/ProjectEditForm")
* )
*
* @param Request $request
* @return Response
* @throws \App\Repository\RepositoryException
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function postAction(Request $request)
{
if (!$this->isGranted('create_project')) {
throw new AccessDeniedHttpException('User cannot create projects');
}
$project = new Project();
$form = $this->createForm(ProjectEditForm::class, $project, [
'csrf_protection' => false,
]);
$form->submit($request->request->all());
if ($form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($project);
$entityManager->flush();
$view = new View($project, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Project']);
return $this->viewHandler->handle($view);
}
$view = new View($form);
$view->getContext()->setGroups(['Default', 'Entity', 'Project']);
return $this->viewHandler->handle($view);
}
/**
* Update an existing project
*
* @SWG\Patch(
* description="Update an existing project, you can pass all or just a subset of all attributes",
* @SWG\Response(
* response=200,
* description="Returns the updated project",
* @SWG\Schema(ref="#/definitions/ProjectEntity")
* )
* )
* @SWG\Parameter(
* name="body",
* in="body",
* required=true,
* @SWG\Schema(ref="#/definitions/ProjectEditForm")
* )
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="Project ID to update",
* required=true,
* )
*
* @param Request $request
* @param string $id
* @return Response
*/
public function patchAction(Request $request, string $id)
{
$project = $this->repository->find($id);
if (null === $project) {
throw new NotFoundException();
}
if (!$this->isGranted('edit', $project)) {
throw new AccessDeniedHttpException('User cannot update project');
}
$form = $this->createForm(ProjectEditForm::class, $project, [
'csrf_protection' => false,
]);
$form->setData($project);
$form->submit($request->request->all(), false);
if (false === $form->isValid()) {
$view = new View($form, Response::HTTP_OK);
$view->getContext()->setGroups(['Default', 'Entity', 'Project']);
return $this->viewHandler->handle($view);
}
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($project);
$entityManager->flush();
$view = new View($project, Response::HTTP_OK);
$view->getContext()->setGroups(['Default', 'Entity', 'Project']);
return $this->viewHandler->handle($view);
}
}

View File

@@ -11,13 +11,14 @@ declare(strict_types=1);
namespace App\API;
use App\Constants;
use App\API\Model\Version;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Nelmio\ApiDocBundle\Annotation\Model;
use Swagger\Annotations as SWG;
class HealthcheckController extends BaseApiController
class StatusController extends BaseApiController
{
/**
* @var ViewHandlerInterface
@@ -33,6 +34,8 @@ class HealthcheckController extends BaseApiController
}
/**
* A testing route for the API
*
* @SWG\Response(
* response=200,
* description="A simple route that returns a 'pong', which you can use for testing the API",
@@ -49,23 +52,18 @@ class HealthcheckController extends BaseApiController
}
/**
* Returns information about the Kimai release
*
* @SWG\Response(
* response=200,
* description="Returns version information about the current release",
* @SWG\Schema(ref=@Model(type=Version::class))
* )
*
* @Rest\Get(path="/version")
*/
public function versionAction()
{
$version = [
'version' => Constants::VERSION,
'candidate' => Constants::STATUS,
'semver' => Constants::VERSION . '-' . Constants::STATUS,
'name' => Constants::NAME,
'copyright' => 'Kimai 2 - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.',
];
return $this->viewHandler->handle(new View($version, 200));
return $this->viewHandler->handle(new View(new Version(), 200));
}
}

View File

@@ -27,10 +27,13 @@ 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\Validator\Constraints;
/**
* @RouteResource("Timesheet")
*
* @Security("is_granted('ROLE_USER')")
*/
class TimesheetController extends BaseApiController
{
@@ -67,26 +70,29 @@ class TimesheetController extends BaseApiController
}
/**
* Returns a collection of timesheet records
*
* @SWG\Response(
* response=200,
* description="Returns the collection of all existing timesheets for the user",
* description="Returns a collection of timesheets records. Be aware that the datetime fields are given in the users local time including the timezone offset via ISO 8601.",
* @SWG\Schema(
* type="array",
* @SWG\Items(ref="#/definitions/TimesheetEntity")
* @SWG\Items(ref="#/definitions/TimesheetCollection")
* )
* )
*
* @Rest\QueryParam(name="user", requirements="\d+|all", strict=true, nullable=true, description="User ID to filter timesheets (needs permission 'view_other_timesheet', pass 'all' to fetch data for all user)")
* @Rest\QueryParam(name="user", requirements="\d+|all", strict=true, nullable=true, description="User ID to filter timesheets. Needs permission 'view_other_timesheet', pass 'all' to fetch data for all user (default: current user)")
* @Rest\QueryParam(name="customer", requirements="\d+", strict=true, nullable=true, description="Customer ID to filter timesheets")
* @Rest\QueryParam(name="project", requirements="\d+", strict=true, nullable=true, description="Project ID to filter timesheets")
* @Rest\QueryParam(name="activity", requirements="\d+", strict=true, nullable=true, description="Activity ID to filter timesheets")
* @Rest\QueryParam(name="page", requirements="\d+", strict=true, nullable=true, description="The page to display, renders a 404 if not found (default: 1)")
* @Rest\QueryParam(name="size", requirements="\d+", strict=true, nullable=true, description="The amount of entries for each page (default: 25)")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order (allowed values: 'ASC', 'DESC')")
* @Rest\QueryParam(name="orderBy", requirements="id|begin|end|rate", strict=true, nullable=true, description="The field by which results will be ordered (allowed values: 'id', 'begin', 'end', 'rate')")
* @Rest\QueryParam(name="begin", requirements=@Constraints\DateTime, strict=true, nullable=true, description="Only records after this date will be included (format: Y-m-d H:i:s)")
* @Rest\QueryParam(name="end", requirements=@Constraints\DateTime, strict=true, nullable=true, description="Only records before this date will be included (format: Y-m-d H:i:s)")
* @Rest\QueryParam(name="exported", requirements="0|1", strict=true, nullable=true, description="Use this flag if you want to filter for export state (0=not exported, 1=exported, null=all")
* @Rest\QueryParam(name="orderBy", requirements="id|begin|end|rate", strict=true, nullable=true, description="The field by which results will be ordered. Allowed values: id, begin, end, rate (default: begin)")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order. Allowed values: ASC, DESC (default: DESC)")
* @Rest\QueryParam(name="begin", requirements=@Constraints\DateTime, strict=true, nullable=true, description="Only records after this date will be included (format: ISO 8601)")
* @Rest\QueryParam(name="end", requirements=@Constraints\DateTime, strict=true, nullable=true, description="Only records before this date will be included (format: ISO 8601)")
* @Rest\QueryParam(name="exported", requirements="0|1", strict=true, nullable=true, description="Use this flag if you want to filter for export state. Allowed values: 0=not exported, 1=exported (default: all)")
* @Rest\QueryParam(name="active", requirements="0|1", strict=true, nullable=true, description="Filter for running/active records. Allowed values: 0=stopped, 1=active. (default: all)")
*
* @Security("is_granted('view_own_timesheet') or is_granted('view_other_timesheet')")
*
@@ -141,6 +147,15 @@ class TimesheetController extends BaseApiController
$query->setEnd(new \DateTime($end));
}
if (null !== ($active = $paramFetcher->get('active'))) {
$active = (int) $active;
if ($active === 1) {
$query->setState(TimesheetQuery::STATE_RUNNING);
} elseif ($active === 0) {
$query->setState(TimesheetQuery::STATE_STOPPED);
}
}
if (null !== ($exported = $paramFetcher->get('exported'))) {
$exported = (int) $exported;
if ($exported === 1) {
@@ -161,35 +176,52 @@ class TimesheetController extends BaseApiController
}
/**
* Returns one timesheet record
*
* @SWG\Response(
* response=200,
* description="Returns one timesheet entity",
* description="Returns one timesheet record. Be aware that the datetime fields are given in the users local time including the timezone offset via ISO 8601.",
* @SWG\Schema(ref="#/definitions/TimesheetEntity")
* )
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="Timesheet record ID to fetch",
* required=true,
* )
*
* @Security("is_granted('view_own_timesheet')")
* @Security("is_granted('view_own_timesheet') or is_granted('view_other_timesheet')")
*
* @param int $id
* @return Response
*/
public function getAction($id)
{
$data = $this->repository->find($id);
if (null === $data) {
$timesheet = $this->repository->find($id);
if (null === $timesheet) {
throw new NotFoundException();
}
$view = new View($data, 200);
if (!$this->isGranted('view', $timesheet)) {
throw new AccessDeniedHttpException('You are not allowed to view this timesheet');
}
$view = new View($timesheet, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Timesheet']);
return $this->viewHandler->handle($view);
}
/**
* Creates a new timesheet record
*
* @SWG\Post(
* description="Creates a new timesheet entry and returns it afterwards",
* description="Creates a new timesheet record for the current user and returns it afterwards.",
* @SWG\Response(
* response=200,
* description="Returns the new created timesheet entry",
* description="Returns the new created timesheet",
* @SWG\Schema(ref="#/definitions/TimesheetEntity"),
* )
* )
@@ -218,20 +250,16 @@ class TimesheetController extends BaseApiController
'csrf_protection' => false,
'include_rate' => $this->isGranted('edit_rate', $timesheet),
'include_exported' => $this->isGranted('edit_export', $timesheet),
'date_format' => self::DATE_FORMAT,
]);
$form->submit($request->request->all());
if ($form->isValid()) {
if (null !== $timesheet->getId()) {
return new Response('This method does not support updates', Response::HTTP_BAD_REQUEST);
}
if (!$this->isGranted('start', $timesheet)) {
return new Response('You are not allowed to start this timesheet record', Response::HTTP_BAD_REQUEST);
}
if (null === $timesheet->getEnd()) {
if (!$this->isGranted('start', $timesheet)) {
throw new AccessDeniedHttpException('You are not allowed to start this timesheet record');
}
$this->repository->stopActiveEntries(
$timesheet->getUser(),
$this->configuration->getActiveEntriesHardLimit()
@@ -255,11 +283,13 @@ class TimesheetController extends BaseApiController
}
/**
* Update an existing timesheet record
*
* @SWG\Patch(
* description="Update an existing timesheet entry, you can pass all or just a subset of all attributes",
* description="Update an existing timesheet record, you can pass all or just a subset of the attributes.",
* @SWG\Response(
* response=200,
* description="Returns the updated timesheet entry",
* description="Returns the updated timesheet",
* @SWG\Schema(ref="#/definitions/TimesheetEntity")
* )
* )
@@ -269,23 +299,35 @@ class TimesheetController extends BaseApiController
* required=true,
* @SWG\Schema(ref="#/definitions/TimesheetEditForm")
* )
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="Timesheet record ID to update",
* required=true,
* )
*
* @param Request $request
* @param string $id
* @param int $id the timesheet to update
* @return Response
*/
public function patchAction(Request $request, string $id)
public function patchAction(Request $request, int $id)
{
$timesheet = $this->repository->find($id);
if (null === $timesheet) {
throw new NotFoundException();
}
if (!$this->isGranted('edit', $timesheet)) {
throw $this->createAccessDeniedException('User cannot update timesheet');
throw new AccessDeniedHttpException('You are not allowed to update this timesheet');
}
$form = $this->createForm(TimesheetEditForm::class, $timesheet, [
'csrf_protection' => false,
'include_rate' => $this->isGranted('edit_rate', $timesheet),
'include_exported' => $this->isGranted('edit_export', $timesheet),
'date_format' => self::DATE_FORMAT,
]);
$form->setData($timesheet);

View File

@@ -11,17 +11,22 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\User;
use App\Repository\Query\UserQuery;
use App\Repository\UserRepository;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
* @RouteResource("User")
*
* @Security("is_granted('ROLE_USER')")
*/
class UserController extends BaseApiController
{
@@ -46,22 +51,46 @@ class UserController extends BaseApiController
}
/**
* Returns the collection of all registered users
*
* @SWG\Response(
* response=200,
* description="Returns the collection of all registered users",
* description="Returns the collection of all registered users. Required permission: view_user",
* @SWG\Schema(
* type="array",
* @SWG\Items(ref="#/definitions/UserEntity")
* @SWG\Items(ref="#/definitions/UserCollection")
* )
* )
*
* @Rest\QueryParam(name="visible", requirements="1|2|3", strict=true, nullable=true, description="Visibility status to filter users. Allowed values: 1=visible, 2=hidden, 3=all (default: 1)")
* @Rest\QueryParam(name="orderBy", requirements="id|username|alias|email", strict=true, nullable=true, description="The field by which results will be ordered. Allowed values: id, username, alias, email (default: username)")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order. Allowed values: ASC, DESC (default: ASC)")
*
* @Security("is_granted('view_user')")
*
* @return Response
*/
public function cgetAction()
public function cgetAction(ParamFetcherInterface $paramFetcher)
{
$data = $this->repository->findAll();
$query = new UserQuery();
$query
->setResultType(UserQuery::RESULT_TYPE_OBJECTS)
->setOrderBy('username')
;
if (null !== ($visible = $paramFetcher->get('visible'))) {
$query->setVisibility($visible);
}
if (null !== ($order = $paramFetcher->get('order'))) {
$query->setOrder($order);
}
if (null !== ($orderBy = $paramFetcher->get('orderBy'))) {
$query->setOrderBy($orderBy);
}
$data = $this->repository->findByQuery($query);
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Collection', 'User']);
@@ -69,24 +98,37 @@ class UserController extends BaseApiController
}
/**
* Return one user entity
*
* @SWG\Response(
* response=200,
* description="Return one user entity",
* description="Return one user entity. Required permission: view_user",
* @SWG\Schema(ref="#/definitions/UserEntity"),
* )
*
* @Security("is_granted('view_user')")
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="User ID to fetch",
* required=true,
* )
*
* @param int $id
* @return Response
*/
public function getAction($id)
{
$data = $this->repository->find($id);
if (null === $data) {
$user = $this->repository->find($id);
if (null === $user) {
throw new NotFoundException();
}
$view = new View($data, 200);
if (!$this->isGranted('view', $user)) {
throw new AccessDeniedHttpException('You are not allowed to view this profile');
}
$view = new View($user, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'User']);
return $this->viewHandler->handle($view);

View File

@@ -222,7 +222,9 @@ class ActivityController extends AbstractController
return $this->createForm(ActivityEditForm::class, $activity, [
'action' => $url,
'method' => 'POST'
'method' => 'POST',
'create_more' => true,
'customer' => true,
]);
}
}

View File

@@ -214,14 +214,11 @@ class ProjectController extends AbstractController
$currency = $project->getCustomer()->getCurrency();
}
return $this->createForm(
ProjectEditForm::class,
$project,
[
'action' => $url,
'method' => 'POST',
'currency' => $currency,
]
);
return $this->createForm(ProjectEditForm::class, $project, [
'action' => $url,
'method' => 'POST',
'currency' => $currency,
'create_more' => true,
]);
}
}

View File

@@ -267,6 +267,7 @@ class TimesheetController extends AbstractController
return $this->createForm(TimesheetEditForm::class, $entry, [
'action' => $this->generateUrl('timesheet_create', ['origin' => $redirectRoute]),
'include_rate' => $this->isGranted('edit_rate', $entry),
'customer' => true,
]);
}
@@ -286,6 +287,7 @@ class TimesheetController extends AbstractController
]),
'include_rate' => $this->isGranted('edit_rate', $entry),
'include_exported' => $this->isGranted('edit_export', $entry),
'customer' => true,
]);
}

View File

@@ -189,6 +189,7 @@ class TimesheetTeamController extends AbstractController
'action' => $this->generateUrl('admin_timesheet_create'),
'include_rate' => $this->isGranted('edit_rate', $entry),
'include_user' => true,
'customer' => true,
]);
}
@@ -208,6 +209,7 @@ class TimesheetTeamController extends AbstractController
'include_rate' => $this->isGranted('edit_rate', $entry),
'include_exported' => $this->isGranted('edit_export', $entry),
'include_user' => true,
'customer' => true,
]);
}

View File

@@ -170,6 +170,7 @@ class TimesheetFixtures extends Fixture implements DependentFixtureInterface
$start = new \DateTime();
$start = $start->modify('- ' . (rand(1, self::TIMERANGE_DAYS)) . ' days');
$start = $start->modify('- ' . (rand(1, 86400)) . ' seconds');
$start->setTimezone(new \DateTimeZone($user->getPreferenceValue(UserPreference::TIMEZONE, date_default_timezone_get())));
$entry = new Timesheet();
$entry

View File

@@ -87,7 +87,7 @@ class UserFixtures extends Fixture
->setEnabled($userData[6])
->setPassword($passwordEncoder->encodePassword($user, self::DEFAULT_PASSWORD))
->setApiToken($passwordEncoder->encodePassword($user, self::DEFAULT_API_TOKEN))
->setPreferences([$this->getUserPreference($user)])
->setPreferences($this->getUserPreferences($user, $userData[7]))
;
$manager->persist($user);
@@ -99,16 +99,28 @@ class UserFixtures extends Fixture
/**
* @param User $user
* @return UserPreference
* @param string|null $timezone
* @return array
*/
private function getUserPreference(user $user)
private function getUserPreferences(User $user, string $timezone = null)
{
$preference = new UserPreference();
$preference->setName(UserPreference::HOURLY_RATE);
$preference->setValue(rand(self::MIN_RATE, self::MAX_RATE));
$preference->setUser($user);
$preferences = [];
return $preference;
$prefHourlyRate = new UserPreference();
$prefHourlyRate->setName(UserPreference::HOURLY_RATE);
$prefHourlyRate->setValue(rand(self::MIN_RATE, self::MAX_RATE));
$prefHourlyRate->setUser($user);
$preferences[] = $prefHourlyRate;
if (null !== $timezone) {
$prefTimezone = new UserPreference();
$prefTimezone->setName(UserPreference::TIMEZONE);
$prefTimezone->setValue($timezone);
$prefTimezone->setUser($user);
$preferences[] = $prefTimezone;
}
return $preferences;
}
/**
@@ -132,7 +144,7 @@ class UserFixtures extends Fixture
->setAvatar(self::DEFAULT_AVATAR)
->setEnabled(true)
->setPassword($passwordEncoder->encodePassword($user, self::DEFAULT_PASSWORD))
->setPreferences([$this->getUserPreference($user)])
->setPreferences($this->getUserPreferences($user))
;
if ($i % self::BATCH_SIZE == 0) {
@@ -152,28 +164,68 @@ class UserFixtures extends Fixture
*/
protected function getUserDefinition()
{
// alias = $userData[0]
// title = $userData[1]
// username = $userData[2]
// email = $userData[3]
// roles = [$userData[4]]
// avatar = $userData[5]
// enabled = $userData[6]
// timezone = $userData[7]
return [
[
'John Doe', 'Developer', self::USERNAME_USER, 'john_user@example.com', User::ROLE_USER,
self::DEFAULT_AVATAR, true
'John Doe',
'Developer',
self::USERNAME_USER,
'john_user@example.com',
User::ROLE_USER,
self::DEFAULT_AVATAR,
true,
'America/Vancouver',
],
// inactive user to test login
[
'Chris Deactive', 'Developer (left company)', 'chris_user', 'chris_user@example.com', User::ROLE_USER,
self::DEFAULT_AVATAR, false
'Chris Deactive',
'Developer (left company)',
'chris_user',
'chris_user@example.com',
User::ROLE_USER,
self::DEFAULT_AVATAR,
false,
'Australia/Sydney',
],
[
'Tony Maier', 'Head of Sales', self::USERNAME_TEAMLEAD, 'tony_teamlead@example.com', User::ROLE_TEAMLEAD,
'https://en.gravatar.com/userimage/3533186/bf2163b1dd23f3107a028af0195624e9.jpeg', true
'Tony Maier',
'Head of Sales',
self::USERNAME_TEAMLEAD,
'tony_teamlead@example.com',
User::ROLE_TEAMLEAD,
'https://en.gravatar.com/userimage/3533186/bf2163b1dd23f3107a028af0195624e9.jpeg',
true,
'Asia/Bangkok',
],
// no avatar to test default image macro
[
'Anna Smith', 'Administrator', self::USERNAME_ADMIN, 'anna_admin@example.com', User::ROLE_ADMIN, null, true
'Anna Smith',
'Administrator',
self::USERNAME_ADMIN,
'anna_admin@example.com',
User::ROLE_ADMIN,
null,
true,
'Europe/London',
],
// no alias to test twig username macro
[
null, 'Super Administrator', self::USERNAME_SUPER_ADMIN, 'susan_super@example.com', User::ROLE_SUPER_ADMIN,
'/build/images/default_avatar.png', true
null,
'Super Administrator',
self::USERNAME_SUPER_ADMIN,
'susan_super@example.com',
User::ROLE_SUPER_ADMIN,
'/build/images/default_avatar.png',
true,
'Europe/Berlin',
]
];
}

View File

@@ -11,13 +11,14 @@ namespace App\Form;
use App\Entity\Activity;
use App\Form\Type\CustomerType;
use App\Form\Type\FixedRateType;
use App\Form\Type\HourlyRateType;
use App\Form\Type\ProjectType;
use App\Form\Type\YesNoType;
use App\Repository\CustomerRepository;
use App\Repository\ProjectRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -66,18 +67,23 @@ class ActivityEditForm extends AbstractType
'label' => 'label.comment',
'required' => false,
])
->add('customer', CustomerType::class, [
'label' => 'label.customer',
'query_builder' => function (CustomerRepository $repo) use ($customer) {
return $repo->builderForEntityType($customer);
},
'data' => $customer ? $customer : null,
'required' => false,
'mapped' => false,
'project_enabled' => true,
])
;
if ($options['customer']) {
$builder
->add('customer', CustomerType::class, [
'query_builder' => function (CustomerRepository $repo) use ($customer) {
return $repo->builderForEntityType($customer);
},
'data' => $customer ? $customer : null,
'required' => false,
'mapped' => false,
'project_enabled' => true,
]);
}
$builder
->add('project', ProjectType::class, [
'label' => 'label.project',
'required' => false,
'query_builder' => function (ProjectRepository $repo) use ($project, $customer) {
return $repo->builderForEntityType($project, $customer);
@@ -103,14 +109,10 @@ class ActivityEditForm extends AbstractType
);
$builder
->add('fixedRate', MoneyType::class, [
'label' => 'label.fixedRate',
'required' => false,
->add('fixedRate', FixedRateType::class, [
'currency' => $currency,
])
->add('hourlyRate', MoneyType::class, [
'label' => 'label.hourlyRate',
'required' => false,
->add('hourlyRate', HourlyRateType::class, [
'currency' => $currency,
])
// boolean
@@ -119,7 +121,7 @@ class ActivityEditForm extends AbstractType
])
;
if (null === $id) {
if (null === $id && $options['create_more']) {
$builder->add('create_more', CheckboxType::class, [
'label' => 'label.create_more',
'required' => false,
@@ -138,6 +140,8 @@ class ActivityEditForm extends AbstractType
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_activity_edit',
'create_more' => false,
'customer' => false,
]);
}
}

View File

@@ -10,12 +10,13 @@
namespace App\Form;
use App\Entity\Customer;
use App\Form\Type\FixedRateType;
use App\Form\Type\HourlyRateType;
use App\Form\Type\YesNoType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -34,8 +35,13 @@ class CustomerEditForm extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Customer $customer */
$customer = $options['data'];
$currency = false;
if (isset($options['data'])) {
/** @var Customer $customer */
$customer = $options['data'];
$currency = $customer->getCurrency();
}
$builder
->add('name', TextType::class, [
@@ -95,15 +101,11 @@ class CustomerEditForm extends AbstractType
->add('timezone', TimezoneType::class, [
'label' => 'label.timezone',
])
->add('fixedRate', MoneyType::class, [
'label' => 'label.fixedRate',
'required' => false,
'currency' => $customer->getCurrency() ?? false,
->add('fixedRate', FixedRateType::class, [
'currency' => $currency ?? false,
])
->add('hourlyRate', MoneyType::class, [
'label' => 'label.hourlyRate',
'required' => false,
'currency' => $customer->getCurrency() ?? false,
->add('hourlyRate', HourlyRateType::class, [
'currency' => $currency ?? false,
])
->add('visible', YesNoType::class, [
'label' => 'label.visible',

View File

@@ -12,6 +12,8 @@ namespace App\Form;
use App\Entity\Customer;
use App\Entity\Project;
use App\Form\Type\CustomerType;
use App\Form\Type\FixedRateType;
use App\Form\Type\HourlyRateType;
use App\Form\Type\YesNoType;
use App\Repository\CustomerRepository;
use Symfony\Component\Form\AbstractType;
@@ -32,15 +34,19 @@ class ProjectEditForm extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Project $entry */
$entry = $options['data'];
$customer = null;
$currency = false;
$id = null;
if ($entry->getId() !== null) {
$customer = $entry->getCustomer();
$currency = $customer->getCurrency();
if (isset($options['data'])) {
/** @var Project $entry */
$entry = $options['data'];
$id = $entry->getId();
if ($id !== null) {
$customer = $entry->getCustomer();
$currency = $customer->getCurrency();
}
}
$builder
@@ -59,19 +65,14 @@ class ProjectEditForm extends AbstractType
'required' => false,
])
->add('customer', CustomerType::class, [
'label' => 'label.customer',
'query_builder' => function (CustomerRepository $repo) use ($customer) {
return $repo->builderForEntityType($customer);
},
])
->add('fixedRate', MoneyType::class, [
'label' => 'label.fixedRate',
'required' => false,
->add('fixedRate', FixedRateType::class, [
'currency' => $currency,
])
->add('hourlyRate', MoneyType::class, [
'label' => 'label.hourlyRate',
'required' => false,
->add('hourlyRate', HourlyRateType::class, [
'currency' => $currency,
])
->add('budget', MoneyType::class, [
@@ -84,7 +85,7 @@ class ProjectEditForm extends AbstractType
])
;
if ($entry->getId() === null) {
if (null === $id && $options['create_more']) {
$builder->add('create_more', CheckboxType::class, [
'label' => 'label.create_more',
'required' => false,
@@ -104,6 +105,7 @@ class ProjectEditForm extends AbstractType
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_project_edit',
'currency' => Customer::DEFAULT_CURRENCY,
'create_more' => false,
]);
}
}

View File

@@ -15,6 +15,8 @@ use App\Form\Type\ActivityType;
use App\Form\Type\CustomerType;
use App\Form\Type\DateTimePickerType;
use App\Form\Type\DurationType;
use App\Form\Type\FixedRateType;
use App\Form\Type\HourlyRateType;
use App\Form\Type\ProjectType;
use App\Form\Type\UserType;
use App\Form\Type\YesNoType;
@@ -23,7 +25,6 @@ use App\Repository\CustomerRepository;
use App\Repository\ProjectRepository;
use App\Timesheet\UserDateTimeFactory;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
@@ -77,6 +78,7 @@ class TimesheetEditForm extends AbstractType
$currency = false;
$end = null;
$begin = null;
$customerCount = $this->customers->countCustomer(true);
if (isset($options['data'])) {
/** @var Timesheet $entry */
@@ -104,12 +106,20 @@ class TimesheetEditForm extends AbstractType
$timezone = $begin->getTimezone()->getName();
}
$dateTimeOptions = [
'model_timezone' => $timezone,
'view_timezone' => $timezone,
];
// primarily for API usage, where we cannot use a user/locale specific format
if (null !== $options['date_format']) {
$dateTimeOptions['format'] = $options['date_format'];
}
if (null === $end || !$this->configuration->isDurationOnly()) {
$builder->add('begin', DateTimePickerType::class, [
'label' => 'label.begin',
'model_timezone' => $timezone,
'view_timezone' => $timezone,
]);
$builder->add('begin', DateTimePickerType::class, array_merge($dateTimeOptions, [
'label' => 'label.begin'
]));
}
if ($this->configuration->isDurationOnly()) {
@@ -126,7 +136,7 @@ class TimesheetEditForm extends AbstractType
function (FormEvent $event) {
/** @var Timesheet $data */
$data = $event->getData();
if (null === $data->getEnd()) {
if (null === $data || null === $data->getEnd()) {
$event->getForm()->get('duration')->setData(null);
}
}
@@ -148,24 +158,19 @@ class TimesheetEditForm extends AbstractType
}
);
} else {
$builder->add('end', DateTimePickerType::class, [
$builder->add('end', DateTimePickerType::class, array_merge($dateTimeOptions, [
'label' => 'label.end',
'model_timezone' => $timezone,
'view_timezone' => $timezone,
'required' => false,
]);
]));
}
$projectOptions = [];
if ($this->customers->countCustomer(true) > 1) {
if ($customerCount < 2) {
$projectOptions['group_by'] = null;
} elseif ($options['customer']) {
$builder
->add('customer', CustomerType::class, [
// documentation is for NelmioApiDocBundle
'documentation' => [
'type' => 'integer',
'description' => 'Customer ID',
],
'query_builder' => function (CustomerRepository $repo) use ($customer) {
return $repo->builderForEntityType($customer);
},
@@ -175,8 +180,6 @@ class TimesheetEditForm extends AbstractType
'mapped' => false,
'project_enabled' => true,
]);
} else {
$projectOptions['group_by'] = null;
}
if ($this->projects->countProject(true) <= 1) {
@@ -188,16 +191,11 @@ class TimesheetEditForm extends AbstractType
'project',
ProjectType::class,
array_merge($projectOptions, [
'placeholder' => '',
'activity_enabled' => true,
// documentation is for NelmioApiDocBundle
'documentation' => [
'type' => 'integer',
'description' => 'Project ID',
],
'query_builder' => function (ProjectRepository $repo) use ($project, $customer) {
return $repo->builderForEntityType($project, $customer);
},
'placeholder' => '',
'activity_enabled' => true,
'query_builder' => function (ProjectRepository $repo) use ($project, $customer) {
return $repo->builderForEntityType($project, $customer);
},
])
);
@@ -223,12 +221,7 @@ class TimesheetEditForm extends AbstractType
$builder
->add('activity', ActivityType::class, [
// documentation is for NelmioApiDocBundle
'placeholder' => '',
'documentation' => [
'type' => 'integer',
'description' => 'Activity ID',
],
'query_builder' => function (ActivityRepository $repo) use ($activity, $project) {
return $repo->builderForEntityType($activity, $project);
},
@@ -262,20 +255,10 @@ class TimesheetEditForm extends AbstractType
if ($options['include_rate']) {
$builder
->add('fixedRate', MoneyType::class, [
'documentation' => [
'type' => 'float'
],
'label' => 'label.fixedRate',
'required' => false,
->add('fixedRate', FixedRateType::class, [
'currency' => $currency,
])
->add('hourlyRate', MoneyType::class, [
'documentation' => [
'type' => 'float'
],
'label' => 'label.hourlyRate',
'required' => false,
->add('hourlyRate', HourlyRateType::class, [
'currency' => $currency,
]);
}
@@ -306,6 +289,8 @@ class TimesheetEditForm extends AbstractType
'include_rate' => true,
'docu_chapter' => 'timesheet.html',
'method' => 'POST',
'date_format' => null,
'customer' => false,
]);
}
}

View File

@@ -67,6 +67,11 @@ class ActivityType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// documentation is for NelmioApiDocBundle
'documentation' => [
'type' => 'integer',
'description' => 'Activity ID',
],
'label' => 'label.activity',
'class' => Activity::class,
'choice_label' => [$this, 'choiceLabel'],

View File

@@ -28,6 +28,11 @@ class CustomerType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// documentation is for NelmioApiDocBundle
'documentation' => [
'type' => 'integer',
'description' => 'Customer ID',
],
'label' => 'label.customer',
'class' => Customer::class,
'choice_label' => 'name',

View File

@@ -9,6 +9,7 @@
namespace App\Form\Type;
use App\API\BaseApiController;
use App\Timesheet\UserDateTimeFactory;
use App\Utils\LocaleSettings;
use Symfony\Component\Form\AbstractType;
@@ -50,6 +51,11 @@ class DateTimePickerType extends AbstractType
$timezone = $this->dateTime->getTimezone()->getName();
$resolver->setDefaults([
'documentation' => [
'type' => 'string',
'format' => 'date-time',
'example' => (new \DateTime())->format(BaseApiController::DATE_FORMAT_PHP),
],
'label' => 'label.begin',
'widget' => 'single_text',
'html5' => false,

View File

@@ -0,0 +1,44 @@
<?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\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to set the fixed rate.
*/
class FixedRateType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// documentation is for NelmioApiDocBundle
'documentation' => [
'type' => 'number',
'description' => 'Fixed rate',
],
'required' => false,
'label' => 'label.fixedRate',
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return MoneyType::class;
}
}

View File

@@ -0,0 +1,44 @@
<?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\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to set the hourly rate.
*/
class HourlyRateType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// documentation is for NelmioApiDocBundle
'documentation' => [
'type' => 'number',
'description' => 'Hourly rate',
],
'required' => false,
'label' => 'label.hourlyRate',
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return MoneyType::class;
}
}

View File

@@ -49,6 +49,11 @@ class ProjectType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// documentation is for NelmioApiDocBundle
'documentation' => [
'type' => 'integer',
'description' => 'Project ID',
],
'label' => 'label.project',
'class' => Project::class,
'choice_label' => 'name',

View File

@@ -16,14 +16,12 @@ use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* Defines the form used to edit the profile of a User.
*/
class UserEditType extends AbstractType
{
/**
* {@inheritdoc}
*/

View File

@@ -43,7 +43,7 @@ class BaseQuery
/**
* @var string
*/
protected $order = 'ASC';
protected $order = self::ORDER_ASC;
/**
* @var string
*/

View File

@@ -50,7 +50,7 @@ class UserRepository extends AbstractRepository implements UserLoaderInterface
/**
* @param UserQuery $query
* @return \Pagerfanta\Pagerfanta
* @return array|\Doctrine\ORM\QueryBuilder|\Pagerfanta\Pagerfanta
*/
public function findByQuery(UserQuery $query)
{
@@ -77,7 +77,7 @@ class UserRepository extends AbstractRepository implements UserLoaderInterface
$qb->andWhere($rolesWhere);
}
return $this->getPager($qb->getQuery(), $query->getPage(), $query->getPageSize());
return $this->getBaseQueryResult($qb, $query);
}
/**

View File

@@ -18,6 +18,7 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
*/
class TimesheetVoter extends AbstractVoter
{
public const VIEW = 'view';
public const START = 'start';
public const STOP = 'stop';
public const EDIT = 'edit';
@@ -31,6 +32,7 @@ class TimesheetVoter extends AbstractVoter
* support rules based on the given $subject (here: Timesheet)
*/
public const ALLOWED_ATTRIBUTES = [
self::VIEW,
self::START,
self::STOP,
self::EDIT,
@@ -87,6 +89,7 @@ class TimesheetVoter extends AbstractVoter
case self::EDIT_RATE:
case self::STOP:
case self::EDIT:
case self::VIEW:
case self::DELETE:
case self::EXPORT:
case self::EDIT_EXPORT: