Repository: TabbyML/tabby
File: ee/tabby-schema/src/schema/mod.rs (Rust)

Code before:
    async fn set_thread_persisted(ctx: &Context, thread_id: ID) -> Result<bool> {
        let user = check_user(ctx).await?;
        let svc = ctx.locator.thread();
        let Some(thread) = svc.get(&thread_id).await? else {
            return Err(CoreError::NotFound("Thread not found"));
        };

        user.policy
            .check_update_thread_persistence(&thread.user_id)?;

        ctx.locator.thread().set_persisted(&thread_id).await?;
        Ok(true)
    }

    async fn update_thread_message(
        ctx: &Context,
        message: thread::UpdateMessageRequest,
    ) -> Result<thread::Message> {
        let user = check_user(ctx).await?;
        let svc = ctx.locator.thread();
        let Some(thread) = svc.get(&message.thread_id).await? else {
            return Err(CoreError::NotFound("Thread not found"));
        };

        user.policy
            .check_update_thread_persistence(&thread.user_id)?;

        let messages = svc
            .list_thread_messages(&message.thread_id, None, None, None, None)
            .await?;

        messages
            .iter()
            .peekable()
            .find(|m| m.id == message.id)
            .cloned()
            .ok_or_else(|| CoreError::NotFound("Message not found"))
    }

    async fn create_custom_document(ctx: &Context, input: CreateCustomDocumentInput) -> Result<ID> {
        check_admin(ctx).await?;
        input.validate()?;
        let id = ctx
            .locator
            .web_documents()
            .create_custom_web_document(input.name, input.url)
            .await?;
        Ok(id)
    }

    async fn delete_custom_document(ctx: &Context, id: ID) -> Result<bool> {

Review comment (suggestion):
create a new policy for this, e.g `check_update_thread_message`

Code after:
    async fn set_thread_persisted(ctx: &Context, thread_id: ID) -> Result<bool> {
        let user = check_user(ctx).await?;
        let svc = ctx.locator.thread();
        let Some(thread) = svc.get(&thread_id).await? else {
            return Err(CoreError::NotFound("Thread not found"));
        };

        user.policy
            .check_update_thread_persistence(&thread.user_id)?;

        ctx.locator.thread().set_persisted(&thread_id).await?;
        Ok(true)
    }

    async fn update_thread_message(
        ctx: &Context,
        input: thread::UpdateMessageInput,
    ) -> Result<bool> {
        let user = check_user(ctx).await?;
        let svc = ctx.locator.thread();
        let Some(thread) = svc.get(&input.thread_id).await? else {
            return Err(CoreError::NotFound("Thread not found"));
        };

        user.policy.check_update_thread_message(&thread.user_id)?;

        svc.update_thread_message(&input).await?;
        Ok(true)
    }

    async fn create_custom_document(ctx: &Context, input: CreateCustomDocumentInput) -> Result<ID> {
        check_admin(ctx).await?;
        input.validate()?;
        let id = ctx
            .locator
            .web_documents()
            .create_custom_web_document(input.name, input.url)
            .await?;
        Ok(id)
    }

    async fn delete_custom_document(ctx: &Context, id: ID) -> Result<bool> {
        check_admin(ctx).await?;
        ctx.locator
            .web_documents()
            .delete_custom_web_document(id)
            .await?;
        Ok(true)
    }

    async fn set_preset_document_active(