Commit 3c61b199 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Création d'un nouveau privilèges pour dissocier le droit sur l'export pdf des...

Création d'un nouveau privilèges pour dissocier le droit sur l'export pdf des états de paiement et l'export pdf des mises en paiement (Demande de Lille # 35845)
parent 9a6676b8
Loading
Loading
Loading
Loading
+110 −0
Original line number Diff line number Diff line
<?php


use BddAdmin\Bdd;

class MigrationPrivilegesExportPdfEtatPaiement extends AbstractMigration
{
    protected $contexte = self::CONTEXTE_POST;



    public function description(): string
    {
        return "SET UP  : Ajout du privileges export pdf etat paiement pour les rôles pouvant exporter en pdf les mises en paiement";
    }



    public function utile(): bool
    {
        return true;
        //test si le privilege export pdf etat paiement existe, si il existe déjà alors pas besoin de jouer cette mise à niveau des privilèges
        $bdd       = $this->manager->getBdd();
        $sql       = "SELECT 
                        p.id
                      FROM 
                        privilege p 
                      JOIN categorie_privilege cp ON p.categorie_id = cp.id AND cp.code = 'mise-en-paiement'
                      WHERE p.code = 'export-pdf-etat'";
        $privilege = $bdd->select($sql);
        if (!empty($privilege)) {
            return false;
        }

        return true;
    }



    public function action(string $contexte)
    {
        if ($contexte == self::CONTEXTE_PRE) {
            $this->before();
        } else {
            $this->after();
        }
    }



    protected function before()
    {

    }



    protected function after()
    {
        $oa      = $this->manager->getOseAdmin();
        $bdd     = $this->manager->getBdd();
        $console = $this->manager->getOseAdmin()->getConsole();

        //On vérifie que le privilege export-pdf-etat existe bien en base
        $sqlPrivilege = "
            SELECT count(*) NB FROM privilege p 
	        JOIN categorie_privilege cp ON p.categorie_id = cp.id AND cp.code = 'mise-en-paiement'
	        WHERE p.code = 'export-pdf-etat'
	        ";

        $res = $bdd->select($sqlPrivilege, [], ['fetch' => $bdd::FETCH_ONE]);

        if ((int)$res['NB'] > 0) {
            //on génére les requêtes insert pour set up le nouveau privilege
            $sqlInsert = "
            SELECT
	            'INSERT INTO role_privilege (ROLE_ID, PRIVILEGE_ID) VALUES ('||rp.role_id||','||(
		            SELECT p.id FROM privilege p 
	                JOIN categorie_privilege cp ON p.categorie_id = cp.id AND cp.code = 'mise-en-paiement'
	                WHERE p.code = 'export-pdf-etat')||')' rsql
            FROM 
	            role_privilege rp 
            WHERE 
	            privilege_id = (
	                SELECT p.id FROM privilege p 
	                JOIN categorie_privilege cp ON p.categorie_id = cp.id AND cp.code = 'mise-en-paiement'
	                WHERE p.code = 'export-pdf' )
            AND role_id NOT IN (
	            SELECT 
		            rp.role_id role_id
		        FROM
		            role_privilege rp 
		        WHERE 
		            privilege_id = (
			            SELECT p.id FROM privilege p 
		                JOIN categorie_privilege cp ON p.categorie_id = cp.id AND cp.code = 'mise-en-paiement'
	    	            WHERE p.code = 'export-pdf-etat') 
                )
        ";


            $inserts = $bdd->select($sqlInsert);
            foreach ($inserts as $insert) {
                $bdd->exec(current($insert));
            }

            $oa->run('clear-cache');
        }
    }
}
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -160,7 +160,8 @@ return [
            'visualisation-gestion'     => 'Visualisation (Gestion)',
            'demande'                   => 'Demande',
            'export-csv'                => 'Export CSV',
            'export-pdf'                => 'Export PDF',
            'export-pdf'                => 'Export PDF mise en paiement',
            'export-pdf-etat'           => 'Export PDF état paiement',
            'mise-en-paiement'          => 'Mise en paiement',
            'export-paie'               => 'Export vers le logiciel de paie',
            'edition'                   => 'Annulation de mises en paiement',
+10 −11
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ class PaiementController extends AbstractController
    use EtatSortieServiceAwareTrait;



    /**
     * Initialisation des filtres Doctrine pour les historique.
     * Objectif : laisser passer les enregistrements passés en historique pour mettre en évidence ensuite les erreurs
@@ -379,7 +378,7 @@ class PaiementController extends AbstractController

        $etatSortie = $this->getServiceEtatSortie()->getByParametre('es_etat_paiement');

        if ($this->params()->fromPost('exporter-pdf') !== null && $this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_PDF))) {
        if ($this->params()->fromPost('exporter-pdf') !== null && ($this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_PDF)) || $this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_PDF_ETAT)))) {
            $document = $this->getServiceEtatSortie()->genererPdf($etatSortie, $recherche->getFilters());
            $document->download($this->makeFilenameFromRecherche($recherche) . '.pdf');
        } elseif ($this->params()->fromPost('exporter-csv-etat') !== null && $this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_CSV))) {
+1 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ class Privileges extends \UnicaenAuth\Provider\Privilege\Privileges
    const MISE_EN_PAIEMENT_EXPORT_CSV                         = 'mise-en-paiement-export-csv';
    const MISE_EN_PAIEMENT_EXPORT_PAIE                        = 'mise-en-paiement-export-paie';
    const MISE_EN_PAIEMENT_EXPORT_PDF                         = 'mise-en-paiement-export-pdf';
    const MISE_EN_PAIEMENT_EXPORT_PDF_ETAT                    = 'mise-en-paiement-export-pdf-etat';
    const MISE_EN_PAIEMENT_MISE_EN_PAIEMENT                   = 'mise-en-paiement-mise-en-paiement';
    const MISE_EN_PAIEMENT_VISUALISATION_GESTION              = 'mise-en-paiement-visualisation-gestion';
    const MISE_EN_PAIEMENT_VISUALISATION_INTERVENANT          = 'mise-en-paiement-visualisation-intervenant';
+51 −43
Original line number Diff line number Diff line
@@ -60,12 +60,18 @@ $this->headTitle()->append($title);

            echo $this->formRow($rechercheForm->get('suite')) . ' ';
            echo $this->formRow($rechercheForm->get('afficher')) . ' ';
        if ($this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_CSV)))
            if ($this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_CSV))) {
                echo $this->formRow($rechercheForm->get('exporter-csv-etat')) . ' ';
            }

        if ($this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_PDF)))
            //Bouton export PDF mise en paiement
            if ($recherche->getEtat() === MiseEnPaiement::A_METTRE_EN_PAIEMENT && $this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_PDF))) {
                echo $this->formRow($rechercheForm->get('exporter-pdf')) . ' ';

            }
            //Bouton export PDF etat de paiement
            if ($recherche->getEtat() === MiseEnPaiement::MIS_EN_PAIEMENT && $this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_EXPORT_PDF_ETAT))) {
                echo $this->formRow($rechercheForm->get('exporter-pdf')) . ' ';
            }


            echo $this->form()->closeTag();
@@ -80,9 +86,11 @@ if (! empty($etatPaiement)){
    if ($recherche->getEtat() === MiseEnPaiement::A_METTRE_EN_PAIEMENT && $this->isAllowed(Privileges::getResourceId(Privileges::MISE_EN_PAIEMENT_MISE_EN_PAIEMENT))) {
        $url = $this->url('paiement/mise-en-paiement', [
            'structure'    => $rechercheForm->get('structure')->getValue(),
            'intervenants'=> implode( ',', $rechercheForm->get('intervenants')->getValue() )
            'intervenants' => implode(',', $rechercheForm->get('intervenants')->getValue()),
        ]);

        ?><a href="<?= $url ?>" data-event="mise-en-paiement-form-submit" data-url-redirect="<?= $this->url(null, [], [], true) ?>" class="btn btn-primary ajax-modal">Mise en paiement</a><?php
        ?><a href="<?= $url ?>" data-event="mise-en-paiement-form-submit"
             data-url-redirect="<?= $this->url(null, [], [], true) ?>" class="btn btn-primary ajax-modal">Mise en
            paiement</a><?php
    }
}
 No newline at end of file