diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-10 15:07:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-10 15:07:47 +0000 |
commit | 8b1228b0d409d7751f01d9fb72ebfbbf62399486 (patch) | |
tree | 1b4126fe48d7666a90c0d7ee26230cf8379b6410 /app/services/concerns | |
parent | 96b0c1245c93585a8b0fe23e22306d32ff4e4905 (diff) | |
download | gitlab-ce-8b1228b0d409d7751f01d9fb72ebfbbf62399486.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/concerns')
-rw-r--r-- | app/services/concerns/spam_check_methods.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/services/concerns/spam_check_methods.rb b/app/services/concerns/spam_check_methods.rb new file mode 100644 index 00000000000..a0945857f89 --- /dev/null +++ b/app/services/concerns/spam_check_methods.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# SpamCheckMethods +# +# Provide helper methods for checking if a given spammable object has +# potential spam data. +# +# Dependencies: +# - params with :request + +module SpamCheckMethods + # rubocop:disable Gitlab/ModuleWithInstanceVariables + 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 + # rubocop:enable Gitlab/ModuleWithInstanceVariables + + # 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. + # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord + 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 + # rubocop: enable CodeReuse/ActiveRecord + # rubocop:enable Gitlab/ModuleWithInstanceVariables +end |