requete.html 157 lignes · 13283 octets
{% extends "layouts/assistant.html" %}
{% import "components/bouton.html" as b %}
{% import "aide/champ.html" as ch %}

{% block title %}Constructeur de requêtes LDAP{% endblock %}

{% block largeur %}max-w-page{% endblock %}

{% block content %}
{# E-024 Constructeur de requêtes LDAP (outil de formation, D-048) #}
{% let onglet = "constructeur" %}{% include "aide/onglets.html" %}
<h1 class="mt-xl text-2xl text-foreground">Constructeur de requêtes LDAP</h1>
<p class="mt-xs text-sm text-muted-foreground">Composez un filtre condition par condition : l'aide écrit le filtre RFC 4515, la commande <code class="font-mono">ldapsearch</code> à lancer vous-même, son équivalent PowerShell pour Active Directory, et explique chaque condition.</p>
{# E024-C1 Bandeau « outil de formation » #}
<p class="mt-md border-l-4 border-l-info bg-info-bg p-md text-sm text-foreground" role="note">Outil de formation : rien n'est exécuté sur votre annuaire. Copiez la commande et lancez-la vous-même.</p>
{# E024-C11 Recette chargée #}
{% if let Some((id, titre)) = recette %}
<p class="mt-md"><a href="/aide/ldap/recettes/{{ id }}" class="inline-flex items-center gap-xxs rounded-full bg-muted px-xs py-xxs text-badge text-ink-secondary underline-offset-4 hover:underline"><span aria-hidden="true">○</span>Recette : {{ titre }}</a></p>
{% endif %}

<div class="mt-xl grid gap-xl lg:grid-cols-5" x-data="constructeurLdap" data-arbre="{{ arbre_json }}" data-catalogue="{{ catalogue_json }}"
     data-avance="{{ avance }}" x-on:htmx:after-swap="apresReponse">
  <div class="flex min-w-0 flex-col gap-xl lg:col-span-3">
    <form id="form-requete" x-ref="formulaire" action="/aide/ldap/requete" method="get" novalidate class="flex flex-col gap-xl"
          hx-get="/aide/ldap/requete/resultat" hx-trigger="submit, arbre-modifie delay:400ms" hx-target="#sorties" hx-swap="innerHTML"
          hx-sync="this:replace">
      <input type="hidden" name="arbre" x-ref="arbre" value="{{ arbre_json }}">

      {# E024-C2 Contexte de recherche : replié sur mobile, ouvert par Alpine à partir de la tablette #}
      <details x-ref="contexte" class="rounded-sm bg-muted p-md">
        <summary class="cursor-pointer text-base text-foreground">Contexte de la recherche</summary>
        <p class="mt-xs text-xs text-muted-foreground"><span class="text-error-ink" aria-hidden="true">*</span> obligatoire</p>
        <div class="mt-md grid gap-md md:grid-cols-2">
          {% call ch::champ("serveur", "Serveur", saisie.serveur(), "ldaps:// recommandé : l'annuaire Open IAM exige TLS pour une liaison simple.", self.erreur("serveur"), true) %}{% endcall %}
          {% call ch::champ("base", "Base de recherche", saisie.base(), "DN d'où part la recherche : ou=users, ou=groups ou ou=applications sous la base de l'annuaire.", self.erreur("base"), true) %}{% endcall %}
          {% call ch::champ("compte", "Compte de liaison", saisie.compte(), "DN du compte qui se connecte ; son mot de passe est demandé au lancement (-W).", self.erreur("compte"), false) %}{% endcall %}
          {% call ch::champ("attributs", "Attributs retournés", saisie.attributs(), "Noms séparés par des espaces ; * pour tous les attributs utilisateur, + pour les opérationnels.", self.erreur("attributs"), false) %}{% endcall %}
          <fieldset class="flex flex-col gap-xs md:col-span-2">
            <legend class="text-sm text-foreground">Portée</legend>
            <div class="flex flex-wrap gap-x-lg gap-y-xs">
              <label class="flex items-center gap-xs text-sm text-foreground"><input type="radio" name="portee" value="base" x-on:input="modifier" class="size-4 accent-primary"{% if saisie.portee() == "base" %} checked{% endif %}> L'entrée de base seule (base)</label>
              <label class="flex items-center gap-xs text-sm text-foreground"><input type="radio" name="portee" value="one" x-on:input="modifier" class="size-4 accent-primary"{% if saisie.portee() == "one" %} checked{% endif %}> Un niveau sous la base (one)</label>
              <label class="flex items-center gap-xs text-sm text-foreground"><input type="radio" name="portee" value="sub" x-on:input="modifier" class="size-4 accent-primary"{% if saisie.portee() == "sub" %} checked{% endif %}> Tout le sous-arbre (sub)</label>
            </div>
          </fieldset>
        </div>
      </details>

      {# E024-C3 Groupes et E024-C4 conditions : arbre tenu par Alpine, aplati en lignes (en-tête, conditions, pied de chaque groupe) #}
      <fieldset class="flex min-w-0 flex-col gap-md">
        <legend class="text-lg text-foreground">Conditions</legend>
        <p class="-mt-xs text-xs text-muted-foreground"><span class="text-error-ink" aria-hidden="true">*</span> obligatoire</p>
        <div class="flex flex-wrap items-center justify-between gap-sm">
          <label class="flex items-center gap-xs text-sm text-foreground">
            <input type="checkbox" :checked="avance" x-on:input="basculerAvance" class="size-4 accent-primary"> Mode avancé : règle d'appariement
          </label>
          {# E024-C12 #}
          <button type="button" x-on:click="reinitialiser" class="{% call b::classes("outline") %}{% endcall %}">Réinitialiser</button>
        </div>
        <div class="flex flex-col gap-sm">
          <template x-for="ligne in lignes" :key="ligne.cle">
            <div :class="ligne.classes">
              <template x-if="ligne.debut">
                <fieldset class="flex flex-col gap-xs">
                  <legend class="text-sm text-foreground" x-text="ligne.titre"></legend>
                  <div class="flex flex-wrap items-center gap-x-lg gap-y-xs">
                    <label class="flex items-center gap-xs text-sm text-foreground">
                      <input type="radio" value="et" :id="ligne.idEt" :name="ligne.nomOperateur" :checked="ligne.estEt" :data-id="ligne.id" x-on:input="choisirOperateur" class="size-4 accent-primary"> Toutes (ET)
                    </label>
                    <label class="flex items-center gap-xs text-sm text-foreground">
                      <input type="radio" value="ou" :id="ligne.idOu" :name="ligne.nomOperateur" :checked="ligne.estOu" :data-id="ligne.id" x-on:input="choisirOperateur" class="size-4 accent-primary"> Au moins une (OU)
                    </label>
                    <label class="flex items-center gap-xs text-sm text-foreground">
                      <input type="checkbox" :checked="ligne.non" :data-id="ligne.id" x-on:input="inverser" class="size-4 accent-primary"> Inverser (NON)
                    </label>
                  </div>
                </fieldset>
              </template>
              <template x-if="ligne.condition">
                <div class="grid gap-xs md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] md:items-start">
                  <div class="flex min-w-0 flex-col gap-xxs">
                    <label :for="ligne.idAttribut" class="text-sm text-foreground"><span class="sr-only" x-text="ligne.prefixe"></span>Attribut <span class="text-error-ink" aria-hidden="true">*</span></label>
                    <input :id="ligne.idAttribut" list="attributs-ldap" aria-required="true" :value="ligne.attribut" :data-id="ligne.id" data-champ="attribut" x-on:input="saisir"
                           spellcheck="false" autocomplete="off" :aria-invalid="ligne.invalideAttribut" :aria-describedby="ligne.decritAttribut"
                           class="h-10 min-w-0 rounded-xs border border-input bg-background px-sm font-mono text-sm text-foreground aria-invalid:border-error">
                    <p :id="ligne.idErreurAttribut" x-show="ligne.erreurAttribut" x-text="ligne.erreurAttribut" class="text-sm text-error-ink"></p>
                    <p :id="ligne.idAide" x-text="ligne.aide" class="text-xs text-muted-foreground"></p>
                  </div>
                  <div class="flex min-w-0 flex-col gap-xxs">
                    <label :for="ligne.idOperateur" class="text-sm text-foreground"><span class="sr-only" x-text="ligne.prefixe"></span>Opérateur</label>
                    <select :id="ligne.idOperateur" :value="ligne.operateur" :data-id="ligne.id" data-champ="operateur" x-on:input="saisir"
                            class="h-10 min-w-0 rounded-xs border border-input bg-background px-sm text-sm text-foreground">
                      {% for o in self.operateurs() %}<option value="{{ o.code }}"{% if o.code == "regle" %} :hidden="ligne.regleMasquee" :disabled="ligne.regleMasquee"{% endif %}>{{ o.libelle }}</option>{% endfor %}
                    </select>
                    <div x-show="ligne.avecRegle" class="flex flex-col gap-xxs">
                      <label :for="ligne.idRegle" class="text-sm text-foreground"><span class="sr-only" x-text="ligne.prefixe"></span>Règle d'appariement</label>
                      <input :id="ligne.idRegle" :value="ligne.regle" :data-id="ligne.id" data-champ="regle" x-on:input="saisir" list="regles-ldap"
                             spellcheck="false" autocomplete="off" :aria-invalid="ligne.invalideRegle" :aria-describedby="ligne.decritRegle"
                             class="h-10 min-w-0 rounded-xs border border-input bg-background px-sm font-mono text-sm text-foreground aria-invalid:border-error">
                      <p :id="ligne.idErreurRegle" x-show="ligne.erreurRegle" x-text="ligne.erreurRegle" class="text-sm text-error-ink"></p>
                    </div>
                  </div>
                  <div x-show="ligne.avecValeur" class="flex min-w-0 flex-col gap-xxs">
                    <label :for="ligne.idValeur" class="text-sm text-foreground"><span class="sr-only" x-text="ligne.prefixe"></span><span x-text="ligne.libelleValeur"></span></label>
                    <input :id="ligne.idValeur" :value="ligne.valeur" :data-id="ligne.id" data-champ="valeur" x-on:input="saisir" :inputmode="ligne.modeSaisie"
                           spellcheck="false" autocomplete="off" :aria-invalid="ligne.invalideValeur" :aria-describedby="ligne.decritValeur"
                           class="h-10 min-w-0 rounded-xs border border-input bg-background px-sm font-mono text-sm text-foreground aria-invalid:border-error">
                    <p :id="ligne.idErreurValeur" x-show="ligne.erreurValeur" x-text="ligne.erreurValeur" class="text-sm text-error-ink"></p>
                    <p :id="ligne.idAideValeur" x-text="ligne.aideValeur" class="text-xs text-muted-foreground"></p>
                  </div>
                  <button type="button" :data-id="ligne.id" x-on:click="supprimer" :aria-label="ligne.libelleSupprimer"
                          class="{% call b::classes("icone") %}{% endcall %} md:mt-xl"><span aria-hidden="true">✕</span></button>
                </div>
              </template>
              <template x-if="ligne.fin">
                <div class="flex flex-wrap items-center gap-xs">
                  <p x-show="ligne.vide" class="w-full text-sm text-muted-foreground">Ce groupe est vide.</p>
                  <button type="button" :id="ligne.idAjouter" :data-id="ligne.id" x-on:click="ajouterCondition" class="{% call b::classes("outline") %}{% endcall %}">
                    <span aria-hidden="true">+</span> Ajouter une condition<span class="sr-only" x-text="ligne.suffixe"></span>
                  </button>
                  <button type="button" x-show="ligne.peutImbriquer" :data-id="ligne.id" x-on:click="ajouterGroupe" class="{% call b::classes("outline") %}{% endcall %}">
                    <span aria-hidden="true">+</span> Ajouter un groupe<span class="sr-only" x-text="ligne.suffixe"></span>
                  </button>
                  <button type="button" x-show="ligne.supprimable" :data-id="ligne.id" x-on:click="supprimer" class="{% call b::classes("outline") %}{% endcall %}">
                    Supprimer le groupe<span class="sr-only" x-text="ligne.suffixeSupprimer"></span>
                  </button>
                </div>
              </template>
            </div>
          </template>
        </div>
      </fieldset>
    </form>

    <details id="coller-filtre" class="rounded-sm bg-muted p-md"{% if coller_ouvert %} open{% endif %}>
      <summary class="cursor-pointer text-base text-foreground">Coller ou saisir un filtre</summary>
      {{ form_filtre|safe }}
    </details>
  </div>

  <section class="min-w-0 lg:col-span-2" aria-labelledby="titre-resultat">
    <div class="flex flex-col gap-md lg:sticky lg:top-md">
      <h2 id="titre-resultat" class="text-lg text-foreground">Résultat</h2>
      <div id="erreurs-requete">{{ erreurs|safe }}</div>
      <div id="sorties" aria-live="polite" class="flex flex-col gap-md">{{ sorties|safe }}</div>
    </div>
  </section>
</div>

<datalist id="attributs-ldap">{% for a in attributs %}<option value="{{ a.nom }}">{{ a.libelle }}</option>{% endfor %}</datalist>
<datalist id="regles-ldap">
  <option value="1.2.840.113556.1.4.803">ET bit à bit (Active Directory)</option>
  <option value="1.2.840.113556.1.4.804">OU bit à bit (Active Directory)</option>
  <option value="1.2.840.113556.1.4.1941">Dans la chaîne : groupes imbriqués (Active Directory)</option>
  <option value="caseExactMatch">Égalité sensible à la casse</option>
</datalist>
{% endblock %}