Class: Spree::DigitalAssets::Create

Inherits:
Workflow
  • Object
show all
Includes:
Writing
Defined in:
app/workflows/spree/digital_assets/create.rb

Overview

Adds a downloadable file (or a provider-backed deliverable) to a product.

The single gate for new assets: the operator's and the seller's nested endpoints and the digital_assets list on a product write all run through it, so a :validate handler sees every file a catalog gains. A host that scans uploads registers on digital_assets.create.validate for a quick check, or on after_create to queue a slower one; the bytes are already in storage when either fires.

Passing seller: applies the marketplace's rules for a seller's file — whether sellers may upload at all, which content types, and whether an approved listing goes back to review. The operator's own writes pass none.

Constant Summary

Constants included from Writing

Writing::REVIEW_REASON

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Workflow

#call, define_argument_readers, #errors, #halt!, hooks, inherited, model_name, #read_attribute_for_validation, #reject!, workflow_key

Methods included from ServiceModule::Base

#call, prepended

Methods included from Workflow::ControlFlow

#failure

Instance Attribute Details

#digital_asset ⇒ Object (readonly)

The unsaved record a :validate handler reads.



21
22
23
# File 'app/workflows/spree/digital_assets/create.rb', line 21

def digital_asset
  @digital_asset
end

Instance Method Details

#perform(product:, attributes: {}, seller: nil, submitted_by: nil) ⇒ Spree::ServiceModule::Result

Returns value is the digital asset.

Parameters:

  • product (Spree::Product)
  • attributes (Hash) (defaults to: {}) —

    signed_id, variant_id, the download limits and, for the operator, the provider fields

  • seller (Spree::Seller, nil) (defaults to: nil) —

    the seller this file is written for

  • submitted_by (Spree.admin_user_class, nil) (defaults to: nil) —

    who made the change, named on the review it may reopen

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/workflows/spree/digital_assets/create.rb', line 30

def perform(product:, attributes: {}, seller: nil, submitted_by: nil)
  super

  step :build_digital_asset
  step :resolve_upload
  step :enforce_seller_rules
  run_hooks :validate

  ApplicationRecord.transaction do
    step :attach_upload
    step :save_digital_asset
    step :reopen_review
    run_hooks :after_create
  end

  success(digital_asset)
end