FIX: 500 error when reviewable has a missing message (#397)
This commit is contained in:
parent
1a5985134a
commit
d9c052f8e7
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
<div class="flagged-post-header">
|
||||
<LinkTo
|
||||
@route="chat.channel.near-message"
|
||||
@models={{array
|
||||
this.chatChannel.slugifiedTitle
|
||||
this.chatChannel.id
|
||||
@reviewable.target_id
|
||||
}}
|
||||
>
|
||||
<ChatChannelTitle @channel={{this.chatChannel}} />
|
||||
</LinkTo>
|
||||
</div>
|
||||
{{#if this.chatChannel}}
|
||||
<div class="flagged-post-header">
|
||||
<LinkTo
|
||||
@route="chat.channel.near-message"
|
||||
@models={{array
|
||||
this.chatChannel.slugifiedTitle
|
||||
this.chatChannel.id
|
||||
@reviewable.target_id
|
||||
}}
|
||||
>
|
||||
<ChatChannelTitle @channel={{this.chatChannel}} />
|
||||
</LinkTo>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<div class="post-contents-wrapper">
|
||||
<ReviewableCreatedBy @user={{@reviewable.target_created_by}} @tagName="" />
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue