Sha256: b29617b0000eaf171f02a99fc24fdffa4c3a821d909bc5ad50ba74ca224fa3bb

Contents?: true

Size: 1013 Bytes

Versions: 13

Compression:

Stored size: 1013 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Accountability
    module Admin
      # A command with all the business logic when an admin imports projects from
      # one component to accountability.
      class ImportProjectsToAccountability < Decidim::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        def initialize(form)
          @form = form
        end

        def call
          return broadcast(:invalid) unless @form.valid?

          ImportProjectsJob.perform_later(projects.pluck(:id), @form.current_component, @form.current_user)
          broadcast(:ok, projects.count)
        end

        private

        def projects
          Decidim::Budgets::Project.joins(:budget).selected.where(
            budget: { component: origin_component }
          ).reject { |item| @form.project_already_copied?(item) }
        end

        def origin_component
          @form.origin_component
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-accountability-0.29.1 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.28.4 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.29.0 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.28.3 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.29.0.rc4 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.29.0.rc3 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.29.0.rc2 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.29.0.rc1 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.28.2 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.28.1 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.28.0 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.28.0.rc5 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb
decidim-accountability-0.28.0.rc4 app/commands/decidim/accountability/admin/import_projects_to_accountability.rb