From ffa8814d0243e2365b982edcb19acbd10cb2f249 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Mon, 4 Oct 2021 15:47:30 +0200 Subject: [PATCH] Fixes #3779 - Core Workflow: Add organization condition attributes for object User. --- .../core_workflow_condition.coffee | 2 +- spec/models/core_workflow_spec.rb | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/core_workflow_condition.coffee b/app/assets/javascripts/app/controllers/_ui_element/core_workflow_condition.coffee index 10634e7a4..6cedd5b90 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/core_workflow_condition.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/core_workflow_condition.coffee @@ -23,7 +23,7 @@ class App.UiElement.core_workflow_condition extends App.UiElement.ApplicationSel organization: name: 'Organization' model: 'Organization' - model_show: ['Organization'] + model_show: ['User', 'Organization'] 'customer.organization': name: 'Organization' model: 'Organization' diff --git a/spec/models/core_workflow_spec.rb b/spec/models/core_workflow_spec.rb index 92c94f933..a98241f7a 100644 --- a/spec/models/core_workflow_spec.rb +++ b/spec/models/core_workflow_spec.rb @@ -1678,4 +1678,43 @@ RSpec.describe CoreWorkflow, type: :model do end end end + + describe 'Core Workflow: Add organization condition attributes for object User #3779' do + let(:organization) { create(:organization, note: 'hello') } + let!(:base_payload) do + { + 'event' => 'core_workflow', + 'request_id' => 'default', + 'class_name' => 'User', + 'screen' => 'create', + 'params' => {}, + } + end + let!(:workflow) do + create(:core_workflow, + object: 'User', + condition_selected: { + 'organization.note': { + operator: 'is', + value: 'hello', + }, + }) + end + + context 'when new user has no organization' do + it 'does not match the workflow' do + expect(result[:matched_workflows]).not_to include(workflow.id) + end + end + + context 'when new user is part of the organization' do + let(:payload) do + base_payload.merge('params' => { 'organization_id' => organization.id.to_s }) + end + + it 'does match the workflow' do + expect(result[:matched_workflows]).to include(workflow.id) + end + end + end end