From d2fd7e489a5a4127a2fe85879b9253932642fa3f Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Sun, 1 Feb 2026 21:18:18 +0900 Subject: [PATCH] Make adding notes to closed issues configurable per tracker --- app/models/issue.rb | 6 +++++ app/models/tracker.rb | 1 + app/views/issues/_edit.html.erb | 4 +--- app/views/trackers/_form.html.erb | 1 + config/locales/en.yml | 1 + ...add_notes_allowed_on_closed_to_trackers.rb | 5 ++++ test/unit/issue_test.rb | 23 +++++++++++++++++++ test/unit/mail_handler_test.rb | 9 ++++++++ 8 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20260201094039_add_notes_allowed_on_closed_to_trackers.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index 1379f6276..deca1efa8 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -222,6 +222,12 @@ class Issue < ApplicationRecord # Returns true if user or current user is allowed to add notes to the issue def notes_addable?(user=User.current) + return false unless tracker + + # Adding notes on closed issues can be restricted per tracker settings + is_closed_without_transition = closed? && !closing? && !reopening? + return false if !tracker.notes_allowed_on_closed? && is_closed_without_transition + user_tracker_permission?(user, :add_issue_notes) end diff --git a/app/models/tracker.rb b/app/models/tracker.rb index f693d15f5..471ef56f4 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -74,6 +74,7 @@ class Tracker < ApplicationRecord 'name', 'default_status_id', 'is_in_roadmap', + 'notes_allowed_on_closed', 'core_fields', 'position', 'custom_field_ids', diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb index a1839636d..f34bcfe9d 100644 --- a/app/views/issues/_edit.html.erb +++ b/app/views/issues/_edit.html.erb @@ -27,8 +27,7 @@ <% end %> <% end %> - <% if @issue.notes_addable? %> -
<%= l(:field_notes) %> +
<%= l(:field_notes) %> <%= f.textarea :notes, :cols => 60, :rows => 10, :class => 'wiki-edit', :data => { :auto_complete => true @@ -42,7 +41,6 @@ <%= call_hook(:view_issues_edit_notes_bottom, { :issue => @issue, :notes => @notes, :form => f }) %>
- <% end %> <% if !@issue.attributes_editable? && User.current.allowed_to?(:add_issue_watchers, @issue.project) %> <%= update_data_sources_for_auto_complete({users: watchers_autocomplete_for_mention_path(project_id: @issue.project, q: '', object_type: 'issue', object_id: @issue.id)}) %> diff --git a/app/views/trackers/_form.html.erb b/app/views/trackers/_form.html.erb index 33e9452e5..d99e14549 100644 --- a/app/views/trackers/_form.html.erb +++ b/app/views/trackers/_form.html.erb @@ -11,6 +11,7 @@ :required => true %>

<%= f.check_box :is_in_roadmap %>

+

<%= f.check_box :notes_allowed_on_closed %>

<%= f.textarea :description, :rows => 4 %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index e99f01f74..068feed20 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -429,6 +429,7 @@ en: field_last_activity_date: Last activity field_thousands_delimiter: Thousands delimiter field_ratio_interval: Ratio interval + field_notes_allowed_on_closed: Allow notes on closed issues setting_app_title: Application title setting_welcome_text: Welcome text diff --git a/db/migrate/20260201094039_add_notes_allowed_on_closed_to_trackers.rb b/db/migrate/20260201094039_add_notes_allowed_on_closed_to_trackers.rb new file mode 100644 index 000000000..210e7f720 --- /dev/null +++ b/db/migrate/20260201094039_add_notes_allowed_on_closed_to_trackers.rb @@ -0,0 +1,5 @@ +class AddNotesAllowedOnClosedToTrackers < ActiveRecord::Migration[6.1] + def change + add_column :trackers, :notes_allowed_on_closed, :boolean, default: true, null: false + end +end diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index e5cd79ade..c5e53cc2a 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -953,6 +953,29 @@ class IssueTest < ActiveSupport::TestCase assert_equal '', issue.notes end + def test_should_not_allow_notes_on_closed_issue_when_tracker_disallows + tracker = Tracker.find(1) + tracker.update!(notes_allowed_on_closed: false) + + issue = Issue.find(8) + user = User.find(2) + issue.init_journal(user) + issue.send :safe_attributes=, {'notes' => 'note'}, user + assert_equal '', issue.notes + end + + def test_should_allow_notes_on_closed_issue_when_reopening + tracker = Tracker.find(1) + tracker.update!(notes_allowed_on_closed: false) + + issue = Issue.find(8) + issue.status_id = 1 + user = User.find(2) + issue.init_journal(user) + issue.send :safe_attributes=, {'notes' => 'note'}, user + assert_equal 'note', issue.notes + end + def test_safe_attributes_should_accept_target_tracker_enabled_fields source = Tracker.find(1) source.core_fields = [] diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 373819be9..b7ae0b12a 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -972,6 +972,15 @@ class MailHandlerTest < ActiveSupport::TestCase assert !journal.notes.match(/^Start Date:/i) end + def test_update_issue_should_not_allow_notes_on_closed_issue_when_tracker_disallows + issue = Issue.find(2) + issue.update!(status: IssueStatus.find_by(:is_closed => true)) + issue.tracker.update!(notes_allowed_on_closed: false) + assert_no_difference 'Journal.count' do + submit_email('ticket_reply.eml') + end + end + def test_update_issue_with_attachment assert_difference 'Journal.count' do assert_difference 'JournalDetail.count' do -- 2.50.1