added API route to fetch infos about installed plugins (#2561)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<a href="https://codecov.io/gh/kevinpapst/kimai2"><img alt="Code Coverage" src="https://codecov.io/gh/kevinpapst/kimai2/branch/master/graph/badge.svg"></a>
|
||||
<a href="https://packagist.org/packages/kevinpapst/kimai2"><img alt="Latest stable version" src="https://poser.pugx.org/kevinpapst/kimai2/v/stable"></a>
|
||||
<a href="https://packagist.org/packages/kevinpapst/kimai2"><img alt="License" src="https://poser.pugx.org/kevinpapst/kimai2/license"></a>
|
||||
<a href="https://twitter.com/kimai_org"><img alt="Twitter" src="https://img.shields.io/badge/follow-%40kimai__org-00acee"></a>
|
||||
</p>
|
||||
|
||||
<h1 align="center">Kimai - time-tracker</h1>
|
||||
|
||||
48
src/API/Model/Plugin.php
Normal file
48
src/API/Model/Plugin.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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\Plugin\Plugin as CorePlugin;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
class Plugin
|
||||
{
|
||||
/**
|
||||
* The plugin name, eg. "ExpensesBundle"
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Groups({"Default"})
|
||||
* @Serializer\Type(name="string")
|
||||
*/
|
||||
protected $name;
|
||||
/**
|
||||
* The plugin version, eg. "1.14"
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Groups({"Default"})
|
||||
* @Serializer\Type(name="string")
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
public function __construct(CorePlugin $plugin)
|
||||
{
|
||||
$this->name = $plugin->getId();
|
||||
$this->version = $plugin->getMetadata()->getVersion();
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)")
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user