diff --git a/app/assets/javascripts/app/controllers/ticket_overview.coffee b/app/assets/javascripts/app/controllers/ticket_overview.coffee index 5e7e393f9..c545020d1 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.coffee @@ -1057,9 +1057,7 @@ class Table extends App.Controller ticketListShow.push App.Ticket.find(ticket.id) # if customer and no ticket exists, show the following message only - if !ticketListShow[0] && !@permissionCheck('ticket.agent') - @html App.view('customer_not_ticket_exists')() - return + return if @renderCustomerNotTicketExistIfNeeded(ticketListShow) # set page title @overview = App.Overview.find(overview.id) @@ -1318,6 +1316,23 @@ class Table extends App.Controller bulkAll.prop('indeterminate', true) ) + renderCustomerNotTicketExistIfNeeded: (ticketListShow) => + user = App.User.current() + @stopListening user, 'refresh' + + return if ticketListShow[0] || @permissionCheck('ticket.agent') + + tickets_count = user.lifetimeCustomerTicketsCount() + @html App.view('customer_not_ticket_exists')(has_any_tickets: tickets_count > 0) + + if tickets_count == 0 + @listenTo user, 'refresh', => + return if tickets_count == user.lifetimeCustomerTicketsCount() + + @renderCustomerNotTicketExistIfNeeded([]) + + return true + shouldShowBulkForm: => items = @$('table').find('input[name="bulk"]:checked') return false if items.length == 0 diff --git a/app/assets/javascripts/app/models/user.coffee b/app/assets/javascripts/app/models/user.coffee index d92327242..f1ed97298 100644 --- a/app/assets/javascripts/app/models/user.coffee +++ b/app/assets/javascripts/app/models/user.coffee @@ -360,6 +360,9 @@ class App.User extends App.Model return false if requester.organization_id is null @organization_id == requester.organization_id + lifetimeCustomerTicketsCount: -> + (@preferences.tickets_closed || 0) + (@preferences.tickets_open || 0) + # Do NOT modify the return value of this method! # It is a direct reference to a value in the App.User.irecords object. @current: App.Session.get diff --git a/app/assets/javascripts/app/views/customer_not_ticket_exists.jst.eco b/app/assets/javascripts/app/views/customer_not_ticket_exists.jst.eco index 7739a68a9..dfd72889b 100644 --- a/app/assets/javascripts/app/views/customer_not_ticket_exists.jst.eco +++ b/app/assets/javascripts/app/views/customer_not_ticket_exists.jst.eco @@ -3,11 +3,15 @@
-

<%- @T('You have not created a ticket yet.') %>

-

<%- @T('The way to communicate with us is this thing called "ticket".') %>

-

<%- @T('Please click the button below to create your first one.') %>

+ <% if @has_any_tickets: %> +

<%- @T('You have no tickets to display in this overview.') %>

+ <% else: %> +

<%- @T('You have not created a ticket yet.') %>

+

<%- @T('The way to communicate with us is this thing called "ticket".') %>

+

<%- @T('Please click the button below to create your first one.') %>

-

<%- @T('Create your first ticket') %>

+

<%- @T('Create your first ticket') %>

+ <% end %>
diff --git a/spec/support/active_job.rb b/spec/support/active_job.rb index eaae485da..a1af672cf 100644 --- a/spec/support/active_job.rb +++ b/spec/support/active_job.rb @@ -15,6 +15,17 @@ module ZammadActiveJobHelper end end +module ZammadActiveJobSystemHelper + include ActiveJob::TestHelper + + alias original_perform_enqueued_jobs perform_enqueued_jobs + + def perform_enqueued_jobs(**kwargs, &block) + ActiveJobLock.destroy_all + original_perform_enqueued_jobs(**kwargs, &block) + end +end + RSpec.configure do |config| activate_for = { @@ -22,6 +33,8 @@ RSpec.configure do |config| performs_jobs: true, # examples performing Jobs } + config.include ZammadActiveJobSystemHelper, performs_jobs: true, type: :system + activate_for.each do |key, value| config.include ZammadActiveJobHelper, key => value config.include RSpec::Rails::JobExampleGroup, key => value diff --git a/spec/system/overview_spec.rb b/spec/system/overview_spec.rb new file mode 100644 index 000000000..f984e1626 --- /dev/null +++ b/spec/system/overview_spec.rb @@ -0,0 +1,55 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe 'Overview', type: :system do + context 'when logged in as customer', authenticated_as: :customer do + let!(:customer) { create(:customer) } + let!(:main_overview) { create(:overview) } + let!(:other_overview) do + create(:overview, condition: { + 'ticket.state_id' => { + operator: 'is', + value: Ticket::State.where(name: %w[merged]).pluck(:id), + }, + }) + end + + it 'shows create button when customer has no tickets' do + visit "ticket/view/#{main_overview.link}" + + within :active_content do + expect(page).to have_text 'Create your first ticket' + end + end + + it 'shows overview-specific message if customer has tickets in other overview', performs_jobs: true do + perform_enqueued_jobs only: TicketUserTicketCounterJob do + create(:ticket, customer: customer) + end + + visit "ticket/view/#{other_overview.link}" + + within :active_content do + expect(page).to have_text 'You have no tickets' + end + end + + it 'replaces button with overview-specific message when customer creates a ticket', performs_jobs: true do + visit "ticket/view/#{other_overview.link}" + visit 'customer_ticket_new' + + find('[name=title]').fill_in with: 'Title' + find(:richtext).send_keys 'content' + find('[name=group_id]').select Group.first.name + click '.js-submit' + + perform_enqueued_jobs only: TicketUserTicketCounterJob + + visit "ticket/view/#{other_overview.link}" + within :active_content do + expect(page).to have_text 'You have no tickets' + end + end + end +end