2018-07-05 06:18:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-01-10 10:07:47 -05:00
|
|
|
# SpamCheckMethods
|
2017-02-14 14:07:11 -05:00
|
|
|
#
|
2020-02-14 19:08:48 -05:00
|
|
|
# Provide helper methods for checking if a given spammable object has
|
2017-02-14 14:07:11 -05:00
|
|
|
# potential spam data.
|
|
|
|
#
|
|
|
|
# Dependencies:
|
|
|
|
# - params with :request
|
2020-01-10 10:07:47 -05:00
|
|
|
|
|
|
|
module SpamCheckMethods
|
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
|
|
|
|
2020-02-14 19:08:48 -05:00
|
|
|
# In order to be proceed to the spam check process, @spammable has to be
|
2017-03-20 22:37:29 -04:00
|
|
|
# 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
|
2020-06-08 02:08:19 -04:00
|
|
|
def spam_check(spammable, user, action:)
|
|
|
|
raise ArgumentError.new('Please provide an action, such as :create') unless action
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
Spam::SpamActionService.new(
|
2020-02-14 19:08:48 -05:00
|
|
|
spammable: spammable,
|
2020-06-08 02:08:19 -04:00
|
|
|
request: @request,
|
|
|
|
user: user,
|
|
|
|
context: { action: action }
|
2020-01-23 10:08:46 -05:00
|
|
|
).execute(
|
|
|
|
api: @api,
|
|
|
|
recaptcha_verified: @recaptcha_verified,
|
2020-06-08 02:08:19 -04:00
|
|
|
spam_log_id: @spam_log_id)
|
2017-02-14 14:07:11 -05:00
|
|
|
end
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2017-02-14 14:07:11 -05:00
|
|
|
end
|