Forums » Development »
How to override method retrieve_query in issue_controller
Added by anhkhoa Michel about 10 years ago
Hi every body. I want to override retrieve_query but It do'nt action. Code in my_plugin\lib\issue_patch.rb:
require_dependency 'issue' module IssuePatch def self.included(base) # :nodoc: base.send(:include, InstanceMethods) base.class_eval do unloadable # Send unloadable so it will not be unloaded in development alias_method_chain :retrieve_query,:rate_query end end module ClassMethods end module InstanceMethods # Wraps the association to get the Deliverable subject. Needed for the # Query and filtering def retrieve_query_with_rate_query if params[:query_id]=="0" if User.current.group_ids.include?8 params[:query_id] = 8 else params[:query_id] = 7 end end if !params[:query_id].blank? cond = "project_id IS NULL" cond << " OR project_id = #{@project.id}" if @project @query = IssueQuery.where(cond).find(params[:query_id]) raise ::Unauthorized unless @query.visible? @query.project = @project session[:query] = {:id => @query.id, :project_id => @query.project_id} sort_clear elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) # Give it a name, required to be valid @query = IssueQuery.new(:name => "_") @query.project = @project @query.build_from_params(params) session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} else # retrieve from session @query = nil @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id] @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) @query.project = @project end end end end
my_plugin\init.rb:
Redmine::Plugin.register :hdexpertises do name 'Hdexpertises plugin' author 'Author name' description 'This is a plugin for Redmine' version '0.0.1' url 'http://example.com/path/to/plugin' author_url 'http://example.com/about' end Redmine::AccessControl.map do |map| map.project_module :issue_tracking do |map| map.permission :hd_copy_issues, {} map.permission :hd_edit_due_date,{} map.permission :hd_edit_issue_due_date,{} map.permission :hd_view_collapsible,{} end end Redmine::MenuManager.map :project_menu do |menu| menu.push :tracker1, { :controller => 'issues', :action => 'index',:set_filter => 1,:tracker_id=>1 }, :param => :project_id, :caption => 'Nhiệm vụ' menu.push :tracker3, { :controller => 'issues', :action => 'index',:query_id => 0 }, :param => :project_id, :caption => 'Dự án' end
Please help me fix this. And i don't know argument of alias_method_chain, Can you explain to me? Thank you very much!
issue_patch.rb (2.09 KB) issue_patch.rb |