Ver Fonte

feat: sélection des hooks système pour les jobs ynh_system

Permet de choisir quels hooks YunoHost inclure dans la sauvegarde système
(ex: exclure data_home et data_mail pour alléger l'archive).
Rétrocompatible : les jobs existants sans config de hooks sauvegardent tout.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cedric Hansen há 1 mês atrás
pai
commit
7c9b709fec
3 ficheiros alterados com 40 adições e 8 exclusões
  1. 10 1
      sources/blueprints/jobs.py
  2. 4 2
      sources/jobs/ynh_backup.py
  3. 26 5
      sources/templates/job_form.html

+ 10 - 1
sources/blueprints/jobs.py

@@ -349,7 +349,16 @@ def _save_job(job):
     if job_type == "ynh_app":
         cfg = {"app_id": f.get("app_id", ""), "core_only": f.get("core_only") == "1"}
     elif job_type == "ynh_system":
-        cfg = {}
+        selected = f.getlist("system_hooks")
+        all_hooks = {"conf_ynh_settings", "conf_ynh_firewall", "conf_ssowat", "conf_nginx",
+                     "conf_ynh_certs", "conf_ynh_domain", "conf_ynh_user", "data_home", "data_mail"}
+        if not selected:
+            flash("Sélectionnez au moins un hook système.", "error")
+            return render_template("job_form.html", job=job,
+                                   ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job.id if job else None)),
+                                   destinations=Destination.query.filter_by(enabled=True).all(),
+                                   remote_instances=RemoteInstance.query.order_by(RemoteInstance.name).all())
+        cfg = {"hooks": [] if set(selected) >= all_hooks else sorted(selected)}
     elif job_type in ("mysql", "postgresql"):
         dbname = f.get("db_database", "").strip()
         if not dbname:

+ 4 - 2
sources/jobs/ynh_backup.py

@@ -116,9 +116,11 @@ def _run_ynh_app(job, instance, backup_dir):
 
 
 def _run_ynh_system(job, instance, backup_dir):
-    archive = _archive_name(instance, "system", backup_dir)
+    cfg = json.loads(job.config_json or "{}")
+    hooks = cfg.get("hooks", [])
 
-    cmd = ["sudo", "yunohost", "backup", "create", "--system", "--name", archive]
+    archive = _archive_name(instance, "system", backup_dir)
+    cmd = ["sudo", "yunohost", "backup", "create", "--system"] + hooks + ["--name", archive]
     result = subprocess.run(cmd, capture_output=True, text=True, timeout=3600)
     log = (result.stdout + result.stderr).strip()
 

+ 26 - 5
sources/templates/job_form.html

@@ -68,12 +68,33 @@
         </div>
       </div>
 
-      {# Type-specific config : ynh_system (rien de spécifique) #}
-      <div id="cfg-ynh_system" class="type-cfg hidden">
-        <p class="text-sm text-gray-500 bg-gray-50 rounded-lg p-3">
-          Sauvegarde la configuration système YunoHost complète.
-          Aucun paramètre supplémentaire.
+      {# Type-specific config : ynh_system — sélection des hooks #}
+      {% set _sys_hooks = [
+        ('conf_ynh_settings', 'Paramètres YunoHost', false),
+        ('conf_ynh_firewall',  'Firewall',            false),
+        ('conf_ssowat',        'Portail SSO',         false),
+        ('conf_nginx',         'Nginx',               false),
+        ('conf_ynh_certs',     'Certificats SSL',     false),
+        ('conf_ynh_domain',    'Domaines',            false),
+        ('conf_ynh_user',      'Utilisateurs LDAP',   false),
+        ('data_home',          'Répertoires home /home/*', true),
+        ('data_mail',          'Courriers Dovecot',   true),
+      ] %}
+      {% set _saved_hooks = (job.config_json | fromjson).get('hooks', []) if job and job.config_json and job.type == 'ynh_system' else [] %}
+      <div id="cfg-ynh_system" class="type-cfg hidden space-y-2">
+        <p class="text-xs text-gray-500 mb-2">
+          Tous cochés = sauvegarde complète. Décochez les hooks volumineux pour alléger l'archive.
         </p>
+        {% for hook_id, hook_label, heavy in _sys_hooks %}
+          <div class="flex items-center gap-2">
+            <input type="checkbox" name="system_hooks" value="{{ hook_id }}" id="hook_{{ hook_id }}"
+                   {% if not _saved_hooks or hook_id in _saved_hooks %}checked{% endif %}
+                   class="rounded border-gray-300 text-blue-600">
+            <label for="hook_{{ hook_id }}" class="text-sm text-gray-700">
+              {{ hook_label }}{% if heavy %} <span class="text-xs text-amber-600 font-medium">(volumineux)</span>{% endif %}
+            </label>
+          </div>
+        {% endfor %}
       </div>
 
       {# Type-specific config : mysql #}