discourse-akismet/jobs/scheduled/check_for_spam_users.rb
Juan David Martínez Cubillos 664cc3f828
FEATURE: Implement Akismet flag and review system for PostVotingComments (#112)
* FEATURE: Implement Akismet flag and review system for PostVotingComments

* polished bugs and completed reviewables implementation

* adding test plugin dependecies

* rubocop fix

* syntax tree fix

* deleted comments

* added requested changes

* linter fixes

* refactored #before_check in post voting bouncer
2024-01-11 16:04:57 -05:00

27 lines
826 B
Ruby

# frozen_string_literal: true
module Jobs
class CheckForSpamUsers < ::Jobs::Scheduled
every SiteSetting.spam_check_interval_mins.minutes
def execute(args)
return unless SiteSetting.akismet_enabled?
return if DiscourseAkismet::AntiSpamService.api_secret_blank?
bouncer = DiscourseAkismet::UsersBouncer.new
client = DiscourseAkismet::AntiSpamService.client
DiscourseAkismet::UsersBouncer
.to_check
.includes(:user_profile)
.find_each do |user|
DistributedMutex.synchronize("akismet_user_#{user.id}") do
if user.custom_fields[DiscourseAkismet::Bouncer::AKISMET_STATE] ==
DiscourseAkismet::Bouncer::PENDING_STATE
bouncer.perform_check(client, user)
end
end
end
end
end
end