mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 07:33:50 +00:00
Add explicit controller definition requirement for APIs
Updated API creation to require an explicit controller definition. This change has been reflected in the ChillMainExtension and ChillPersonExtension files. Also, it has introduced a new exception, the InvalidCrudConfiguration, which will be thrown when a new API or CRUD is created without this explicit controller definition.
This commit is contained in:
@@ -11,31 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
|
||||
class StoredObjectApiController
|
||||
{
|
||||
public function __construct(private readonly Security $security) {}
|
||||
|
||||
#[Route(path: '/api/1.0/doc-store/stored-object/{uuid}/is-ready')]
|
||||
public function isDocumentReady(StoredObject $storedObject): Response
|
||||
{
|
||||
if (!$this->security->isGranted('ROLE_USER')) {
|
||||
throw new AccessDeniedHttpException();
|
||||
}
|
||||
|
||||
return new JsonResponse(
|
||||
[
|
||||
'id' => $storedObject->getId(),
|
||||
'filename' => $storedObject->getFilename(),
|
||||
'status' => $storedObject->getStatus(),
|
||||
'type' => $storedObject->getType(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
class StoredObjectApiController extends ApiController {}
|
||||
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class StoredObjectStatusApiController
|
||||
{
|
||||
public function __construct(private readonly Security $security) {}
|
||||
|
||||
#[Route(path: '/api/1.0/doc-store/stored-object/{uuid}/is-ready')]
|
||||
public function isDocumentReady(StoredObject $storedObject): Response
|
||||
{
|
||||
if (!$this->security->isGranted('ROLE_USER')) {
|
||||
throw new AccessDeniedHttpException();
|
||||
}
|
||||
|
||||
return new JsonResponse(
|
||||
[
|
||||
'id' => $storedObject->getId(),
|
||||
'filename' => $storedObject->getFilename(),
|
||||
'status' => $storedObject->getStatus(),
|
||||
'type' => $storedObject->getType(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\DependencyInjection;
|
||||
|
||||
use Chill\DocStoreBundle\Controller\StoredObjectApiController;
|
||||
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
@@ -57,6 +58,7 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf
|
||||
'apis' => [
|
||||
[
|
||||
'class' => \Chill\DocStoreBundle\Entity\StoredObject::class,
|
||||
'controller' => StoredObjectApiController::class,
|
||||
'name' => 'stored_object',
|
||||
'base_path' => '/api/1.0/docstore/stored-object',
|
||||
'base_role' => 'ROLE_USER',
|
||||
|
Reference in New Issue
Block a user