diff --git a/module/Application/src/Application/Controller/PieceJointeController.php b/module/Application/src/Application/Controller/PieceJointeController.php index e7b9a19c6965b5eb0c739bceec5d64d71c2a2c50..87931a153ac42f6caf464f1eca24e3cfc2241b5d 100755 --- a/module/Application/src/Application/Controller/PieceJointeController.php +++ b/module/Application/src/Application/Controller/PieceJointeController.php @@ -2,6 +2,7 @@ namespace Application\Controller; +use Application\Entity\Db\Fichier; use Application\Entity\Db\Intervenant; use Application\Entity\Db\PieceJointe; use Application\Entity\Db\TblPieceJointe; @@ -191,6 +192,13 @@ class PieceJointeController extends AbstractController $this->initFilters(); /** @var PieceJointe $pj */ $pj = $this->getEvent()->getParam('pieceJointe'); + + $intervenant = $this->getServiceContext()->getSelectedIdentityRole()->getIntervenant(); + if ($intervenant && $pj->getIntervenant() != $intervenant) { + // un intervenant tente d'archiver la PJ d'un autre intervenant + throw new \Exception('Vous ne pouvez pas archiver la pièce justificative d\'un autre intervenant'); + } + $pj = $this->getServicePieceJointe()->archiver($pj); $this->updateTableauxBord($pj->getIntervenant(), true); $viewModel = new ViewModel(); @@ -227,6 +235,11 @@ class PieceJointeController extends AbstractController if (empty($pj)) { $typePieceJointe = $this->getEvent()->getParam('typePieceJointe'); $pj = $this->getServicePieceJointe()->getByType($intervenant, $typePieceJointe); + } else { + if ($pj->getIntervenant() != $intervenant) { + // un intervenant tente d'archiver la PJ d'un autre intervenant + throw new \Exception('Vous ne pouvez pas visualiser la liste des pièces jointes d\'un autre intervenant'); + } } return compact('pj'); @@ -257,8 +270,20 @@ class PieceJointeController extends AbstractController public function telechargerAction() { + /** @var Fichier $fichier */ $fichier = $this->getEvent()->getParam('fichier'); + /** @var PieceJointe $pieceJointe */ + $pieceJointe = $fichier->getPieceJointe(); + + /** @var Intervenant $intervenant */ + $intervenant = $this->getEvent()->getParam('intervenant'); + + if (!$pieceJointe || $pieceJointe->getIntervenant() != $intervenant) { + // un intervenant tente de télécharger la PJ d'un autre intervenant + throw new \Exception('La pièce jointe n\'existe pas ou bien elle appartient à un autre intervenant'); + } + $this->uploader()->download($fichier); } @@ -274,6 +299,12 @@ class PieceJointeController extends AbstractController $pj = $this->getEvent()->getParam('pieceJointe'); $fichier = $this->getEvent()->getParam('fichier'); + $intervenant = $this->getServiceContext()->getSelectedIdentityRole()->getIntervenant(); + if ($intervenant && $pj->getIntervenant() != $intervenant) { + // un intervenant tente de supprimer la PJ d'un autre intervenant + throw new \Exception('Vous ne pouvez pas supprimer la pièce jointe d\'un autre intervenant'); + } + if ($fichier) { $this->getServicePieceJointe()->supprimerFichier($fichier, $pj); } diff --git a/module/Application/src/Application/Entity/Db/Fichier.php b/module/Application/src/Application/Entity/Db/Fichier.php index 0862cf451ee14a8e2f3c33f57267ca781f341bba..05311f1482d24327b2a1d40e0e12aa7fb21927af 100755 --- a/module/Application/src/Application/Entity/Db/Fichier.php +++ b/module/Application/src/Application/Entity/Db/Fichier.php @@ -333,14 +333,14 @@ class Fichier implements HistoriqueAwareInterface, ResourceInterface, UploadedFi - /** - * Get pieceJointe - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getPieceJointe() + public function getPieceJointe(): ?PieceJointe { - return $this->pieceJointe; + $pj = $this->pieceJointe; + if ($pj->count() == 1) { + return $this->pieceJointe->first(); + } + + return null; } diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Fichier.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Fichier.dcm.xml index c3d006d3dd0a0e972b512a632a69d002b1c33fa2..9d7d0dcc8f63a997916730d6ce23be429ecbe744 100755 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Fichier.dcm.xml +++ b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Fichier.dcm.xml @@ -32,6 +32,6 @@ <join-column name="VALIDATION_ID" referenced-column-name="ID"/> </join-columns> </many-to-one> - <one-to-many field="pieceJointe" target-entity="Application\Entity\Db\PieceJointe" mapped-by="fichier" /> + <many-to-many field="pieceJointe" target-entity="Application\Entity\Db\PieceJointe" mapped-by="fichier" /> </entity> </doctrine-mapping> diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.PieceJointe.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.PieceJointe.dcm.xml index 12284a7a223059b8027f88edbd9121d16a93b2c3..de3480143bc53b9374be404523553e0ea35ee120 100755 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.PieceJointe.dcm.xml +++ b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.PieceJointe.dcm.xml @@ -17,7 +17,7 @@ <join-column name="INTERVENANT_ID" referenced-column-name="ID"/> </join-columns> </many-to-one> - <many-to-many field="fichier" target-entity="Application\Entity\Db\Fichier"> + <many-to-many field="fichier" inversed-by="pieceJointe" target-entity="Application\Entity\Db\Fichier"> <join-table name="PIECE_JOINTE_FICHIER"> <join-columns> <join-column name="PIECE_JOINTE_ID" referenced-column-name="ID"/>