Просмотр исходного кода

Fixes #4421 - CC field cannot be customized in the new ticket templates.

Dusan Vuckovic 2 лет назад
Родитель
Сommit
070561bbba

+ 7 - 7
app/assets/javascripts/app/controllers/_ui_element/_application_action.coffee

@@ -16,9 +16,9 @@ UI Element options:
 
 - Allows pre conditions like current_user.id or user session specific values (default: true)
 
-**attribute.article_body_only**
+**attribute.article_body_cc_only**
 
-- Renders only article body text attribute (default: false)
+- Renders only article body and cc attributes (default: false)
 
 **attribute.no_dates**
 
@@ -52,7 +52,7 @@ class App.UiElement.ApplicationAction
         model: 'Ticket'
       article:
         name: __('Article')
-        model: if attribute.article_body_only then 'TicketArticle' else 'Article'
+        model: if attribute.article_body_cc_only then 'TicketArticle' else 'Article'
 
     if attribute.notification
       groups.notification =
@@ -73,10 +73,10 @@ class App.UiElement.ApplicationAction
 
         for row in App[groupMeta.model].configure_attributes
 
-          # ignore all article attributes except body
-          if attribute.article_body_only
+          # ignore all article attributes except body and cc
+          if attribute.article_body_cc_only
             if groupMeta.model is 'TicketArticle'
-              if row.name isnt 'body'
+              if row.name isnt 'body' and row.name isnt 'cc'
                 continue
 
           # ignore all date and datetime attributes
@@ -265,7 +265,7 @@ class App.UiElement.ApplicationAction
       elementRow.find('.js-setAttribute').html('').addClass('hide')
       elementRow.find('.js-setArticle').html('').addClass('hide')
       @buildNotificationArea(notificationType, elementFull, elementRow, groupAndAttribute, elements, meta, attribute)
-    else if !attribute.article_body_only && _.isArray(articleTypeMatch) && articleType = articleTypeMatch[1]
+    else if !attribute.article_body_cc_only && _.isArray(articleTypeMatch) && articleType = articleTypeMatch[1]
       elementRow.find('.js-setAttribute').html('').addClass('hide')
       elementRow.find('.js-setNotification').html('').addClass('hide')
       @buildArticleArea(articleType, elementFull, elementRow, groupAndAttribute, elements, meta, attribute)

+ 1 - 1
app/assets/javascripts/app/models/template.coffee

@@ -4,7 +4,7 @@ class App.Template extends App.Model
   @url: @apiPath + '/templates'
   @configure_attributes = [
     { name: 'name',        display: __('Name'),     tag: 'input', type: 'text', limit: 100, null: false },
-    { name: 'options',     display: __('Actions'),  tag: 'ticket_perform_action', user_action: false, article_body_only: true, no_richtext_uploads: true, sender_type: true, skip_unknown_attributes: true, null: true },
+    { name: 'options',     display: __('Actions'),  tag: 'ticket_perform_action', user_action: false, article_body_cc_only: true, no_richtext_uploads: true, sender_type: true, skip_unknown_attributes: true, null: true },
     { name: 'updated_at',  display: __('Updated'),  tag: 'datetime', readonly: 1 },
     { name: 'active',      display: __('Active'),   tag: 'active', default: true },
   ]

+ 2 - 1
public/assets/tests/qunit/form_ticket_perform_action.js

@@ -736,7 +736,7 @@ QUnit.test( "ticket_perform_action check template attributes", assert => {
           display:                   'TicketPerformAction8',
           tag:                       'ticket_perform_action',
           user_action:               false,
-          article_body_only:         true,
+          article_body_cc_only:      true,
           sender_type:               true,
           no_richtext_uploads:       true,
           skip_unknown_attributes:   true,
@@ -764,6 +764,7 @@ QUnit.test( "ticket_perform_action check template attributes", assert => {
   var options = select.find('option').map((index, option) => option.value).toArray().sort()
   var test_options = [
     'article.body',
+    'article.cc',
     'ticket.customer_id',
     'ticket.formSenderType',
     'ticket.group_id',

+ 30 - 0
spec/system/manage/template_spec.rb

@@ -35,6 +35,21 @@ RSpec.describe 'Manage > Templates', type: :system do
         expect(Template.last.active).to be(false)
       end
     end
+
+    it 'with cc attribute #4421' do
+      cc_recipients = Array.new(2) { Faker::Internet.unique.email }.join(', ')
+
+      in_modal do
+        fill_in('name', with: Faker::Name.unique.name)
+        find('.js-attributeSelector select').find(:option, 'CC').select_option
+        fill_in('options::article.cc::value', with: cc_recipients)
+        click_button('Submit')
+
+        await_empty_ajax_queue
+      end
+
+      expect(Template.last.options['article.cc']['value']).to eq(cc_recipients)
+    end
   end
 
   context 'when editing an existing template' do
@@ -194,6 +209,21 @@ RSpec.describe 'Manage > Templates', type: :system do
       end
     end
 
+    context 'with cc attribute #4421' do
+      let(:template) do
+        create(:template,
+               options: {
+                 'article.cc': {
+                   value: Array.new(3) { Faker::Internet.unique.email }.join(', '),
+                 },
+               })
+      end
+
+      it 'restores correct value' do
+        check_input_field_value('options::article.cc::value', template.options['article.cc']['value'])
+      end
+    end
+
     context 'with active field' do
       let(:template) do
         create(:template,

+ 69 - 0
spec/system/ticket/create_spec.rb

@@ -1456,4 +1456,73 @@ RSpec.describe 'Ticket Create', type: :system do
       expect(find('#form-template select[name="id"]')).to have_selector('option', text: active_template.name).and(have_no_selector('option', text: inactive_template.name))
     end
   end
+
+  describe 'CC field cannot be customized in the new ticket templates #4421', authenticated_as: :agent do
+    let(:group)         { create(:group) }
+    let(:agent)         { create(:agent, groups: [group]) }
+    let(:customer)      { create(:customer) }
+    let(:cc_recipients) { Array.new(3) { Faker::Internet.unique.email }.join(', ') }
+    let!(:template) do
+      create(:template,
+             options: {
+               'ticket.title':          {
+                 value: Faker::Name.name_with_middle,
+               },
+               'ticket.customer_id':    {
+                 value:            customer.id,
+                 value_completion: "#{customer.firstname} #{customer.lastname} <#{customer.email}>",
+               },
+               'ticket.group_id':       {
+                 value: group.id,
+               },
+               'ticket.formSenderType': {
+                 value: form_sender_type,
+               },
+               'article.cc':            {
+                 value: cc_recipients,
+               },
+               'article.body':          {
+                 value: Faker::Hacker.say_something_smart,
+               },
+             })
+    end
+
+    before do
+      visit 'ticket/create'
+    end
+
+    context 'with email article type' do
+      let(:form_sender_type) { 'email-out' }
+
+      it 'applies configured cc value' do
+        use_template(template)
+
+        await_empty_ajax_queue
+
+        expect(page).to have_css('label', text: 'CC')
+
+        check_input_field_value('cc', cc_recipients, visible: :all)
+
+        click '.js-submit'
+
+        expect(Ticket::Article.last).to have_attributes(cc: cc_recipients)
+      end
+    end
+
+    context 'with phone article type' do
+      let(:form_sender_type) { 'phone-out' }
+
+      it 'ignores configured cc value' do
+        use_template(template)
+
+        await_empty_ajax_queue
+
+        expect(page).to have_no_css('label', text: 'CC')
+
+        click '.js-submit'
+
+        expect(Ticket::Article.last).not_to have_attributes(cc: cc_recipients)
+      end
+    end
+  end
 end