Commit fac17188 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Ajout de l'assertion pour la visibilité de l'adresse électronique de contact

parent 4a46522e
Loading
Loading
Loading
Loading
+54 −9
Changes for data/assertions/README.md: 54 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -2,21 +2,26 @@

## Interprétation du fichier CSV

Dans le fichier CSV, la première ligne désigne la classe d'assertion liée au fichier CSV.
Dans le fichier CSV, la première ligne désigne la classe d'assertion qui sera générée à partir du fichier CSV.
Par exemple, `class;Application\Assertion\These\GeneratedTheseEntityAssertion` pour la classe `GeneratedTheseEntityAssertion`.

Les lignes correspondent au privilièges et les colonnes aux prédicats utilisés. 
Pour lire comment interpréter le fichier, on regarde pour un privilège les lignes (consécutives?) qui lui sont associées et les prédicats pour lesquel la cellule est non vide.
La ligne 2 liste des prédicats qui peuvent être utilisés  et qui doivent être définit dans le classe mère `TheseEntityAssertion`.  

La colonne C correspond aux privilèges concernés.
 
Pour lire comment interpréter le fichier, on regarde pour un privilège les lignes (consécutives?) qui lui sont associées 
et les prédicats pour lesquel la cellule est non vide.


Par exemple, pour le privilège `THESE_DEPOT_INITIAL` :

| privilege                   | isTheseEnCours | isTheseSoutenue |...| return |
|-----------------------------|----------------|-----------------|---|--------|
|THESE_DEPOT_VERSION_INITIALE |1:0             |                 |...| 0      |
|THESE_DEPOT_VERSION_INITIALE |                | 1:1             |...| 0      |
| ... | ... | ... | ... | ... |
|THESE_DEPOT_VERSION_INITIALE |                |                 |...| 1      |
| privilege                     | isRoleDoctorantSelected | isTheseEnCours | isTheseSoutenue | isUtilisateurEstAuteurDeLaThese |...| return |
|-------------------------------|-------------------------|----------------|-----------------|---------------------------------|---|--------| 
|THESE_DEPOT_VERSION_INITIALE   |                         | 1:0            | 1:0             |                                 |...| 0      |
|THESE_DEPOT_VERSION_INITIALE   |                         |                | 1:1             |                                 |...| 0      |
|THESE_DEPOT_VERSION_INITIALE   |                         |                |                 |                                 |...| 1      |
|DOCTORANT_AFFICHER_MAIL_CONTACT| 1:1                     |                |                 | 2:1                             |...| 0      |
|DOCTORANT_AFFICHER_MAIL_CONTACT|                         |                |                 |                                 |...| 1      |

La cellule au croissement de `THESE_DEPOT_VERSION_INITIALE` et de `isTheseEnCours` vaut `1:0`.
Elle s'interprète comme si le prédicat est `faux` alors l'assertion retourne `0`.
@@ -26,6 +31,46 @@ Elle s'interprète comme si le prédicat est `vrai` alors l'assertion retourne `

La dernière ligne indique que si on a franchi toutes les étapes précédentes alors l'assertion retourne `1`.

```php
if ($privilege === \Application\Provider\Privilege\ThesePrivileges::THESE_DEPOT_VERSION_INITIALE) {
        //--------------------------------------------------------------------------------------
            /* line 4 */
            $this->linesTrace[] = '/* line 4 */';
            if (! $this->isTheseEnCours() /* test 5 */) {
                $this->failureMessage = "L’état de la thèse ne permet pas cette opération.";
                return false;
            }
            /* line 5 */
            $this->linesTrace[] = '/* line 5 */';
            if ($this->isTheseSoutenue() /* test 6 */) {
                $this->failureMessage = "Le dépôt initial n'est plus autorisé car la date de soutenance est passée.";
                return false;
            }
            /* line 9 */
            $this->linesTrace[] = '/* line 9 */';
            return true;
        }
```

Dans le cas `DOCTORANT_AFFICHER_MAIL_CONTACT` l'ordre indiqué par le premier nombre va impacter l'ordre d'utilisation des prédicats.
 
 ```php
if ($privilege === \Application\Provider\Privilege\DoctorantPrivileges::DOCTORANT_AFFICHER_EMAIL_CONTACT) {
        //--------------------------------------------------------------------------------------
            /* line 77 */
            $this->linesTrace[] = '/* line 77 */';
            if ($this->isRoleDoctorantSelected() /* test 1 */ && 
                ! $this->isUtilisateurEstAuteurDeLaThese() /* test 22 */) {
                $this->failureMessage = "Vous ne pouvez pas visualiser l’adresse de contact car vous n’êtes pas l’auteur de la thèse";
                return false;
            }
            /* line 78 */
            $this->linesTrace[] = '/* line 78 */';
            return true;
        }
```


## Ajouter une nouvelle assertion

***TODO***
+2 −0
Changes for data/assertions/TheseEntityAssertion.csv: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -76,3 +76,5 @@ line;enabled;privilege;isRoleDoctorantSelected;;isStructureDuRoleRespectee;;isTh
74;1;\Application\Provider\Privilege\ThesePrivileges::THESE_SAISIE_AUTORISATION_DIFFUSION_VERSION_INITIALE;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;
75;1;\Application\Provider\Privilege\ThesePrivileges::THESE_TELECHARGEMENT_FICHIER /* évite UnexpectedPrivilegeException */;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;
76;1;\Application\Provider\Privilege\ThesePrivileges::THESE_SAISIE_CORREC_AUTORISEE_FORCEE /* évite UnexpectedPrivilegeException */;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;
77;1;\Application\Provider\Privilege\DoctorantPrivileges::DOCTORANT_AFFICHER_EMAIL_CONTACT;1:1;;;;;;;;;;;;;;;;;;;;;2:0;;;;;;0;Vous ne pouvez pas visualiser l’adresse de contact car vous n’êtes pas l’auteur de la thèse
78;1;\Application\Provider\Privilege\DoctorantPrivileges::DOCTORANT_AFFICHER_EMAIL_CONTACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;
+2 −8
Changes for module/Application/config/others/doctorant.config.php: 2 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -5,18 +5,14 @@ use Application\Provider\Privilege\DoctorantPrivileges;
use Application\Service\Doctorant\DoctorantService;
use Application\Service\Doctorant\DoctorantServiceFactory;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenAuth\Provider\Rule\PrivilegeRuleProvider;

return [
    'bjyauthorize'    => [
//        'rule_providers'     => [
//            PrivilegeRuleProvider::class => [
//                'allow' => [
//                    [
//                        'privileges' => [
//                        ],
//                        'resources'  => ['These'],
//                        'assertion'  => 'Assertion\\These',
//                    ],
//                    [],
//                ],
//            ],
//        ],
@@ -92,8 +88,6 @@ return [
        )
    ),
    'service_manager' => [
        'invokables' => array(
        ),
        'factories' => [
            'DoctorantService' => DoctorantServiceFactory::class,
        ],
+1 −0
Changes for module/Application/config/others/these.config.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ use Application\Form\Factory\PointsDeVigilanceHydratorFactory;
use Application\Form\Factory\RdvBuHydratorFactory;
use Application\Form\Factory\RdvBuTheseDoctorantFormFactory;
use Application\Form\Factory\RdvBuTheseFormFactory;
use Application\Provider\Privilege\DoctorantPrivileges;
use Application\Provider\Privilege\ThesePrivileges;
use Application\Service\Acteur\ActeurService;
use Application\Service\Financement\FinancementService;
+0 −74
Changes for module/Application/src/Application/Assertion/DoctorantAssertion.php: 0 added lines, 74 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Assertion\These;

use Application\Assertion\BaseAssertion;
use Application\Entity\Db\Role;
use Application\Entity\Db\These;
use Application\Provider\Privilege\DoctorantPrivileges;
use Application\Service\UserContextService;
use Zend\Permissions\Acl\Resource\ResourceInterface;

/**
 * Class TheseAssertion
 *
 * @package Application\Assertion
 * @method UserContextService getServiceUserContext()
 */
class DoctorantAsserction extends BaseAssertion {

    protected function assertEntity(ResourceInterface $these, $privilege = null)
    {
        if (!parent::assertEntity($these, $privilege)) {
            return false;
        }

        /** @var These $these */
        $role = $this->userContextService->getSelectedIdentityRole();
        $individu = $this->userContextService->getIdentityIndividu();
        switch ($privilege) {
            case $privilege === DoctorantPrivileges::DOCTORANT_AFFICHER_EMAIL_CONTACT :
                // doctorant
                if ($role->getCode() === Role::CODE_ADMIN_TECH) return true;
                if ($role->getCode() === Role::CODE_DOCTORANT) return $these->getDoctorant()->getIndividu() === $individu;
                return false;
                break;
        }

        return true;
    }

    /**
     * @return static
     */
    protected function initControllerAssertion()
    {
        $this->controllerAssertion->setContext([
            'these'     => $this->getRouteMatch()->getThese(),
            'doctorant' => $this->getRouteMatch()->getDoctorant(),
        ]);

        return $this;
    }

    /**
     * @return static
     */
    protected function initPageAssertion()
    {
        $this->pageAssertion->setContext(['these' => $this->getRouteMatch()->getThese()]);

        return $this;
    }

    /**
     * @param ResourceInterface $entity
     * @return static
     */
    protected function initEntityAssertion(ResourceInterface $entity)
    {
        $this->entityAssertion->setContext(['these' => $entity]);

        return $this;
    }
}
 No newline at end of file
Loading