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

Bouton refresh sur l'utilisateur

parent e4e60e06
Loading
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ return [
                    'controller' => UtilisateurController::class,
                    'action' => [
                        'changer-statut',
                        'refresh',
                    ],
                    'privileges' => [
                        UtilisateurPrivileges::UTILISATEUR_CHANGERSTATUS,
@@ -224,6 +225,16 @@ return [
                            ],
                        ],
                    ],
                    'refresh' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'       => '/refresh/:utilisateur',
                            'defaults'    => [
                                /** @see UtilisateurController::refreshAction() */
                                'action' => 'refresh',
                            ],
                        ],
                    ],
                    'supprimer' => [
                        'type'          => Segment::class,
                        'options'       => [
+24 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace UnicaenUtilisateur\Controller;
use BjyAuthorize\Provider\Identity\ProviderInterface;
use DateTime;
use Exception;
use Laminas\Http\Response;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenApp\View\Model\CsvModel;
use UnicaenUtilisateur\Entity\Db\UserInterface;
@@ -64,7 +65,7 @@ class UtilisateurController extends AbstractActionController
        $this->usernamefield = $usernamefield;
    }

    public function indexAction()
    public function indexAction(): ViewModel|Response
    {
        $roles = $this->roleService->findAll();
        $form = $this->userRechercheForm;
@@ -382,4 +383,26 @@ class UtilisateurController extends AbstractActionController

        return $CSV;    
    }

    public function refreshAction(): ViewModel
    {
        $id = $this->params()->fromRoute('utilisateur');
        $user = $this->userService->find($id);
        $fromLdap = $this->searchServices['ldap']->findById($user->getUsername($this->usernamefield));

        $request = $this->getRequest();
        if ($request->isPost()) {
            $user->setUsername($fromLdap->getUsername($this->usernamefield));
            $user->setDisplayName($fromLdap->getDisplayName());
            $user->setEmail($fromLdap->getEmail());
            $this->getUserService()->update($user);
            exit();
        }

        return new ViewModel([
            'title' => "Rafraichissement des données de l'utilisateur",
            'user' => $user,
            'fromLdap' => $fromLdap,
        ]);
    }
}
 No newline at end of file
+21 −2
Original line number Diff line number Diff line
@@ -101,8 +101,22 @@ $canCreerLocal = $canAjouter;

    <div class="card border-default mb-3">
        <div class="card-header bg-default">
            <div class="row">
                <div class="col-md-10">
                    <h2>Identité de l'utilisateur #<?php echo $utilisateur->getId() ?></h2>
                </div>
                <div class="col-md-2">
                    <?php if($canSuspendre): ?>
                        <?php /** @see UtilisateurController::refreshAction() */ ?>
                        <a href='<?php echo $this->url('unicaen-utilisateur/refresh', ['utilisateur' => $utilisateur->getId()], [], true); ?>'
                           class='btn btn-primary pull-right ajax-modal' data-event="modification">
                            <span class="icon icon-refresh"></span>
                            Mettre à jour
                        </a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <ul class="list-group list-group-flush">
            <li class="list-group-item">
                <div class="row">
@@ -292,7 +306,12 @@ $canCreerLocal = $canAjouter;

<script>
    $(function () {
        $("body").on("modification " +
        $("body")
            .on("modification", function (event) {
                event.div.modal('hide');
                window.location.reload();
            })
            .on("modification " +
            "event-unicaen-utilisateur-ajouter",
            function (event) {
                event.div.modal('hide');
+44 −0
Original line number Diff line number Diff line
<?php

use UnicaenUtilisateur\Entity\Db\User;use UnicaenUtilisateur\Service\RechercheIndividu\RechercheIndividuResultatInterface;

/** @see UtilisateurController::refreshAction()
 * @var User $user
 * @var RechercheIndividuResultatInterface $fromLdap
 *
 * */

?>

<table class="table table-condensed">
    <thead>
    <tr>
        <td style="border: none;"></td>
        <th>Depuis l'application</th>
        <th>Depuis le système d'information</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th>Identifiant </th>
        <td><?php echo $user->getUsername(); ?></td>
        <td><?php echo $fromLdap->getUsername(); ?></td>
    </tr>
    <tr>
        <th>Nom affiché </th>
        <td><?php echo $user->getDisplayName(); ?></td>
        <td><?php echo $fromLdap->getDisplayname(); ?></td>
    </tr>
    <tr>
        <th>Adresse électronique </th>
        <td><?php echo $user->getEmail(); ?></td>
        <td><?php echo $fromLdap->getEmail(); ?></td>
    </tr>
    </tbody>
</table>

<form action="<?php echo $this->url('unicaen-utilisateur/refresh', ['utilisateur' => $user->getId()]); ?>" method="post">
    <button class="btn btn-success">
        <span class="icon icon-refresh">Mettre à jour avec les données du système d'information</span>
    </button>
</form>
 No newline at end of file