From: Go MAEDA Date: Sun, 3 Nov 2024 07:11:07 +0000 (+0000) Subject: Improve tracker deletion error message to display projects containing issues under... X-Git-Tag: 6.0.0~31 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e5867ffc8d20cbfc075afa9f1151d2266fe9f95d;p=redmine.git Improve tracker deletion error message to display projects containing issues under the tracker (#12521). Patch by Go MAEDA (user:maeda). git-svn-id: https://svn.redmine.org/redmine/trunk@23181 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index c1415bc2c..824ce93ef 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -89,7 +89,11 @@ class TrackersController < ApplicationController def destroy @tracker = Tracker.find(params[:id]) unless @tracker.issues.empty? - flash[:error] = l(:error_can_not_delete_tracker) + projects = Project.joins(:issues).where(issues: {tracker_id: @tracker.id}).sorted.distinct + links = projects.map do |p| + view_context.link_to(p, project_issues_path(p, set_filter: 1, tracker_id: @tracker.id)) + end.join(', ') + flash[:error] = l(:error_can_not_delete_tracker_html, projects: links.html_safe) else @tracker.destroy end diff --git a/config/locales/en.yml b/config/locales/en.yml index 200bdcdfc..cea117d09 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -205,7 +205,7 @@ en: error_no_tracker_in_project: 'No tracker is associated to this project. Please check the Project settings.' error_no_default_issue_status: 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' error_can_not_delete_custom_field: Unable to delete custom field - error_can_not_delete_tracker: "This tracker contains issues and cannot be deleted." + error_can_not_delete_tracker_html: "This tracker contains issues and cannot be deleted.

The following projects have issues with this tracker:
%{projects}

" error_can_not_remove_role: "This role is in use and cannot be deleted." error_can_not_reopen_issue_on_closed_version: 'An issue assigned to a closed version cannot be reopened' error_can_not_archive_project: This project cannot be archived diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb index c2d2405e3..6f62c9f0a 100644 --- a/test/functional/trackers_controller_test.rb +++ b/test/functional/trackers_controller_test.rb @@ -274,11 +274,21 @@ 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 + assert_no_difference 'Tracker.count' do - delete :destroy, :params => {:id => 1} + 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_redirected_to :action => 'index' - assert_not_nil flash[:error] end def test_get_fields