Browse Source

Fixes #5178 - Mail::AddressList can not parse error when S/MIME or PGP integration is active

Martin Edenhofer 9 months ago
parent
commit
e8eb395879

+ 12 - 4
app/assets/javascripts/app/controllers/agent_ticket_create.coffee

@@ -616,10 +616,18 @@ class App.TicketCreate extends App.Controller
     # to replace in text modules properly
     params.customer = App.User.find(params.customer_id) || {}
 
-    # show selected user display name in customer attribute in UI
-    if _.isEmpty(@el.find('input[name=customer_id_completion]').val())
-      if params.customer && params.customer.displayName
-        @el.find('input[name=customer_id_completion]').val(params.customer.displayName())
+    # if customer is given in params (e. g. from CTI integration) show selected customer
+    # display name with email address (if exists) in customer attribute in UI
+    fillCompletionIfRequiredCallback = =>
+      return if !_.isEmpty(@el.find('input[name=customer_id_completion]').val())
+      return if !params.customer
+      return if !params.customer.displayName
+      completion = params.customer.displayName()
+      if params.customer.email
+        completion = App.Utils.buildEmailAddress(params.customer.displayName(), params.customer.email)
+      return if !completion
+      @el.find('input[name=customer_id_completion]').val(completion)
+    @delay(fillCompletionIfRequiredCallback, 10)
 
     @sidebarWidget.render(params)
     @textModule.reload(

+ 1 - 1
spec/system/cti_spec.rb

@@ -112,7 +112,7 @@ RSpec.describe 'Caller log', authenticated_as: :authenticate, type: :system do
           expect(page).to have_css('input[name="title"][value="Call from 0190333"]', visible: :all)
           expect(page).to have_css('.tabsSidebar-tab[data-tab="customer"]', visible: :all)
           expect(page).to have_css("input[name=customer_id][value='#{customer.id}']", visible: :hide)
-          expect(find('[name=customer_id_completion]').value).to eq customer.fullname
+          expect(find('[name=customer_id_completion]').value).to eq "#{customer.fullname} <#{customer.email}>"
         end
       end
     end

+ 46 - 21
spec/system/ticket/create/secure_mailing_spec.rb

@@ -374,38 +374,63 @@ RSpec.describe 'Ticket create > Secure mailing', authenticated_as: :authenticate
         create(:smime_certificate, fixture: recipient_email_address)
       end
 
-      it_behaves_like 'showing security type switcher'
+      shared_examples 'switching between security types' do
+        it 'switches between security types' do
+          within(:active_content) do
 
-      it 'switches between security types' do
-        visit 'ticket/create'
+            click '.btn', text: 'PGP'
 
-        within(:active_content) do
-          use_template(template)
+            # Wait until the security options check AJAX call is ready.
+            expect(page).to have_css('div.js-securityEncrypt.btn--active')
+            expect(page).to have_css('div.js-securitySign.btn--active')
 
-          click '.btn', text: 'PGP'
+            expect(page).to have_css('.btn.btn--active', text: 'PGP')
+            expect(page).to have_no_css('.btn.btn--active', text: 'S/MIME')
 
-          # Wait until the security options check AJAX call is ready.
-          expect(page).to have_css('div.js-securityEncrypt.btn--active')
-          expect(page).to have_css('div.js-securitySign.btn--active')
+            expect(find('.js-securityEncryptComment')['title']).to eq('The PGP keys for pgp+smime-recipient@example.com were found.')
+            expect(find('.js-securitySignComment')['title']).to eq('The PGP key for pgp+smime-sender@example.com was found.')
 
-          expect(page).to have_css('.btn.btn--active', text: 'PGP')
-          expect(page).to have_no_css('.btn.btn--active', text: 'S/MIME')
+            click '.btn', text: 'S/MIME'
 
-          expect(find('.js-securityEncryptComment')['title']).to eq('The PGP keys for pgp+smime-recipient@example.com were found.')
-          expect(find('.js-securitySignComment')['title']).to eq('The PGP key for pgp+smime-sender@example.com was found.')
+            # Wait until the security options check AJAX call is ready.
+            expect(page).to have_css('div.js-securityEncrypt.btn--active')
+            expect(page).to have_css('div.js-securitySign.btn--active')
 
-          click '.btn', text: 'S/MIME'
+            expect(page).to have_no_css('.btn.btn--active', text: 'PGP')
+            expect(page).to have_css('.btn.btn--active', text: 'S/MIME')
 
-          # Wait until the security options check AJAX call is ready.
-          expect(page).to have_css('div.js-securityEncrypt.btn--active')
-          expect(page).to have_css('div.js-securitySign.btn--active')
+            expect(find('.js-securityEncryptComment')['title']).to eq('The certificates for pgp+smime-recipient@example.com were found.')
+            expect(find('.js-securitySignComment')['title']).to eq('The certificate for pgp+smime-sender@example.com was found.')
+          end
+        end
+      end
+
+      it_behaves_like 'showing security type switcher'
 
-          expect(page).to have_no_css('.btn.btn--active', text: 'PGP')
-          expect(page).to have_css('.btn.btn--active', text: 'S/MIME')
+      context 'when customer selection is based on template' do
+        before do
+          visit 'ticket/create'
 
-          expect(find('.js-securityEncryptComment')['title']).to eq('The certificates for pgp+smime-recipient@example.com were found.')
-          expect(find('.js-securitySignComment')['title']).to eq('The certificate for pgp+smime-sender@example.com was found.')
+          within(:active_content) do
+            use_template(template)
+          end
+        end
+
+        it_behaves_like 'switching between security types'
+      end
+
+      context 'when customer selection is based on manual selection' do
+        before do
+          visit 'ticket/create'
+
+          within(:active_content) do
+            click '.tab', text: 'Send Email'
+            find('[name=customer_id_completion]').fill_in with: customer.firstname
+            find("li.recipientList-entry.js-object[data-object-id='#{customer.id}']").click
+          end
         end
+
+        it_behaves_like 'switching between security types'
       end
     end
   end