Sha256: 71761d918d1a420634f142ddba7b831243fb275394fc377ae839508e2f0f19a3

Contents?: true

Size: 911 Bytes

Versions: 12

Compression:

Stored size: 911 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # A command with all the business logic to create an editor image.
  class CreateEditorImage < Rectify::Command
    # Public: Initializes the command.
    #
    # form - A form object with the params.
    def initialize(form)
      @form = form
    end

    # Executes the command. Broadcasts these events:
    #
    # - :ok when everything is valid.
    # - :invalid if the form wasn't valid and we couldn't proceed.
    #
    # Returns nothing.
    def call
      return broadcast(:invalid) if form.invalid?

      transaction do
        create_editor_image
      end

      broadcast(:ok, @editor_image)
    end

    private

    attr_reader :form

    def create_editor_image
      @editor_image = EditorImage.create!(
        decidim_author_id: form.current_user.id,
        organization: form.organization,
        file: form.file
      )
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.9 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.8 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.7 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.5 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.4 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.3 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.2 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.1 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.0 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.0.rc2 app/commands/decidim/create_editor_image.rb
decidim-core-0.26.0.rc1 app/commands/decidim/create_editor_image.rb