mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-16 11:46:33 +08:00
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.
14 lines
513 B
Ruby
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
|