FIX: 500 error when reviewable has a missing message (#397)

This commit is contained in:
Jan Cernik 2024-01-03 11:49:47 -03:00 committed by GitHub
parent 1a5985134a
commit d9c052f8e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 14 deletions

View File

@ -34,7 +34,8 @@ class ReviewableAiChatMessage < Reviewable
def build_actions(actions, guardian, args)
return unless pending?
return if chat_message.blank?
return build_action(actions, :ignore, icon: "external-link-alt") if chat_message.blank?
agree =
actions.add_bundle("#{id}-agree", icon: "thumbs-up", label: "reviewables.actions.agree.title")

View File

@ -10,7 +10,7 @@ class ReviewableAiChatMessageSerializer < ReviewableSerializer
has_one :chat_channel, serializer: AiChatChannelSerializer, root: false, embed: :objects
def chat_channel
object.chat_message.chat_channel
object.chat_message&.chat_channel
end
def target_id

View File

@ -1,4 +1,5 @@
<div class="flagged-post-header">
{{#if this.chatChannel}}
<div class="flagged-post-header">
<LinkTo
@route="chat.channel.near-message"
@models={{array
@ -9,7 +10,8 @@
>
<ChatChannelTitle @channel={{this.chatChannel}} />
</LinkTo>
</div>
</div>
{{/if}}
<div class="post-contents-wrapper">
<ReviewableCreatedBy @user={{@reviewable.target_created_by}} @tagName="" />

View File

@ -3,6 +3,9 @@ import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
export default class ReviewableAiChatMessage extends Component {
get chatChannel() {
if (!this.args.reviewable.chat_channel) {
return;
}
return ChatChannel.create(this.args.reviewable.chat_channel);
}
}

View File

@ -23,4 +23,20 @@ RSpec.describe "Toxicity-flagged chat messages", type: :system, js: true do
expect(page).to have_selector(".reviewable-ai-chat-message .reviewable-actions")
end
context "when the message is hard deleted" do
before { chat_message.destroy! }
it "does not throw an error" do
visit("/review")
expect(page).to have_selector(".reviewable-ai-chat-message .reviewable-actions")
end
it "adds the option to ignore the flag" do
visit("/review")
expect(page).to have_selector(".reviewable-actions .chat-message-ignore")
end
end
end