Fixes #3721 - Fields are falsey displayed as mandatory if they contain historic screen values.

This commit is contained in:
Rolf Schmidt 2021-09-03 15:16:34 +02:00 committed by Thorsten Eckel
parent b43bcc4983
commit b4e6c3d0f2
2 changed files with 31 additions and 7 deletions

View file

@ -82,16 +82,18 @@ class CoreWorkflow::Attributes
end
end
def attribute_mandatory?(attribute)
return false if @payload['request_id'] == 'ChecksCoreWorkflow.validate_workflows'
return screen_value(attribute, 'required').present? if !screen_value(attribute, 'required').nil?
return screen_value(attribute, 'null').blank? if !screen_value(attribute, 'null').nil?
false
end
# dont cache this else the result object will work with references and cache bugs occur
def mandatory_default
object_elements.each_with_object({}) do |attribute, result|
result[ attribute[:name] ] = if @payload['request_id'] == 'ChecksCoreWorkflow.validate_workflows'
false
elsif screen_value(attribute, 'required').nil?
!screen_value(attribute, 'null')
else
screen_value(attribute, 'required')
end
result[ attribute[:name] ] = attribute_mandatory?(attribute)
end
end

View file

@ -259,6 +259,28 @@ RSpec.describe CoreWorkflow, type: :model do
end
end
describe '.perform - Default - #3721 - Fields are falsey displayed as mandatory if they contain historic screen values', db_strategy: :reset do
let(:field_name) { SecureRandom.uuid }
let(:screens) do
{
create_middle: {
'ticket.agent' => {
shown: true,
},
},
}
end
before do
create(:object_manager_attribute_text, object_name: 'Ticket', name: field_name, display: field_name, screens: screens)
ObjectManager::Attribute.migration_execute
end
it 'does show the field as optional because it has no required value' do
expect(result[:mandatory][field_name]).to eq(false)
end
end
describe '.perform - Custom - Pending Time' do
it 'does not show pending time for non pending state' do
expect(result[:visibility]['pending_time']).to eq('remove')