commit 9bc628a695d77f137af892deff5dcd99547a351d
parent ecd11e20284f89142f972d1bc56fa5baec352b16
Author: Silas Brack <silasbrack@gmail.com>
Date: Sat, 25 Apr 2026 15:10:37 +0200
fix: include user_id/created_by in create requests
TrailBase ACL rules require these fields to match _USER_.id.
Now passing client.user().sub for story, comment, and vote creation.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat:
1 file changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/trailbase.rs b/src/trailbase.rs
@@ -128,8 +128,29 @@ pub struct CreateStory {
pub language: String,
}
+#[derive(Debug, Serialize)]
+struct CreateStoryWithUser {
+ url: Option<String>,
+ title: String,
+ text: String,
+ domain: Option<String>,
+ published: String,
+ language: String,
+ created_by: String,
+}
+
pub async fn create_story(client: &Client, story: CreateStory) -> Result<Story, ClientError> {
- let id_str = client.records("story").create(&story).await?;
+ let user = client.user().ok_or_else(|| ClientError::Auth("Not authenticated".to_string()))?;
+ let story_with_user = CreateStoryWithUser {
+ url: story.url,
+ title: story.title,
+ text: story.text,
+ domain: story.domain,
+ published: story.published,
+ language: story.language,
+ created_by: user.sub,
+ };
+ let id_str = client.records("story").create(&story_with_user).await?;
let id: i64 = id_str.parse().unwrap_or(0);
get_story(client, id).await?.ok_or_else(|| {
ClientError::Auth("Failed to retrieve created story".to_string())
@@ -203,8 +224,27 @@ pub struct CreateComment {
pub text: String,
}
+#[derive(Debug, Serialize)]
+struct CreateCommentWithUser {
+ story_id: i64,
+ parent_id: Option<i64>,
+ path: String,
+ depth: i64,
+ text: String,
+ created_by: String,
+}
+
pub async fn create_comment(client: &Client, comment: CreateComment) -> Result<Comment, ClientError> {
- let id_str = client.records("comment").create(&comment).await?;
+ let user = client.user().ok_or_else(|| ClientError::Auth("Not authenticated".to_string()))?;
+ let comment_with_user = CreateCommentWithUser {
+ story_id: comment.story_id,
+ parent_id: comment.parent_id,
+ path: comment.path,
+ depth: comment.depth,
+ text: comment.text,
+ created_by: user.sub,
+ };
+ let id_str = client.records("comment").create(&comment_with_user).await?;
let id: i64 = id_str.parse().unwrap_or(0);
// Fetch the created comment