Sha256: f8ea343b6eb6997014f3c541813aacf44a2539f3ec4a4ed40728fe2456c4534e

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 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 < Decidim::Commands::CreateResource
        include ::Decidim::GalleryMethods
        fetch_form_attributes :budget, :scope, :category, :title, :description, :budget_amount, :address, :latitude, :longitude

        private

        attr_reader :gallery

        def run_after_hooks
          @attached_to = resource
          link_proposals
          create_gallery if process_gallery?
        end

        def run_before_hooks
          return unless process_gallery?

          build_gallery
          raise Decidim::Commands::HookError if gallery_invalid?
        end

        def extra_params
          { visibility: "all" }
        end

        def resource_class = Decidim::Budgets::Project

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-budgets-0.29.1 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.29.0 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.29.0.rc4 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.29.0.rc3 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.29.0.rc2 app/commands/decidim/budgets/admin/create_project.rb
decidim-budgets-0.29.0.rc1 app/commands/decidim/budgets/admin/create_project.rb