From a65b282066505a4aa2483fbcbaca603eebff6fbc Mon Sep 17 00:00:00 2001 From: Henry Park Date: Fri, 27 Feb 2026 10:34:22 -0800 Subject: [PATCH] fix: web UI routines tab shows all routines regardless of creating channel (#391) Routines created via Telegram (or any WASM channel) were invisible in the web UI because the routines list endpoint filtered by GATEWAY_USER_ID, which didn't match the Telegram user's ID stored on the routine. Add list_all_routines() to the RoutineStore trait (both libSQL and PostgreSQL backends) and use it in the web dashboard handlers so all routines are visible regardless of which channel created them. Co-authored-by: Claude Opus 4.6 (1M context) --- src/channels/web/handlers/routines.rs | 4 ++-- src/channels/web/server.rs | 4 ++-- src/db/libsql/routines.rs | 21 +++++++++++++++++++++ src/db/mod.rs | 1 + src/db/postgres.rs | 4 ++++ src/history/store.rs | 9 +++++++++ 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/channels/web/handlers/routines.rs b/src/channels/web/handlers/routines.rs index be25681b..f23f3a94 100644 --- a/src/channels/web/handlers/routines.rs +++ b/src/channels/web/handlers/routines.rs @@ -23,7 +23,7 @@ pub async fn routines_list_handler( ))?; let routines = store - .list_routines(&state.user_id) + .list_all_routines() .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; @@ -41,7 +41,7 @@ pub async fn routines_summary_handler( ))?; let routines = store - .list_routines(&state.user_id) + .list_all_routines() .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; diff --git a/src/channels/web/server.rs b/src/channels/web/server.rs index 974aebba..f5bd9bfe 100644 --- a/src/channels/web/server.rs +++ b/src/channels/web/server.rs @@ -2146,7 +2146,7 @@ async fn routines_list_handler( ))?; let routines = store - .list_routines(&state.user_id) + .list_all_routines() .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; @@ -2164,7 +2164,7 @@ async fn routines_summary_handler( ))?; let routines = store - .list_routines(&state.user_id) + .list_all_routines() .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; diff --git a/src/db/libsql/routines.rs b/src/db/libsql/routines.rs index 3635dcb3..f85ba0e3 100644 --- a/src/db/libsql/routines.rs +++ b/src/db/libsql/routines.rs @@ -141,6 +141,27 @@ impl RoutineStore for LibSqlBackend { Ok(routines) } + async fn list_all_routines(&self) -> Result, DatabaseError> { + let conn = self.connect().await?; + let mut rows = conn + .query( + &format!("SELECT {} FROM routines ORDER BY name", ROUTINE_COLUMNS), + (), + ) + .await + .map_err(|e| DatabaseError::Query(e.to_string()))?; + + let mut routines = Vec::new(); + while let Some(row) = rows + .next() + .await + .map_err(|e| DatabaseError::Query(e.to_string()))? + { + routines.push(row_to_routine_libsql(&row)?); + } + Ok(routines) + } + async fn list_event_routines(&self) -> Result, DatabaseError> { let conn = self.connect().await?; let mut rows = conn diff --git a/src/db/mod.rs b/src/db/mod.rs index dcf80e02..1101a311 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -247,6 +247,7 @@ pub trait RoutineStore: Send + Sync { name: &str, ) -> Result, DatabaseError>; async fn list_routines(&self, user_id: &str) -> Result, DatabaseError>; + async fn list_all_routines(&self) -> Result, DatabaseError>; async fn list_event_routines(&self) -> Result, DatabaseError>; async fn list_due_cron_routines(&self) -> Result, DatabaseError>; async fn update_routine(&self, routine: &Routine) -> Result<(), DatabaseError>; diff --git a/src/db/postgres.rs b/src/db/postgres.rs index 49c66f5b..094b268f 100644 --- a/src/db/postgres.rs +++ b/src/db/postgres.rs @@ -373,6 +373,10 @@ impl RoutineStore for PgBackend { self.store.list_routines(user_id).await } + async fn list_all_routines(&self) -> Result, DatabaseError> { + self.store.list_all_routines().await + } + async fn list_event_routines(&self) -> Result, DatabaseError> { self.store.list_event_routines().await } diff --git a/src/history/store.rs b/src/history/store.rs index 8f7c41cb..7e2ff0f3 100644 --- a/src/history/store.rs +++ b/src/history/store.rs @@ -963,6 +963,15 @@ impl Store { rows.iter().map(row_to_routine).collect() } + /// List all routines across all users. + pub async fn list_all_routines(&self) -> Result, DatabaseError> { + let conn = self.conn().await?; + let rows = conn + .query("SELECT * FROM routines ORDER BY name", &[]) + .await?; + rows.iter().map(row_to_routine).collect() + } + /// List all enabled routines with event triggers (for event matching). pub async fn list_event_routines(&self) -> Result, DatabaseError> { let conn = self.conn().await?;