From 52a44abc2dc95300aa93e292eea96dd0cc8fa43a Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Mon, 31 Aug 2020 06:27:27 +0200 Subject: [PATCH] Fixes #2672 - Changing article visibility will not update ticket view for customers --- app/models/ticket/article.rb | 6 ++++++ spec/system/ticket/zoom_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index 16a4365c3..9576a24f7 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -21,6 +21,7 @@ class Ticket::Article < ApplicationModel before_create :check_subject, :check_body, :check_message_id_md5 before_update :check_subject, :check_body, :check_message_id_md5 + before_save :touch_ticket_if_needed after_destroy :store_delete store :preferences @@ -338,4 +339,9 @@ returns ) end + def touch_ticket_if_needed + return if !internal_changed? + + ticket&.touch # rubocop:disable Rails/SkipsModelValidations + end end diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index bdca01829..530ee04b0 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -1024,4 +1024,31 @@ RSpec.describe 'Ticket zoom', type: :system do include_examples 'shows attributes and values for customer view' end end + + describe 'note visibility', authenticated_as: :customer do + context 'when logged in as a customer' do + let(:customer) { create(:customer) } + let(:ticket) { create(:ticket, customer: customer) } + let!(:ticket_article) { create(:ticket_article, ticket: ticket) } + let!(:ticket_note) { create(:ticket_article, ticket: ticket, internal: true, type_name: 'note') } + + it 'previously created private note is not visible' do + visit "ticket/zoom/#{ticket_article.ticket.id}" + + expect(page).to have_no_selector(:active_ticket_article, ticket_note) + end + + it 'previously created private note shows up via WS push' do + visit "ticket/zoom/#{ticket_article.ticket.id}" + + # make sure ticket is done loading and change will be pushed via WS + find(:active_ticket_article, ticket_article) + await_empty_ajax_queue + + ticket_note.update!(internal: false) + + expect(page).to have_selector(:active_ticket_article, ticket_note) + end + end + end end