Commit dfa0de77 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Ajout d'un écran de confirmation pour la suppression d'une personne

parent 9da11c6e
Loading
Loading
Loading
Loading
+110 −97
Original line number Diff line number Diff line
@@ -93,23 +93,47 @@ class PersonController extends AbstractOscarController
            return $this->jsonError($e->getMessage());
        }
    }
    public function deleteAction(): array

    public function deleteAction(): array|Response
    {
        $method = $this->getHttpXMethod();
        $this->getOscarUserContextService()->check(Privileges::PERSON_EDIT);
        $personId = $this->params()->fromRoute('id');
        $error = null;
        $person = null;

        try {
            if ($method != 'POST') {
                return $this->getResponseBadRequest("Opération non-authorisée");
            $person = $this->getPersonService()->getPerson($personId);
        } catch (\Exception $e) {
            return [
                'person' => $person,
                'error' => "Impossible de charger la personne : " . $e->getMessage()
            ];
        }

            $this->getPersonDeleteService()->delete($this->params()->fromRoute('id'));
        if ($method != 'POST') {
            return [
                'person' => $person,
                'error' => $error
            ];
        }

            if ($this->getOscarUserContextService()->check(Privileges::PERSON_INDEX)) {
                $this->redirect()->toRoute('person/index');
        try {
            $request = $this->getRequest();
            if ($request->getPost('confirm') === 'Confirmer') {
                $this->getPersonDeleteService()->delete($personId);
                $this->getFlashMessenger()->addSuccessMessage("Suppression de '$person' effectuée");
                if ($this->getOscarUserContextService()->hasPrivileges(Privileges::PERSON_INDEX)) {
                    return $this->redirect()->toRoute('person');
                }
            } else {
                return $this->redirect()->toRoute('person/show', array('id' => $personId));
            }
            $this->redirect()->toRoute('home');
        } catch (\Exception $e) {
            throw new OscarException("PAS POSSIBLE : " . $e->getMessage());
            return [
                'person' => $person,
                'error' => "La procédure de suppression a échouée : " . $e->getMessage()
            ];
        }
    }

@@ -197,8 +221,7 @@ class PersonController extends AbstractOscarController
        $extended = $this->params()->fromQuery('extended', 0);
        if ($extended) {
            $datas = $this->getPersonService()->searchPersonnel($q, $page, $params);
        }
        else {
        } else {
            $datas = $this->getPersonService()->getPersonsSearchPaged($q, $page, $params);
        }

@@ -297,8 +320,7 @@ class PersonController extends AbstractOscarController
        if ($this->getOscarUserContextService()->hasPrivileges(Privileges::PERSON_SHOW)) {
            $allow = true;
            $justXHR = false;
        }
        else {
        } else {
            $context = $this->getRequest()->getQuery("context");
            $context_param = $this->getRequest()->getQuery("context_param");
            if ($context) {
@@ -311,8 +333,7 @@ class PersonController extends AbstractOscarController
                        return new JsonModel($persons);
                        break;
                }
            }
            else {
            } else {
                $allow = $this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles(
                    [
                        Privileges::ACTIVITY_INDEX,
@@ -330,8 +351,7 @@ class PersonController extends AbstractOscarController
            );
            if ($justXHR) {
                return $this->getResponseUnauthorized();
            }
            else {
            } else {
                throw new UnAuthorizedException();
            }
        }
@@ -585,8 +605,7 @@ class PersonController extends AbstractOscarController
    {
        if (array_key_exists($key, $array)) {
            return $array[$key];
        }
        else {
        } else {
            return null;
        }
    }
@@ -615,8 +634,7 @@ class PersonController extends AbstractOscarController
        if ($person) {
            $this->getPersonService()->synchronize($person);
            return $this->redirect()->toRoute('person/show', ['id' => $person->getId()]);
        }
        else {
        } else {
            return $this->getResponseNotFound('Personne introuvable');
        }
    }
@@ -640,8 +658,7 @@ class PersonController extends AbstractOscarController
                    if ($declarerId) {
                        // Détails pour le déclarant
                        return $this->getResponseNotImplemented("Fonctionnalité à venir");
                    }
                    else {
                    } else {
                        $output = $this->baseJsonResponse();
                        $period = DateTimeUtils::extractPeriodDatasFromString(
                            $this->params()->fromQuery('period', date('Y-m'))
@@ -783,12 +800,10 @@ class PersonController extends AbstractOscarController
                                $person->setCustomSettingsObj($custom);
                                $this->getEntityManager()->flush($person);
                                $this->getLoggerService()->info(print_r($custom, true));
                            }
                            elseif ($daysLength != null) {
                            } elseif ($daysLength != null) {
                                $this->getUserParametersService()->performChangeSchedule($daysLength, $person);
                                return $this->getResponseOk("Heures enregistrées");
                            }
                            else {
                            } else {
                                if (!array_key_exists($model, $models)) {
                                    return $this->getResponseBadRequest("Modèle inconnu");
                                }
@@ -879,8 +894,7 @@ class PersonController extends AbstractOscarController
                        default:
                            throw new OscarException("Opération inconnue");
                    }
                }
                else {
                } else {
                    return $this->getResponseUnauthorized(
                        "Vous n'avez pas le droit de déléguer la déclaration d'une personne à une autre."
                    );
@@ -908,8 +922,7 @@ class PersonController extends AbstractOscarController
                    if ($mode == 'replace') {
                        $this->getPersonService()->refererentReplaceBy($newReferent, $referent);
                        return $this->redirect()->toRoute('person/show', ['id' => $newReferent->getId()]);
                    }
                    else {
                    } else {
                        $this->getPersonService()->refererentAddFromReferent($newReferent, $referent);
                        return $this->redirect()->toRoute('person/show', ['id' => $newReferent->getId()]);
                    }
+5 −0
Original line number Diff line number Diff line
@@ -1120,4 +1120,9 @@ class Person implements ResourceInterface
        }
        return $this;
    }

    public function countAffectations()
    {
        return $this->getActivities()->count() + $this->getProjectAffectations()->count();
    }
}
+23 −0
Original line number Diff line number Diff line
<div class="container">
    <?php if($error): ?>
    <h1>Suppression de la personne Impossible</h1>
    <div class="alert alert-danger">
        <strong>Erreur de suppression : </strong>
        <code><?= $error ?></code>
    </div>
    <?php else: ?>
    <h1>Supprimer <strong><?= $person ?></strong></h1>
    <div class="alert-warning alert">
        Attention, cette suppression est définitive !
    </div>
        <form action="" method="post">
            <button type="submit" class="btn btn-danger" name="confirm" value="Confirmer">
                Confirmer
            </button>
            <button type="cancel" class="btn btn-light">
                annuler
            </button>
        </form>

    <?php endif; ?>
</div>
+27 −34
Original line number Diff line number Diff line
@@ -8,35 +8,47 @@
/** @var \Oscar\Entity\Person $entity */
?>
<section class="container">
    <div class="row">

    <div>
        <header class="fiche header">
            <h1 class="">
            <h1>
                <?= $entity->getFirstname() ?>
                <strong class="lastname"><?= $entity->getLastname() ?></strong>
            </h1>
            <?php if($entity->getLdapAffectation() ):?>
                    <small> (<?= $entity->getLdapAffectation() ?>)</small>
                <h2><?= $entity->getLdapAffectation() ?></h2>
            <?php endif; ?>
            </h1>
        </header>

        <nav>
        <nav class="buttons-bar">
            <?php if( $this->grant(\Oscar\Provider\Privileges::ACTIVITY_INDEX)): ?>
            <a href="<?= $this->url('contract/search-global') ?>?&project=1&f[]=ap%3B<?= $entity->getId() ?>%3B%3B"
               class="btn btn-light">
                Voir les projets
               class="btn <?= $entity->getProjectAffectations()->count() ? 'btn-primary' : 'btn-light' ?>">
                <i class="icon-cubes"></i>
                <?= $this->oscarText('Voir les projets') ?>
            </a>
            <a href="<?= $this->url('contract/search-global') ?>?&project=0&f[]=ap%3B<?= $entity->getId() ?>%3B%3B"
               class="btn btn-light">
                Voir les activités
               class="btn <?= $entity->getActivities()->count() ? 'btn-primary' : 'btn-light' ?>">
                <i class="icon-cube"></i>
                <?= $this->oscarText('Voir les activités') ?>
            </a>
            <?php endif; ?>

            <?php if( $this->grant(\Oscar\Provider\Privileges::PERSON_EDIT)): ?>
                <a class="btn btn-primary" href="<?= $this->url('person/edit', ['id'=>$entity->getId()]) ?>">
                    <i class="icon-pencil"></i>
                    Éditer les informations
                    Modifier
                </a>
                <a class="btn btn-danger" href="<?= $this->url('person/delete', ['id'=>$entity->getId()]) ?>">
                    <i class="icon-trash"></i>
                    Supprimer
                </a>
                <?php /*
                <form class="form-inline" action="<?= $this->url('person/delete', ['id' => $entity->getId()]) ?>" method="post">
                    <button type="submit" class="btn btn-danger">
                        <i class="icon-trash"></i>
                        Supprimer
                    </button>
                </form> */ ?>

                <span id="replacer"></span>
                <script>
@@ -58,14 +70,6 @@
                    });
                </script>


                <form class="form-inline" action="<?= $this->url('person/delete', ['id' => $entity->getId()]) ?>" method="post">
                    <button type="submit" class="btn btn-danger">
                        <i class="icon-trash"></i>
                        Supprimer
                    </button>
                </form>

            <?php endif ?>

            <?php if($this->grant()->privilege(\Oscar\Provider\Privileges::DROIT_PRIVILEGE_VISUALISATION)): ?>
@@ -91,16 +95,6 @@
            <?php endif; ?>
        </nav>




        <p>



        </p>


        <div class="row">
            <section class="col-md-6">
                <h2>
@@ -208,7 +202,7 @@
                    </div>
                </div>
            </section>

            <?php if( $this->grant()->privilege(\Oscar\Provider\Privileges::ACTIVITY_TIMESHEET_VIEW)): ?>
            <section class="col-md-6">
                <h2><i class="icon-sitemap"></i> Hiérarchie</h2>
                <p>Les informations hiérarchiques sont utilisées par Oscar pour déterminer les personnes en charge lors de la procédure de <strong>validation des feuilles de temps</strong>.</p>
@@ -537,8 +531,7 @@
                    <?php endif; ?>
                </div>
            </section>
        </div>
        <div class="row">
            <?php endif; ?>

            <section class="col-md-6">

@@ -564,7 +557,7 @@
                <?php endif; ?>


                <h2><i class="icon-building-filled"></i> Structures</h2>
                <h2><i class="icon-building-filled"></i> Affectations</h2>

                <?php if( count($entity->getOrganizations()) ): ?>
                <?php