Browse Source

Fixes #4771 - Use of first & last name variables in text modules returns -- in ticket.

Co-authored-by: Florian Liebe <fl@zammad.com>
Rolf Schmidt 1 year ago
parent
commit
cdd6b3c99e

+ 7 - 6
app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee

@@ -244,7 +244,8 @@ class App.TicketZoomArticleNew extends App.Controller
 
     # show text module UI
     if ticket.currentView() is 'agent'
-      textModule = new App.WidgetTextModule(
+      @textModule?.releaseController()
+      @textModule = new App.WidgetTextModule(
         el: @$('.js-textarea').parent()
         data:
           ticket: ticket
@@ -252,12 +253,12 @@ class App.TicketZoomArticleNew extends App.Controller
           config: App.Config.all()
         taskKey: @taskKey
       )
-      callback = (ticket) ->
-        textModule.reload(
-          ticket: ticket
-          user: App.Session.get()
-        )
       if !@subscribeIdTextModule
+        callback = (ticket) =>
+          @textModule.reload(
+            ticket: ticket
+            user: App.Session.get()
+          )
         @subscribeIdTextModule = ticket.subscribe(callback)
 
     if _.isArray(@attachments)

+ 39 - 0
spec/system/ticket/update_spec.rb

@@ -309,6 +309,45 @@ RSpec.describe 'Ticket Update', type: :system do
 
   context 'when using text modules' do
     include_examples 'text modules', path: "#ticket/zoom/#{Ticket.first.id}"
+
+    context 'when owner is used in a text module and was updated in the ticket', authenticated_as: :authenticate do
+      let(:user)         { User.find_by(email: 'agent1@example.com') }
+      let(:another_user) { create(:agent, groups: [Group.find_by(name: 'Users')]) }
+      let(:ticket)       { create(:ticket, group: group, owner: user) }
+      let(:text_module)  { create(:text_module, name: 'firstlast', keywords: 'firstlast', content: '#{ticket.owner.firstname} #{ticket.owner.lastname}') } # rubocop:disable Lint/InterpolationCheck
+
+      def authenticate
+        ticket && text_module && another_user
+
+        true
+      end
+
+      def select_text_module
+        find(:richtext).send_keys(':')
+        find(:richtext).send_keys(':')
+        find(:richtext).send_keys('firstlast')
+        expect(page).to have_selector(:text_module, text_module.id)
+        find(:richtext).send_keys(:enter)
+      end
+
+      it 'updates used data' do
+        visit "#ticket/zoom/#{ticket.id}"
+
+        expect(page).to have_field('owner_id', with: user.id)
+
+        within(:active_content) do
+          select_text_module
+          expect(find(:richtext).text).to include("#{user.firstname} #{user.lastname}")
+
+          select another_user.fullname, from: 'Owner'
+          find('.js-submit').click
+          expect(ticket.reload.owner_id).to eq(another_user.id)
+
+          select_text_module
+          expect(find(:richtext).text).to include("#{another_user.firstname} #{another_user.lastname}")
+        end
+      end
+    end
   end
 
   context 'when using macros' do