diff --git a/.idea/cc34.iml b/.idea/cc34.iml index 5897e87..2fd9812 100644 --- a/.idea/cc34.iml +++ b/.idea/cc34.iml @@ -1,143 +1,144 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml index 8026c7c..f0f901d 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,160 +1,161 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/migrations/Version20230208161544.php b/migrations/Version20230208161544.php index 1321846..ab01f25 100644 --- a/migrations/Version20230208161544.php +++ b/migrations/Version20230208161544.php @@ -1,37 +1,37 @@ -addSql('DROP TABLE atelier'); - $this->addSql('CREATE TABLE atelier (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, instructeur_id INTEGER NOT NULL, nom VARCHAR(255) NOT NULL, description VARCHAR(1024) DEFAULT NULL, CONSTRAINT FK_E1BB182325FCA809 FOREIGN KEY (instructeur_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); - $this->addSql('CREATE INDEX IDX_E1BB182325FCA809 ON atelier (instructeur_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TEMPORARY TABLE __temp__atelier AS SELECT id, nom, description FROM atelier'); - $this->addSql('DROP TABLE atelier'); - $this->addSql('CREATE TABLE atelier (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, description VARCHAR(1024) DEFAULT NULL)'); - $this->addSql('INSERT INTO atelier (id, nom, description) SELECT id, nom, description FROM __temp__atelier'); - $this->addSql('DROP TABLE __temp__atelier'); - } -} +addSql('DROP TABLE atelier'); + $this->addSql('CREATE TABLE atelier (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, instructeur_id INTEGER NOT NULL, nom VARCHAR(255) NOT NULL, description VARCHAR(1024) DEFAULT NULL, CONSTRAINT FK_E1BB182325FCA809 FOREIGN KEY (instructeur_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_E1BB182325FCA809 ON atelier (instructeur_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE TEMPORARY TABLE __temp__atelier AS SELECT id, nom, description FROM atelier'); + $this->addSql('DROP TABLE atelier'); + $this->addSql('CREATE TABLE atelier (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, description VARCHAR(1024) DEFAULT NULL)'); + $this->addSql('INSERT INTO atelier (id, nom, description) SELECT id, nom, description FROM __temp__atelier'); + $this->addSql('DROP TABLE __temp__atelier'); + } +} diff --git a/src/Controller/AtelierController.php b/src/Controller/AtelierController.php index 9587c1a..273112a 100644 --- a/src/Controller/AtelierController.php +++ b/src/Controller/AtelierController.php @@ -56,6 +56,10 @@ class AtelierController extends AbstractController #[Route('/{id}/edit', name: 'app_atelier_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Atelier $atelier, AtelierRepository $atelierRepository): Response { + if ($atelier->getInstructeur() !== $this->getUser()) { + return $this->render("error.html.twig", [], new Response(null, Response::HTTP_FORBIDDEN)); + } + $form = $this->createForm(AtelierType::class, $atelier); $form->handleRequest($request); @@ -75,6 +79,10 @@ class AtelierController extends AbstractController #[Route('/{id}', name: 'app_atelier_delete', methods: ['POST'])] public function delete(Request $request, Atelier $atelier, AtelierRepository $atelierRepository): Response { + if ($atelier->getInstructeur() !== $this->getUser()) { + return $this->render("error.html.twig", [], new Response(null, Response::HTTP_FORBIDDEN)); + } + if ($this->isCsrfTokenValid('delete' . $atelier->getId(), $request->request->get('_token'))) { $atelierRepository->remove($atelier, true); } diff --git a/src/DataFixtures/AtelierFixture.php b/src/DataFixtures/AtelierFixture.php index e775966..e44a5e5 100644 --- a/src/DataFixtures/AtelierFixture.php +++ b/src/DataFixtures/AtelierFixture.php @@ -1,30 +1,30 @@ -setEmail('test@hotmail.com') - ->setNom("test") - ->setPrenom("test") - ->setPassword(""); - $manager->persist($user); - for ($i = 0; $i <= 20; $i++) { - $atelier = new Atelier(); - $atelier->setNom($faker->word) - ->setDescription("# " . $faker->sentence(3) . "\n" . $faker->paragraph()) - ->setInstructeur($user); - $manager->persist($atelier); - } - $manager->flush(); - } -} +setEmail('test@hotmail.com') + ->setNom("test") + ->setPrenom("test") + ->setPassword(""); + $manager->persist($user); + for ($i = 0; $i <= 20; $i++) { + $atelier = new Atelier(); + $atelier->setNom($faker->word) + ->setDescription("# " . $faker->sentence(3) . "\n" . $faker->paragraph()) + ->setInstructeur($user); + $manager->persist($atelier); + } + $manager->flush(); + } +} diff --git a/src/Entity/Atelier.php b/src/Entity/Atelier.php index 1a34dbc..1bbe61e 100644 --- a/src/Entity/Atelier.php +++ b/src/Entity/Atelier.php @@ -1,66 +1,66 @@ -id; - } - - public function getNom(): ?string - { - return $this->nom; - } - - public function setNom(string $nom): self - { - $this->nom = $nom; - - return $this; - } - - public function getDescription(): ?string - { - return $this->description; - } - - public function setDescription(?string $description): self - { - $this->description = $description; - - return $this; - } - - public function getInstructeur(): ?User - { - return $this->instructeur; - } - - public function setInstructeur(?User $instructeur): self - { - $this->instructeur = $instructeur; - - return $this; - } -} +id; + } + + public function getNom(): ?string + { + return $this->nom; + } + + public function setNom(string $nom): self + { + $this->nom = $nom; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): self + { + $this->description = $description; + + return $this; + } + + public function getInstructeur(): ?User + { + return $this->instructeur; + } + + public function setInstructeur(?User $instructeur): self + { + $this->instructeur = $instructeur; + + return $this; + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index ab2c99f..507d85b 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -1,172 +1,172 @@ -ateliersFormÃÃÃes = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - public function getEmail(): ?string - { - return $this->email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUserIdentifier(): string - { - return (string) $this->email; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - $roles[] = 'ROLE_INSTRUCTOR'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see PasswordAuthenticatedUserInterface - */ - public function getPassword(): string - { - return $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } - - public function getNom(): ?string - { - return $this->nom; - } - - public function setNom(string $nom): self - { - $this->nom = $nom; - - return $this; - } - - public function getPrenom(): ?string - { - return $this->prenom; - } - - public function setPrenom(string $prenom): self - { - $this->prenom = $prenom; - - return $this; - } - - /** - * @return Collection - */ - public function getAteliersFormÃÃÃes(): Collection - { - return $this->ateliersFormÃÃÃes; - } - - public function addAteliersFormE(Atelier $ateliersFormE): self - { - if (!$this->ateliersFormÃÃÃes->contains($ateliersFormE)) { - $this->ateliersFormÃÃÃes->add($ateliersFormE); - $ateliersFormE->setInstructeur($this); - } - - return $this; - } - - public function removeAteliersFormE(Atelier $ateliersFormE): self - { - if ($this->ateliersFormÃÃÃes->removeElement($ateliersFormE)) { - // set the owning side to null (unless already changed) - if ($ateliersFormE->getInstructeur() === $this) { - $ateliersFormE->setInstructeur(null); - } - } - - return $this; - } -} +ateliersFormÃÃÃes = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function setEmail(string $email): self + { + $this->email = $email; + + return $this; + } + + /** + * A visual identifier that represents this user. + * + * @see UserInterface + */ + public function getUserIdentifier(): string + { + return (string) $this->email; + } + + /** + * @see UserInterface + */ + public function getRoles(): array + { + $roles = $this->roles; + // guarantee every user at least has ROLE_USER + $roles[] = 'ROLE_USER'; + $roles[] = 'ROLE_INSTRUCTOR'; + + return array_unique($roles); + } + + public function setRoles(array $roles): self + { + $this->roles = $roles; + + return $this; + } + + /** + * @see PasswordAuthenticatedUserInterface + */ + public function getPassword(): string + { + return $this->password; + } + + public function setPassword(string $password): self + { + $this->password = $password; + + return $this; + } + + /** + * @see UserInterface + */ + public function eraseCredentials() + { + // If you store any temporary, sensitive data on the user, clear it here + // $this->plainPassword = null; + } + + public function getNom(): ?string + { + return $this->nom; + } + + public function setNom(string $nom): self + { + $this->nom = $nom; + + return $this; + } + + public function getPrenom(): ?string + { + return $this->prenom; + } + + public function setPrenom(string $prenom): self + { + $this->prenom = $prenom; + + return $this; + } + + /** + * @return Collection + */ + public function getAteliersFormÃÃÃes(): Collection + { + return $this->ateliersFormÃÃÃes; + } + + public function addAteliersFormE(Atelier $ateliersFormE): self + { + if (!$this->ateliersFormÃÃÃes->contains($ateliersFormE)) { + $this->ateliersFormÃÃÃes->add($ateliersFormE); + $ateliersFormE->setInstructeur($this); + } + + return $this; + } + + public function removeAteliersFormE(Atelier $ateliersFormE): self + { + if ($this->ateliersFormÃÃÃes->removeElement($ateliersFormE)) { + // set the owning side to null (unless already changed) + if ($ateliersFormE->getInstructeur() === $this) { + $ateliersFormE->setInstructeur(null); + } + } + + return $this; + } +} diff --git a/templates/error.html.twig b/templates/error.html.twig new file mode 100644 index 0000000..2b8c329 --- /dev/null +++ b/templates/error.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello PagesController!{% endblock %} + +{% block body %} +

Vous n'avez pas le droit de faire ceci !

+{% endblock %}