Module: Spam::Concerns::HasSpamActionResponseFields

Extended by:
ActiveSupport::Concern
Included in:
Mutations::SpamProtection, SpammableActions::CaptchaCheck::JsonFormatActionsSupport, SpammableActions::CaptchaCheck::RestApiActionsSupport
Defined in:
lib/spam/concerns/has_spam_action_response_fields.rb

Overview

This concern is shared by the controller and GraphQL layer to handle addition of spam/CAPTCHA related fields in the response.

Instance Method Summary collapse

Instance Method Details

#spam_action_response_fields(spammable) ⇒ Object

spam_action_response_fields(spammable) -> hash

Takes a Spammable as an argument and returns response fields necessary to display a CAPTCHA on the client.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/spam/concerns/has_spam_action_response_fields.rb', line 14

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