diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2022-03-22 06:52:50 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2022-03-22 06:52:50 +0000 |
commit | eaa858265199c649bb4aa9c104275ea201b19e8d (patch) | |
tree | 193cc19dfece5fe5144f297e32365a153cd3cbbb | |
parent | ad308fbff751a2cc9a1268aa77ffeecd30f718cb (diff) | |
download | redmine-eaa858265199c649bb4aa9c104275ea201b19e8d.tar.gz redmine-eaa858265199c649bb4aa9c104275ea201b19e8d.zip |
Merged r21488 and r21489 to 4.1-stable (#36593).
git-svn-id: https://svn.redmine.org/redmine/branches/4.1-stable@21492 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/project.rb | 11 | ||||
-rw-r--r-- | test/unit/project_test.rb | 7 |
2 files changed, 18 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index d4af06ca1..4b9812ba4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -883,6 +883,17 @@ class Project < ActiveRecord::Base end end + # Overrides Redmine::Acts::Customizable::InstanceMethods#validate_custom_field_values + # so that custom values that are not editable are not validated (eg. a custom field that + # is marked as required should not trigger a validation error if the user is not allowed + # to edit this field). + def validate_custom_field_values + user = User.current + if new_record? || custom_field_values_changed? + editable_custom_field_values(user).each(&:validate_value) + end + end + # Returns the custom_field_values that can be edited by the given user def editable_custom_field_values(user=nil) visible_custom_field_values(user) diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index de4b632e8..af577e40c 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -344,6 +344,13 @@ class ProjectTest < ActiveSupport::TestCase assert_equal parent.children.sort_by(&:name), parent.children.to_a end + def test_validate_custom_field_values_of_project + User.current = User.find(3) + ProjectCustomField.generate!(:name => 'CustomFieldTest', :field_format => 'int', :is_required => true, :visible => false, :role_ids => [1]) + p = Project.new(:name => 'Project test', :identifier => 'project-t') + assert p.save! + end + def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy # Parent issue with a hierarchy project's fixed version parent_issue = Issue.find(1) |