Commit 4933c2a0 authored by jplang's avatar jplang

Don't validate custom fields that are not editable (#19193).

git-svn-id: https://svn.redmine.org/redmine/trunk@14045 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent fae69e81
......@@ -640,6 +640,17 @@ class Issue < 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 = new_record? ? author : current_journal.try(:user)
if new_record? || custom_field_values_changed?
editable_custom_field_values(user).each(&:validate_value)
end
end
# Set the done_ratio using the status if that setting is set. This will keep the done_ratios
# even if the user turns off the setting later
def update_done_ratio_from_issue_status
......
......@@ -860,6 +860,29 @@ class IssueTest < ActiveSupport::TestCase
assert issue.save
end
def test_required_custom_field_that_is_not_visible_for_the_user_should_not_be_required
CustomField.delete_all
field = IssueCustomField.generate!(:is_required => true, :visible => false, :role_ids => [1], :trackers => Tracker.all, :is_for_all => true)
user = User.generate!
User.add_to_project(user, Project.find(1), Role.find(2))
issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
:subject => 'Required fields', :author => user)
assert_save issue
end
def test_required_custom_field_that_is_visible_for_the_user_should_be_required
CustomField.delete_all
field = IssueCustomField.generate!(:is_required => true, :visible => false, :role_ids => [1], :trackers => Tracker.all, :is_for_all => true)
user = User.generate!
User.add_to_project(user, Project.find(1), Role.find(1))
issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
:subject => 'Required fields', :author => user)
assert !issue.save
assert_include "#{field.name} cannot be blank", issue.errors.full_messages
end
def test_required_attribute_names_for_multiple_roles_should_intersect_rules
WorkflowPermission.delete_all
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment