mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 17:39:06 +02:00
Added a simple Voter for checking, if a user is allowed, to view/edit/create a part.
This commit is contained in:
parent
ab3f5db174
commit
01e1f27b68
10 changed files with 750 additions and 4 deletions
|
@ -40,6 +40,7 @@ use App\Services\AttachmentFilenameService;
|
|||
use App\Services\EntityURLGenerator;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -54,6 +55,8 @@ class PartController extends AbstractController
|
|||
*/
|
||||
public function show(Part $part, AttachmentFilenameService $attachmentFilenameService)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('read', $part);
|
||||
|
||||
$filename = $part->getMasterPictureFilename(true);
|
||||
|
||||
return $this->render('show_part_info.html.twig',
|
||||
|
@ -72,8 +75,9 @@ class PartController extends AbstractController
|
|||
*/
|
||||
public function edit(Part $part, Request $request, EntityManagerInterface $em)
|
||||
{
|
||||
$form = $this->createForm(PartType::class, $part);
|
||||
$this->denyAccessUnlessGranted('edit', $part);
|
||||
|
||||
$form = $this->createForm(PartType::class, $part);
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
@ -98,6 +102,8 @@ class PartController extends AbstractController
|
|||
{
|
||||
$new_part = new Part();
|
||||
|
||||
$this->denyAccessUnlessGranted('create', $new_part);
|
||||
|
||||
$cid = $request->get('cid', 1);
|
||||
|
||||
$category = $em->find(Category::class, $cid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue