mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-18 11:59:35 +08:00
In the older implementation of translation, there exists these two site settings are part of the criteria that determines if 🌐 shows up per post * `restrict translation by group` - Only allowed groups can translate * `restrict translation by poster group` - Only allow translation of posts made by users in allowed groups. If empty, allow translations of posts from all users. In a recent update with experimental features, we updated the cases where 🌐 will show up and caused a regression where the 🌐 shows up for everyone in `restrict translation by group`, ignoring `restrict translation by poster group`. This commit makes sure these two site settings are adhered to when the experimental topic setting is turned off.
34 lines
1.1 KiB
Ruby
34 lines
1.1 KiB
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
|
|
|
|
def can_detect_language?(post)
|
|
(
|
|
SiteSetting.restrict_translation_by_poster_group_map.empty? ||
|
|
post&.user&.in_any_groups?(SiteSetting.restrict_translation_by_poster_group_map)
|
|
) && post.raw.present? && post.post_type != Post.types[:small_action]
|
|
end
|
|
|
|
def can_translate?(post)
|
|
return false if !user_group_allow_translate?
|
|
|
|
if SiteSetting.experimental_topic_translation
|
|
return false if post.locale_matches?(I18n.locale)
|
|
return false if post.translation_for(I18n.locale).present?
|
|
true
|
|
else
|
|
return false if post.locale_matches?(I18n.locale)
|
|
poster_group_allow_translate?(post)
|
|
end
|
|
end
|
|
end
|