0

I am writing a redmine plugin and need to add some actions to before_filter that is already defined in redmine's 'IssuesController'

For example,

issues_controller.rb

class IssuesController < ApplicationController
   before_filter :find_issue, :only => [:show, :edit, :update]
   before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
   before_filter :find_project, :only => [:new, :create, :update_form]
   before_filter :authorize, :except => [:index]
end

I want to add more actions to filters find_issue and find_project

So, in my plugin i'm gonna write a module and include it in IssuesController

issues_controller_patch.rb

  module IssuesControllerPatch
    def self.included(base) # :nodoc:
      base.send(:include, InstanceMethods)
      base.class_eval do
        before_filter :find_issue, :only => [:new_action1, :new_action2]
        before_filter :find_project, :only => [:new_action1, :new_action2]
        #prepend_before_filter :find_issue, :only => [:new_action1, :new_action2]
        #prepend_before_filter :find_project, :only => [:new_action1, :new_action2]
      end
    end

    module InstanceMethods
    end
  end

  unless IssuesController.included_modules.include?(IssuesControllerPatch)
    IssuesController.send(:include, IssuesControllerPatch)
  end

This is not working for me, because it's putting it on the bottom of filters chain and authorize action is executed and authorization is because authorization depends on project.

I also tried to use prepend_before_filter and it's also not working because it's putting it on the top of filters chain, even before the user loads from session.

So, how can I update action list for filters defined in IssuesController?

Rails 3.2, Ruby 1.9.3, Redmine 2.6

Ramiz Raja
  • 5,942
  • 3
  • 27
  • 39

0 Answers0