02_filter_subtask_from_issues_autocomplete.patch

Marius BALTEANU, 2017-01-20 11:03

Download (2.55 KB)

View differences:

app/controllers/auto_completes_controller.rb
22 22
    @issues = []
23 23
    q = (params[:q] || params[:term]).to_s.strip
24 24
    status = params[:status].to_s.strip
25
    issue = params[:issue].to_i
25 26
    if q.present?
26 27
      scope = Issue.cross_project_scope(@project, params[:scope]).visible
27 28
      scope = scope.open if status == 'o'
28 29
      scope = scope.joins(:status).where("#{IssueStatus.table_name}.is_closed = 1") if status == 'c'
30
      scope = scope.where("#{Issue.table_name}.id <> ?", issue) if issue
29 31
      if q.match(/\A#?(\d+)\z/)
30 32
        @issues << scope.find_by_id($1.to_i)
31 33
      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')}')" %>
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 => @issue.id)}')" %>
51 51
<% end %>
52 52

  
53 53
<% if @issue.safe_attribute? 'start_date' %>
test/functional/auto_completes_controller_test.rb
95 95
    assert_include "closed", response.body
96 96
    assert_not_include "Issue due today", response.body
97 97
  end
98

  
99
  def test_auto_complete_with_issue_id_should_not_return_that_issue
100
    get :issues, :project_id => 'ecookbook', :q => 'issue', :issue => '12'
101
    assert_response :success
102
    assert_include "issue", response.body
103
    assert_not_include "Bug #12: Closed issue on a locked version", response.body
104
  end
98 105
end