pass user info

This commit is contained in:
Sam Saffron 2025-06-09 13:21:10 +10:00
parent e0c9fe993d
commit a61f2fc04a
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5
3 changed files with 12 additions and 3 deletions

View File

@ -37,6 +37,11 @@ module DiscourseAi
).as_json,
has_more: has_more,
total_count: total_count,
users:
key_values
.map { |kv| kv.user }
.uniq
.map { |u| BasicUserSerializer.new(u, root: nil).as_json },
}
end

View File

@ -1,9 +1,7 @@
# frozen_string_literal: true
class AiArtifactKeyValueSerializer < ApplicationSerializer
attributes :id, :key, :value, :public, :created_at, :updated_at
has_one :user, serializer: BasicUserSerializer
attributes :id, :key, :value, :public, :user_id, :created_at, :updated_at
def include_value?
!options[:keys_only]

View File

@ -63,6 +63,12 @@ RSpec.describe DiscourseAi::AiBot::ArtifactKeyValuesController do
)
expect(json["has_more"]).to eq(false)
expect(json["total_count"]).to eq(2)
expect(json["key_values"].map { |kv| kv["user_id"] }).to contain_exactly(
user.id,
other_user.id,
)
expect(json["users"].map { |u| u["id"] }).to contain_exactly(user.id, other_user.id)
end
it "returns 404 for private artifact" do