fix: garde-fou edition base sur label projet au lieu de TYPES_SYSTEME fige
- _est_editable() dans trilium_api.py : editable si label projet ou type=projet - tool_update_note + delete_note_safe utilisent ce critere - tool_get_children : filtre TYPES_SYSTEME retire (transparence) Corrige : composants techniques editables, get_children ne les masque plus. Revele par le test Phase 3 (agent bloque sur edition de composant).
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"Forgejo": "ArTsdwSCqXod",
|
||||
"Docker": "fLQXL4Tyz7gg",
|
||||
"GrosseBertha": "PEll7MT00sL9"
|
||||
}
|
||||
+4
-12
@@ -460,30 +460,22 @@ def tool_get_note(note_id):
|
||||
"contenu": get_note_content(note_id)}
|
||||
|
||||
def tool_get_children(parent_id):
|
||||
from trilium_api import TYPES_SYSTEME
|
||||
out = []
|
||||
for child in get_children(parent_id):
|
||||
cid = child.get("noteId")
|
||||
n = get_note(cid)
|
||||
if not n:
|
||||
continue
|
||||
tv = _type_systeme(n)
|
||||
if tv in TYPES_SYSTEME:
|
||||
out.append({"id": cid, "titre": n.get("title", ""), "type": tv})
|
||||
out.append({"id": cid, "titre": n.get("title", ""), "type": _type_systeme(n)})
|
||||
return {"parent": parent_id, "count": len(out), "notes": out}
|
||||
|
||||
def tool_update_note(note_id, contenu, format="markdown"):
|
||||
from trilium_api import TYPES_SYSTEME
|
||||
from trilium_api import _est_editable
|
||||
note = get_note(note_id)
|
||||
if not note:
|
||||
return {"error": "Note introuvable"}
|
||||
type_val = None
|
||||
for a in note.get("attributes", []):
|
||||
if a.get("type") == "label" and a.get("name") == "type":
|
||||
type_val = a.get("value")
|
||||
break
|
||||
if type_val not in TYPES_SYSTEME:
|
||||
return {"error": "Refus : note sans type systeme connu (type=%s)" % type_val}
|
||||
if not _est_editable(note):
|
||||
return {"error": "Refus : note structurelle protegee (sans label projet)"}
|
||||
if format == "html":
|
||||
body = contenu
|
||||
else:
|
||||
|
||||
+14
-7
@@ -138,13 +138,8 @@ def delete_note_safe(note_id: str):
|
||||
note = get_note(note_id)
|
||||
if not note:
|
||||
return (False, "Note introuvable")
|
||||
type_val = None
|
||||
for a in note.get("attributes", []):
|
||||
if a.get("type") == "label" and a.get("name") == "type":
|
||||
type_val = a.get("value")
|
||||
break
|
||||
if type_val not in TYPES_SYSTEME:
|
||||
return (False, "Refus : note sans type systeme connu (type=%s)" % type_val)
|
||||
if not _est_editable(note):
|
||||
return (False, "Refus : note structurelle protegee (sans label projet)")
|
||||
titre = note.get("title", "?")
|
||||
ok = _ea().delete_note(note_id)
|
||||
if ok:
|
||||
@@ -214,3 +209,15 @@ def add_relation_safe(source_id, nom, cible_id):
|
||||
except Exception as e:
|
||||
return (False, "Echec creation relation: %s" % e)
|
||||
return (True, "Relation creee: %s ~%s %s" % (source_id, nom, cible_id))
|
||||
|
||||
|
||||
def _est_editable(note):
|
||||
"""Nouveau critere de garde-fou : une note est editable/supprimable si elle
|
||||
porte un label projet (note de projet, propriete du projet), ou si son type
|
||||
est 'projet' lui-meme. Sinon (ontologie, skills universels, dossiers
|
||||
structurels) elle est protegee par defaut. Remplace TYPES_SYSTEME (liste
|
||||
figee, desynchronisee de l ontologie a chaque nouvelle classe)."""
|
||||
labels = {a.get("name"): a.get("value") for a in note.get("attributes", []) if a.get("type") == "label"}
|
||||
if labels.get("type") == "projet":
|
||||
return True
|
||||
return bool(labels.get("projet"))
|
||||
|
||||
Reference in New Issue
Block a user