Class: SpreeCmCommissioner::Users::Block

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/users/block.rb

Overview

Blocks a user: they can no longer sign in, obtain new OAuth tokens, or use the ones they already have. Existing tokens are revoked here rather than only being rejected per request so that a block takes effect even on paths that never resolve spree_current_user.

Instance Method Summary collapse

Instance Method Details

#call(user:, reason: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'app/services/spree_cm_commissioner/users/block.rb', line 9

def call(user:, reason: nil)
  user.blocked_at = Time.zone.now
  user.blocked_reason = reason.presence

  return failure(:user_save_failed, user.errors.full_messages.to_sentence) unless user.save

  revoke_access_tokens(user)

  success(user)
end