Class: Spree::Api::V3::Admin::CustomersController
- Inherits:
-
ResourceController
- Object
- ActionController::API
- BaseController
- ResourceController
- ResourceController
- Spree::Api::V3::Admin::CustomersController
- Includes:
- BulkOperations
- Defined in:
- app/controllers/spree/api/v3/admin/customers_controller.rb
Constant Summary
Constants included from ScopedAuthorization
ScopedAuthorization::READ_ACTIONS
Constants inherited from BaseController
BaseController::RATE_LIMIT_RESPONSE
Constants included from Idempotent
Idempotent::IDEMPOTENCY_HEADER, Idempotent::IDEMPOTENCY_TTL, Idempotent::MAX_KEY_LENGTH, Idempotent::MUTATING_METHODS
Constants included from ErrorHandler
Constants included from JwtAuthentication
JwtAuthentication::JWT_AUDIENCE_ADMIN, JwtAuthentication::JWT_AUDIENCE_STORE, JwtAuthentication::JWT_ISSUER, JwtAuthentication::USER_TYPE_ADMIN, JwtAuthentication::USER_TYPE_CUSTOMER
Instance Method Summary collapse
-
#bulk_add_to_groups ⇒ Object
Bulk add the given customers to the given groups.
-
#bulk_remove_from_groups ⇒ Object
Bulk remove the given customers from the given groups.
- #create ⇒ Object
- #destroy ⇒ Object
- #update ⇒ Object
Methods included from BulkOperations
#bulk_add_tags, #bulk_remove_tags
Methods inherited from ResourceController
Methods included from Spree::Api::V3::ApiKeyAuthentication
#authenticate_api_key!, #authenticate_secret_key!
Methods included from JwtAuthentication
#authenticate_user, #require_authentication!
Instance Method Details
#bulk_add_to_groups ⇒ Object
Bulk add the given customers to the given groups. Idempotent —customers already in a group are skipped at the model layer.
54 55 56 |
# File 'app/controllers/spree/api/v3/admin/customers_controller.rb', line 54 def bulk_add_to_groups apply_groups(:add_customers) end |
#bulk_remove_from_groups ⇒ Object
Bulk remove the given customers from the given groups.
59 60 61 |
# File 'app/controllers/spree/api/v3/admin/customers_controller.rb', line 59 def bulk_remove_from_groups apply_groups(:remove_customers) end |
#create ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/spree/api/v3/admin/customers_controller.rb', line 12 def create @resource = Spree.user_class.new(permitted_params) # Admin-created customers don't pick a password upfront — they # claim the account via password reset later. # `Spree::UserMethods` exposes `skip_password_validation` so # Devise's `:validatable` lets a nil credential through on this # code path. Storefront registration never sets the flag, so # customer self-signup still requires a password. @resource.skip_password_validation = true if @resource.password.blank? (:create, @resource) if @resource.save render json: serialize_resource(@resource), status: :created else render_validation_error(@resource.errors) end end |
#destroy ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/spree/api/v3/admin/customers_controller.rb', line 40 def destroy (@resource) @resource.destroy head :no_content rescue Spree::Core::DestroyWithOrdersError => e render_error( code: 'customer_has_orders', message: e..presence || Spree.t(:error_user_destroy_with_orders), status: :unprocessable_content ) end |
#update ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/spree/api/v3/admin/customers_controller.rb', line 30 def update (@resource) if @resource.update(permitted_params) render json: serialize_resource(@resource.reload) else render_validation_error(@resource.errors) end end |