From 453e2019125559f3bb7d65030c5a6cc9e6383886 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 23 Oct 2015 13:45:20 +0200 Subject: [PATCH] Prevent submitting attachments without article body. --- .../app/controllers/ticket_zoom.coffee | 20 +++++++--- .../agent_ticket_actions_level6_test.rb | 38 +++++++++++++++++++ test/browser_test_helper.rb | 2 +- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 20b7d9ce3..5d9a188f6 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -547,6 +547,15 @@ class App.TicketZoom extends App.Controller # validate article articleParams = @formParam( @$('.article-add') ) console.log 'submit article', articleParams + + # check if attachment exists but no body + attachmentCount = @$('.article-add .textBubble .attachments .attachment').length + if !articleParams['body'] && attachmentCount > 0 + if !confirm( App.i18n.translateContent('Please fill also some text in!') ) + @formEnable(e) + @autosaveStart() + return + if articleParams['body'] articleParams.from = @Session.get().displayName() articleParams.ticket_id = ticket.id @@ -590,12 +599,11 @@ class App.TicketZoom extends App.Controller # check attachment if articleParams['body'] - if App.Utils.checkAttachmentReference( articleParams['body'] ) - if @$('.article-add .textBubble .attachments .attachment').length < 1 - if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') ) - @formEnable(e) - @autosaveStart() - return + if App.Utils.checkAttachmentReference( articleParams['body'] ) && attachmentCount < 1 + if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') ) + @formEnable(e) + @autosaveStart() + return article.load(articleParams) errors = article.validate() diff --git a/test/browser/agent_ticket_actions_level6_test.rb b/test/browser/agent_ticket_actions_level6_test.rb index 8b5b5f9e5..096b44d3d 100644 --- a/test/browser/agent_ticket_actions_level6_test.rb +++ b/test/browser/agent_ticket_actions_level6_test.rb @@ -107,6 +107,44 @@ class AgentTicketActionLevel6Test < TestCase value: 'test 6 - ticket 1-1', ) + # add attachment without body + @browser.execute_script( "App.TestHelper.attachmentUploadFake('.active .article-add .textBubble .attachments')" ) + + # submit form + click( + css: '.active .js-submit', + ) + sleep 2 + + # check warning + alert = @browser.switch_to.alert + alert.dismiss() + + ticket_update( + data: { + body: 'now submit should work', + }, + do_not_submit: true, + ) + + # submit form + click( + css: '.active .js-submit', + ) + sleep 2 + + # discard changes should gone away + watch_for_disappear( + css: '.content.active .js-reset', + value: '(Discard your unsaved changes.|Verwerfen der)', + no_quote: true, + ) + ticket_verify( + data: { + body: '', + }, + ) + # # ticket customer change checks # diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index eba1b6ed7..31768a43f 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -1076,7 +1076,7 @@ wait untill text in selector disabppears element.clear # workaround, sometimes focus is not triggered - element.send_keys( data[:customer] ) + element.send_keys( data[:customer] + '*' ) sleep 3.5 # check if pulldown is open, it's not working stable via selenium