Sha256: 34b11790e9f3a3841c3792e2b11fc20fd6932c7679337736dc29c510281584fe

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    module Admin
      class ProposalsImportsController < Admin::ApplicationController
        helper_method :budget

        def new
          enforce_permission_to :import_proposals, :projects

          @form = form(Admin::ProjectImportProposalsForm).instance
        end

        def create
          enforce_permission_to :import_proposals, :projects

          @form = form(Admin::ProjectImportProposalsForm).from_params(params, budget:)
          Admin::ImportProposalsToBudgets.call(@form) do
            on(:ok) do |projects|
              flash[:notice] = I18n.t("proposals_imports.create.success", scope: "decidim.budgets.admin", number: projects.length)
              redirect_to budget_projects_path(budget)
            end

            on(:invalid) do
              flash[:alert] = I18n.t("proposals_imports.create.invalid", scope: "decidim.budgets.admin")
              render action: "new"
            end
          end
        end

        private

        def budget
          @budget ||= Budget.where(component: current_component).find_by(id: params[:budget_id])
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-budgets-0.29.1 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.28.4 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.29.0 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.28.3 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.29.0.rc4 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.29.0.rc3 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.29.0.rc2 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.29.0.rc1 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.28.2 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.28.1 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.28.0 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.28.0.rc5 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb
decidim-budgets-0.28.0.rc4 app/controllers/decidim/budgets/admin/proposals_imports_controller.rb