2018-07-05 06:18:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-14 14:07:11 -05:00
|
|
|
# SpamCheckService
|
|
|
|
#
|
|
|
|
# Provide helper methods for checking if a given spammable object has
|
|
|
|
# potential spam data.
|
|
|
|
#
|
|
|
|
# Dependencies:
|
|
|
|
# - params with :request
|
|
|
|
#
|
|
|
|
module SpamCheckService
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-02-14 14:07:11 -05:00
|
|
|
def filter_spam_check_params
|
|
|
|
@request = params.delete(:request)
|
|
|
|
@api = params.delete(:api)
|
|
|
|
@recaptcha_verified = params.delete(:recaptcha_verified)
|
|
|
|
@spam_log_id = params.delete(:spam_log_id)
|
|
|
|
end
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2017-02-14 14:07:11 -05:00
|
|
|
|
2017-03-20 22:37:29 -04:00
|
|
|
# In order to be proceed to the spam check process, @spammable has to be
|
|
|
|
# a dirty instance, which means it should be already assigned with the new
|
|
|
|
# attribute values.
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-02-14 14:07:11 -05:00
|
|
|
def spam_check(spammable, user)
|
|
|
|
spam_service = SpamService.new(spammable, @request)
|
|
|
|
|
|
|
|
spam_service.when_recaptcha_verified(@recaptcha_verified, @api) do
|
|
|
|
user.spam_logs.find_by(id: @spam_log_id)&.update!(recaptcha_verified: true)
|
|
|
|
end
|
|
|
|
end
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2017-02-14 14:07:11 -05:00
|
|
|
end
|