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

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

View File

@ -40,7 +40,8 @@ module Chat
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(

View File

@ -15,7 +15,7 @@ module Chat
end
def chat_channel
object.chat_message.chat_channel
object.chat_message&.chat_channel
end
def target_id

View File

@ -17,22 +17,27 @@ export default class ReviewableChatMessage extends Component {
@cached
get channel() {
if (!this.args.reviewable.chat_channel) {
return;
}
return ChatChannel.create(this.args.reviewable.chat_channel);
}
<template>
<div class="flagged-post-header">
<LinkTo
@route="chat.channel.near-message"
@models={{array
this.channel.slugifiedTitle
this.channel.id
@reviewable.target_id
}}
>
<ChannelTitle @channel={{this.channel}} />
</LinkTo>
</div>
{{#if this.channel}}
<div class="flagged-post-header">
<LinkTo
@route="chat.channel.near-message"
@models={{array
this.channel.slugifiedTitle
this.channel.id
@reviewable.target_id
}}
>
<ChannelTitle @channel={{this.channel}} />
</LinkTo>
</div>
{{/if}}
<div class="post-contents-wrapper">
<ReviewableCreatedBy

View File

@ -24,4 +24,20 @@ describe "Reviewables", type: :system do
expect(page).to have_content(message_1.message)
end
end
context "when the message is hard deleted" do
before { message_1.destroy! }
it "does not throw an error" do
visit("/review?type=Chat%3A%3AReviewableMessage")
expect(page).to have_selector(".reviewable-item.reviewable-chat-message")
end
it "adds the option to ignore the flag" do
visit("/review?type=Chat%3A%3AReviewableMessage")
expect(page).to have_selector(".reviewable-actions .chat-message-ignore")
end
end
end