Sha256: 7a42903f7885b2666b137cabeb0bd2d51db7160ed92458964515b2ee92f0e56f

Contents?: true

Size: 1.69 KB

Versions: 58

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    module Admin
      # A command with all the business logic when creating a new participatory
      # process group in the system.
      class CreateParticipatoryProcessGroup < 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?
          group = create_participatory_process_group

          if group.persisted?
            broadcast(:ok, group)
          else
            form.errors.add(:hero_image, group.errors[:hero_image]) if group.errors.include? :hero_image
            form.errors.add(:banner_image, group.errors[:banner_image]) if group.errors.include? :banner_image
            broadcast(:invalid)
          end
        end

        private

        attr_reader :form

        def create_participatory_process_group
          transaction do
            ParticipatoryProcessGroup.create(
              name: form.name,
              description: form.description,
              hero_image: form.hero_image,
              participatory_processes: participatory_processes,
              organization: form.current_organization
            )
          end
        end

        def participatory_processes
          Decidim::ParticipatoryProcess.where(id: form.participatory_process_ids)
        end
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 2 rubygems

Version Path
decidim-participatory_processes-0.18.1 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.17.2 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.18.0 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.17.1 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.16.1 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.17.0 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.16.0 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.15.2 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.15.1 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.15.0 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.14.4 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.14.3 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.14.2 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.14.1 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.13.1 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.12.2 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.13.0 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.12.1 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.13.0.pre1 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb
decidim-participatory_processes-0.12.0 app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb