Backport r23945 from trunk to 5.1-stable (#43161).

git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@23952 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu
2025-09-07 06:39:34 +00:00
parent 3d13696dd1
commit 12f01696df
2 changed files with 26 additions and 0 deletions

View File

@@ -108,6 +108,7 @@ class Issue < ActiveRecord::Base
end)
before_validation :default_assign, on: :create
before_validation :force_default_value_on_noneditable_custom_fields, on: :create
before_validation :clear_disabled_fields
before_save :close_duplicates, :update_done_ratio_from_issue_status,
:force_updated_on_change, :update_closed_on
@@ -2074,6 +2075,20 @@ class Issue < ActiveRecord::Base
end
end
# Forcefully set the default value to any custom field values which are not
# editable by the current user when creating a new issue. This may overwrite
# existing custom values of a copied issue which are not editable by the
# current user.
def force_default_value_on_noneditable_custom_fields
return unless custom_field_values_changed?
editable_custom_field_ids = editable_custom_fields(author).map(&:id)
custom_field_values.each do |field_value|
unless editable_custom_field_ids.include?(field_value.custom_field_id)
field_value.value = field_value.custom_field.default_value
end
end
end
def filter_projects_scope(scope=nil)
case scope
when 'system'

View File

@@ -1575,6 +1575,17 @@ class IssueTest < ActiveSupport::TestCase
assert_equal 'relation', j.details[0].property
end
def test_copy_should_only_copy_editable_custom_fields
cf = CustomField.find 1
cf.roles << Role.find(1)
cf.visible = false
cf.save!
User.current = User.find(3)
issue = Issue.new.copy_from(Issue.find(3))
assert issue.save
assert_equal '', issue.custom_field_value(1)
end
def test_should_not_call_after_project_change_on_creation
issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
:subject => 'Test', :author_id => 1)