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

Correction de la faille PJ

(cherry picked from commit de0f44b0)
parent f5b5afa7
Branches
Tags
1 merge request!54Correction de la faille PJ
......@@ -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;
......@@ -188,6 +189,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();
......@@ -226,6 +234,11 @@ class PieceJointeController extends AbstractController
{
$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');
......@@ -256,8 +269,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);
}
......@@ -273,6 +298,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);
}
......
......@@ -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;
}
......
......@@ -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>
......@@ -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"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment