]> source.dussan.org Git - redmine.git/commitdiff
Skip validation of required custom fields when creating a project if user does not...
authorMarius Balteanu <marius.balteanu@zitec.com>
Mon, 21 Mar 2022 22:13:19 +0000 (22:13 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Mon, 21 Mar 2022 22:13:19 +0000 (22:13 +0000)
Patch by mathieu-mbru.

git-svn-id: https://svn.redmine.org/redmine/trunk@21488 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
app/views/boards/new.html.erb
test/unit/project_test.rb

index 90ef0e2e95060e910872a8a4a6457e1964320708..7ba9b41973a1f819ed114d66f230e8da870abd41 100644 (file)
@@ -963,6 +963,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 acdf43fcfaeeeb30e4cca7a4fd69fd61e7f5c115..bf11bd146679e8709733ea6b9c45ea255a31c879 100644 (file)
@@ -1,6 +1,6 @@
-<h2><%= l(:label_board_new) %></h2>
+<%# <h2><%= l(:label_board_new) %></h2>
 
 <%= labelled_form_for @board, :url => project_boards_path(@project) do |f| %>
   <%= render :partial => 'form', :locals => {:f => f} %>
   <%= submit_tag l(:button_create) %>
-<% end %>
+<% end %> %>
index cf457a48c841bdadf41fcf91376d2a5816c67fac..bf77b623521fb725f5b58a6013cf0851d501e9b7 100644 (file)
@@ -358,6 +358,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)