Commit 08ed5a10 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- Ajout/Suppression depuis la Black/White list

parent aa4a60b1
Loading
Loading
Loading
Loading
+34 −3
Original line number Diff line number Diff line
@@ -166,6 +166,36 @@ class AdministrationController extends AbstractOscarController implements UsePro
                    $this->redirect()->toRoute('administration/listdeclarers');
                    break;

                case 'add-to-blacklist' :
                    $personIds = $this->params()->fromPost('persons');
                    if( !$personIds ){
                        $this->flashMessenger()->addWarningMessage(
                            "Rien à ajouter"
                        );
                    }
                    else {
                        $persons = $this->getProjectGrantService()->getPersonService()->getPersonsByIds($personIds);
                        $adder = $this->getCurrentPerson();
                        $this->getProjectGrantService()->getPersonService()->addDeclarersToBlacklist(
                            $persons,
                            $adder
                        );
                        $this->redirect()->toRoute('administration/listdeclarers');
                    }
                    break;

                case 'remove-from-blacklist' :
                    $personId = $this->params()->fromPost('personid');
                    $persons = $this->getProjectGrantService()->getPersonService()->removeDeclarersFromBlacklist($personId);
                    $this->redirect()->toRoute('administration/listdeclarers');
                    break;

                case 'remove-from-whitelist' :
                    $personId = $this->params()->fromPost('personid');
                    $persons = $this->getProjectGrantService()->getPersonService()->removeDeclarersFromWhitelist($personId);
                    $this->redirect()->toRoute('administration/listdeclarers');
                    break;

                default:
                    throw new OscarException("Action inconnue");
            }
@@ -176,6 +206,7 @@ class AdministrationController extends AbstractOscarController implements UsePro
        return [
            "useWhiteList" => $useWhitelist,
            "whitelist" => $useWhitelist ? $this->getProjectGrantService()->getPersonService()->getDeclarersWhitelist() : null,
            "blacklist" => $this->getProjectGrantService()->getPersonService()->getDeclarersBlacklist()
        ];
    }

+98 −4
Original line number Diff line number Diff line
@@ -22,7 +22,19 @@ class RecallExceptionRepository extends EntityRepository
        $qb = $this->getBaseIncludeQueryBuilder()
            ->select('p.id');

        $r = $qb->getQuery()->setParameter('include', RecallException::TYPE_INCLUDED)->getArrayResult();
        $r = $qb->getQuery()->getArrayResult();
        return array_map('current', $r);
    }

    /**
     * @return int[]
     */
    public function getExcludedPersonsIds(): array
    {
        $qb = $this->getBaseExcludeQueryBuilder()
            ->select('p.id');

        $r = $qb->getQuery()->getArrayResult();
        return array_map('current', $r);
    }

@@ -34,14 +46,96 @@ class RecallExceptionRepository extends EntityRepository
        return $this->getBaseIncludeQueryBuilder()->select('e')->getQuery()->getResult();
    }

    /**
     * @return RecallException[]
     */
    public function getBlacklist()
    {
        return $this->getBaseExcludeQueryBuilder()->select('e')->getQuery()->getResult();
    }

    /**
     * @param int $personId
     * @return bool
     */
    public function isInWhiteList( int $personId ): bool
    {
        $r = $this->getBaseIncludeQueryBuilder()
            ->andWhere('p.id = :personid')
            ->setParameter('personid', $personId)
            ->getQuery()
            ->getResult();

        return count($r) > 0;
    }

    /**
     * @param int $personId
     * @return bool
     */
    public function isInBlackList( int $personId ): bool
    {
        $r = $this->getBaseExcludeQueryBuilder()
            ->andWhere('p.id = :personid')
            ->setParameter('personid', $personId)
            ->getQuery()
            ->getResult();

        return count($r) > 0;
    }

    public function removeDeclarerFromBlacklist( int $personId ):void
    {
        $exceptions = $this->getBaseExcludeQueryBuilder()
            ->andWhere('e.person = :personId')
            ->setParameter('personId', $personId)
            ->getQuery()
            ->getResult();
        foreach ($exceptions as $exception) {
            $this->getEntityManager()->remove($exception);
        }
    }

    public function removeDeclarerFromWhitelist( int $personId ):void
    {
        $exceptions = $this->getBaseIncludeQueryBuilder()
            ->andWhere('e.person = :personId')
            ->setParameter('personId', $personId)
            ->getQuery()
            ->getResult();
        foreach ($exceptions as $exception) {
            $this->getEntityManager()->remove($exception);
        }
    }


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /**
     * @return \Doctrine\ORM\QueryBuilder
     */
    protected function getBaseExcludeQueryBuilder()
    {
        return $this->getBaseQueryBuilder()
            ->andWhere('e.type = :exclude')
            ->setParameter('exclude', RecallException::TYPE_EXCLUDED);
    }

    /**
     * @return \Doctrine\ORM\QueryBuilder
     */
    protected function getBaseIncludeQueryBuilder()
    {
        return $this->createQueryBuilder('e')
            ->innerJoin('e.person', 'p')
            ->where('e.type = :include')
        return $this->getBaseQueryBuilder()
            ->andWhere('e.type = :include')
            ->setParameter('include', RecallException::TYPE_INCLUDED);
    }

    /**
     * @return \Doctrine\ORM\QueryBuilder
     */
    protected function getBaseQueryBuilder()
    {
        return $this->createQueryBuilder('e')
            ->innerJoin('e.person', 'p');
    }
}
 No newline at end of file
+79 −9
Original line number Diff line number Diff line
@@ -1468,25 +1468,56 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U
        return $queryBuilder;
    }

    /**
     * @return RecallExceptionRepository
     */
    public function getRecallExceptionRepository(): RecallExceptionRepository
    {
        return $this->getEntityManager()->getRepository(RecallException::class);
    }

    public function declarerCanReceiveTimesheetMail(Person $declarer): bool
    {
        $receive = true;
        if ($this->getOscarConfigurationService()->useDeclarersWhiteList()) {
            $receive = $this->getRecallExceptionRepository()->isInWhiteList($declarer->getId());
        }
        if ($receive == true) {
            $receive = !$this->getRecallExceptionRepository()->isInBlackList($declarer->getId());
        }
        return $receive;
    }


    /**
     * Liste des personnes dans la liste blanche
     *
     * @return RecallException[]
     */
    public function getDeclarersWhitelist()
    {
        /** @var RecallExceptionRepository $recallExceptions */
        $recallExceptions = $this->getEntityManager()->getRepository(RecallException::class);
        return $this->getRecallExceptionRepository()->getWhitelist();
    }

        return $recallExceptions->getWhitelist();
    /**
     * Liste des personnes dans la liste noire
     *
     * @return RecallException[]
     */
    public function getDeclarersBlacklist()
    {
        return $this->getRecallExceptionRepository()->getBlacklist();
    }

    /**
     * Ajout d'une personne dans la liste blanche.
     *
     * @param Person[] $persons
     * @param Person $adder
     */
    public function addDeclarersToWhitelist(array $persons, Person $adder): void
    {
        /** @var RecallExceptionRepository $recallExceptions */
        $recallExceptions = $this->getEntityManager()->getRepository(RecallException::class);

        $included = $recallExceptions->getIncludedPersonsIds();
        $included = $this->getRecallExceptionRepository()->getIncludedPersonsIds();
        foreach ($persons as $person) {
            if (!in_array($person->getId(), $included)) {
                $include = new RecallException();
@@ -1498,10 +1529,49 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U
        $this->getEntityManager()->flush();
    }

    /**
     * Ajout d'une personne dans la liste noire.
     *
     * @param Person[] $persons
     * @param Person $adder
     */
    public function addDeclarersToBlacklist(array $persons, Person $adder): void
    {
        $excluded = $this->getRecallExceptionRepository()->getExcludedPersonsIds();
        foreach ($persons as $person) {
            if (!in_array($person->getId(), $excluded)) {
                $excluded = new RecallException();
                $excluded->setPerson($person)
                    ->setType(RecallException::TYPE_EXCLUDED);
                $this->getEntityManager()->persist($excluded);
            }
        }
        $this->getEntityManager()->flush();
    }

    /**
     * Suppression d'une personne dans la liste noire.
     *
     * @param Person[] $persons
     * @param Person $adder
     */
    public function removeDeclarersFromBlacklist(int $personId): void
    {
        $this->getRecallExceptionRepository()->removeDeclarerFromBlacklist($personId);
        $this->getEntityManager()->flush();
    }



    /**
     * Suppression d'une personne dans la liste noire.
     *
     * @param Person[] $persons
     * @param Person $adder
     */
    public function removeDeclarersFromWhitelist(int $personId): void
    {
        $this->getRecallExceptionRepository()->removeDeclarerFromWhitelist($personId);
        $this->getEntityManager()->flush();
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///
+84 −30
Original line number Diff line number Diff line
@@ -3,7 +3,8 @@
    <div class="row">
        <div class="col-md-6">
            <h2>Liste blanche</h2>
            <?php if( $useWhiteList ):?>
            <?php
            if ($useWhiteList): ?>
                <form action="" method="post">
                    <div class="alert alert-warning">
                        <div><em>Whitelist</em> : <strong>ACTIVE</strong></div>
@@ -11,7 +12,8 @@
                            Le système de rappel des déclarants est en mode <em>Whitelist</em>,
                            seul les déclarants identifiés en liste blanche seront notifiés par mail
                            en cas de défaut de déclaration. <br>
                            Il y'a pour le moment <strong><?= count($whitelist) ?> personne(s) en <em>whitelist</em></strong></small>
                            Il y'a pour le moment <strong><?= count($whitelist) ?> personne(s) en
                                <em>whitelist</em></strong></small>
                    </div>
                    <input type="hidden" name="action" value="disabled-whitelist"/>
                    <button type="submit" class="btn btn-danger">
@@ -22,30 +24,53 @@
                <hr>
                <section>

                    <?php if(count($whitelist) == 0):?>
                    <?php
                    if (count($whitelist) == 0): ?>
                        <div class="alert alert-warning">
                            Aucun déclarant
                        </div>
                    <?php else: ?>
                        <?php foreach ($whitelist as $exception): ?>
                        <article class="card xs">
                            <h3 class="card-title"><?= $exception->getPerson() ?></h3>
                        </article>
                        <?php endforeach; ?>
                    <?php endif; ?>
                    <?php
                    else: ?>
                        <?php
                        foreach ($whitelist as $exception): ?>
                            <div class="card">
                                <h3 class="card-title">
                                    <div>
                                        <?= $exception->getPerson() ?> <small>(<?= $exception->getPerson(
                                            )->getLdapAffectation() ?>)</small><br>
                                        <small><?= $exception->getPerson()->getEmail() ?></small>
                                    </div>
                                    <form action="" method="post" class="form-inline right">
                                        <input type="hidden" name="action" value="remove-from-whitelist"/>
                                        <input type="hidden" name="personid"
                                               value="<?= $exception->getPerson()->getId() ?>"/>
                                        <button type="submit" class="btn btn-danger btn-sm">
                                            <i class="icon-minus-circled"></i>
                                            Retirer
                                        </button>
                                    </form>
                                </h3>
                            </div>
                        <?php
                        endforeach; ?>
                    <?php
                    endif; ?>
                </section>

                <form action="" method="post">
                    <input type="hidden" name="action" value="add-to-whitelist"/>

                    <select name="persons[]" multiple="multiple" data-url="<?= $this->url('person/search') ?>" class="select2"></select>
                    <select name="persons[]" multiple="multiple" data-url="<?= $this->url('person/search') ?>"
                            class="select2"></select>
                    <button type="submit" class="btn btn-success">
                        <i class="icon-plus-circled"></i>
                        Ajouter à la liste blanche</button>
                        Ajouter à la liste blanche
                    </button>

                </form>

            <?php else: ?>
            <?php
            else: ?>
                <form action="" method="post">
                    <div class="alert alert-success">
                        <div><em>Whitelist</em> : <strong>INACTIVE</strong></div>
@@ -59,22 +84,49 @@

                    </button>
                </form>
            <?php endif; ?>
            <?php
            endif; ?>
        </div>
        <div class="col-md-6">
            <h2>Liste noire</h2>
            <div class="alert alert-danger">
                Les personnes listées ci-dessous ne seront jamais notifiées par email dans le cadre des déclarations de temps.
                Les personnes listées ci-dessous ne seront jamais notifiées par email dans le cadre des déclarations de
                temps.
            </div>

            <?php
            foreach ($blacklist as $exception): ?>
                <article class="card xs">
                    <h3 class="card-title">
                        <div>
                            <?= $exception->getPerson() ?> <small>(<?= $exception->getPerson()->getLdapAffectation() ?>
                                )</small><br>
                            <small><?= $exception->getPerson()->getEmail() ?></small>
                        </div>
                        <form action="" method="post" class="form-inline right">
                            <input type="hidden" name="action" value="remove-from-blacklist"/>
                            <input type="hidden" name="personid" value="<?= $exception->getPerson()->getId() ?>"/>
                            <button type="submit" class="btn btn-danger btn-sm">
                                <i class="icon-minus-circled"></i>
                                Retirer
                            </button>
                        </form>
                    </h3>
                </article>
            <?php
            endforeach; ?>


            <form action="" method="post">
                <input type="hidden" name="action" value="add-to-blacklist"/>


                <select name="persons[]" multiple="multiple" data-url="<?= $this->url('person/search') ?>" class="select2"></select>
                <select id="blacklisted" name="persons[]" multiple="multiple"
                        data-url="<?= $this->url('person/search') ?>" class="select2"></select>
                <button type="submit" class="btn btn-danger">
                    <i class="icon-plus-circled"></i>
                    Ajouter à la liste noire</button>
                    Ajouter à la liste noire
                </button>

            </form>

@@ -87,6 +139,7 @@
    .select2-close-mask {
        z-index: 2099;
    }

    .select2-dropdown {
        z-index: 3051;
    }
@@ -122,7 +175,8 @@

        Initer.ready(function () {
            require(['select2'], function () {
                $.fn.modal.Constructor.prototype.enforceFocus = function() {};
                $.fn.modal.Constructor.prototype.enforceFocus = function () {
                };

                if ($('.select2').length === 0) {
                    return;