Class: Spree::DigitalAssets::Update

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

Overview

Changes a digital asset: its download limits, the variant it hangs off, or the file itself. Replacing the file keeps every already-issued link working, since links resolve through the asset rather than the blob.

Handlers reading digital_asset.changes in :validate see the pending edit; blob is the replacement file, when the payload carries one.

Constant Summary

Constants included from Writing

Writing::REVIEW_REASON

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 Method Details

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

Returns value is the digital asset.

Parameters:

  • digital_asset (Spree::DigitalAsset)
  • attributes (Hash) (defaults to: {}) —

    see Spree::DigitalAssets::Create

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

    the seller this change is written for

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

    who made the change

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/workflows/spree/digital_assets/update.rb', line 19

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

  step :assign_attributes
  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_update
  end

  success(digital_asset)
end