diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /lib/spam | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'lib/spam')
-rw-r--r-- | lib/spam/concerns/has_spam_action_response_fields.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/spam/concerns/has_spam_action_response_fields.rb b/lib/spam/concerns/has_spam_action_response_fields.rb new file mode 100644 index 00000000000..d49f5cd6454 --- /dev/null +++ b/lib/spam/concerns/has_spam_action_response_fields.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Spam + module Concerns + # This concern is shared by the controller and GraphQL layer to handle + # addition of spam/CAPTCHA related fields in the response. + module HasSpamActionResponseFields + extend ActiveSupport::Concern + + # spam_action_response_fields(spammable) -> hash + # + # Takes a Spammable as an argument and returns response fields necessary to display a CAPTCHA on + # the client. + def spam_action_response_fields(spammable) + { + spam: spammable.spam?, + # NOTE: These fields are intentionally named with 'captcha' instead of 'recaptcha', so + # that they can be applied to future alternative CAPTCHA implementations other than + # reCAPTCHA (such as FriendlyCaptcha) without having to change the response field name + # in the API. + needs_captcha_response: spammable.render_recaptcha?, + spam_log_id: spammable.spam_log&.id, + captcha_site_key: Gitlab::CurrentSettings.recaptcha_site_key + } + end + + # with_spam_action_response_fields(spammable) { {other_fields: true} } -> hash + # + # Takes a Spammable and a block as arguments. + # + # The block passed should be a hash, which the spam_action_fields will be merged into. + def with_spam_action_response_fields(spammable) + yield.merge(spam_action_response_fields(spammable)) + end + end + end +end |