From: Go MAEDA Date: Fri, 14 Apr 2023 01:05:02 +0000 (+0000) Subject: Ability to disable the priority field (#38416). X-Git-Tag: 5.1.0~176 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=55408c480b64f1af10aaf6e264b214d9d757cb84;p=redmine.git Ability to disable the priority field (#38416). Patch by Go MAEDA. git-svn-id: https://svn.redmine.org/redmine/trunk@22185 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/issue.rb b/app/models/issue.rb index f267f3f48..d6d6c7c8b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 diff --git a/app/models/tracker.rb b/app/models/tracker.rb index da39ae934..ce476092d 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -20,11 +20,11 @@ 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 diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index c7cd5689c..6f0a0a984 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -47,8 +47,10 @@
<%= 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 diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb index 24bd3bff3..218397ca5 100644 --- a/test/functional/trackers_controller_test.rb +++ b/test/functional/trackers_controller_test.rb @@ -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 diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 08bc50df8..188230022 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -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|