From 1952a139aee364766fd3ab0242c94624796b1822 Mon Sep 17 00:00:00 2001 From: thibaud-lclr Date: Wed, 15 Apr 2026 17:33:20 +0200 Subject: [PATCH] feat: gate live and task actions when modules are disabled --- src-tauri/src/commands/task.rs | 15 +++++++++++ src/components/projects/ProjectLiveAgent.tsx | 27 +++++++++++++++++--- src/components/projects/ProjectTasks.tsx | 26 ++++++++++++++++--- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/commands/task.rs b/src-tauri/src/commands/task.rs index c016013..e7ea954 100644 --- a/src-tauri/src/commands/task.rs +++ b/src-tauri/src/commands/task.rs @@ -1,6 +1,7 @@ use crate::error::AppError; use crate::models::agent::Agent; use crate::models::agent_task::AgentTask; +use crate::models::module::{ProjectModule, MODULE_AGENT_TASK_RUNNER}; use crate::models::project::Project; use crate::AppState; use tauri::State; @@ -24,6 +25,13 @@ pub fn create_agent_task( .lock() .map_err(|e| AppError::from(format!("Database lock failed: {}", e)))?; + let enabled = ProjectModule::is_enabled(&db, &project_id, MODULE_AGENT_TASK_RUNNER)?; + if !enabled { + return Err(AppError::from( + "Le module Agent task runner est désactivé pour ce projet".to_string(), + )); + } + Project::get_by_id(&db, &project_id)?; Agent::get_by_id(&db, &agent_id)?; @@ -59,6 +67,13 @@ pub fn retry_agent_task(state: State<'_, AppState>, task_id: String) -> Result<( .map_err(|e| AppError::from(format!("Database lock failed: {}", e)))?; let task = AgentTask::get_by_id(&db, &task_id)?; + let enabled = ProjectModule::is_enabled(&db, &task.project_id, MODULE_AGENT_TASK_RUNNER)?; + if !enabled { + return Err(AppError::from( + "Le module Agent task runner est désactivé pour ce projet".to_string(), + )); + } + if task.status != "error" && task.status != "cancelled" && task.status != "done" { return Err(AppError::from(format!( "Impossible de relancer une tâche avec le statut '{}'", diff --git a/src/components/projects/ProjectLiveAgent.tsx b/src/components/projects/ProjectLiveAgent.tsx index 07e3780..9f83bc6 100644 --- a/src/components/projects/ProjectLiveAgent.tsx +++ b/src/components/projects/ProjectLiveAgent.tsx @@ -5,6 +5,7 @@ import { createLiveSession, listAgents, listLiveMessages, + listProjectModules, listLiveSessions, sendLiveMessage, } from "../../lib/api"; @@ -28,6 +29,7 @@ export default function ProjectLiveAgent() { const [draft, setDraft] = useState(""); const [sending, setSending] = useState(false); const [creatingSession, setCreatingSession] = useState(false); + const [moduleEnabled, setModuleEnabled] = useState(true); const [error, setError] = useState(null); const usableAgents = useMemo( @@ -68,8 +70,14 @@ export default function ProjectLiveAgent() { setError(null); try { - const [availableAgents] = await Promise.all([listAgents()]); + const [availableAgents, modules] = await Promise.all([ + listAgents(), + listProjectModules(projectId), + ]); setAgents(availableAgents); + setModuleEnabled( + modules.find((mod) => mod.module_key === "ai_live_chat")?.enabled ?? true + ); const firstAgentId = availableAgents[0]?.id ?? ""; setSelectedAgentId((current) => current || firstAgentId); @@ -113,6 +121,10 @@ export default function ProjectLiveAgent() { async function handleCreateSession(event: FormEvent) { event.preventDefault(); if (!projectId || !selectedAgentId) return; + if (!moduleEnabled) { + setError("Le module Live chat agent est désactivé pour ce projet."); + return; + } setCreatingSession(true); setError(null); @@ -130,6 +142,10 @@ export default function ProjectLiveAgent() { async function handleSendMessage(event: FormEvent) { event.preventDefault(); if (!selectedSessionId || !draft.trim()) return; + if (!moduleEnabled) { + setError("Le module Live chat agent est désactivé pour ce projet."); + return; + } const content = draft.trim(); setDraft(""); @@ -172,6 +188,11 @@ export default function ProjectLiveAgent() { {error} )} + {!moduleEnabled && ( +
+ Le module est désactivé. La lecture reste possible, mais la création de session et l'envoi de message sont bloqués. +
+ )}

Nouvelle session

@@ -196,7 +217,7 @@ export default function ProjectLiveAgent() { />