debian-mirror-gitlab/app/controllers/concerns/spammable_actions/captcha_check/common.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
1 KiB
Ruby
Raw Permalink Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
2022-05-07 20:08:51 +05:30
module SpammableActions
module CaptchaCheck
module Common
extend ActiveSupport::Concern
2021-10-27 15:23:28 +05:30
2022-05-07 20:08:51 +05:30
private
2021-10-27 15:23:28 +05:30
2022-05-07 20:08:51 +05:30
def with_captcha_check_common(spammable:, captcha_render_lambda:, &block)
# If the Spammable indicates that CAPTCHA is not necessary (either due to it not being flagged
# as spam, or if spam/captcha is disabled for some reason), then we will go ahead and
# yield to the block containing the action's original behavior, then return.
return yield unless spammable.render_recaptcha?
2021-10-27 15:23:28 +05:30
2022-05-07 20:08:51 +05:30
# If we got here, we need to render the CAPTCHA instead of yielding to action's original
# behavior. We will present a CAPTCHA to be solved by executing the lambda which was passed
# as the `captcha_render_lambda:` argument. This lambda contains either the HTML-specific or
# JSON-specific behavior to cause the CAPTCHA modal to be rendered.
Gitlab::Recaptcha.load_configurations!
captcha_render_lambda.call
end
2021-10-27 15:23:28 +05:30
end
end
end