Skip to content
Snippets Groups Projects
Commit de0f44b0 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Correction de la faille PJ

parent a7e942fe
No related branches found
No related tags found
1 merge request!55Ll bug report services
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Application\Controller; namespace Application\Controller;
use Application\Entity\Db\Fichier;
use Application\Entity\Db\Intervenant; use Application\Entity\Db\Intervenant;
use Application\Entity\Db\PieceJointe; use Application\Entity\Db\PieceJointe;
use Application\Entity\Db\TblPieceJointe; use Application\Entity\Db\TblPieceJointe;
...@@ -191,6 +192,13 @@ class PieceJointeController extends AbstractController ...@@ -191,6 +192,13 @@ class PieceJointeController extends AbstractController
$this->initFilters(); $this->initFilters();
/** @var PieceJointe $pj */ /** @var PieceJointe $pj */
$pj = $this->getEvent()->getParam('pieceJointe'); $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); $pj = $this->getServicePieceJointe()->archiver($pj);
$this->updateTableauxBord($pj->getIntervenant(), true); $this->updateTableauxBord($pj->getIntervenant(), true);
$viewModel = new ViewModel(); $viewModel = new ViewModel();
...@@ -227,6 +235,11 @@ class PieceJointeController extends AbstractController ...@@ -227,6 +235,11 @@ class PieceJointeController extends AbstractController
if (empty($pj)) { if (empty($pj)) {
$typePieceJointe = $this->getEvent()->getParam('typePieceJointe'); $typePieceJointe = $this->getEvent()->getParam('typePieceJointe');
$pj = $this->getServicePieceJointe()->getByType($intervenant, $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'); return compact('pj');
...@@ -257,8 +270,20 @@ class PieceJointeController extends AbstractController ...@@ -257,8 +270,20 @@ class PieceJointeController extends AbstractController
public function telechargerAction() public function telechargerAction()
{ {
/** @var Fichier $fichier */
$fichier = $this->getEvent()->getParam('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); $this->uploader()->download($fichier);
} }
...@@ -274,6 +299,12 @@ class PieceJointeController extends AbstractController ...@@ -274,6 +299,12 @@ class PieceJointeController extends AbstractController
$pj = $this->getEvent()->getParam('pieceJointe'); $pj = $this->getEvent()->getParam('pieceJointe');
$fichier = $this->getEvent()->getParam('fichier'); $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) { if ($fichier) {
$this->getServicePieceJointe()->supprimerFichier($fichier, $pj); $this->getServicePieceJointe()->supprimerFichier($fichier, $pj);
} }
......
...@@ -333,14 +333,14 @@ class Fichier implements HistoriqueAwareInterface, ResourceInterface, UploadedFi ...@@ -333,14 +333,14 @@ class Fichier implements HistoriqueAwareInterface, ResourceInterface, UploadedFi
/** public function getPieceJointe(): ?PieceJointe
* Get pieceJointe
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPieceJointe()
{ {
return $this->pieceJointe; $pj = $this->pieceJointe;
if ($pj->count() == 1) {
return $this->pieceJointe->first();
}
return null;
} }
......
...@@ -32,6 +32,6 @@ ...@@ -32,6 +32,6 @@
<join-column name="VALIDATION_ID" referenced-column-name="ID"/> <join-column name="VALIDATION_ID" referenced-column-name="ID"/>
</join-columns> </join-columns>
</many-to-one> </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> </entity>
</doctrine-mapping> </doctrine-mapping>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<join-column name="INTERVENANT_ID" referenced-column-name="ID"/> <join-column name="INTERVENANT_ID" referenced-column-name="ID"/>
</join-columns> </join-columns>
</many-to-one> </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-table name="PIECE_JOINTE_FICHIER">
<join-columns> <join-columns>
<join-column name="PIECE_JOINTE_ID" referenced-column-name="ID"/> <join-column name="PIECE_JOINTE_ID" referenced-column-name="ID"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment