Skip to content

Commit c7b3148

Browse files
authored
FIX: Allow user to be deleted (#236)
There is a bug now where the post's user may not always be available, causing can_translate? to throw an error.
1 parent f6ea0b4 commit c7b3148

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/discourse_translator/guardian_extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def can_detect_language?(post)
2222
end
2323

2424
def can_translate?(post)
25-
return false if post.user.bot?
25+
return false if post.user&.bot?
2626
return false if !user_group_allow_translate?
2727
return false if post.locale_matches?(I18n.locale)
2828

spec/lib/guardian_extension_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,11 @@
244244
end
245245
end
246246
end
247+
248+
it "does not error out when post user is deleted" do
249+
post.update(user: nil)
250+
251+
expect { guardian.can_translate?(post) }.not_to raise_error
252+
end
247253
end
248254
end

0 commit comments

Comments
 (0)