Browse Source

Fixes #5004 - Core Workflow: "fill in empty" fires on non-empty fields during ticket creation when logged in as customer.

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

+ 22 - 16
app/assets/javascripts/app/controllers/customer_ticket_create.coffee

@@ -68,6 +68,7 @@ class CustomerTicketCreate extends App.ControllerAppContent
       events:
         'fileUploadStart .richtext': => @submitDisable()
         'fileUploadStop .richtext': => @submitEnable()
+      articleParamsCallback: @articleParams
     )
 
     @$('[name="group_id"], [name="organization_id"]').bind('change', =>
@@ -86,6 +87,26 @@ class CustomerTicketCreate extends App.ControllerAppContent
   params: =>
     params = @formParam(@$('.main form'))
 
+  articleParams: =>
+    params = @params()
+    if params.group_id
+      group = App.Group.find( params.group_id )
+
+    # find sender_id
+    sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' )
+    type   = App.TicketArticleType.findByAttribute( 'name', 'web' )
+
+    {
+      from:         "#{ @Session.get().displayName() }"
+      to:           (group && group.name) || ''
+      subject:      params.subject
+      body:         params.body
+      type_id:      type.id
+      sender_id:    sender.id
+      form_id:      @form_id
+      content_type: 'text/html'
+    }
+
   submit: (e) ->
     e.preventDefault()
 
@@ -108,23 +129,8 @@ class CustomerTicketCreate extends App.ControllerAppContent
     ticket = new App.Ticket
     @log 'CustomerTicketCreate', 'notice', 'updateAttributes', params
 
-    # find sender_id
-    sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' )
-    type   = App.TicketArticleType.findByAttribute( 'name', 'web' )
-    if params.group_id
-      group = App.Group.find( params.group_id )
-
     # create article
-    params['article'] = {
-      from:         "#{ @Session.get().displayName() }"
-      to:           (group && group.name) || ''
-      subject:      params.subject
-      body:         params.body
-      type_id:      type.id
-      sender_id:    sender.id
-      form_id:      @form_id
-      content_type: 'text/html'
-    }
+    params['article'] = @articleParams()
 
     ticket.load(params)
 

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

@@ -1515,4 +1515,55 @@ RSpec.describe 'Ticket Create', type: :system do
       expect(page).to have_text(group_2.signature.body)
     end
   end
+
+  describe 'CoreWorkflow "fill in empty" fires on non-empty fields during ticket creation when logged in as customer #5004' do
+    let(:body_content) { SecureRandom.uuid }
+    let(:workflow) do
+      create(:core_workflow,
+             object:  'Ticket',
+             perform: { 'article.body' => { 'operator' => 'fill_in_empty', 'fill_in_empty' => body_content } })
+    end
+
+    def setup_workflows
+      workflow
+    end
+
+    context 'when agent', authenticated_as: :authenticate do
+      def authenticate
+        setup_workflows
+        true
+      end
+
+      before do
+        visit '#ticket/create'
+      end
+
+      it 'does fill the body' do
+        check_editor_field_value('body', body_content)
+        set_editor_field_value('body', 'new_content')
+        check_editor_field_value('body', 'new_content')
+        page.find('[name=priority_id]').select '3 high'
+        check_editor_field_value('body', 'new_content')
+      end
+    end
+
+    context 'when customer', authenticated_as: :authenticate do
+      def authenticate
+        setup_workflows
+        create(:customer)
+      end
+
+      before do
+        visit 'customer_ticket_new'
+      end
+
+      it 'does fill the body' do
+        check_editor_field_value('body', body_content)
+        set_editor_field_value('body', 'new_content')
+        check_editor_field_value('body', 'new_content')
+        page.find('[name=state_id]').select 'closed'
+        check_editor_field_value('body', 'new_content')
+      end
+    end
+  end
 end