diff --git a/README.md b/README.md index c13bc562..1c629245 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Code Coverage Latest stable version License + Twitter

Kimai - time-tracker

diff --git a/src/API/Model/Plugin.php b/src/API/Model/Plugin.php new file mode 100644 index 00000000..e7d03880 --- /dev/null +++ b/src/API/Model/Plugin.php @@ -0,0 +1,48 @@ +name = $plugin->getId(); + $this->version = $plugin->getMetadata()->getVersion(); + } +} diff --git a/src/API/StatusController.php b/src/API/StatusController.php index 709ace8d..ecde781a 100644 --- a/src/API/StatusController.php +++ b/src/API/StatusController.php @@ -11,17 +11,22 @@ declare(strict_types=1); namespace App\API; +use App\API\Model\Plugin; use App\API\Model\Version; +use App\Plugin\PluginManager; use FOS\RestBundle\Controller\Annotations as Rest; use FOS\RestBundle\View\View; use FOS\RestBundle\View\ViewHandlerInterface; use Nelmio\ApiDocBundle\Annotation\Model; use Nelmio\ApiDocBundle\Annotation\Security as ApiSecurity; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Swagger\Annotations as SWG; use Symfony\Component\HttpFoundation\Response; /** * @SWG\Tag(name="Default") + * + * @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')") */ class StatusController extends BaseApiController { @@ -74,4 +79,32 @@ class StatusController extends BaseApiController { return $this->viewHandler->handle(new View(new Version(), 200)); } + + /** + * Returns information about installed Plugins + * + * @SWG\Response( + * response=200, + * description="Returns a list of plugin names and versions", + * @SWG\Schema( + * type="array", + * @SWG\Items(ref=@Model(type=Plugin::class)) + * ) + * ) + * + * @Rest\Get(path="/plugins") + * + * @ApiSecurity(name="apiUser") + * @ApiSecurity(name="apiToken") + */ + public function pluginAction(PluginManager $pluginManager): Response + { + $plugins = []; + foreach ($pluginManager->getPlugins() as $plugin) { + $pluginManager->loadMetadata($plugin); + $plugins[] = new Plugin($plugin); + } + + return $this->viewHandler->handle(new View($plugins, 200)); + } } diff --git a/src/API/TimesheetController.php b/src/API/TimesheetController.php index fd0d4477..55b13e25 100644 --- a/src/API/TimesheetController.php +++ b/src/API/TimesheetController.php @@ -120,7 +120,7 @@ class TimesheetController extends BaseApiController * @Rest\QueryParam(name="activities", requirements="[\d|,]+", strict=true, nullable=true, description="Comma separated list of activity IDs 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: 50)") - * @Rest\QueryParam(name="tags", strict=true, nullable=true, description="The name of tags which are in the datasets") + * @Rest\QueryParam(name="tags", strict=true, nullable=true, description="Comma separated list of tag names") * @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(format="Y-m-d\TH:i:s"), strict=true, nullable=true, description="Only records after this date will be included (format: HTML5)") diff --git a/src/Form/Toolbar/AbstractToolbarForm.php b/src/Form/Toolbar/AbstractToolbarForm.php index ef094fe4..343f7e76 100644 --- a/src/Form/Toolbar/AbstractToolbarForm.php +++ b/src/Form/Toolbar/AbstractToolbarForm.php @@ -17,6 +17,7 @@ use App\Form\Type\PageSizeType; use App\Form\Type\ProjectType; use App\Form\Type\SearchTermType; use App\Form\Type\TagsType; +use App\Form\Type\TeamType; use App\Form\Type\UserRoleType; use App\Form\Type\UserType; use App\Form\Type\VisibilityType; @@ -65,12 +66,39 @@ abstract class AbstractToolbarForm extends AbstractType protected function addUsersChoice(FormBuilderInterface $builder) { $builder->add('users', UserType::class, [ + 'documentation' => [ + 'type' => 'array', + 'items' => ['type' => 'integer', 'description' => 'User ID'], + 'description' => 'Array of user IDs', + ], 'label' => 'label.user', 'multiple' => true, 'required' => false, ]); } + protected function addTeamChoice(FormBuilderInterface $builder) + { + $builder->add('team', TeamType::class, [ + 'label' => 'label.team', + 'required' => false, + ]); + } + + protected function addTeamsChoice(FormBuilderInterface $builder) + { + $builder->add('teams', TeamType::class, [ + 'documentation' => [ + 'type' => 'array', + 'items' => ['type' => 'integer', 'description' => 'Team ID'], + 'description' => 'Array of team IDs', + ], + 'label' => 'label.team', + 'multiple' => true, + 'required' => false, + ]); + } + protected function addCustomerChoice(FormBuilderInterface $builder, array $options = [], bool $multiProject = false) { $this->addCustomerSelect($builder, $options, false, $multiProject); @@ -89,7 +117,15 @@ abstract class AbstractToolbarForm extends AbstractType } // just a fake field for having this field at the right position in the frontend - $builder->add($name, HiddenType::class); + $builder->add($name, CustomerType::class, [ + 'documentation' => [ + 'type' => 'array', + 'items' => ['type' => 'integer', 'description' => 'Customer ID'], + 'description' => 'Array of customer IDs', + ], + 'choices' => [], + 'multiple' => $multiCustomer, + ]); $builder->addEventListener( FormEvents::PRE_SUBMIT, @@ -182,7 +218,15 @@ abstract class AbstractToolbarForm extends AbstractType $name = 'projects'; } // just a fake field for having this field at the right position in the frontend - $builder->add($name, HiddenType::class); + $builder->add($name, ProjectType::class, [ + 'documentation' => [ + 'type' => 'array', + 'items' => ['type' => 'integer', 'description' => 'Project ID'], + 'description' => 'Array of project IDs', + ], + 'choices' => [], + 'multiple' => $multiProject, + ]); $builder->addEventListener( FormEvents::PRE_SUBMIT, @@ -244,7 +288,15 @@ abstract class AbstractToolbarForm extends AbstractType } // just a fake field for having this field at the right position in the frontend - $builder->add($name, HiddenType::class); + $builder->add($name, ActivityType::class, [ + 'documentation' => [ + 'type' => 'array', + 'items' => ['type' => 'integer', 'description' => 'Activity ID'], + 'description' => 'Array of activity IDs', + ], + 'choices' => [], + 'multiple' => $multiActivity, + ]); $builder->addEventListener( FormEvents::PRE_SUBMIT, @@ -294,6 +346,10 @@ abstract class AbstractToolbarForm extends AbstractType protected function addHiddenPagination(FormBuilderInterface $builder) { $builder->add('page', HiddenType::class, [ + 'documentation' => [ + 'type' => 'integer', + 'description' => 'Page number. Default: 1', + ], 'empty_data' => 1 ]); } @@ -303,6 +359,10 @@ abstract class AbstractToolbarForm extends AbstractType @trigger_error('addHiddenOrder() is deprecated and will be removed with 2.0, use the new search modal instead', E_USER_DEPRECATED); $builder->add('order', HiddenType::class, [ + 'documentation' => [ + 'type' => 'string', + 'description' => 'The order for returned items', + ], 'constraints' => [ new Choice(['choices' => [BaseQuery::ORDER_ASC, BaseQuery::ORDER_DESC]]) ] @@ -312,6 +372,9 @@ abstract class AbstractToolbarForm extends AbstractType protected function addOrder(FormBuilderInterface $builder) { $builder->add('order', ChoiceType::class, [ + 'documentation' => [ + 'description' => 'The order for returned items', + ], 'label' => 'label.order', 'choices' => [ 'label.asc' => BaseQuery::ORDER_ASC, diff --git a/src/Form/Type/TeamType.php b/src/Form/Type/TeamType.php index a56dec07..5bbe3d56 100644 --- a/src/Form/Type/TeamType.php +++ b/src/Form/Type/TeamType.php @@ -32,6 +32,10 @@ class TeamType extends AbstractType 'choice_label' => function (Team $team) { return $team->getName(); }, + 'documentation' => [ + 'type' => 'integer', + 'description' => 'Team ID', + ], ]); $resolver->setDefault('query_builder', function (Options $options) { diff --git a/src/Repository/TagRepository.php b/src/Repository/TagRepository.php index 085f0002..33870fa1 100644 --- a/src/Repository/TagRepository.php +++ b/src/Repository/TagRepository.php @@ -57,7 +57,7 @@ class TagRepository extends EntityRepository * @param string $tagNames * @return array */ - public function findIdsByTagNameList($tagNames) + public function findIdsByTagNameList(string $tagNames) { $qb = $this ->createQueryBuilder('t') diff --git a/tests/API/StatusControllerTest.php b/tests/API/StatusControllerTest.php index d04f5451..74c40d6a 100644 --- a/tests/API/StatusControllerTest.php +++ b/tests/API/StatusControllerTest.php @@ -27,6 +27,11 @@ class StatusControllerTest extends APIControllerBaseTest $this->assertUrlIsSecured('/api/version'); } + public function testIsSecurePlugins() + { + $this->assertUrlIsSecured('/api/plugins'); + } + public function testPing() { $client = $this->getClientForAuthenticatedUser(User::ROLE_USER); @@ -62,4 +67,13 @@ class StatusControllerTest extends APIControllerBaseTest $result['copyright'] ); } + + public function testPlugins() + { + $client = $this->getClientForAuthenticatedUser(User::ROLE_USER); + $this->assertAccessIsGranted($client, '/api/plugins'); + $result = json_decode($client->getResponse()->getContent(), true); + + $this->assertIsArray($result); + } }