]> source.dussan.org Git - redmine.git/commitdiff
Ability to disable the priority field (#38416).
authorGo MAEDA <maeda@farend.jp>
Fri, 14 Apr 2023 01:05:02 +0000 (01:05 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 14 Apr 2023 01:05:02 +0000 (01:05 +0000)
Patch by Go MAEDA.

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

app/models/issue.rb
app/models/tracker.rb
app/views/issues/show.html.erb
test/functional/trackers_controller_test.rb
test/unit/issue_test.rb

index f267f3f4807aae1a117d1f47682c6c8e65c61a23..d6d6c7c8b2430f05189af12cc5ebf7de82c198e2 100644 (file)
@@ -2050,6 +2050,7 @@ class Issue < ActiveRecord::Base
       tracker.disabled_core_fields.each do |attribute|
         send "#{attribute}=", nil
       end
+      self.priority_id ||= IssuePriority.default&.id || IssuePriority.active.first.id
       self.done_ratio ||= 0
     end
   end
index da39ae934ee9e2503759ce23f55c12ebc746aee2..ce476092d8177596813bf52bfba06a6b4ddcf825 100644 (file)
 class Tracker < ActiveRecord::Base
   include Redmine::SafeAttributes
 
-  CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject priority_id is_private).freeze
+  CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject is_private).freeze
   # Fields that can be disabled
   # Other (future) fields should be appended, not inserted!
   CORE_FIELDS =
-    %w(assigned_to_id category_id fixed_version_id parent_issue_id
+    %w(priority_id assigned_to_id category_id fixed_version_id parent_issue_id
        start_date due_date estimated_hours done_ratio description).freeze
   CORE_FIELDS_ALL = (CORE_FIELDS_UNDISABLABLE + CORE_FIELDS).freeze
 
index c7cd5689c7067c76b8b44e1a6a92de3de00a8c0e..6f0a0a98498cadb9c16ed169e7eebf4c34aaccf5 100644 (file)
 <div class="attributes">
 <%= issue_fields_rows do |rows|
   rows.left l(:field_status), @issue.status.name, :class => 'status'
-  rows.left l(:field_priority), @issue.priority.name, :class => 'priority'
 
+  unless @issue.disabled_core_fields.include?('priority_id')
+    rows.left l(:field_priority), @issue.priority.name, :class => 'priority'
+  end
   unless @issue.disabled_core_fields.include?('assigned_to_id')
     rows.left l(:field_assigned_to), (@issue.assigned_to ? link_to_principal(@issue.assigned_to) : "-"), :class => 'assigned-to'
   end
index 24bd3bff3d560ff17a6de650278202ce06309cd0..218397ca5d160dd9bf2a6dbac2550a810ab345c6 100644 (file)
@@ -209,6 +209,9 @@ class TrackersControllerTest < Redmine::ControllerTest
     assert_select 'input[name=?][value=category_id]', 'tracker[core_fields][]'
     assert_select 'input[name=?][value=category_id][checked=checked]', 'tracker[core_fields][]', 0
 
+    assert_select 'input[name=?][value=priority_id]', 'tracker[core_fields][]'
+    assert_select 'input[name=?][value=priority_id][checked=checked]', 'tracker[core_fields][]', 0
+
     assert_select 'input[name=?][value=""][type=hidden]', 'tracker[core_fields][]'
   end
 
index 08bc50df86fd47ef4dea7d8407b29263be2ccc8a..1882300227b1af3d56ebfc5f696e210763965907 100644 (file)
@@ -83,6 +83,16 @@ class IssueTest < ActiveSupport::TestCase
     assert_save issue
   end
 
+  def test_default_priority_should_be_set_when_priority_field_is_disabled
+    tracker = Tracker.find(1)
+    tracker.core_fields = tracker.core_fields - ['priority_id']
+    tracker.save!
+
+    issue = Issue.new(:project_id => 1, :tracker_id => tracker.id, :author_id => 1, :subject => 'priority_id is disabled')
+    issue.save!
+    assert_equal IssuePriority.default, issue.priority
+  end
+
   def test_start_date_format_should_be_validated
     set_language_if_valid 'en'
     ['2012', 'ABC', '2012-15-20'].each do |invalid_date|