Project

General

Profile

How to override method retrieve_query in issue_controller ยป issue_patch.rb

anhkhoa Michel, 2014-11-03 04:39

 
1
require_dependency 'issue'
2
# Patches Redmine's Issues dynamically.  Adds a relationship 
3
# Issue +belongs_to+ to Deliverable
4
module IssuePatch
5
  def self.included(base) # :nodoc:
6
    base.send(:include, InstanceMethods)
7

    
8
    base.class_eval do
9
      unloadable # Send unloadable so it will not be unloaded in development
10

    
11
      alias_method_chain :retrieve_query
12
    end
13
  end
14

    
15
  module ClassMethods
16

    
17
  end
18
  module InstanceMethods
19
    # Wraps the association to get the Deliverable subject.  Needed for the 
20
    # Query and filtering
21
    def retrieve_query_with_rate_query
22
      #  if User.current.allowed_to?(:hd_view_admin, @project)
23
      #    params[:query_id] = 8
24
      # else
25
      #    params[:query_id] = 7
26
      #  end
27
      if params[:query_id]=="0"
28
        if User.current.group_ids.include?8
29
          params[:query_id] = 8
30
        else
31
          params[:query_id] = 7
32
        end
33
      end
34

    
35
      if !params[:query_id].blank?
36
        cond = "project_id IS NULL"
37
        cond << " OR project_id = #{@project.id}" if @project
38
        @query = IssueQuery.where(cond).find(params[:query_id])
39
        raise ::Unauthorized unless @query.visible?
40
        @query.project = @project
41
        session[:query] = {:id => @query.id, :project_id => @query.project_id}
42
        sort_clear
43
      elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
44
        # Give it a name, required to be valid
45
        @query = IssueQuery.new(:name => "_")
46
        @query.project = @project
47
        @query.build_from_params(params)
48
        session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
49
      else
50
        # retrieve from session
51
        @query = nil
52
        @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
53
        @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
54
        @query.project = @project
55
      end
56
    end
57
  end
58
end
    (1-1/1)