From 1a3ecd91f42a5b80f84f50ebfa947b0fffc307a9 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 15 Sep 2021 10:00:44 +0100 Subject: [PATCH] Fixes #3739 - Core Workflow: Show hidden attributes on group selection (ticket edit). --- .../_application_controller/form.coffee | 2 +- .../ticket_zoom/sidebar_ticket.coffee | 2 +- .../app/models/_application_model.coffee | 9 ++-- spec/system/ticket/zoom_spec.rb | 49 +++++++++++++++++++ 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller/form.coffee b/app/assets/javascripts/app/controllers/_application_controller/form.coffee index bcdc01a85..7102465ca 100644 --- a/app/assets/javascripts/app/controllers/_application_controller/form.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller/form.coffee @@ -92,7 +92,7 @@ class App.ControllerForm extends App.Controller if @model.attributesGet attributesClean = @model.attributesGet(@screen) else - attributesClean = App.Model.attributesGet(@screen, @model.configure_attributes) + attributesClean = App.Model.attributesGet(@screen, @model.configure_attributes, undefined, @model.className) for attributeName, attribute of attributesClean diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_ticket.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_ticket.coffee index 2b1fdfaee..5f033dd86 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_ticket.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_ticket.coffee @@ -38,7 +38,7 @@ class Edit extends App.ControllerObserver else @controllerFormSidebarTicket = new App.ControllerForm( elReplace: @el - model: { configure_attributes: @formMeta.configure_attributes || App.Ticket.configure_attributes } + model: { className: 'Ticket', configure_attributes: @formMeta.configure_attributes || App.Ticket.configure_attributes } screen: 'edit' handlersConfig: handlers filter: @formMeta.filter diff --git a/app/assets/javascripts/app/models/_application_model.coffee b/app/assets/javascripts/app/models/_application_model.coffee index e5ff9764b..78782a842 100644 --- a/app/assets/javascripts/app/models/_application_model.coffee +++ b/app/assets/javascripts/app/models/_application_model.coffee @@ -211,9 +211,12 @@ set new attributes of model (remove already available attributes) ### - @attributesGet: (screen = undefined, attributes = false, noDefaultAttributes = false) -> + @attributesGet: (screen = undefined, attributes = false, noDefaultAttributes = false, className = undefined) -> + if !className + className = @.className + if !attributes - attributes = clone(App[@.className].configure_attributes, true) + attributes = clone(App[className].configure_attributes, true) else attributes = clone(attributes, true) @@ -224,7 +227,7 @@ set new attributes of model (remove already available attributes) attributesNew = {} if screen for attribute in attributes - if attribute && attribute.screen && attribute.screen[screen] && (!_.isEmpty(attribute.screen[screen]) && (attribute.screen[screen].shown is true || attribute.screen[screen].shown is undefined || App.FormHandlerCoreWorkflow.checkScreen(@.className, screen))) + if attribute && attribute.screen && attribute.screen[screen] && (!_.isEmpty(attribute.screen[screen]) && (attribute.screen[screen].shown is true || attribute.screen[screen].shown is undefined || App.FormHandlerCoreWorkflow.checkScreen(className, screen))) for item, value of attribute.screen[screen] attribute[item] = value attributesNew[ attribute.name ] = attribute diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index 23eaa9421..0d8050cc8 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -1908,4 +1908,53 @@ RSpec.describe 'Ticket zoom', type: :system do end end end + + describe 'Core Workflow: Show hidden attributes on group selection (ticket edit) #3739', authenticated_as: :authenticate do + let!(:ticket) { create(:ticket, group: Group.find_by(name: 'Users')) } + let(:field_name) { SecureRandom.uuid } + let(:field) do + create :object_manager_attribute_text, name: field_name, display: field_name, screens: { + 'edit' => { + 'ticket.agent' => { + 'shown' => false, + 'required' => false, + } + } + } + ObjectManager::Attribute.migration_execute + end + + before do + visit "#ticket/zoom/#{ticket.id}" + end + + context 'when field visible' do + let(:workflow) do + create(:core_workflow, + object: 'Ticket', + perform: { "ticket.#{field_name}" => { 'operator' => 'show', 'show' => 'true' } }) + end + + def authenticate + field + workflow + true + end + + it 'does show up the field' do + expect(page).to have_css("div[data-attribute-name='#{field_name}']") + end + end + + context 'when field hidden' do + def authenticate + field + true + end + + it 'does not show the field' do + expect(page).to have_css("div[data-attribute-name='#{field_name}'].is-hidden", visible: :hidden) + end + end + end end