From 42144843b2cbd8441696a6ff85bf6d0ca67d7f01 Mon Sep 17 00:00:00 2001 From: Antti Hukkanen Date: Mon, 4 Dec 2023 14:50:10 +0200 Subject: [PATCH] Fix the admin new/edit views for projects after changing the form The budget was not passed as a context variable to the form objects in the new/edit views. --- .../admin/projects_controller_extensions.rb | 29 +++++++++++++++++++ lib/decidim/budgeting_pipeline/engine.rb | 3 ++ 2 files changed, 32 insertions(+) create mode 100644 app/controllers/concerns/decidim/budgeting_pipeline/admin/projects_controller_extensions.rb diff --git a/app/controllers/concerns/decidim/budgeting_pipeline/admin/projects_controller_extensions.rb b/app/controllers/concerns/decidim/budgeting_pipeline/admin/projects_controller_extensions.rb new file mode 100644 index 0000000..cd748bf --- /dev/null +++ b/app/controllers/concerns/decidim/budgeting_pipeline/admin/projects_controller_extensions.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Decidim + module BudgetingPipeline + module Admin + # Customizes the admin projects controller to fix a bug on passing the + # budget through the form context. + module ProjectsControllerExtensions + extend ActiveSupport::Concern + + included do + def new + enforce_permission_to :create, :project + @form = form(Decidim::Budgets::Admin::ProjectForm).from_params( + { attachment: form(AttachmentForm).instance }, + budget: budget + ) + end + + def edit + enforce_permission_to :update, :project, project: project + @form = form(Decidim::Budgets::Admin::ProjectForm).from_model(project, budget: budget) + @form.attachment = form(AttachmentForm).instance + end + end + end + end + end +end diff --git a/lib/decidim/budgeting_pipeline/engine.rb b/lib/decidim/budgeting_pipeline/engine.rb index c8e703c..220519f 100644 --- a/lib/decidim/budgeting_pipeline/engine.rb +++ b/lib/decidim/budgeting_pipeline/engine.rb @@ -146,6 +146,9 @@ class Engine < ::Rails::Engine Decidim::Budgets::Admin::BudgetsController.include( Decidim::BudgetingPipeline::Admin::BudgetsControllerExtensions ) + Decidim::Budgets::Admin::ProjectsController.include( + Decidim::BudgetingPipeline::Admin::ProjectsControllerExtensions + ) # Cell extensions Decidim::Budgets::ProjectMCell.include(