Commit e265afeb authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Dépôt de fichiers dits "communs" (dans le menu Administration), ex: modèle...

Dépôt de fichiers dits "communs" (dans le menu Administration), ex: modèle d'avenant à la convention de MEL.
parent a3d5d6d5
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
--
-- Fichiers communs.
--
-- Nouvelle catégorie.
insert into CATEGORIE_PRIVILEGE(ID, CODE, LIBELLE, ORDRE)
values (47, 'fichier-commun', 'Dépôt de fichier commun (non lié à une thèse)', 50)
/
insert into PRIVILEGE(ID, CATEGORIE_ID, CODE, LIBELLE, ORDRE)
select privilege_id_seq.nextval, cp.id, 'televerser', 'Téléversement de fichier commun non lié à une thèse particulière (ex: PV de soutenance)', 10
from CATEGORIE_PRIVILEGE cp where cp.CODE = 'fichier-commun'
/
insert into PRIVILEGE(ID, CATEGORIE_ID, CODE, LIBELLE, ORDRE)
select privilege_id_seq.nextval, cp.id, 'telecharger', 'Téléchargement de fichier commun non lié à une thèse particulière (ex: PV de soutenance)', 20
from CATEGORIE_PRIVILEGE cp where cp.CODE = 'fichier-commun'
/
-- Ajout des privilèges fichier-commun/* au profil 'ADMIN_TECH'
insert into PROFIL_PRIVILEGE (PRIVILEGE_ID, PROFIL_ID)
with data(categ, priv) as (
    select 'fichier-commun',  'televerser'  from dual union
    select 'fichier-commun',  'telecharger' from dual
)
select p.id as PRIVILEGE_ID, profil.id as PROFIL_ID
from data
         join PROFIL on profil.ROLE_ID in ('ADMIN_TECH', 'BU', 'BDD')
         join CATEGORIE_PRIVILEGE cp on cp.CODE = data.categ
         join PRIVILEGE p on p.CATEGORIE_ID = cp.id and p.code = data.priv
/
-- Attribution (si pas déjà fait) des privilèges fichier-divers/* au rôle 'ADMIN_TECH' (grâce au profil 'ADMIN_TECH').
insert into ROLE_PRIVILEGE (ROLE_ID, PRIVILEGE_ID)
SELECT r.id as ROLE_ID, p.ID as PRIVILEGE_ID
from PROFIL_PRIVILEGE pp
         join profil on PROFIL.ID = pp.PROFIL_ID and profil.ROLE_ID in ('ADMIN_TECH', 'BU', 'BDD')
         join PRIVILEGE p on p.id = pp.PRIVILEGE_ID
         join CATEGORIE_PRIVILEGE cp on cp.id = p.CATEGORIE_ID and cp.CODE = 'fichier-commun'
         join role r on r.CODE = PROFIL.ROLE_ID
where not exists (
        select * from ROLE_PRIVILEGE rp where rp.ROLE_ID = r.id and rp.PRIVILEGE_ID = p.id
    );


--
-- Nouvelle NATURE_FICHIER : 'COMMUNS'
--
insert into NATURE_FICHIER (ID, CODE, LIBELLE)
values (11, 'COMMUNS', 'Fichier commun (ex: modèle d''avenant à la convention de MEL)')
/



select * from PRIVILEGE p
join CATEGORIE_PRIVILEGE cp on cp.id = p.CATEGORIE_ID and cp.CODE = 'fichier-divers';
+123 −24
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@ use Application\Command\CheckWSValidationFichierCinesCommandFactory;
use Application\Command\ValidationFichierCinesCommandFactory;
use Application\Controller\Factory\FichierControllerFactory;
use Application\Controller\Factory\FichierTheseControllerFactory;
use Application\Controller\FichierTheseController;
use Application\Controller\Plugin\UrlFichier;
use Application\Controller\Plugin\UrlFichierThese;
use Application\Provider\Privilege\FichierPrivileges;
use Application\Provider\Privilege\ThesePrivileges;
use Application\Provider\Privilege\ValidationPrivileges;
use Application\Service\Fichier\FichierService;
@@ -15,9 +19,29 @@ use Application\Service\NatureFichier\NatureFichierService;
use Application\Service\ValiditeFichier\ValiditeFichierService;
use Application\Service\VersionFichier\VersionFichierService;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenAuth\Provider\Rule\PrivilegeRuleProvider;

return array(
return [
    'bjyauthorize'    => [
        'resource_providers' => [
            'BjyAuthorize\Provider\Resource\Config' => [
                'Fichier' => [],
            ],
        ],
        'rule_providers'     => [
            PrivilegeRuleProvider::class => [
                'allow' => [
                    [
                        'privileges' => [
                            FichierPrivileges::FICHIER_COMMUN_TELECHARGER,
                            FichierPrivileges::FICHIER_COMMUN_TELEVERSER,
                        ],
                        'resources'  => ['Fichier'],
                        //'assertion'  => 'Assertion\\These',
                    ],
                ],
            ],
        ],
        'guards' => [
            PrivilegeController::class => [
                [
@@ -30,7 +54,6 @@ return array(
                [
                    'controller' => 'Application\Controller\FichierThese',
                    'action'     => [
                        'lister',
                        'lister-fichiers',
                    ],
                    'privileges' => ThesePrivileges::THESE_CONSULTATION_DEPOT,
@@ -80,12 +103,40 @@ return array(
                    ],
                    'roles' => [],
                ],

                [
                    'controller' => 'Application\Controller\Fichier',
                    'action'     => [
                        'lister-fichiers-communs',
                    ],
                    'privileges' => FichierPrivileges::FICHIER_COMMUN_TELECHARGER,
                ],

                [
                    'controller' => 'Application\Controller\Fichier',
                    'action'     => [
                        'telecharger',
                    ],
                    'privileges' => [
                        FichierPrivileges::FICHIER_COMMUN_TELECHARGER,
                    ],
                ],
                [
                    'controller' => 'Application\Controller\Fichier',
                    'action'     => [
                        'televerser-fichiers-communs',
                        'supprimer',
                    ],
                    'privileges' => [
                        FichierPrivileges::FICHIER_COMMUN_TELEVERSER,
                    ],
                ],
            ],
        ],
    ],

    'router' => array(
        'routes' => array(
    'router' => [
        'routes' => [

            'fichier' => [
                'type'          => 'Segment',
@@ -114,21 +165,13 @@ return array(
                        ],
                        'may_terminate' => false,
                        'child_routes'  => [
                            'lister'     => [
                                'type'     => 'Segment',
                                'options'  => [
                                    'route' => '/lister',
                                    'defaults' => [
                                        'action' => 'lister',
                                    ],
                                ],
                            ],
                            'lister-fichiers'     => [
                                'type'     => 'Segment',
                                'options'  => [
                                    'route' => '/lister-fichiers',
                                    'defaults' => [
                                        'action' => 'lister-fichiers',
                                        /* @see FichierTheseController::listerFichiersAction() */
                                    ],
                                ],
                            ],
@@ -208,11 +251,60 @@ return array(
                            ],
                        ],
                    ],

                    /*--------------- Hors Thèse --------------*/
                    'telecharger' => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route' => '/telecharger/:fichier[/:fichierNom]',
                            'constraints' => [
                                'fichier' => '[a-zA-Z0-9-]+',
                            ],
                            'defaults'      => [
                                'controller' => 'Fichier',
                                'action' => 'telecharger',
                            ],
                        ],
                    ],
                    'supprimer' => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route' => '/supprimer/:fichier[/:fichierNom]',
                            'constraints' => [
                                'fichier' => '[a-zA-Z0-9-]+',
                            ],
                            'defaults'      => [
                                'controller' => 'Fichier',
                                'action' => 'supprimer',
                            ],
                        ],
                    ],

                    'televerser-fichiers-communs' => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route' => '/televerser-fichiers-communs',
                            'defaults'      => [
                                'controller' => 'Fichier',
                                'action' => 'televerser-fichiers-communs',
                            ],
                        ],
                    ],
                    'lister-fichiers-communs' => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route' => '/lister-fichiers-communs',
                            'defaults'      => [
                                'controller' => 'Fichier',
                                'action' => 'lister-fichiers-communs',
                            ],
                        ],
                    ],
                ],
            ], // 'fichier'

        ),
    ),
        ],
    ],
    'console' => [
        'router' => [
            'routes' => [
@@ -235,31 +327,37 @@ return array(
                    'admin' => [
                        'pages' => [
                            'fichiers-deposes' => [
                                'label'    => 'Fichiers déposés',
                                'label'    => 'Fichiers de thèses',
                                'route'    => 'fichier/deposes',
                                'order'    => 100,
                                'resource' => PrivilegeController::getResourceId('Application\Controller\FichierThese', 'deposes'),
                            ],
                            'fichiers-communs' => [
                                'label'    => 'Fichiers communs',
                                'route'    => 'fichier/lister-fichiers-communs',
                                'order'    => 200,
                                'resource' => PrivilegeController::getResourceId('Application\Controller\Fichier', 'lister-fichiers-communs'),
                            ],
                        ],
                    ],
                ],
            ],
        ],
    'service_manager' => array(
        'invokables' => array(
    ],
    'service_manager' => [
        'invokables' => [
            'VersionFichierService' => VersionFichierService::class,
            'NatureFichierService' => NatureFichierService::class,
            'ValiditeFichierService' => ValiditeFichierService::class,
        ),
        'factories' => array(
        ],
        'factories' => [
            FileService::class => FileServiceFactory::class,
            FichierService::class => FichierServiceFactory::class,
            'FichierTheseService' => FichierTheseServiceFactory::class,
            'ValidationFichierCinesCommand' => ValidationFichierCinesCommandFactory::class,
            'CheckWSValidationFichierCinesCommand' => CheckWSValidationFichierCinesCommandFactory::class,
        ),
    ),
        ],
    ],
    'controllers' => [
        'factories' => [
            'Application\Controller\Fichier' => FichierControllerFactory::class,
@@ -268,7 +366,8 @@ return array(
    ],
    'controller_plugins' => [
        'invokables' => [
            'urlFichierThese'       => 'Application\Controller\Plugin\UrlFichierThese',
            'urlFichier'            => UrlFichier::class,
            'urlFichierThese'       => UrlFichierThese::class,
        ],
    ],
);
];
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Application\Controller;
use Application\Controller\Plugin\Uploader\UploaderPlugin;
use Application\Controller\Plugin\Url\UrlThesePlugin;
use Application\Controller\Plugin\UrlDoctorant;
use Application\Controller\Plugin\UrlFichier;
use Application\Controller\Plugin\UrlFichierThese;
use Application\Controller\Plugin\UrlWorkflow;
use Application\Entity\Db\These;
@@ -28,6 +29,7 @@ use ZfcUser\Controller\Plugin\ZfcUserAuthentication;
 * @method boolean isAllowed($resource, $privilege)
 * @method UrlThesePlugin urlThese()
 * @method UrlDoctorant urlDoctorant()
 * @method UrlFichier urlFichier()
 * @method UrlFichierThese urlFichierThese()
 * @method UrlWorkflow urlWorkflow()
 * @method Mail mail()
+0 −5
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ namespace Application\Controller\Factory;

use Application\Controller\FichierController;
use Application\Service\Fichier\FichierService;
use Application\Service\FichierThese\FichierTheseService;
use Zend\Mvc\Controller\ControllerManager;

class FichierControllerFactory
@@ -19,14 +18,10 @@ class FichierControllerFactory
    {
        $sl = $controllerManager->getServiceLocator();

        /** @var FichierTheseService $fichierTheseService */
        $fichierTheseService = $sl->get('FichierTheseService');

        /** @var FichierService $fichierService */
        $fichierService = $sl->get(FichierService::class);

        $service = new FichierController();
        $service->setFichierTheseService($fichierTheseService);
        $service->setFichierService($fichierService);

        return $service;
+96 −9
Original line number Diff line number Diff line
@@ -3,31 +3,88 @@
namespace Application\Controller;

use Application\Entity\Db\Fichier;
use Application\Entity\Db\NatureFichier;
use Application\Provider\Privilege\FichierPrivileges;
use Application\RouteMatch;
use Application\Service\Fichier\FichierServiceAwareTrait;
use Application\Service\FichierThese\FichierTheseServiceAwareTrait;
use Application\View\Helper\Sortable;
use BjyAuthorize\Exception\UnAuthorizedException;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\Tools\Pagination\Paginator;
use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;


class FichierController extends AbstractController
{
    use FichierTheseServiceAwareTrait;
    use FichierServiceAwareTrait;

    public function uploadAction()
    public function listerFichiersCommunsAction()
    {
        /**
         * Application des filtres et tris par défaut.
         */
        $needsRedirect = false;
        $queryParams = $this->params()->fromQuery();
        $sort = $this->params()->fromQuery('sort');
        if ($sort === null) { // null <=> paramètre absent
            // tri par défaut
            $queryParams = array_merge($queryParams, ['sort' => 'f.nom', 'direction' => Sortable::ASC]);
            $needsRedirect = true;
        }
        if ($needsRedirect) {
            return $this->redirect()->toRoute(null, [], ['query' => $queryParams], true);
        }

        $dir  = $this->params()->fromQuery('direction', Sortable::ASC);
        $maxi = $this->params()->fromQuery('maxi', 40);
        $page = $this->params()->fromQuery('page', 1);

        $qb = $this->fichierService->getRepository()->createQueryBuilder('f');
        $qb
            ->addSelect('n, hc, i')
            ->join('f.histoCreateur', 'hc')
            ->join('hc.individu', 'i')
            ->join('f.nature', 'n', Join::WITH, 'n.code = :code')
            ->setParameter('code', NatureFichier::CODE_COMMUNS);

        foreach (explode('+', $sort) as $sortProp) {
            $qb->addOrderBy($sortProp, $dir);
        }

        $paginator = new \Zend\Paginator\Paginator(new DoctrinePaginator(new Paginator($qb, true)));
        $paginator
            ->setPageRange(20)
            ->setItemCountPerPage((int)$maxi)
            ->setCurrentPageNumber((int)$page);

        $vm = new ViewModel([
            'fichiers' => $paginator,
            'urlFichierPlugin' => $this->urlFichier(),
        ]);

        return $vm;
    }

    public function televerserFichiersCommunsAction()
    {
        if (! $this->getRequest()->isPost()) {
            return $this->redirect()->toUrl($this->urlFichier()->listerFichiersCommuns());
        }

        $result = $this->uploader()->upload();

        if ($result instanceof JsonModel) {
            return $result;
        }
        if (is_array($result)) {
            return $result;
            return $this->redirect()->toUrl($this->urlFichier()->listerFichiersCommuns());
        }

        return false;
        $this->fichierService->createFichiersFromUpload($result, NatureFichier::CODE_COMMUNS);

        return $this->redirect()->toUrl($this->urlFichier()->listerFichiersCommuns());
    }

    public function downloadAction()
    public function telechargerAction()
    {
        $fichier = $this->requestFichier();

@@ -38,6 +95,36 @@ class FichierController extends AbstractController
        $this->uploader()->download($fichier);
    }

    public function supprimerAction()
    {
        $fichier = $this->requestFichier();

        if (! $this->isAllowed($fichier, FichierPrivileges::privilegeTeleverserFor($fichier->getNature()))) {
            throw new UnAuthorizedException("Suppression non autorisée.");
        }

        $result = $this->confirm()->execute();

        // si un tableau est retourné par le plugin Confirm, l'opération a été confirmée
        if (is_array($result)) {
            $this->fichierService->supprimerFichiers([$fichier]);

            $this->flashMessenger()->addSuccessMessage("Fichier '{$fichier->getNomOriginal()}' supprimé avec succès.");

            return $this->redirect()->toUrl($this->urlFichier()->listerFichiersCommuns());
        }

        $viewModel = $this->confirm()->getViewModel();
        $viewModel->setVariables([
            'title'   => "Suppression d'un fichier",
            'fichier' => $fichier,
        ]);

        return $viewModel;


    }

    /**
     * @return Fichier
     */
Loading