Skip to content

Commit

Permalink
fix(webserver): forbid empty content message update
Browse files Browse the repository at this point in the history
  • Loading branch information
zwpaper committed Nov 8, 2024
1 parent 8d2439d commit dd29aac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,8 @@ impl Mutation {
input: thread::UpdateMessageInput,
) -> Result<bool> {
let user = check_user(ctx).await?;
input.validate()?;

Check warning on line 1186 in ee/tabby-schema/src/schema/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/mod.rs#L1186

Added line #L1186 was not covered by tests

let svc = ctx.locator.thread();
let Some(thread) = svc.get(&input.thread_id).await? else {
return Err(CoreError::NotFound("Thread not found"));
Expand Down
4 changes: 3 additions & 1 deletion ee/tabby-schema/src/schema/thread/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use tabby_common::api::{
code::{CodeSearchDocument, CodeSearchHit, CodeSearchScores},
doc::{DocSearchDocument, DocSearchHit},
};
use validator::Validate;

use crate::{juniper::relay::NodeType, Context};

Expand Down Expand Up @@ -44,11 +45,12 @@ impl NodeType for Message {
}
}

#[derive(GraphQLInputObject, Clone)]
#[derive(GraphQLInputObject, Clone, Validate)]

Check warning on line 48 in ee/tabby-schema/src/schema/thread/types.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/thread/types.rs#L48

Added line #L48 was not covered by tests
#[graphql(context = Context)]
pub struct UpdateMessageInput {
pub id: ID,
pub thread_id: ID,
#[validate(length(min = 1, message = "content can not be empty"))]

Check failure on line 53 in ee/tabby-schema/src/schema/thread/types.rs

View workflow job for this annotation

GitHub Actions / ast-grep-lint

validate-requires-code

Validations requires code / message being set for frontend error display
pub content: String,
}

Expand Down

0 comments on commit dd29aac

Please sign in to comment.