Fixes #3752 - Core Workflow "is not" operator is working unexpected.

This commit is contained in:
Rolf Schmidt 2021-09-21 09:22:13 +01:00
parent 3be8f6d032
commit b51ae211b3
2 changed files with 33 additions and 3 deletions

View file

@ -4,11 +4,11 @@ class CoreWorkflow::Condition::IsNot < CoreWorkflow::Condition::Backend
def match def match
return true if value.blank? return true if value.blank?
result = false result = true
value.each do |current_value| value.each do |current_value|
next if condition_value.include?(current_value) next if condition_value.exclude?(current_value)
result = true result = false
break break
end end

View file

@ -1603,4 +1603,34 @@ RSpec.describe CoreWorkflow, type: :model do
end end
end end
end end
describe 'Core Workflow "is not" operator is working unexpected #3752' do
let(:approval_role) { create(:role) }
let!(:workflow) do
create(:core_workflow,
object: 'Ticket',
condition_selected: {
'session.role_ids': {
operator: 'is_not',
value: [ approval_role.id.to_s ]
},
})
end
context 'when not action user has approval role' do
let(:action_user) { create(:agent, roles: [Role.find_by(name: 'Agent'), approval_role]) }
it 'does not match' do
expect(result[:matched_workflows]).not_to include(workflow.id)
end
end
context 'when action user has not approval role' do
let(:action_user) { create(:agent) }
it 'does match' do
expect(result[:matched_workflows]).to include(workflow.id)
end
end
end
end end