discourse-translator/lib/discourse_translator/guardian_extension.rb
Ted Johansson 17bd836196
FIX: Don't error out on deleted users (#149)
The GuardianExtension#poster_group_allow_translate? method restricts and determines whether a post can be translated based on the poster's group membership. There are reports that this errors out when deleting spammers.

The problem is that when a spammer is deleted, their post user_id is nullified, and because the above method doesn't account for this case, we try to call #in_any_groups? on nil, which errors out.

This PR fixes that by explicitly accounting for the case of a post with a nil user ID.
2024-06-18 09:56:35 +08:00

14 lines
513 B
Ruby

# frozen_string_literal: true
module DiscourseTranslator::GuardianExtension
def user_group_allow_translate?
return false if !current_user
current_user.in_any_groups?(SiteSetting.restrict_translation_by_group_map)
end
def poster_group_allow_translate?(post)
return false if !current_user
return true if SiteSetting.restrict_translation_by_poster_group_map.empty?
return false if post.user.nil?
post.user.in_any_groups?(SiteSetting.restrict_translation_by_poster_group_map)
end
end