fetch user preferences via API (#2905)

This commit is contained in:
Kevin Papst
2021-11-15 21:14:45 +01:00
committed by GitHub
parent 5896ae26c6
commit a1992494d3
5 changed files with 63 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ namespace App\API;
use App\Configuration\SystemConfiguration;
use App\Entity\User;
use App\Event\PrepareUserEvent;
use App\Form\API\UserApiCreateForm;
use App\Form\API\UserApiEditForm;
use App\Repository\Query\UserQuery;
@@ -26,6 +27,7 @@ use HandcraftedInTheAlps\RestRoutingBundle\Controller\Annotations\RouteResource;
use Nelmio\ApiDocBundle\Annotation\Security as ApiSecurity;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Swagger\Annotations as SWG;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -137,7 +139,7 @@ final class UserController extends BaseApiController
* @ApiSecurity(name="apiUser")
* @ApiSecurity(name="apiToken")
*/
public function getAction(int $id): Response
public function getAction(int $id, EventDispatcherInterface $dispatcher): Response
{
$user = $this->repository->find($id);
@@ -149,6 +151,10 @@ final class UserController extends BaseApiController
throw new AccessDeniedHttpException('You are not allowed to view this profile');
}
// we need to prepare the user preferences, which is done via an EventSubscriber
$event = new PrepareUserEvent($user);
$dispatcher->dispatch($event);
$view = new View($user, 200);
$view->getContext()->setGroups(self::GROUPS_ENTITY);