]> source.dussan.org Git - redmine.git/commitdiff
Improve tracker deletion error message to display projects containing issues under...
authorGo MAEDA <maeda@farend.jp>
Sun, 3 Nov 2024 07:11:07 +0000 (07:11 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 3 Nov 2024 07:11:07 +0000 (07:11 +0000)
Patch by Go MAEDA (user:maeda).

git-svn-id: https://svn.redmine.org/redmine/trunk@23181 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/trackers_controller.rb
config/locales/en.yml
test/functional/trackers_controller_test.rb

index c1415bc2c5dc4d59ccdef693785ebd3a528ba075..824ce93ef945a3e4909c9e7dfa4baa69193839fd 100644 (file)
@@ -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
index 200bdcdfc5c922d632e9fbffb19d2718de3f80fa..cea117d0961cb6c11db30e300c07f65685288ec3 100644 (file)
@@ -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.<p>The following projects have issues with this tracker:<br>%{projects}</p>"
   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
index c2d2405e34cfe89d035cab6850ade91c52ccdfb4..6f62c9f0aad5695cdd3e45393750ffabff748f78 100644 (file)
@@ -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