Commit 17ef4199 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

WIP note intervenant

parent 4832bc7e
Loading
Loading
Loading
Loading
+1
Changes for data/privileges.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ return [
            'lien-systeme-information' => 'Afficher le lien vers le système d\'information dans la fiche',
            'note-visualisation'       => 'Notes (Visualisation)',
            'note-edition'             => 'Notes (Édition)',
            'note-suppression'         => 'Notes (Suppression)',
        ],
    ],

+1
Changes for module/Application/src/Provider/Privilege/Privileges.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ class Privileges extends \UnicaenAuth\Provider\Privilege\Privileges
    const INTERVENANT_STATUT_VISUALISATION                    = 'intervenant-statut-visualisation';
    const INTERVENANT_NOTE_EDITION                            = 'intervenant-note-edition';
    const INTERVENANT_NOTE_VISUALISATION                      = 'intervenant-note-visualisation';
    const INTERVENANT_NOTE_SUPPRESSION                        = 'intervenant-note-suppression';
    const INTERVENANT_SUPPRESSION                             = 'intervenant-suppression';
    const INTERVENANT_VISUALISATION_HISTORISES                = 'intervenant-visualisation-historises';
    const MISE_EN_PAIEMENT_DEMANDE                            = 'mise-en-paiement-demande';
+1
Changes for module/Application/view/application/intervenant/voir.phtml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
<?php


use Application\Provider\Privilege\Privileges;

/* @var $intervenant \Application\Entity\Db\Intervenant */
+55 −4
Changes for module/Intervenant/config/module.config.php: 55 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -4,14 +4,12 @@ namespace Intervenant;

use Application\Provider\Privilege\Privileges;


return [
    'routes' => [
        'note'   => [
            'options'       => [
                'route'       => '/note/:intervenant/',
                'constraints' => [
                    'statut' => '[0-9]*',
                ],
                'route'    => '/note/:intervenant',
                'defaults' => [
                    '__NAMESPACE__' => 'Intervenant\Controller',
                    'controller'    => 'Note',
@@ -20,6 +18,30 @@ return [
            ],
            'may_terminate' => true,
            'child_routes'  => [
                'saisir'    => [
                    'options'       => [
                        'route'       => '/saisir[/:note]',
                        'constraints' => [
                            'note' => '[0-9]*',
                        ],
                        'defaults'    => [
                            'action' => 'saisir',
                        ],
                    ],
                    'may_terminate' => true,
                ],
                'supprimer' => [
                    'options'       => [
                        'route'       => '/supprimer/:note',
                        'constraints' => [
                            'note' => '[0-9]*',
                        ],
                        'defaults'    => [
                            'action' => 'supprimer',
                        ],
                    ],
                    'may_terminate' => true,
                ],
            ],
        ],
        'statut' => [
@@ -98,6 +120,32 @@ return [
            'controller' => 'Intervenant\Controller\Note',
            'action'     => ['index'],
            'privileges' => [Privileges::INTERVENANT_NOTE_VISUALISATION],

        ],
        [
            'controller' => 'Intervenant\Controller\Note',
            'action'     => ['saisir'],
            'privileges' => [Privileges::INTERVENANT_NOTE_EDITION],
        ],
        [
            'controller' => 'Intervenant\Controller\Note',
            'action'     => ['supprimer'],
            'privileges' => [Privileges::INTERVENANT_NOTE_SUPPRESSION],
            'assertion'  => Assertion\NoteAssertion::class,
        ],
    ],

    'resources' => [
        'Note',
    ],

    'rules' => [
        [
            'privileges' => [
                Privileges::INTERVENANT_NOTE_SUPPRESSION,
            ],
            'resources'  => 'Note',
            'assertion'  => Assertion\NoteAssertion::class,
        ],
    ],

@@ -110,6 +158,9 @@ return [
        Service\TypeIntervenantService::class => Service\TypeIntervenantServiceFactory::class,
        Service\StatutService::class          => Service\StatutServiceFactory::class,
        Service\NoteService::class            => Service\NoteServiceFactory::class,
        Service\TypeNoteService::class        => Service\TypeNoteServiceFactory::class,
        Assertion\NoteAssertion::class        => \UnicaenAuth\Assertion\AssertionFactory::class,

        Assertion\StatutAssertion::class => Assertion\StatutAssertionFactory::class,
    ],

+x+83
Changes for module/Intervenant/src/Assertion/NoteAssertion.php: 83 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Intervenant\Assertion;

use Application\Entity\Db\Intervenant;
use Application\Acl\Role;
use Application\Entity\Db\WfEtape;
use Application\Provider\Privilege\Privileges;
use Application\Service\Traits\ContextServiceAwareTrait;
use Intervenant\Entity\Db\Note;
use UnicaenAuth\Assertion\AbstractAssertion;
use Laminas\Permissions\Acl\Resource\ResourceInterface;


/**
 * Description of NoteService
 *
 * @author Antony Le Courtes <antony.lecourtes at unicaen.fr>
 */
class NoteAssertion extends AbstractAssertion
{
    use ContextServiceAwareTrait;

    protected function assertEntity(ResourceInterface $entity, $privilege = null)
    {
        $here = '';
        switch (true) {
            case $entity instanceof Note:
                switch ($privilege) {
                    case Privileges::INTERVENANT_NOTE_SUPPRESSION:
                        return $this->assertSuppressionNote($entity);
                }
            break;
        }

        return true;
    }



    /**
     * @param string $controller
     * @param string $action
     * @param string $privilege
     *
     * @return boolean
     */
    protected function assertController($controller, $action = null, $privilege = null)
    {
        /**
         * @var Note $note
         */
        $note = $this->getMvcEvent()->getParam('note');

        switch ($action) {
            case 'supprimer':
                return $this->assertSuppressionNote($note);
            break;
        }

        return true;
    }



    protected function assertSuppressionNote(Note $note = null)
    {
        if (empty($note)) {
            return false;
        }

        if ($this->getServiceContext()->getUtilisateur() == $note->getHistoCreateur()) {
            return true;
        }

        if ($this->getRole()->hasPrivilege(Privileges::INTERVENANT_NOTE_SUPPRESSION)) {
            return true;
        }

        return false;
    }

}
 No newline at end of file
Loading