From 3cf7b79edcc828de060d073bf67c5798afe0e845 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 20 Oct 2021 13:01:45 +0200 Subject: [PATCH] Fixes #3801 - Remote change of the group id does show it falsly as user change and not render the new value to the ticket. --- .../app/controllers/ticket_zoom.coffee | 9 +++ .../ticket_zoom/sidebar_ticket.coffee | 60 ++++++++----------- spec/system/ticket/zoom_spec.rb | 7 +++ 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 6b560691b..0698fda57 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -641,6 +641,7 @@ class App.TicketZoom extends App.Controller # update changes in ui currentStore = @currentStore() modelDiff = @formDiff(currentParams, currentStore) + return if _.isEmpty(modelDiff) # set followup state if needed @setDefaultFollowUpState(modelDiff, currentStore) @@ -735,6 +736,14 @@ class App.TicketZoom extends App.Controller # do not compare null or undefined value if currentStore.ticket + + # make sure that the compared state is same in local storage and + # rendered html. Else we could have race conditions of data + # which is not rendered yet + renderedUpdatedAt = @el.find('.edit').attr('data-ticket-updated-at') + return if !renderedUpdatedAt + return if currentStore.ticket.updated_at.toString() isnt renderedUpdatedAt + for key, value of currentStore.ticket if value is null || value is undefined currentStore.ticket[key] = '' diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_ticket.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_ticket.coffee index bdb18819b..4b516e209 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_ticket.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/sidebar_ticket.coffee @@ -29,41 +29,33 @@ class Edit extends App.Controller # for the new ticket + eventually changed task state @formMeta.core_workflow = undefined - if followUpPossible == 'new_ticket' && ticketState != 'closed' || - followUpPossible != 'new_ticket' || - @permissionCheck('admin') || @ticket.currentView() is 'agent' - @controllerFormSidebarTicket = new App.ControllerForm( - elReplace: @el - model: { className: 'Ticket', configure_attributes: @formMeta.configure_attributes || App.Ticket.configure_attributes } - screen: 'edit' - handlersConfig: handlers - filter: @formMeta.filter - formMeta: @formMeta - params: defaults - isDisabled: !@ticket.editable() - taskKey: @taskKey - core_workflow: { - callbacks: [@markForm] - } - #bookmarkable: true - ) - else - @controllerFormSidebarTicket = new App.ControllerForm( - elReplace: @el - model: { className: 'Ticket', configure_attributes: @formMeta.configure_attributes || App.Ticket.configure_attributes } - screen: 'edit' - handlersConfig: handlers - filter: @formMeta.filter - formMeta: @formMeta - params: defaults - isDisabled: @ticket.editable() - taskKey: @taskKey - core_workflow: { - callbacks: [@markForm] - } - #bookmarkable: true - ) + editable = @ticket.editable() + if followUpPossible == 'new_ticket' && ticketState != 'closed' || followUpPossible != 'new_ticket' || @permissionCheck('admin') || @ticket.currentView() is 'agent' + editable = !editable + # reset updated_at for the sidbar because we render a new state + # it is used to compare the ticket with the rendered data later + # and needed to prevent race conditions + @el.removeAttr('data-ticket-updated-at') + + @controllerFormSidebarTicket = new App.ControllerForm( + elReplace: @el + model: { className: 'Ticket', configure_attributes: @formMeta.configure_attributes || App.Ticket.configure_attributes } + screen: 'edit' + handlersConfig: handlers + filter: @formMeta.filter + formMeta: @formMeta + params: defaults + isDisabled: editable + taskKey: @taskKey + core_workflow: { + callbacks: [@markForm] + } + #bookmarkable: true + ) + + # set updated_at for the sidbar because we render a new state + @el.attr('data-ticket-updated-at', defaults.updated_at) @markForm(true) return if @resetBind diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index 07b57b31d..7f48eb9db 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -2149,6 +2149,13 @@ RSpec.describe 'Ticket zoom', type: :system do expect(page.find("select[name='priority_id']").value).to eq(high_prio.id.to_s) end + it 'does show up the new group (different case because it will also trigger a full rerender because of potential permission changes)' do + group = Group.find_by(name: 'some group1') + ticket.update(group: group) + wait(10, interval: 0.5).until { page.find("select[name='group_id']").value == group.id.to_s } + expect(page.find("select[name='group_id']").value).to eq(group.id.to_s) + end + it 'does show up the new state and pending time' do pending_state = Ticket::State.find_by(name: 'pending reminder') ticket.update(state: pending_state, pending_time: 1.day.from_now)