mainio / decidim-module-term_customizer

Decidim module that allows customizing the localization terms in the system for specific contexts.
GNU Affero General Public License v3.0
16 stars 21 forks source link

Error when visiting consultations #28

Closed aitorlb closed 5 years ago

aitorlb commented 5 years ago

Describe the bug

Consultations frontend crashes when using decidim-consultations with decidim-term_customizer.

To Reproduce

Steps to reproduce the behavior:

  1. Generate a development_app
    $ bundle exec rake development_app
  2. Add the consultations gem to the development_app Gemfile
    gem "decidim-consultations", Decidim::TermCustomizer::DECIDIM_VERSION
  3. Install the gem and run migrations
    $ bundle
    $ bundle exec rails decidim_consultations:install:migrations
    $ bundle exec rails db:migrate
  4. Visit http://localhost:3000/consultations
  5. See error

Expected behavior

Should not crash.

Screenshots

If applicable, add screenshots to help explain your problem.

not_implemented_error

Stacktrace

If applicable, add the error stacktrace to help explain your problem.

/home/aitorlopez/workspace/decidim-codit/decidim/decidim-core/app/controllers/concerns/decidim/participatory_space_context.rb:42:in `current_participatory_space'
/home/aitorlopez/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/decidim-module-term_customizer-a0055f708cfe/lib/decidim/term_customizer/context/controller_context.rb:19:in `resolve!'
/home/aitorlopez/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/decidim-module-term_customizer-a0055f708cfe/lib/decidim/term_customizer/context/base.rb:24:in `initialize'
/home/aitorlopez/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/decidim-module-term_customizer-a0055f708cfe/lib/decidim/term_customizer/engine.rb:20:in `new'
/home/aitorlopez/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/decidim-module-term_customizer-a0055f708cfe/lib/decidim/term_customizer/engine.rb:20:in `block (2 levels) in <class:Engine>'
ahukkanen commented 5 years ago

This is "fixed" by 5d7dca16af4f4cb049f1f573f6c5eefd8b427fc0 (the not crashing part).

Hard to fix "properly" without that core patch but there is a workaround for this issue:

  1. Create a custom controller context for Term Customizer
# frozen_string_literal: true

# lib/term_customizer_custom_controller_context.rb
class TermCustomizerCustomControllerContext < Decidim::TermCustomizer::Context::ControllerContext
  def resolve!
    env = data[:headers].env
    controller = env["action_controller.instance"]

    @organization = env["decidim.current_organization"]

    if controller.respond_to?(:current_consultation)
      consultation = controller.send(:current_consultation)

      @space = consultation
      @component = env["decidim.current_component"]

      return
    end

    super
  end
end
  1. Apply that to Term Customizer
# config/initializers/term_customizer.rb

require "term_customizer_custom_controller_context"
Decidim::TermCustomizer.controller_context_class = TermCustomizerCustomControllerContext