Skip to content

Commit

Permalink
Fix the admin new/edit views for projects after changing the form
Browse files Browse the repository at this point in the history
The budget was not passed as a context variable to the form
objects in the new/edit views.
  • Loading branch information
ahukkanen committed Dec 4, 2023
1 parent c98b5b1 commit 4214484
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/decidim/budgeting_pipeline/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4214484

Please sign in to comment.