Commit 05f92d8e authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Refactoring assertion offreEmploi

parent 2d66bf08
Loading
Loading
Loading
Loading
Loading
+13 −6
Changes for front/Mission/OffreEmploi.vue: 13 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -8,7 +8,9 @@
                <!--                <span v-if="nbPostesRestants > 0" class="badge rounded-pill bg-success">{{ nbPostesRestants }} poste(s) restant(s)</span>&nbsp;
                                <span v-if="nbPostesRestants <= 0" class="badge rounded-pill bg-danger">Tous les postes sont pourvus</span>&nbsp;-->
                <span v-if="offre.validation" class="badge rounded-pill bg-success">Validée le <u-date
                    :value="offre.validation.histoCreation"/> par {{ offre.validation.histoCreateur.displayName }}</span>
                    :value="offre.validation.histoCreation"/> par {{
                        offre.validation.histoCreateur.displayName
                    }}</span>
                <span v-if="!offre.validation" class="badge rounded-pill bg-warning"> En attente de validation par la DRH</span>&nbsp;
            </div>

@@ -49,14 +51,17 @@
        <div v-if="!this.utilisateur" class="alert alert-primary d-flex align-items-center" role="alert">
            <i class="fa-solid fa-user"></i>
            <div class="ms-2">
                Vous devez <a :href="connectionLink" class="text-decoration-underline alert-link">être identifé</a> pour pouvoir
                Vous devez <a :href="connectionLink" class="text-decoration-underline alert-link">être identifé</a> pour
                pouvoir
                postuler.
            </div>
        </div>
        <div v-if="!offre.canPostuler && this.utilisateur" class="alert alert-primary d-flex align-items-center" role="alert">
        <div v-if="!offre.canPostuler && this.utilisateur" class="alert alert-primary d-flex align-items-center"
             role="alert">
            <i class="fa-solid fa-circle-xmark"></i>
            <div class="ms-2">
                Vous n'avez pas les droits pour postuler à cette offre, merci de contacter votre administration de rattachement.
                Vous n'avez pas les droits pour postuler à cette offre, merci de contacter votre administration de
                rattachement.
            </div>
        </div>
        <div v-if="isCandidat && this.utilisateur" class="alert alert-primary d-flex align-items-center" role="alert">
@@ -118,8 +123,10 @@
                        :value="candidature.validation.histoCreation"/> par {{
                            candidature.validation.histoCreateur.displayName
                        }}</span>
                        <span v-if="!candidature.validation && candidature.motif !== null" class="badge rounded-pill bg-danger">{{ candidature.motif }}</span>
                        <span v-if="!candidature.validation && candidature.motif === null" class="badge rounded-pill bg-warning">En attente d'acceptation</span>
                        <span v-if="!candidature.validation && candidature.motif !== null"
                              class="badge rounded-pill bg-danger">{{ candidature.motif }}</span>
                        <span v-if="!candidature.validation && candidature.motif === null"
                              class="badge rounded-pill bg-warning">En attente d'acceptation</span>
                    </td>
                    <td v-if="this.canValiderCandidature">
                        <a :href="urlVoirCandidature(candidature)"
+13 −10
Changes for module/Mission/config/offre-emploi.config.php: 13 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ return [
                    'controller' => OffreEmploiController::class,
                    'action'     => 'get-candidatures',
                    'privileges' => [Privileges::MISSION_CANDIDATURE_VISUALISATION],
                    'assertion'  => Assertion\OffreEmploiAssertion::class,
                ],
            ],
        ],
@@ -40,41 +39,45 @@ return [
            'route'         => '/offre-emploi',
            'controller'    => OffreEmploiController::class,
            'action'        => 'index',
            'privileges'    => ['guest', Privileges::MISSION_OFFRE_EMPLOI_VISUALISATION],
            'assertion'     => Assertion\OffreEmploiAssertion::class,
            'privileges'    => ['guest',
                                'user'],
            'may_terminate' => true,
            'child_routes'  => [
                'saisir'               => [
                    'route'      => '/saisir[/:offreEmploi]',
                    'controller' => OffreEmploiController::class,
                    'privileges' => [Privileges::MISSION_OFFRE_EMPLOI_MODIFIER, Privileges::MISSION_OFFRE_EMPLOI_VISUALISATION],
                    'privileges' => [Privileges::MISSION_OFFRE_EMPLOI_MODIFIER,
                                     Privileges::MISSION_OFFRE_EMPLOI_AJOUTER],
                    'assertion'  => Assertion\OffreEmploiAssertion::class,
                    'action'     => 'saisir',
                ],
                'detail'               => [
                    'route'      => '/detail[/:offreEmploi]',
                    'privileges' => ['guest',
                                     'user'],
                    'controller' => OffreEmploiController::class,
                    'privileges' => Privileges::MISSION_OFFRE_EMPLOI_VISUALISATION,
                    'action'     => 'detail',
                ],
                'get'                  => [
                    'route'      => '/get/:offreEmploi',
                    'controller' => OffreEmploiController::class,
                    'action'     => 'get',
                    'privileges' => ['guest', Privileges::MISSION_OFFRE_EMPLOI_VISUALISATION],
                    'assertion'  => Assertion\OffreEmploiAssertion::class,
                    'privileges' => ['guest',
                                     'user'],
                ],
                'liste'                => [
                    'route'      => '/liste',
                    'controller' => OffreEmploiController::class,
                    'action'     => 'liste',
                    'privileges' => ['guest', Privileges::MISSION_OFFRE_EMPLOI_VISUALISATION],
                    'assertion'  => Assertion\OffreEmploiAssertion::class,
                    'privileges' => ['guest',
                                     'user'],
                ],
                'supprimer'            => [
                    'route'      => '/supprimer/:offreEmploi',
                    'controller' => OffreEmploiController::class,
                    'action'     => 'supprimer',
                    'privileges' => Privileges::MISSION_OFFRE_EMPLOI_SUPPRESSION,
                    'assertion'  => Assertion\OffreEmploiAssertion::class,
                ],
                'valider'              => [
                    'route'      => '/valider/:offreEmploi',
@@ -106,7 +109,6 @@ return [
                    'controller' => OffreEmploiController::class,
                    'action'     => 'refuser-candidature',
                    'privileges' => Privileges::MISSION_CANDIDATURE_REFUSER,
                    'assertion'  => Assertion\OffreEmploiAssertion::class,
                ],
            ],
        ],
@@ -131,6 +133,7 @@ return [
                    'icon'      => 'fas fa-duotone fa-pen-to-square',
                    'title'     => "Offre",
                    'route'     => 'offre-emploi',
                    'assertion' => Assertion\OffreEmploiAssertion::class,
                    'order'     => 60,
                    'color'     => '#217DD8',
                    'pages'     => [
+79 −47
Changes for module/Mission/src/Assertion/OffreEmploiAssertion.php: 79 added lines, 47 removed lines.
Original line number Diff line number Diff line
@@ -4,12 +4,10 @@ namespace Mission\Assertion;

use Application\Provider\Privileges;
use Application\Service\Traits\ContextServiceAwareTrait;
use Intervenant\Entity\Db\Intervenant;
use Mission\Entity\Db\Mission;
use Mission\Entity\Db\VolumeHoraireMission;
use Mission\Controller\OffreEmploiController;
use Unicaen\Framework\Authorize\AbstractAssertion;
use Unicaen\Framework\Authorize\UnAuthorizedException;
use Unicaen\Framework\Navigation\Page;
use Unicaen\Framework\User\UserProfile;
use Laminas\Permissions\Acl\Resource\ResourceInterface;
use Lieu\Entity\Db\Structure;
use Mission\Entity\Db\Candidature;
@@ -36,19 +34,10 @@ class OffreEmploiAssertion extends AbstractAssertion implements EntityManagerAwa
    {
        $page = $page->getData();
        switch ($page['route']) {
            case 'offre-emploi':
            case 'candidature':
            case 'offre-emploi':
                //Si il n'y a pas d'offre d'emploi alors il ne peut pas y avoir des candidatures
                if (!$this->canHaveCandidature()) {
                    return false;
                }

                if ($this->authorize->isAllowedPrivilege(UserProfile::PRIVILEGE_GUEST)) {
                    // Visible si on n'est pas connecté
                    return true;
                }
                if (!$this->getServiceContext()->getIntervenant()) {
                    //Pas visible par les gestionnaires
                if (!$this->canHaveCandidature() || !$this->canHaveOffreEmploi()) {
                    return false;
                }

@@ -84,9 +73,9 @@ class OffreEmploiAssertion extends AbstractAssertion implements EntityManagerAwa
            case $entity instanceof Candidature:
                switch ($privilege) {
                    case Privileges::MISSION_CANDIDATURE_VALIDER:
                        return $this->assertCandidatureValider($entity);
                        return $this->canValiderRefuserCandidature($entity);
                    case Privileges::MISSION_CANDIDATURE_REFUSER:
                        return $this->assertCandidatureRefuser($entity);
                        return $this->canValiderRefuserCandidature($entity);
                }
                break;
        }
@@ -98,32 +87,24 @@ class OffreEmploiAssertion extends AbstractAssertion implements EntityManagerAwa

    protected function assertController(string $controller, ?string $action): bool
    {
        $entity = $this->getServiceContext()->getIntervenant();
        if (!$entity) {
            $entity = $this->getParam(Intervenant::class);
        }
        if (!$entity) {
            $entity = $this->getParam(Candidature::class);
        }

        switch ($action) {
            case 'accepterCandidature':
            case 'refuserCandidature':
                if ($entity instanceof Candidature) {
                    $assert = $this->assertCandidatureValider($entity);
                    return $assert;
                }
                break;
            case 'candidature':
                return $this->canHaveCandidature();
                break;
            case 'get':
            case 'liste':
            case 'index':
                return true;
        $candidature = $this->getParam(Candidature::class);
        $offreEmploi = $this->getParam(OffreEmploi::class);


        switch ($controller . '.' . $action) {
            case OffreEmploiController::class . '.accepterCandidature':
                return $this->canValiderRefuserCandidature($candidature);
            case OffreEmploiController::class . '.candidature':
                return $this->canHaveCandidature();
            case OffreEmploiController::class . '.saisir':
                return $this->canModifierOffreEmploi($offreEmploi);
            case OffreEmploiController::class . '.supprimer':
                return $this->canSupprimerOffreEmploi($offreEmploi);
            default:
                throw new UnAuthorizedException('Action de contrôleur ' . $controller . ':' . $action . ' non traitée');
        }
        return false;

    }


@@ -139,7 +120,6 @@ class OffreEmploiAssertion extends AbstractAssertion implements EntityManagerAwa

    protected function assertStructure(?Structure $structure): bool
    {

        if (!$structure) {
            return true;
        }
@@ -222,30 +202,82 @@ class OffreEmploiAssertion extends AbstractAssertion implements EntityManagerAwa

    protected function canHaveCandidature(): bool
    {
        $query = 'SELECT id FROM offre_emploi WHERE histo_destruction IS NULL AND validation_id IS NOT NULL';
        $query = <<<'SQL'
        SELECT id 
        FROM offre_emploi 
        WHERE histo_destruction IS NULL 
          AND validation_id IS NOT NULL
        SQL;

        $conn = $this->getEntityManager()->getConnection();
        if (false === $conn->executeQuery($query)->fetchOne()) {
            return false;
        }

        return true;
    }



    protected function assertCandidatureValider(Candidature $candidature): bool
    protected function canHaveOffreEmploi(): bool
    {
        $query = <<<'SQL'
        SELECT
        a.id
        FROM affectation a
        WHERE EXISTS (
            SELECT 1
            FROM role_privilege rp
            JOIN privilege p
                ON p.id = rp.privilege_id
            WHERE rp.role_id = a.role_id
              AND p.code = 'offre-emploi-ajouter'
        )
        SQL;

        $conn = $this->getEntityManager()->getConnection();
        if (false === $conn->executeQuery($query, ['privilege_code' => 'offre-emploi-ajouter'])->fetchOne()) {
            return false;
        }

        return true;
    }



    protected function canValiderRefuserCandidature(Candidature $candidature): bool
    {
        $feuilleDeRoute = $this->getServiceWorkflow()->getFeuilleDeRoute($candidature->getIntervenant(), $candidature->getOffre()->getStructure());
        $wfEtape        = $feuilleDeRoute->get(WorkflowEtape::CANDIDATURE_VALIDATION);
        $structureOffre = $candidature->getOffre()->getStructure();

        return $wfEtape && $wfEtape->isAllowed();
        return $wfEtape && $wfEtape->isAllowed() && $this->assertStructure($structureOffre);
    }



    protected function assertCandidatureRefuser(Candidature $candidature): bool
    protected function canModifierOffreEmploi(OffreEmploi $offreEmploi): bool
    {
        $structureOffre = $candidature->getOffre()->getStructure();
        return $this->assertStructure($structureOffre);
        $structureOffre = $offreEmploi->getStructure();


        if ($offreEmploi->isValide() || !$this->assertStructure($structureOffre)) {
            return false;
        }

        return true;
    }



    protected function canSupprimerOffreEmploi(OffreEmploi $offreEmploi): bool
    {
        $structureOffre = $offreEmploi->getStructure();
        $candidatures   = $offreEmploi->getCandidatures();

        return empty($candidatures) && !$this->assertStructure($structureOffre);

    }


}
 No newline at end of file
+5 −4
Changes for module/Mission/src/Controller/OffreEmploiController.php: 5 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -115,9 +115,10 @@ class OffreEmploiController extends AbstractController
        $params['annee'] = $annee;

        $canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::MISSION_OFFRE_EMPLOI_MODIFIER));
        $canVisu = $this->isAllowed(Privileges::getResourceId(Privileges::MISSION_OFFRE_EMPLOI_VISUALISATION));


        if ($canEdit) {
        if ($canVisu || $canEdit) {
            if ($structure = $this->getServiceContext()->getStructure()) {
                $params['structure'] = $structure->idsFilter();
            }
@@ -163,7 +164,8 @@ class OffreEmploiController extends AbstractController
        $this->em()->clear();

        $annee = $this->getServiceContext()->getAnnee();
        $model = $this->getServiceOffreEmploi()->data(['offreEmploi' => $offreEmploi, 'annee' => $annee]);
        $model = $this->getServiceOffreEmploi()->data(['offreEmploi' => $offreEmploi,
                                                       'annee'       => $annee]);
        $model->returnFirstItem();

        return $model;
@@ -332,8 +334,7 @@ class OffreEmploiController extends AbstractController
        $feuilleDeRoute = $this->getServiceWorkflow()->getFeuilleDeRoute($intervenant);

        $etapeDonneesPersos = $feuilleDeRoute->get(WorkflowEtape::DONNEES_PERSO_SAISIE);
        if(!empty($etapeDonneesPersos))
        {
        if (!empty($etapeDonneesPersos)) {
            $renseignerDonneesPersonnelles = !$etapeDonneesPersos->isFranchie();
        }

+33 −5
Changes for module/Mission/src/Service/OffreEmploiService.php: 33 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -86,11 +86,16 @@ class OffreEmploiService extends AbstractEntityService

        $properties = [
            'id',
            ['typeMission', ['libelle']],
            ['typeMission',
             ['libelle']],
            'dateDebut',
            'dateFin',
            'dateLimite',
            ['structure', ['libelleLong', 'libelleCourt', 'code', 'id']],
            ['structure',
             ['libelleLong',
              'libelleCourt',
              'code',
              'id']],
            'titre',
            'description',
            'nombreHeures',
@@ -101,7 +106,25 @@ class OffreEmploiService extends AbstractEntityService
            'candidats',
            'candidaturesValides',
            'valide',
            ['candidatures', ['id', 'motif', ['intervenant', ['id', 'nomUsuel', 'prenom', 'emailPro', 'code', ['structure', ['libelleLong', 'libelleCourt', 'code', 'id']], ['statut', ['libelle', 'code']]]], 'histoCreation', 'validation']],
            ['candidatures',
             ['id',
              'motif',
              ['intervenant',
               ['id',
                'nomUsuel',
                'prenom',
                'emailPro',
                'code',
                ['structure',
                 ['libelleLong',
                  'libelleCourt',
                  'code',
                  'id']],
                ['statut',
                 ['libelle',
                  'code']]]],
              'histoCreation',
              'validation']],
        ];


@@ -187,11 +210,16 @@ class OffreEmploiService extends AbstractEntityService

        $properties = [
            'id',
            ['typeMission', ['libelle']],
            ['typeMission',
             ['libelle']],
            'dateDebut',
            'dateFin',
            'dateLimite',
            ['structure', ['libelleLong', 'libelleCourt', 'code', 'id']],
            ['structure',
             ['libelleLong',
              'libelleCourt',
              'code',
              'id']],
            'titre',
            'description',
            'nombreHeures',
Loading