Sha256: fa538b804c96f35defa084fc4a4ec9888a5076bafd3adc5415bee4e202fbbdbc

Contents?: true

Size: 1.26 KB

Versions: 29

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    module Admin
      # This command is executed when the user creates a Project from the admin
      # panel.
      class CreateProject < Rectify::Command
        def initialize(form)
          @form = form
        end

        # Creates the project if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if @form.invalid?

          transaction do
            create_project
            link_proposals
          end

          broadcast(:ok)
        end

        private

        attr_reader :project

        def create_project
          @project = Decidim.traceability.create!(
            Project,
            @form.current_user,
            scope: @form.scope,
            category: @form.category,
            component: @form.current_component,
            title: @form.title,
            description: @form.description,
            budget: @form.budget
          )
        end

        def proposals
          @proposals ||= project.sibling_scope(:proposals).where(id: @form.proposal_ids)
        end

        def link_proposals
          project.link_resources(proposals, "included_proposals")
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
decidim-budgets-0.21.0 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.20.1 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.20.0 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.19.1 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.18.1 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.19.0 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.17.2 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.18.0 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.17.1 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.16.1 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.17.0 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.16.0 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.15.2 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.15.1 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.15.0 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.14.4 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.14.3 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.14.2 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.14.1 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.13.1 app/commands/decidim/budgets/admin/create_project.rb