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

Duplication des privilèges d'autres profils

parent a24666a8
Loading
Loading
Loading
Loading
+12 −1
Changes for module/Application/config/others/profil.config.php: 12 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ return [
                        'gerer-roles',
                        'ajouter-role',
                        'retirer-role',
                        'dupliquer-privileges',
                        'modifier-profil-privilege'
                    ],
                    'privileges' => [
@@ -81,7 +82,17 @@ return [
                        ],
                        'may_terminate' => true,
                    ],

                    'dupliquer' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'    => '/dupliquer/:profil',
                            'defaults' => [
                                'controller'    => ProfilController::class,
                                'action'        => 'dupliquer-privileges',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'gerer-roles' => [
                        'type'          => Segment::class,
                        'options'       => [
+24 −0
Changes for module/Application/src/Application/Controller/ProfilController.php: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -160,4 +160,28 @@ class ProfilController extends AbstractActionController {

        $this->redirect()->toRoute('profil/gerer-roles', ['profil' => $profil->getId()], [], true);
    }

    public function dupliquerPrivilegesAction()
    {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');
        $profil = $this->getProfilService()->getProfil($profilId);

        /** @var Request $request */
        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $profilFrom = $this->getProfilService()->getProfil($data['profil']);

            $this->getProfilService()->copyPrivilegeFrom($profilFrom, $profil);
            $this->redirect()->toRoute('profil', [], [], true);
        }

        $profils = $this->getProfilService()->getProfils();
        return new ViewModel([
            'title' => 'Sélectionner un profil pour dupliquer les privilèges',
            'profil' => $profil,
            'profils' => $profils,
        ]);
    }
}
 No newline at end of file
+25 −0
Changes for module/Application/src/Application/Service/Profil/ProfilService.php: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -123,4 +123,29 @@ class ProfilService {
            }
        }
    }

    /**
     * @param Profil $from
     * @param Profil $to
     */
    public function copyPrivilegeFrom($from, $to)
    {
        foreach ($to->getPrivileges() as $privilege) {
            $to->removePrivilege($privilege);
        }
        try {
            $this->getEntityManager()->flush($to);
        } catch (OptimisticLockException $e) {
            throw new RuntimeException("Un problème est survenu lors du retrait des privilèges initiaux", $e);
        }

        foreach ($from->getPrivileges() as $privilege) {
            $to->addPrivilege($privilege);
        }
        try {
            $this->getEntityManager()->flush($to);
        } catch (OptimisticLockException $e) {
            throw new RuntimeException("Un problème est survenu lors de l'ajout des privilèges", $e);
        }
    }
}
 No newline at end of file
+23 −0
Changes for module/Application/view/application/profil/dupliquer-privileges.phtml: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @var Profil[] $profils
 * @var Profil $profil
 */

use Application\Entity\Db\Profil;

?>

Dupliquer le profil :

<form method="POST" action="<?php echo $this->url('profil/dupliquer', ['profil' => $profil->getId()], [], true); ?>">
    <select name="profil">
        <?php foreach ($profils as $profil): ?>
            <option value="<?php echo $profil->getId(); ?>">
                <?php echo $profil->getLibelle(); ?>
            </option>
        <?php endforeach; ?>
    </select>
    <input type="submit" value="Appliquer"/>
</form>
 No newline at end of file
+13 −0
Changes for module/Application/view/application/profil/index.phtml: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -48,6 +48,11 @@ $canChangePrivilege = true;
                        <span class="glyphicon glyphicon-pencil" title="Éditer les informations du profil"></span>
                    </a>
                <?php endif; ?>
                <?php if ($canEdit) : ?>
                    <a class="ajax-modal" data-event="modification" href="<?php echo $this->url('profil/dupliquer', ['profil' => $profil->getId()], [], true);?>">
                        <span class="glyphicon glyphicon-paste" title="Recopier privilèges d'une autre profil"></span>
                    </a>
                <?php endif; ?>
                <?php if ($canDelete) : ?>
                    <a href="<?php echo $this->url('profil/supprimer', ['profil' => $profil->getId()], [], true);?>">
                        <span class="glyphicon glyphicon-trash" title="Supprimer le profil"></span>
@@ -110,6 +115,14 @@ $canChangePrivilege = true;
</style>

<script>
    $(function() {
        $("body").on("modification", function (event) {
            event.div.modal('hide');
            window.location.reload();
        });
    });


    $(document).ready(function() {
        $("td").click(function() {