Skip to content

Commit

Permalink
Fixes zammad#5347 - Saved organization selection in ticket create scr…
Browse files Browse the repository at this point in the history
…een is not restored properly.

Co-authored-by: Dusan Vuckovic <[email protected]>
Co-authored-by: Rolf Schmidt <[email protected]>
  • Loading branch information
dvuckovic and rolfschmidt committed Sep 20, 2024
1 parent 0ee2996 commit a618063
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@ class App.TicketZoomFormHandlerMultiOrganization
# for customers there is no customer field so run it on title field
return if attribute.name isnt 'title' && ui.permissionCheck('ticket.customer') && !ui.permissionCheck('ticket.agent')

organization_id = form.find('div[data-attribute-name=organization_id] .js-input')
return if !organization_id
organization_input = form.find('div[data-attribute-name=organization_id] .js-input')
return if !organization_input

if ui.permissionCheck('ticket.agent')
customer = App.User.find(params.customer_id)
else
customer = App.Session.get()

if customer && customer.organization_ids.length > 0
if customer.organization_id
customer_organization = App.Organization.find(customer.organization_id)
if customer_organization
organization_id.get(0).selectValue(customer_organization.id, customer_organization.name)
return if not customer?.organization_ids.length

# Select current or default customer organization (#5347).
organization_id =
if params.organization_id and customer.isInOrganization(params.organization_id)
then params.organization_id
else customer.organization_id

return if not organization_id

customer_organization = App.Organization.find(organization_id)
return if not customer_organization

organization_input.get(0).selectValue(customer_organization.id, customer_organization.name)

App.Config.set('200-MultiOrganization', App.TicketZoomFormHandlerMultiOrganization, 'TicketCreateFormHandler')
2 changes: 1 addition & 1 deletion app/assets/javascripts/app/models/user.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class App.User extends App.Model
(@preferences.tickets_closed || 0) + (@preferences.tickets_open || 0)

isInOrganization: (organization_id) ->
_.contains(@allOrganizationIds(), organization_id)
_.contains(@allOrganizationIds(), parseInt(organization_id, 10))

allOrganizationIds: ->
result = []
Expand Down
19 changes: 19 additions & 0 deletions spec/system/ticket/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,25 @@ def authenticate
click '.js-submit'
wait.until { Ticket.last.organization_id == user1.organizations[0].id }
end

it 'restores saved organization selection correctly (#5347)' do
find('[name=customer_id_completion]').fill_in with: user1.firstname
wait.until { page.all("li.recipientList-entry.js-object[data-object-id='#{user1.id}']").present? }
find("li.recipientList-entry.js-object[data-object-id='#{user1.id}']").click

find('div[data-attribute-name=organization_id] .js-input').fill_in with: organization2.name, fill_options: { clear: :backspace }
wait.until { page.all("div[data-attribute-name=organization_id] .js-option[data-value='#{organization2.id}']").present? }

taskbar_timestamp = Taskbar.last.updated_at

page.find("div[data-attribute-name=organization_id] .js-option[data-value='#{organization2.id}'] span").click

wait.until { Taskbar.last.updated_at != taskbar_timestamp }

refresh

expect(find('div[data-attribute-name=organization_id] .js-input').value).to eq(organization2.name)
end
end

context 'when customer' do
Expand Down

0 comments on commit a618063

Please sign in to comment.