* Split Settings::Authentication from SiteConfig * Move specs * Sort fields * Update settings usages * Update recaptcha usages * Add data update script * Update spec * Rename SiteConfigParams concern * Fixes, new route, new controller * Controller and service refactoring * More controller and service updates * Spec updates * More spec fixes * Move file * Fix FeedbackMessagesController * Update admin/configs_spec * Fix remaining specs in admin/configs_spec * Fix configs API * Formatting * Clean up old service object * Various fixes * Update DUS * Add model argument to admin_config_label * Fix key name * Fix specs * Add distinct request caches for settings classes * Fix e2e tests * Fix remaining system spec * Make DUS idempotent * Move routes block * Cleanup * Switch to ActiveSupport::CurrentAttributes * Pinned rails-settings-cached * Update e2e test * Update lib/data_update_scripts/20210316091354_move_authentication_settings.rb Co-authored-by: rhymes <rhymes@hey.com> * Add guard to DUS * Temporarily re-add two SiteConfig fields * Fix config show view Co-authored-by: rhymes <rhymes@hey.com>
38 lines
1.3 KiB
Ruby
38 lines
1.3 KiB
Ruby
# This service encapsulates the logic related to validating if reCAPTCHA is
|
|
# enabled in the current Forem instance. The decision is based on making
|
|
# sure the necessary SiteConfig keys are available and also on the user
|
|
# object passed in.
|
|
#
|
|
# Example use: ReCaptcha::CheckEnabled.call(current_user) => true/false
|
|
module ReCaptcha
|
|
class CheckEnabled
|
|
def self.call(user = nil)
|
|
new(user).call
|
|
end
|
|
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
def call
|
|
# recaptcha will not be enabled if site key and secret key aren't set
|
|
return false unless keys_configured?
|
|
# recaptcha will always be enabled when not logged in
|
|
return true if @user.nil?
|
|
# recaptcha will not be enabled for tag moderator/trusted/admin users
|
|
return false if @user.tag_moderator? || @user.trusted || @user.any_admin?
|
|
# recaptcha will be enabled if the user has been suspended
|
|
return true if @user.suspended?
|
|
|
|
# recaptcha will be enabled if the user has a vomit or is too recent
|
|
@user.vomitted_on? || @user.created_at.after?(1.month.ago)
|
|
end
|
|
|
|
private
|
|
|
|
def keys_configured?
|
|
Settings::Authentication.recaptcha_site_key.present? &&
|
|
Settings::Authentication.recaptcha_secret_key.present?
|
|
end
|
|
end
|
|
end
|