]> source.dussan.org Git - redmine.git/commitdiff
Merged r21488 and r21489 to 4.2-stable (#36593).
authorMarius Balteanu <marius.balteanu@zitec.com>
Tue, 22 Mar 2022 06:52:09 +0000 (06:52 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Tue, 22 Mar 2022 06:52:09 +0000 (06:52 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@21491 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/unit/project_test.rb

index 2845db2350ee41dd25587aa224204f9690dc4918..2d2ff57481b678da758d14450d6c769107e9e492 100644 (file)
@@ -968,6 +968,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)
index 63f1e01b7c2dbfd9f1f9e0d0bd060058fe02d6a2..10d55b9990c59bb8301b0c8244d9090b5e6c65fd 100644 (file)
@@ -348,6 +348,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)