mirror of
https://github.com/redmine/redmine.git
synced 2026-02-01 04:09:56 +01:00
Clear non-editable custom fields when creating an issue (43161).
This ensures that only editable custom fields are saved on a new issue when copying an existing one. Patch by Holger Just (user:hjust). git-svn-id: https://svn.redmine.org/redmine/trunk@23945 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -22,6 +22,7 @@ class Issue < ApplicationRecord
|
||||
include Redmine::Utils::DateCalculation
|
||||
include Redmine::I18n
|
||||
before_validation :default_assign, on: :create
|
||||
before_validation :force_default_value_on_noneditable_custom_fields, on: :create
|
||||
before_validation :clear_disabled_fields
|
||||
before_save :set_parent_id
|
||||
include Redmine::NestedSet::IssueNestedSet
|
||||
@@ -2100,6 +2101,21 @@ class Issue < ApplicationRecord
|
||||
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'
|
||||
|
||||
@@ -1575,6 +1575,19 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user