Skip to content

Commit

Permalink
Fixes #5115 - ".value" in text modules for external data sources brea…
Browse files Browse the repository at this point in the history
…ks ticket zoom
  • Loading branch information
mantas committed Apr 25, 2024
1 parent effdae6 commit dff64d2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/app/lib/app_post/utils.coffee
Expand Up @@ -880,10 +880,10 @@ class App.Utils
dataRef = objects
dataRefLast = undefined
for level in levels
if typeof dataRef is 'object' && level of dataRef
if _.isObject(dataRef) && dataRef && level of dataRef
dataRefLast = dataRef
dataRef = dataRef[level]
else if typeof dataRef is 'object' && typeof level is 'string' && matches = level.match(/(?<functionName>\w+)\((?<params>.*?)\)/)
else if _.isObject(dataRef) && typeof level is 'string' && matches = level.match(/(?<functionName>\w+)\((?<params>.*?)\)/)
dataRefLast = dataRef
{ functionName, params } = matches.groups
parameters = params.split(',').map((param) -> param.trim())
Expand Down
45 changes: 45 additions & 0 deletions spec/system/examples/text_modules_examples.rb
Expand Up @@ -194,6 +194,51 @@
end
end

context 'when text module refers external data source', authenticated_as: :authenticate, db_strategy: :reset do
let(:custom_attribute) { create(:object_manager_attribute_autocompletion_ajax_external_data_source) }
let(:text_module_external) do
create(:text_module,
name: 'external data source',
content: "external \#{ticket.#{custom_attribute.name}.value}")
end

def authenticate
text_module_external
custom_attribute
ObjectManager::Attribute.migration_execute
true
end

context 'when ticket external field value is not set' do
it 'inserts text module with placeholder' do
visit path
within(:active_content) do
find(:richtext).send_keys('::ext')
page.send_keys(:enter)
expect(find(:richtext)).to have_text 'external -'
end
end
end

if path.starts_with? '#ticket/zoom'
context 'when ticket external field value is set' do
before do
ticket.reload[custom_attribute.name] = { value: 'aaa', label: 'AAA' }
ticket.save!
end

it 'inserts text module with external value' do
visit path
within(:active_content) do
find(:richtext).send_keys('::ext')
page.send_keys(:enter)
expect(find(:richtext)).to have_text 'external aaa'
end
end
end
end
end

context 'when Group restriction for text modules not working on ticket creation (specific scenario only) #4358', authenticated_as: :authenticate do
let(:agent) { create(:agent, groups: [group1]) }

Expand Down

0 comments on commit dff64d2

Please sign in to comment.