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)
|
def build_actions(actions, guardian, args)
|
||||||
return unless pending?
|
return unless pending?
|
||||||
return if chat_message.blank?
|
|
||||||
|
return build_action(actions, :ignore, icon: "external-link-alt") if chat_message.blank?
|
||||||
|
|
||||||
agree =
|
agree =
|
||||||
actions.add_bundle("#{id}-agree", icon: "thumbs-up", label: "reviewables.actions.agree.title")
|
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
|
has_one :chat_channel, serializer: AiChatChannelSerializer, root: false, embed: :objects
|
||||||
|
|
||||||
def chat_channel
|
def chat_channel
|
||||||
object.chat_message.chat_channel
|
object.chat_message&.chat_channel
|
||||||
end
|
end
|
||||||
|
|
||||||
def target_id
|
def target_id
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
<div class="flagged-post-header">
|
{{#if this.chatChannel}}
|
||||||
<LinkTo
|
<div class="flagged-post-header">
|
||||||
@route="chat.channel.near-message"
|
<LinkTo
|
||||||
@models={{array
|
@route="chat.channel.near-message"
|
||||||
this.chatChannel.slugifiedTitle
|
@models={{array
|
||||||
this.chatChannel.id
|
this.chatChannel.slugifiedTitle
|
||||||
@reviewable.target_id
|
this.chatChannel.id
|
||||||
}}
|
@reviewable.target_id
|
||||||
>
|
}}
|
||||||
<ChatChannelTitle @channel={{this.chatChannel}} />
|
>
|
||||||
</LinkTo>
|
<ChatChannelTitle @channel={{this.chatChannel}} />
|
||||||
</div>
|
</LinkTo>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<div class="post-contents-wrapper">
|
<div class="post-contents-wrapper">
|
||||||
<ReviewableCreatedBy @user={{@reviewable.target_created_by}} @tagName="" />
|
<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 {
|
export default class ReviewableAiChatMessage extends Component {
|
||||||
get chatChannel() {
|
get chatChannel() {
|
||||||
|
if (!this.args.reviewable.chat_channel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
return ChatChannel.create(this.args.reviewable.chat_channel);
|
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")
|
expect(page).to have_selector(".reviewable-ai-chat-message .reviewable-actions")
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue