Sha256: 708d7e2cbb50b526da8c21ed31d7f21041baa021874e026870cc26bbd3ce0e3e

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 < Decidim::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.27.9 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.8 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.7 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.6 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.5 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.4 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.3 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.2 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.1 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.0 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.0.rc2 app/commands/decidim/create_editor_image.rb
decidim-core-0.27.0.rc1 app/commands/decidim/create_editor_image.rb