A platform for community discussion. Free, open, simple.
FIX: Allow artifacts on posts via API (#37870)
Sam558389b5f0bb
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/ai_bot/artifacts_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/ai_bot/artifacts_controller.rbindex 1f680d2fe31..bd28435782c 100644--- a/plugins/discourse-ai/app/controllers/discourse_ai/ai_bot/artifacts_controller.rb+++ b/plugins/discourse-ai/app/controllers/discourse_ai/ai_bot/artifacts_controller.rb@@ -15,7 +15,6 @@ module DiscourseAiif artifact.public?# no guardian neededelse- raise Discourse::NotFound if !post&.topic&.private_message?raise Discourse::NotFound if !guardian.can_see?(post)enddiff --git a/plugins/discourse-ai/spec/requests/ai_bot/artifacts_controller_spec.rb b/plugins/discourse-ai/spec/requests/ai_bot/artifacts_controller_spec.rbindex ab7ca954dd3..1beb5729dd1 100644--- a/plugins/discourse-ai/spec/requests/ai_bot/artifacts_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/ai_bot/artifacts_controller_spec.rb@@ -70,6 +70,39 @@ RSpec.describe DiscourseAi::AiBot::ArtifactsController doendend+ context "with non-PM artifact" do+ fab!(:regular_topic) { Fabricate(:topic, user: user) }+ fab!(:regular_post) { Fabricate(:post, user: user, topic: regular_topic) }+ fab!(:regular_artifact) do+ AiArtifact.create!(+ user: user,+ post: regular_post,+ name: "Regular Topic Artifact",+ html: "<div>Regular</div>",+ css: "",+ js: "",+ metadata: {+ public: false,+ },+ )+ end++ it "shows artifact to user who can see the post" do+ sign_in(user)+ get "/discourse-ai/ai-bot/artifacts/#{regular_artifact.id}"+ expect(response.status).to eq(200)+ expect(parse_srcdoc(response.body)).to include(regular_artifact.html)+ end++ it "returns 404 when user cannot see the post" do+ other_user = Fabricate(:user)+ regular_topic.update!(category: Fabricate(:private_category, group: Fabricate(:group)))+ sign_in(other_user)+ get "/discourse-ai/ai-bot/artifacts/#{regular_artifact.id}"+ expect(response.status).to eq(404)+ end+ end+context "with public artifact" dobefore { artifact.update!(metadata: { public: true }) }