Skip to content

Commit

Permalink
Fixes #5004 - Core Workflow: "fill in empty" fires on non-empty field…
Browse files Browse the repository at this point in the history
…s during ticket creation when logged in as customer.

Co-authored-by: Florian Liebe <fl@zammad.com>
  • Loading branch information
rolfschmidt and fliebe92 committed Jan 15, 2024
1 parent c8bc3ed commit 83e5cdf
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', =>
Expand All @@ -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()

Expand All @@ -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)

Expand Down
51 changes: 51 additions & 0 deletions spec/system/ticket/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1513,4 +1513,55 @@ def authenticate
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

0 comments on commit 83e5cdf

Please sign in to comment.