Sha256: 6ebfd5fc0899ee68df6120173c1ecbe563c71d86f857f7a8d540156d595fdb2c

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic to add an attachment collection
    # to a participatory space.
    class CreateAttachmentCollection < Decidim::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      # collection_for - The ActiveRecord::Base that will hold the collection
      def initialize(form, collection_for, user)
        @form = form
        @collection_for = collection_for
        @user = user
      end

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

        create_attachment_collection
        broadcast(:ok)
      end

      private

      attr_reader :form

      def create_attachment_collection
        Decidim.traceability.create!(
          AttachmentCollection,
          @user,
          attributes
        )
      end

      def attributes
        {
          name: form.name,
          weight: form.weight,
          description: form.description,
          collection_for: @collection_for
        }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-admin-0.28.5 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.28.4 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.28.3 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.28.2 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.28.1 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.28.0 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/create_attachment_collection.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/create_attachment_collection.rb