Fixes #3554 - Zammad sends mails even though there is no email address visible in TO or CC fields (any more)

This commit is contained in:
Romit Choudhary 2021-08-18 09:49:45 +02:00 committed by Thorsten Eckel
parent 28bbd774c2
commit 3486390843
3 changed files with 72 additions and 2 deletions

View file

@ -75,6 +75,9 @@ class App.TicketZoomArticleNew extends App.Controller
if data.position is 'end'
@placeCaretAtEnd(@textarea.get(0))
return
# fixes email validation issue right after new ticket creation
@tokanice(data.type.name)
)
# add article attachment

View file

@ -6,6 +6,9 @@
* Edit: Felix
* - remove maxTokenWidth
*
* Edit: Romit
* - allow to remove token by clearing it's text manually
*
*/
(function (factory) {
@ -233,7 +236,10 @@
this.$element.trigger(createEvent)
// Bail out if there if attributes are empty or event was defaultPrevented
if (!createEvent.attrs || createEvent.isDefaultPrevented()) return
if (!createEvent.attrs || createEvent.isDefaultPrevented()) {
this.updateTokensOnEditDiscard(triggerChange)
return
}
var $token = $('<div class="token" />')
.append('<span class="token-label" />')
@ -303,10 +309,21 @@
return this.$element.get(0)
}
, updateTokensOnEditDiscard: function(triggerChange) {
// if the field is being edited, update original field's value
if(this.$input.data('edit') && triggerChange) {
// Trigger change event on the original field
this.$element.val( this.getTokensList() ).trigger( $.Event('change', { initiator: 'tokenfield' }) )
}
}
, setTokens: function (tokens, add, triggerChange) {
if (!add) this.$wrapper.find('.token').remove()
if (!tokens) return
if (!tokens) {
this.updateTokensOnEditDiscard(triggerChange)
return
}
if (typeof triggerChange === 'undefined') {
triggerChange = true

View file

@ -0,0 +1,50 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'rails_helper'
RSpec.describe 'Ticket > Update > Email Reply', current_user_id: -> { current_user.id }, type: :system, time_zone: 'Europe/London' do
let(:group) { Group.find_by(name: 'Users') }
let(:ticket) { create(:ticket, group: group) }
let(:ticket_article) { create(:ticket_article, ticket: ticket, from: 'Example Name <asdf1@example.com>') }
let(:customer) { create(:customer) }
let(:current_user) { customer }
before do
visit "ticket/zoom/#{ticket_article.ticket.id}"
end
context 'when TO field is being edited' do
it 'shows error dialog when updated value is an invalid email' do
within(:active_content) do
click_reply
find('.token').double_click
find('.js-to', visible: false).sibling('.token-input').set('test')
find('.js-textarea').set('welcome to the community')
find('.js-submitDropdown button.js-submit').click
expect(page).to have_text 'Need recipient in "To" or "Cc".'
end
end
it 'updates article when updated value is a valid email' do
within(:active_content) do
click_reply
find('.token').double_click
find('.js-to', visible: false).sibling('.token-input').set('user@test.com')
find('.js-textarea').set('welcome to the community')
find('.js-submitDropdown button.js-submit').click
expect(page).to have_text 'welcome to the community'
end
end
end
def click_reply
click '.js-ArticleAction[data-type=emailReply]'
end
end