From 5cdd13073a6255e0e67a5dae3b6b7958f66ac9d2 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Sat, 9 Nov 2024 06:18:10 +0800 Subject: [PATCH] fix(webserver): forbid empty content message update (#3390) --- ee/tabby-schema/src/schema/mod.rs | 2 ++ ee/tabby-schema/src/schema/thread/types.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ee/tabby-schema/src/schema/mod.rs b/ee/tabby-schema/src/schema/mod.rs index 623973384db5..07113202962c 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -1183,6 +1183,8 @@ impl Mutation { input: thread::UpdateMessageInput, ) -> Result { let user = check_user(ctx).await?; + input.validate()?; + let svc = ctx.locator.thread(); let Some(thread) = svc.get(&input.thread_id).await? else { return Err(CoreError::NotFound("Thread not found")); diff --git a/ee/tabby-schema/src/schema/thread/types.rs b/ee/tabby-schema/src/schema/thread/types.rs index 53be7993a3f1..afcdb907d886 100644 --- a/ee/tabby-schema/src/schema/thread/types.rs +++ b/ee/tabby-schema/src/schema/thread/types.rs @@ -5,6 +5,7 @@ use tabby_common::api::{ code::{CodeSearchDocument, CodeSearchHit, CodeSearchScores}, doc::{DocSearchDocument, DocSearchHit}, }; +use validator::Validate; use crate::{juniper::relay::NodeType, Context}; @@ -44,11 +45,12 @@ impl NodeType for Message { } } -#[derive(GraphQLInputObject, Clone)] +#[derive(GraphQLInputObject, Clone, Validate)] #[graphql(context = Context)] pub struct UpdateMessageInput { pub id: ID, pub thread_id: ID, + #[validate(length(min = 1, code = "content", message = "content can not be empty"))] pub content: String, }