Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 82d9079

Browse files
committed
lint
1 parent d655138 commit 82d9079

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

app/controllers/discourse_ai/ai_bot/artifacts_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ def show
5050

5151
def require_site_settings!
5252
if !SiteSetting.discourse_ai_enabled ||
53-
!SiteSetting.ai_artifact_security.in?(%w[lax strict])
53+
!SiteSetting.ai_artifact_security.in?(%w[lax strict])
5454
raise Discourse::NotFound
5555
end
5656
end
57-
5857
end
5958
end
6059
end

app/models/ai_artifact.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ def self.url(id)
1616

1717
def self.share_publicly(id:, post:)
1818
artifact = AiArtifact.find_by(id: id)
19-
if artifact&.post&.topic&.id == post.topic.id
20-
artifact.update!(metadata: { public: true })
21-
end
19+
artifact.update!(metadata: { public: true }) if artifact&.post&.topic&.id == post.topic.id
2220
end
2321

2422
def self.unshare_publicly(id:)

app/models/shared_ai_conversation.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,18 @@ def self.build_conversation_data(topic, max_posts: DEFAULT_MAX_POSTS, include_us
183183

184184
def self.cook_artifacts(post)
185185
html = post.cooked
186-
return html if !["lax", "strict"].include?(SiteSetting.ai_artifact_security)
186+
return html if !%w[lax strict].include?(SiteSetting.ai_artifact_security)
187187

188188
doc = Nokogiri::HTML5.fragment(html)
189-
doc.css("div.ai-artifact").each do |node|
190-
id = node["data-ai-artifact-id"].to_i
191-
if id > 0
192-
AiArtifact.share_publicly(id: id, post: post)
193-
node.replace(AiArtifact.iframe_for(id))
189+
doc
190+
.css("div.ai-artifact")
191+
.each do |node|
192+
id = node["data-ai-artifact-id"].to_i
193+
if id > 0
194+
AiArtifact.share_publicly(id: id, post: post)
195+
node.replace(AiArtifact.iframe_for(id))
196+
end
194197
end
195-
end
196198

197199
doc.to_s
198200
end

spec/requests/ai_bot/shared_ai_conversations_spec.rb

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,26 @@ def share_error(key)
8787
end
8888

8989
context "when ai artifacts are in lax mode" do
90-
before do
91-
SiteSetting.ai_artifact_security = "lax"
92-
end
90+
before { SiteSetting.ai_artifact_security = "lax" }
9391

9492
it "properly shares artifacts" do
9593
first_post = user_pm_share.posts.first
9694

97-
artifact_not_allowed = AiArtifact.create!(
98-
user: bot_user,
99-
post: Fabricate(:private_message_post),
100-
name: "test",
101-
html: "<div>test</div>",
102-
)
103-
104-
artifact = AiArtifact.create!(
105-
user: bot_user,
106-
post: first_post,
107-
name: "test",
108-
html: "<div>test</div>",
109-
)
95+
artifact_not_allowed =
96+
AiArtifact.create!(
97+
user: bot_user,
98+
post: Fabricate(:private_message_post),
99+
name: "test",
100+
html: "<div>test</div>",
101+
)
102+
103+
artifact =
104+
AiArtifact.create!(
105+
user: bot_user,
106+
post: first_post,
107+
name: "test",
108+
html: "<div>test</div>",
109+
)
110110

111111
# lets log out and see we can not access the artifacts
112112
delete "/session/#{user.id}"
@@ -134,7 +134,6 @@ def share_error(key)
134134
get "#{path}/#{key}"
135135
expect(response).to have_http_status(:success)
136136

137-
138137
expect(response.body).to include(artifact.url)
139138
expect(response.body).to include(artifact_not_allowed.url)
140139

0 commit comments

Comments
 (0)