From b51ae211b306c8d5820da299b2248f0ec5d70fe2 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Tue, 21 Sep 2021 09:22:13 +0100 Subject: [PATCH] Fixes #3752 - Core Workflow "is not" operator is working unexpected. --- app/models/core_workflow/condition/is_not.rb | 6 ++-- spec/models/core_workflow_spec.rb | 30 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/models/core_workflow/condition/is_not.rb b/app/models/core_workflow/condition/is_not.rb index b13b16d7b..ca67f863c 100644 --- a/app/models/core_workflow/condition/is_not.rb +++ b/app/models/core_workflow/condition/is_not.rb @@ -4,11 +4,11 @@ class CoreWorkflow::Condition::IsNot < CoreWorkflow::Condition::Backend def match return true if value.blank? - result = false + result = true value.each do |current_value| - next if condition_value.include?(current_value) + next if condition_value.exclude?(current_value) - result = true + result = false break end diff --git a/spec/models/core_workflow_spec.rb b/spec/models/core_workflow_spec.rb index 03668a83d..08baa6699 100644 --- a/spec/models/core_workflow_spec.rb +++ b/spec/models/core_workflow_spec.rb @@ -1603,4 +1603,34 @@ RSpec.describe CoreWorkflow, type: :model do 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