Project

General

Profile

Feature #38416 » ability-to-disable-priority_id.patch

Go MAEDA, 2023-04-06 10:39

View differences:

app/models/issue.rb
2050 2050
      tracker.disabled_core_fields.each do |attribute|
2051 2051
        send "#{attribute}=", nil
2052 2052
      end
2053
      self.priority_id ||= IssuePriority.default&.id || IssuePriority.active.first.id
2053 2054
      self.done_ratio ||= 0
2054 2055
    end
2055 2056
  end
app/models/tracker.rb
20 20
class Tracker < ActiveRecord::Base
21 21
  include Redmine::SafeAttributes
22 22

  
23
  CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject priority_id is_private).freeze
23
  CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject is_private).freeze
24 24
  # Fields that can be disabled
25 25
  # Other (future) fields should be appended, not inserted!
26 26
  CORE_FIELDS =
27
    %w(assigned_to_id category_id fixed_version_id parent_issue_id
27
    %w(priority_id assigned_to_id category_id fixed_version_id parent_issue_id
28 28
       start_date due_date estimated_hours done_ratio description).freeze
29 29
  CORE_FIELDS_ALL = (CORE_FIELDS_UNDISABLABLE + CORE_FIELDS).freeze
30 30

  
app/views/issues/show.html.erb
47 47
<div class="attributes">
48 48
<%= issue_fields_rows do |rows|
49 49
  rows.left l(:field_status), @issue.status.name, :class => 'status'
50
  rows.left l(:field_priority), @issue.priority.name, :class => 'priority'
51 50

  
51
  unless @issue.disabled_core_fields.include?('priority_id')
52
    rows.left l(:field_priority), @issue.priority.name, :class => 'priority'
53
  end
52 54
  unless @issue.disabled_core_fields.include?('assigned_to_id')
53 55
    rows.left l(:field_assigned_to), (@issue.assigned_to ? link_to_principal(@issue.assigned_to) : "-"), :class => 'assigned-to'
54 56
  end
test/functional/trackers_controller_test.rb
209 209
    assert_select 'input[name=?][value=category_id]', 'tracker[core_fields][]'
210 210
    assert_select 'input[name=?][value=category_id][checked=checked]', 'tracker[core_fields][]', 0
211 211

  
212
    assert_select 'input[name=?][value=priority_id]', 'tracker[core_fields][]'
213
    assert_select 'input[name=?][value=priority_id][checked=checked]', 'tracker[core_fields][]', 0
214

  
212 215
    assert_select 'input[name=?][value=""][type=hidden]', 'tracker[core_fields][]'
213 216
  end
214 217

  
test/unit/issue_test.rb
83 83
    assert_save issue
84 84
  end
85 85

  
86
  def test_default_priority_should_be_set_when_priority_field_is_disabled
87
    tracker = Tracker.find(1)
88
    tracker.core_fields = tracker.core_fields - ['priority_id']
89
    tracker.save!
90

  
91
    issue = Issue.new(:project_id => 1, :tracker_id => tracker.id, :author_id => 1, :subject => 'priority_id is disabled')
92
    issue.save!
93
    assert_equal IssuePriority.default, issue.priority
94
  end
95

  
86 96
  def test_start_date_format_should_be_validated
87 97
    set_language_if_valid 'en'
88 98
    ['2012', 'ABC', '2012-15-20'].each do |invalid_date|
(1-1/2)