mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 23:36:11 +08:00
FIX: Reintroduce auto_silence_first_post_regex (#12223)
Follow-up to 533800a87ba1e170be6620bff2f8b5f97713cefa.
This commit is contained in:
@ -54,6 +54,25 @@ class NewPostManager
|
||||
manager.user.trust_level <= SiteSetting.auto_silence_fast_typers_max_trust_level
|
||||
end
|
||||
|
||||
def self.matches_auto_silence_regex?(manager)
|
||||
args = manager.args
|
||||
|
||||
pattern = SiteSetting.auto_silence_first_post_regex
|
||||
|
||||
return false unless pattern.present?
|
||||
return false unless is_first_post?(manager)
|
||||
|
||||
begin
|
||||
regex = Regexp.new(pattern, Regexp::IGNORECASE)
|
||||
rescue => e
|
||||
Rails.logger.warn "Invalid regex in auto_silence_first_post_regex #{e}"
|
||||
return false
|
||||
end
|
||||
|
||||
"#{args[:title]} #{args[:raw]}" =~ regex
|
||||
|
||||
end
|
||||
|
||||
def self.exempt_user?(user)
|
||||
user.staff?
|
||||
end
|
||||
@ -83,6 +102,8 @@ class NewPostManager
|
||||
|
||||
return :fast_typer if is_fast_typer?(manager)
|
||||
|
||||
return :auto_silence_regex if matches_auto_silence_regex?(manager)
|
||||
|
||||
return :staged if SiteSetting.approve_unless_staged? && user.staged?
|
||||
|
||||
return :category if post_needs_approval_in_its_category?(manager)
|
||||
@ -147,6 +168,8 @@ class NewPostManager
|
||||
I18n.with_locale(SiteSetting.default_locale) do
|
||||
if is_fast_typer?(manager)
|
||||
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.new_user_typed_too_fast"))
|
||||
elsif matches_auto_silence_regex?(manager)
|
||||
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.content_matches_auto_silence_regex"))
|
||||
elsif reason == :email_spam && is_first_post?(manager)
|
||||
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.email_in_spam_header"))
|
||||
end
|
||||
|
Reference in New Issue
Block a user