Commit 261c536c authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- Demande de signature (DB) + écran d'administration

- Nouvelle demande de signature "libre"
- Calcule de l'état
- Envoi de la demande au parafeur par défaut
parent 5a8399b9
Loading
Loading
Loading
Loading
Loading
+38 −2
Changes for config/merged/signature.config.php: 38 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ return [
                [
                    'controller' => SignatureController::class,
                    'action' => [
                        'workflows', 'signRequests'
                        'workflows', 'signRequests', 'signatures', 'new', 'delete', 'send', 'status'
                    ],
//                    'privileges' => [
//                        Unicaencalendrier_indexPrivileges::INDEX,
@@ -55,11 +55,47 @@ return [
                    'route' => '/signature',
                    'defaults' => [
                        'controller' => SignatureController::class,
                        'action' => 'index',
                        'action' => 'signatures',
                    ],
                ],
                'may_terminate' => true,
                    'child_routes' => [
                        'new' => [
                            'type' => Segment::class,
                            'options' => [
                                'route' => '/new',
                                'defaults' => [
                                    'action' => 'new'
                                ]
                            ]
                        ],
                        'send' => [
                            'type' => Segment::class,
                            'options' => [
                                'route' => '/send/:id',
                                'defaults' => [
                                    'action' => 'send'
                                ]
                            ]
                        ],
                        'status' => [
                            'type' => Segment::class,
                            'options' => [
                                'route' => '/status/:id',
                                'defaults' => [
                                    'action' => 'status'
                                ]
                            ]
                        ],
                        'delete' => [
                            'type' => Segment::class,
                            'options' => [
                                'route' => '/delete/:id',
                                'defaults' => [
                                    'action' => 'delete'
                                ]
                            ]
                        ],
                        'workflows' => [
                            'type' => Segment::class,
                            'options' => [
+6 −6
Changes for config/module.config.php: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -76,34 +76,34 @@ return [
        ///
        ////////////////////////////////////////////////////////////
        'signature_levels' => [
            'visa_hidden' => [
            \UnicaenSignature\Utils\SignatureConstants::VISA_HIDDEN => [
                'label' => 'Visa caché',
                'used' => true,
                'description' => 'Visa applicatif, pas de trace dans le document',
                'log_message' => "La personne '%s' a validée le document '%s'",
                'letterfile_key' => 'internal' ],
            'visa_visuel' => [
            \UnicaenSignature\Utils\SignatureConstants::VISA_VISUAL => [
                'label' => 'Visa visuel',
                'used' => true,
                'description' => 'Visa visuel. Nom, prénom et date appliqués sur le document.',
                'log_message' => "La personne '%s' a marquée comme vu le document '%s'",
                'letterfile_key' => 'external' ],
            'sign_visuel' => [
            \UnicaenSignature\Utils\SignatureConstants::SIGN_VISUAL => [
                'label' => 'Signature calligraphique',
                'used' => true,
                'description' => 'Signature calligraphique. Signature au format image. Appliquée sur le document.',
                'log_message' => "La personne '%s' a signée le document '%s'",
                'letterfile_key' => 'external' ],
            'sign_certif' => [
            \UnicaenSignature\Utils\SignatureConstants::SIGN_CERTIF => [
                'label' => 'Signature par certificat (PKCS12)',
                'used' => true,
                'description' => 'Signature certifiée avec un keystore/certificat via un magasin de clés au format PKCS12. Appliquée sur le document.',
                'log_message' => "La personne '%s' a signée et certifiée le document '%s'",
                'letterfile_key' => 'external' ],
            'sign_eidas' => [
            \UnicaenSignature\Utils\SignatureConstants::SIGN_EIDAS => [
                'label' => 'Signature par clef cryptographique',
                'used' => true,
                'description' => "Signature par clef cryptographique via clé usb (eIDAS) qui contient un certificat. Cetificat qui peut être personnel ou au titre de l'établissement (cachet établissement). Appliquée sur le document.",
                'description' => "Signature par clef cryptographique via clé usb (eIDAS) qui contient un certificat. Certificat qui peut être personnel ou au titre de l'établissement (cachet établissement). Appliquée sur le document.",
                'log_message' => "La personne '%s' a signée et certifiée le document '%s'",
                'letterfile_key' => 'external' ],
        ],
+2 −1
Changes for src/Command/SignatureConfigCheckCommand.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ class SignatureConfigCheckCommand extends SignatureCommandAbstract
            $io->text("Par défaut : " . ($config["default"] ? "✅" : "<red>non</red>"));
            $io->text("Type de signature prise en charge : ");

            foreach ($config['levels'] as $level => $keyInLetterFile) {
            foreach ($config['config']['levels'] as $level => $keyInLetterFile) {
                $levelInfos = $this->getSignatureService()->getSignatureConfigurationService()->getLevelByName($level);
                $io->text(
                    sprintf(
@@ -74,6 +74,7 @@ class SignatureConfigCheckCommand extends SignatureCommandAbstract
            $headers = ["clef", "valeur", "type"];
            $rows = [];
            foreach ($config['config'] as $key => $value) {
                if( $key == 'levels' ) continue;
                $row = [$key, $value, gettype($value)];
                $rows[] = $row;
            }
+93
Changes for src/Controller/SignatureController.php: 93 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ namespace UnicaenSignature\Controller;

use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
use UnicaenSignature\Entity\Db\Signature;
use UnicaenSignature\Form\SignatureForm;
use UnicaenSignature\Service\SignatureServiceAwareTrait;

class SignatureController extends AbstractActionController
@@ -40,6 +42,97 @@ class SignatureController extends AbstractActionController
        ]);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////// SIGNATURE

    /**
     * @return ViewModel
     */
    public function signaturesAction(): ViewModel
    {
        return new ViewModel(
            [
                'signatures' => $this->getSignatureService()->getSignatures()
            ]
        );
    }

    /**
     * @return ViewModel
     */
    public function newAction(): ViewModel
    {
        $parfeurkey = $this->params('letterfile', null);
        $letterFile = $this->getSignatureService()->getLetterfileService()->getLetterFileStrategy($parfeurkey);
        $marksSelector = $this->getSignatureService()->getMarksSelectFrom(array_keys($letterFile->marksAvailable()));
        $signature = new Signature();
        $form = new SignatureForm($marksSelector);
        $form->setSignatureService($this->getSignatureService());
        $form->init();
        $form->setObject($signature);

        if( $this->getRequest()->isPost() ){
            $post = array_merge_recursive(
                $this->getRequest()->getPost()->toArray(),
                $this->getRequest()->getFiles()->toArray()
            );
            $form->setData($post);
            if( $form->isValid() ){
                $this->getSignatureService()->saveNewSignature($form->getData());
                return $this->redirect()->toRoute('unicaen-signature');
            } else {
                // meh
            }
        }

        $view = new ViewModel(
            [
                'form' => $form
            ]
        );

        $view->setTemplate('unicaen-signature/signature/form');

        return $view;
    }

    public function sendAction(): ViewModel
    {
        $id = intval($this->params('id'));
        $this->getSignatureService()->sendSignatureById($id);
        $this->redirect()->toRoute('unicaen-signature');
    }

    public function statusAction(): ViewModel
    {
        $id = intval($this->params('id'));
        $this->getSignatureService()->updateStatusSignatureById($id);
        $this->redirect()->toRoute('unicaen-signature');
    }

    /**
     * @return ViewModel
     */
    public function deleteAction(): ViewModel
    {
        var_dump($this->getRequest()->getMethod());
        die("todo");
        $id = $this->params('id');
        try {
            $this->getSignatureService()->deleteSignature($id);
        } catch (\Exception $e) {
            throw $e;
        }
    }

    /**
     * Affiche le formulaire d'ajout/édition
     * @return ViewModel
     */
    public function signatureFormAction() :ViewModel
    {

    }

    public function listSignAction(): ViewModel
    {
        return new ViewModel([]);
+152 −23
Changes for src/Entity/Db/Signature.php: 152 added lines, 23 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ namespace UnicaenSignature\Entity\Db;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use DateTime;
use UnicaenSignature\Service\SignatureService;
use UnicaenSignature\Utils\SignatureConstants;

/**
 * @ORM\Entity
@@ -18,6 +20,19 @@ class Signature
    const STATUS_SIGNATURE_CANCEL = 401;
    const STATUS_SIGNATURE_REJECT = 501;

    /**
     * @param $id
     */
    public function __construct()
    {
        $this->recipients = new ArrayCollection();
        $this->document_path = "";
        $this->status = self::STATUS_SIGNATURE_DRAFT;
        $this->type = "";
        $this->label = "";
        $this->description = "";
    }

    /**
     * @return string[]
     */
@@ -51,7 +66,7 @@ class Signature
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private int $id;
    private $id;

    /**
     * @var ?DateTime
@@ -71,13 +86,33 @@ class Signature
     */
    private int $status;

    /**
     * @var string|null
     * @ORM\Column(type="string", nullable=true)
     */
    private ?string $label;

    /**
     * @var string|null
     * @ORM\Column(type="string", nullable=true)
     */
    private ?string $description;

    /**
     * Liste des contrats de financement pour le projet.
     *
     * @var SignatureRecipient[]
     * @ORM\OneToMany(targetEntity="SignatureRecipient", mappedBy="signature")
     * @var ArrayCollection
     * @ORM\OneToMany(targetEntity="SignatureRecipient", mappedBy="signature", cascade={"persist"})
     */
    protected array $recipients;
    protected $recipients;

    /**
     * Date d'envoi au parafeur
     *
     * @var ?DateTime
     * @ORM\Column(type="datetime", nullable=true)
     */
    private ?DateTime $dateSend;

    /**
     * Date du dernier changement d'état.
@@ -96,10 +131,10 @@ class Signature
    /**
     * Clef permettant d'identifier le document côté parafeur
     *
     * @var string
     * @ORM\Column (type="string", length=255, nullable=false)
     * @var ?string
     * @ORM\Column (type="string", length=255, nullable=true)
     */
    private string $document_remotekey;
    private ?string $document_remotekey;

    /**
     * Clef permettant d'identifier le document côté application
@@ -120,10 +155,10 @@ class Signature
    /**
     * Nom de la procédure de signature dans le parapheur
     *
     * @var string
     * @ORM\Column (type="string", length=255, nullable=false)
     * @var ?string
     * @ORM\Column (type="string", length=255, nullable=true)
     */
    private string $letterfile_process;
    private ?string $letterfile_process;

    /**
     * URL permettant d'identifier la procédure dans le parapheur
@@ -133,10 +168,12 @@ class Signature
     */
    private ?string $letterfile_url;



    /**
     * @return int
     */
    public function getId(): int
    public function getId() :?int
    {
        return $this->id;
    }
@@ -159,6 +196,23 @@ class Signature
        return $this;
    }

    /**
     * @return DateTime|null
     */
    public function getDateSend(): ?DateTime
    {
        return $this->dateSend;
    }

    /**
     * @param DateTime|null $dateSend
     */
    public function setDateSend(?DateTime $dateSend): self
    {
        $this->dateSend = $dateSend;
        return $this;
    }

    /**
     * @return string|null
     */
@@ -177,6 +231,40 @@ class Signature
        return $this;
    }

    /**
     * @return string|null
     */
    public function getLabel(): ?string
    {
        return $this->label;
    }

    /**
     * @param string|null $label
     */
    public function setLabel(?string $label): self
    {
        $this->label = $label;
        return $this;
    }

    /**
     * @return string|null
     */
    public function getDescription(): ?string
    {
        return $this->description;
    }

    /**
     * @param string|null $description
     */
    public function setDescription(?string $description): self
    {
        $this->description = $description;
        return $this;
    }

    /**
     * @return int|null
     */
@@ -214,9 +302,9 @@ class Signature
    }

    /**
     * @return array
     * @return SignatureRecipient[]
     */
    public function getRecipients(): array
    public function getRecipients()
    {
        return $this->recipients;
    }
@@ -227,7 +315,16 @@ class Signature
     */
    public function setRecipients(array $recipients): self
    {
        $this->recipients = $recipients;
        $this->recipients = new ArrayCollection($recipients);
        return $this;
    }

    /**
     * @return Signature
     */
    public function addRecipient(SignatureRecipient $recipient): self
    {
        $this->recipients->add($recipient);
        return $this;
    }

@@ -249,18 +346,18 @@ class Signature
    }

    /**
     * @return string
     * @return string|null
     */
    public function getDocumentRemotekey(): string
    public function getDocumentRemotekey(): ?string
    {
        return $this->document_remotekey;
    }

    /**
     * @param string $document_remotekey
     * @param string|null $document_remotekey
     * @return Signature
     */
    public function setDocumentRemotekey(string $document_remotekey): self
    public function setDocumentRemotekey(?string $document_remotekey): self
    {
        $this->document_remotekey = $document_remotekey;
        return $this;
@@ -285,18 +382,18 @@ class Signature
    }

    /**
     * @return string
     * @return string|null
     */
    public function getLetterfileProcess(): string
    public function getLetterfileProcess(): ?string
    {
        return $this->letterfile_process;
    }

    /**
     * @param string $letterfile_process
     * @param string|null $letterfile_process
     * @return Signature
     */
    public function setLetterfileProcess(string $letterfile_process): self
    public function setLetterfileProcess(?string $letterfile_process): self
    {
        $this->letterfile_process = $letterfile_process;
        return $this;
@@ -305,7 +402,7 @@ class Signature
    /**
     * @return string
     */
    public function getLetterfileKey(): string
    public function getLetterfileKey(): ?string
    {
        return $this->letterfile_key;
    }
@@ -337,4 +434,36 @@ class Signature
        $this->letterfile_url = $letterfile_url;
        return $this;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public function isSendable() :bool
    {
        return $this->getStatus() == self::STATUS_SIGNATURE_DRAFT;
    }

    public function isSend() :bool
    {
        return $this->getDateSend() !== null;
    }

    public function isDeletable() :bool
    {
        return true;
    }

    public function getStatusText() :string {
        return self::getStatusLabel($this->getStatus());
    }

    /**
     * @return string[]
     */
    public function getRecipientsEmailsArray() :array
    {
        $out = [];
        foreach ($this->getRecipients() as $recipient) {
            $out[] = $recipient->getEmail();
        }
        return $out;
    }
}
 No newline at end of file
Loading