diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index f2d8e3873..eae5f219f 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -90,8 +90,15 @@ class TrackersController < ApplicationController @tracker = Tracker.find(params[:id]) unless @tracker.issues.empty? projects = Project.joins(:issues).where(issues: {tracker_id: @tracker.id}).sorted.distinct + tracker_project_ids = @tracker.projects.ids links = projects.map do |p| - view_context.link_to(p, project_issues_path(p, set_filter: 1, tracker_id: @tracker.id, status_id: '*')) + if tracker_project_ids.include?(p.id) || p.rolled_up_trackers.ids.include?(@tracker.id) + view_context.link_to(p, project_issues_path(p, set_filter: 1, tracker_id: @tracker.id, status_id: '*')) + else + # This tracker is not enabled in the project, + # so we can't link to the issues list + ERB::Util.html_escape(p.name) + end end.join(', ') flash[:error] = l(:error_can_not_delete_tracker_html, projects: links.html_safe) else diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb index f3f614198..3e3f504fc 100644 --- a/test/functional/trackers_controller_test.rb +++ b/test/functional/trackers_controller_test.rb @@ -272,21 +272,31 @@ class TrackersControllerTest < Redmine::ControllerTest end def test_destroy_tracker_in_use - tracker = Tracker.generate!(name: 'In use') - projects = Array.new(2) do - project = Project.generate! - Issue.generate!(project: project, tracker: tracker) - project - end + tracker = Tracker.find_by(name: 'Bug') + # A project where the tracker is explicitly enabled + project_with_tracker = Project.find_by(identifier: 'private-child') + # A project where the tracker is disabled, but rolled up from subprojects + project_with_rolled_up_tracker = Project.find_by(identifier: 'ecookbook') + project_with_rolled_up_tracker.trackers.delete(tracker) + # A project where the tracker is completely disabled + project_without_tracker = Project.find_by(identifier: 'onlinestore') + project_without_tracker.trackers.delete(tracker) assert_no_difference 'Tracker.count' do delete :destroy, params: {id: tracker.id} end assert_redirected_to action: 'index' - assert_match /The following projects have issues with this tracker:/, flash[:error] - projects.each do |project| - assert_match /#{project.name}/, flash[:error] - end + assert_includes flash[:error], 'The following projects have issues with this tracker:' + + # projects with the tracker enabled or rolled up have a link in the error message + assert_includes flash[:error], project_with_tracker.name + assert_match %r{}, flash[:error] + assert_includes flash[:error], project_with_rolled_up_tracker.name + assert_match %r{}, flash[:error] + + # projects without the tracker appear as text in the error message, without a link + assert_includes flash[:error], project_without_tracker.name + assert_no_match %r{}, flash[:error] end def test_get_fields