0003-Auto-complete-should-propose-only-valid-parents.patch

Marius BALTEANU, 2018-05-01 14:28

Download (4.01 KB)

View differences:

app/controllers/auto_completes_controller.rb
23 23
    q = (params[:q] || params[:term]).to_s.strip
24 24
    status = params[:status].to_s
25 25
    issue_id = params[:issue_id].to_s
26
    parent_tracker_id = params[:parent_tracker_id].to_s
26 27
    if q.present?
27 28
      scope = Issue.cross_project_scope(@project, params[:scope]).visible
28 29
      if status.present?
......
31 32
      if issue_id.present?
32 33
        scope = scope.where.not(:id => issue_id.to_i)
33 34
      end
35
      if parent_tracker_id.present?
36
        allowed_subtasks = Tracker.find(parent_tracker_id.to_i).allowed_subtask_ids
37
        scope = scope.joins(:tracker).where(:tracker => allowed_subtasks)
38
      end
34 39
      if q.match(/\A#?(\d+)\z/)
35 40
        @issues << scope.find_by_id($1.to_i)
36 41
      end
app/views/issues/_attributes.html.erb
47 47
<div class="splitcontentright">
48 48
<% if @issue.safe_attribute? 'parent_issue_id' %>
49 49
<p id="parent_issue"><%= f.text_field :parent_issue_id, :size => 10, :required => @issue.required_attribute?('parent_issue_id') %></p>
50
<%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @issue.project, :scope => Setting.cross_project_subtasks, :status => @issue.closed? ? 'c' : 'o', :issue_id => @issue.id)}')" %>
50
<%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @issue.project, :scope => Setting.cross_project_subtasks, :status => @issue.closed? ? 'c' : 'o', :issue_id => @issue.id, :parent_tracker_id => @issue.tracker.id)}')" %>
51 51
<% end %>
52 52
<% if @issue.safe_attribute? 'start_date' %>
test/functional/auto_completes_controller_test.rb
21 21
  fixtures :projects, :issues, :issue_statuses,
22 22
           :enumerations, :users, :issue_categories,
23 23
           :trackers,
24
           :trackers_subtasks,
24 25
           :projects_trackers,
25 26
           :roles,
26 27
           :member_roles,
......
138 139
    assert_include "issue", response.body
139 140
    assert_not_include "Bug #12: Closed issue on a locked version", response.body
140 141
  end
142

  
143
  def test_auto_complete_with_parent_tracker_id_should_return_only_valid_subtasks
144
    Issue.generate!(:subject => "Feature request with issue in subject", :tracker_id => 2)
145
    tracker = Tracker.find(1)
146
    tracker.subtask_ids = [2, 3]
147
    tracker.save!
148

  
149
    get :issues, :params => {
150
        :project_id => 'ecookbook',
151
        :q => 'issue',
152
        :parent_tracker_id => '1'
153
      }
154

  
155
    assert_response :success
156

  
157
    json = ActiveSupport::JSON.decode(response.body)
158
    assert_kind_of Array, json
159
    assert_equal 1, json.count
160

  
161
    assert_include "Feature request with issue in subject", response.body
162
    assert_not_include "Bug", response.body
163
  end
141 164
end
142
-