added API route to fetch infos about installed plugins (#2561)

This commit is contained in:
Kevin Papst
2021-05-12 14:03:46 +02:00
committed by GitHub
parent f10aad927f
commit f81f9ba492
8 changed files with 168 additions and 5 deletions

48
src/API/Model/Plugin.php Normal file
View 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();
}
}

View File

@@ -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));
}
}

View File

@@ -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)")