Class: SpreeCmCommissioner::FraudCheck
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::FraudCheck
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/fraud_check.rb
Constant Summary collapse
- DEFAULTS =
{ 'max_votes_per_minute_per_user' => 5, 'max_votes_per_minute_per_ip' => 10, 'max_accounts_per_device' => 3, 'block_vpn' => false }.freeze
- RATE_WINDOW =
seconds
60- VPN_CACHE_TTL =
1 hour
3600
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#voting_session ⇒ Object
readonly
Returns the value of attribute voting_session.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(voting_session:, user:, params:, request:) ⇒ FraudCheck
constructor
A new instance of FraudCheck.
Constructor Details
#initialize(voting_session:, user:, params:, request:) ⇒ FraudCheck
Returns a new instance of FraudCheck.
29 30 31 32 33 34 |
# File 'app/services/spree_cm_commissioner/fraud_check.rb', line 29 def initialize(voting_session:, user:, params:, request:) @voting_session = voting_session @user = user @params = params @request = request end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
27 28 29 |
# File 'app/services/spree_cm_commissioner/fraud_check.rb', line 27 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
27 28 29 |
# File 'app/services/spree_cm_commissioner/fraud_check.rb', line 27 def request @request end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
27 28 29 |
# File 'app/services/spree_cm_commissioner/fraud_check.rb', line 27 def user @user end |
#voting_session ⇒ Object (readonly)
Returns the value of attribute voting_session.
27 28 29 |
# File 'app/services/spree_cm_commissioner/fraud_check.rb', line 27 def voting_session @voting_session end |
Instance Method Details
#call ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/services/spree_cm_commissioner/fraud_check.rb', line 36 def call return success(nil) if fraud_config.blank? check_user_rate_limit! check_ip_rate_limit! check_device_account_limit! check_vpn_block! success(nil) rescue RuntimeError => e failure(nil, e.) rescue Redis::BaseError => e # Fail-open: a Redis outage should not take down voting entirely. # Log the error so it is visible in monitoring, but let the vote through. # If the policy should be fail-closed instead, replace the rescue body # with: failure(I18n.t('voting.errors.service_unavailable')) CmAppLogger.error( label: 'FraudCheck Redis error — failing open', data: { voting_session_id: voting_session.id, user_id: user&.id, error_class: e.class.name, error_message: e. } ) success(nil) end |