From 4abc3179f588f03aba2e5c9d7a5fb29570dc2614 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 21 Jan 2017 09:59:12 +0000 Subject: [PATCH] Filter parent task issues in auto complete by open/closed status depending on the subtask status (#24877). Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@16243 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/auto_completes_controller.rb | 9 ++++++++ app/views/issues/_attributes.html.erb | 2 +- .../auto_completes_controller_test.rb | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb index 3fe572ab6..ab46465ac 100644 --- a/app/controllers/auto_completes_controller.rb +++ b/app/controllers/auto_completes_controller.rb @@ -21,11 +21,20 @@ class AutoCompletesController < ApplicationController def issues @issues = [] q = (params[:q] || params[:term]).to_s.strip + status = params[:status].to_s + issue_id = params[:issue_id].to_s if q.present? scope = Issue.cross_project_scope(@project, params[:scope]).visible + if status.present? + scope = scope.open(status == 'o') + end + if issue_id.present? + scope = scope.where("#{Issue.table_name}.id <> ?", issue_id.to_i) + end if q.match(/\A#?(\d+)\z/) @issues << scope.find_by_id($1.to_i) end + @issues += scope.where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%").order("#{Issue.table_name}.id DESC").limit(10).to_a @issues.compact! end diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb index 224960617..640a00e0b 100644 --- a/app/views/issues/_attributes.html.erb +++ b/app/views/issues/_attributes.html.erb @@ -47,7 +47,7 @@
<% if @issue.safe_attribute? 'parent_issue_id' %>

<%= f.text_field :parent_issue_id, :size => 10, :required => @issue.required_attribute?('parent_issue_id') %>

-<%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @issue.project, :scope => Setting.cross_project_subtasks)}')" %> +<%= 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)}')" %> <% end %> <% if @issue.safe_attribute? 'start_date' %> diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb index 5360eac9b..d02addc1a 100644 --- a/test/functional/auto_completes_controller_test.rb +++ b/test/functional/auto_completes_controller_test.rb @@ -81,4 +81,25 @@ class AutoCompletesControllerTest < Redmine::ControllerTest assert_equal 13, issue['value'] assert_equal 'Bug #13: Subproject issue two', issue['label'] end + + def test_auto_complete_with_status_o_should_return_open_issues_only + get :issues, :project_id => 'ecookbook', :q => 'issue', :status => 'o' + assert_response :success + assert_include "Issue due today", response.body + assert_not_include "closed", response.body + end + + def test_auto_complete_with_status_c_should_return_closed_issues_only + get :issues, :project_id => 'ecookbook', :q => 'issue', :status => 'c' + assert_response :success + assert_include "closed", response.body + assert_not_include "Issue due today", response.body + end + + def test_auto_complete_with_issue_id_should_not_return_that_issue + get :issues, :project_id => 'ecookbook', :q => 'issue', :issue_id => '12' + assert_response :success + assert_include "issue", response.body + assert_not_include "Bug #12: Closed issue on a locked version", response.body + end end -- 2.39.5