Sha256: 54b2a59a58130a3d0f3879d6ca1dd774303a889596c416509c560f380420930c

Contents?: true

Size: 1.36 KB

Versions: 54

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    module Admin
      # This command is executed when the user changes a Project from the admin
      # panel.
      class UpdateProject < Rectify::Command
        # Initializes an UpdateProject Command.
        #
        # form - The form from which to get the data.
        # project - The current instance of the project to be updated.
        def initialize(form, project)
          @form = form
          @project = project
        end

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

          transaction do
            update_project
            link_proposals
          end

          broadcast(:ok)
        end

        private

        attr_reader :project, :form

        def update_project
          project.update_attributes!(
            scope: form.scope,
            category: form.category,
            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

54 entries across 54 versions & 2 rubygems

Version Path
decidim-budgets-0.9.3 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.9.2 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.9.1 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.9.0 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.8.4 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.8.3 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.8.2 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.8.1 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.8.0 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.7.4 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.7.3 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.7.2 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.7.1 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.7.0 app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.6.8 app/commands/decidim/budgets/admin/update_project.rb
decidim-0.6.8 decidim-budgets/app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.6.7 app/commands/decidim/budgets/admin/update_project.rb
decidim-0.6.7 decidim-budgets/app/commands/decidim/budgets/admin/update_project.rb
decidim-budgets-0.6.6 app/commands/decidim/budgets/admin/update_project.rb
decidim-0.6.6 decidim-budgets/app/commands/decidim/budgets/admin/update_project.rb