diff --git a/front/Mission/ListeCandidatures.vue b/front/Mission/ListeCandidatures.vue index b9084f3a6ccd487fee1216ed964a9ce8b5eb56a6..cb25ace94fa3b86c0a3e054ce5aa6f613c85d298 100644 --- a/front/Mission/ListeCandidatures.vue +++ b/front/Mission/ListeCandidatures.vue @@ -12,12 +12,12 @@ <th>Composante</th> <th>Etat</th> <th>Date commission</th> - <th v-if="canValiderCandidature || canRefuserCandidature">Action</th> + <th>Action</th> </tr> </thead> <tbody> <tr v-if="candidatures.length == 0"> - <td v-if="canValiderCandidature" colspan="5" style="text-align:center;">Aucune candidature</td> + <td colspan="5" style="text-align:center;">Aucune candidature</td> </tr> @@ -37,8 +37,8 @@ <u-date v-if="candidature.dateCommission" :value="candidature.dateCommission"/> </td> - <td v-if="this.canValiderCandidature || this.canRefuserCandidature" style="text-align:center;"> - <a v-if="!candidature.validation && this.canValiderCandidature" + <td style="text-align:center;"> + <a v-if="!candidature.validation && candidature.canValider" :href="urlAccepterCandidature(candidature)" class="btn btn-success" data-content="Êtes vous sûr de vouloir accepter cette candidature ?" @@ -48,7 +48,7 @@ @click.prevent="validerCandidature"> <i class="fa-solid fa-check"></i> </a> - <a v-if="this.canRefuserCandidature" :href="urlRefuserCandidature(candidature)" + <a v-if="!candidature.motif && candidature.canRefuser" :href="urlRefuserCandidature(candidature)" class="btn btn-danger" data-content="Êtes vous sûr de vouloir refuser cette candidature ?" data-title="Refuser la candidature" @@ -81,8 +81,6 @@ export default { name: "ListeCandidatures.vue", props: { intervenant: {required: true}, - canValiderCandidature: {type: Boolean, required: false}, - canRefuserCandidature: {type: Boolean, required: false}, renseignerDonneesPersonnelles: {type: Boolean, required: false}, }, diff --git a/module/Mission/config/offre-emploi.config.php b/module/Mission/config/offre-emploi.config.php index cf7085af7a30ad721c8ed40da9da0c9bb899d577..bd2702279ed53d90040422c36f8fd66be3e06e73 100644 --- a/module/Mission/config/offre-emploi.config.php +++ b/module/Mission/config/offre-emploi.config.php @@ -91,12 +91,14 @@ return [ 'controller' => OffreEmploiController::class, 'action' => 'accepter-candidature', 'privileges' => Privileges::MISSION_CANDIDATURE_VALIDER, + 'assertion' => Assertion\OffreEmploiAssertion::class, ], 'refuser-candidature' => [ 'route' => '/refuser-candidature/:candidature', 'controller' => OffreEmploiController::class, 'action' => 'refuser-candidature', 'privileges' => Privileges::MISSION_CANDIDATURE_REFUSER, + 'assertion' => Assertion\OffreEmploiAssertion::class, ], @@ -167,7 +169,6 @@ return [ Privileges::MISSION_OFFRE_EMPLOI_VALIDER, Privileges::MISSION_OFFRE_EMPLOI_POSTULER, Privileges::MISSION_CANDIDATURE_VISUALISATION, - Privileges::MISSION_CANDIDATURE_VALIDER, Privileges::MISSION_OFFRE_EMPLOI_SUPPRESSION, ], @@ -179,7 +180,7 @@ return [ Privileges::MISSION_CANDIDATURE_VALIDER, Privileges::MISSION_CANDIDATURE_REFUSER, ], - 'resources' => ['Intervenant'], + 'resources' => 'Candidature', 'assertion' => Assertion\OffreEmploiAssertion::class, ], diff --git a/module/Mission/src/Assertion/OffreEmploiAssertion.php b/module/Mission/src/Assertion/OffreEmploiAssertion.php index 50c728b3755a8ce7867aa881acd06240c6da018c..adb15fa92a55b8e9edff5e83d459566a085ac5e5 100755 --- a/module/Mission/src/Assertion/OffreEmploiAssertion.php +++ b/module/Mission/src/Assertion/OffreEmploiAssertion.php @@ -9,6 +9,7 @@ use Application\Service\Traits\WorkflowServiceAwareTrait; use Intervenant\Entity\Db\Intervenant; use Laminas\Permissions\Acl\Resource\ResourceInterface; use Lieu\Entity\Db\Structure; +use Mission\Entity\Db\Candidature; use Mission\Entity\Db\OffreEmploi; use UnicaenApp\Service\EntityManagerAwareInterface; use UnicaenApp\Service\EntityManagerAwareTrait; @@ -87,9 +88,10 @@ class OffreEmploiAssertion extends AbstractAssertion implements EntityManagerAwa return $this->assertOffreEmploiSupprimer($role, $entity); } break; - case $entity instanceof Intervenant: + case $entity instanceof Candidature: switch ($privilege) { case Privileges::MISSION_CANDIDATURE_VALIDER: + case Privileges::MISSION_CANDIDATURE_REFUSER: return $this->assertCandidatureValider($role, $entity); } break; @@ -121,16 +123,19 @@ class OffreEmploiAssertion extends AbstractAssertion implements EntityManagerAwa if (!$entity) { $entity = $this->getMvcEvent()->getParam('volumeHoraireMission'); } + if (!$entity) { + $entity = $this->getMvcEvent()->getParam('candidature'); + } if (!$entity) { return false; } switch ($action) { - case 'candidature': - if ($entity instanceof Intervenant){ - // à revoir : réorganiser l'assertion - // intégrer le workflow - return $entity->getStatut()->getOffreEmploiPostuler(); + case 'accepter-candidature': + case 'refuser-candidature': + if ($entity instanceof Candidature){ + $assert = $this->assertCandidatureValider($role, $entity); + return $assert; } break; } @@ -258,14 +263,16 @@ class OffreEmploiAssertion extends AbstractAssertion implements EntityManagerAwa - protected function assertCandidatureValider (Role $role, Intervenant $intervenant) + protected function assertCandidatureValider (Role $role, Candidature $candidature) { $codeEtape = WfEtape::CANDIDATURE_VALIDATION; + $intervenant = $candidature->getIntervenant(); $wfEtape = $this->getServiceWorkflow()->getEtape($codeEtape, $intervenant); + $structureOffre = $candidature->getOffre()->getStructure(); return $this->asserts([ $wfEtape && $wfEtape->isAtteignable(), - $this->haveRole(), + $this->assertStructure($role, $structureOffre), ]); } diff --git a/module/Mission/src/Service/CandidatureService.php b/module/Mission/src/Service/CandidatureService.php index ac429e664049c472081d743c93d209de9e0400a8..faf0e1d5d14ced74230f17f4a3bff84e3c9029dd 100755 --- a/module/Mission/src/Service/CandidatureService.php +++ b/module/Mission/src/Service/CandidatureService.php @@ -3,6 +3,7 @@ namespace Mission\Service; use Application\Acl\Role; +use Application\Provider\Privilege\Privileges; use Application\Service\AbstractEntityService; use Application\Service\Traits\ContextServiceAwareTrait; use Application\Service\Traits\ParametresServiceAwareTrait; @@ -108,13 +109,22 @@ class CandidatureService extends AbstractEntityService $query = $this->getEntityManager()->createQuery($dql)->setParameters($parameters); $result = $query->getResult(); - $triggers = []; + $triggers = [ + '/' => function (Candidature $original, array $extracted) { + $extracted['canValider'] = $this->getAuthorize()->isAllowed($original, Privileges::MISSION_CANDIDATURE_VALIDER); + $extracted['canRefuser'] = $this->getAuthorize()->isAllowed($original, Privileges::MISSION_CANDIDATURE_REFUSER); + + return $extracted; + }, + ]; $properties = [ 'id', 'motif', 'validation', 'dateCommission', + 'canValider', + 'canRefuser', ['offre', ['id', 'typeMission', 'titre', ['structure', ['libelleCourt']]]], ['intervenant', ['id', 'nomUsuel', 'prenom', 'emailPro', 'code', ['structure', ['libelleLong', 'libelleCourt', 'code', 'id']], ['statut', ['libelle', 'code']]]], ]; diff --git a/module/Mission/view/mission/offre-emploi/candidature.phtml b/module/Mission/view/mission/offre-emploi/candidature.phtml index 88887ca8d88f905bec10f7ef3926d3b8ff26360e..8a31fb251dada764e708a3d648ab513894eae11e 100755 --- a/module/Mission/view/mission/offre-emploi/candidature.phtml +++ b/module/Mission/view/mission/offre-emploi/candidature.phtml @@ -1,17 +1,11 @@ <?php -use Application\Provider\Privilege\Privileges; $this->intervenant($intervenant)->renderTitle('Candidature'); -$canValiderCandidature = $this->isAllowed($intervenant, Privileges::MISSION_CANDIDATURE_VALIDER); -$canRefuserCandidature = $this->isAllowed($intervenant, Privileges::MISSION_CANDIDATURE_REFUSER); - echo $this->vue('mission/liste-candidatures', [ 'intervenant' => $intervenant->getId(), - 'canValiderCandidature' => $canValiderCandidature, - 'canRefuserCandidature' => $canRefuserCandidature, 'renseignerDonneesPersonnelles' => $renseignerDonneesPersonnelles, ]);