Fixes #3053 - “You have not created a ticket yet” shown but I already have closed tickets
This commit is contained in:
parent
cc2c5678f0
commit
0402c755de
5 changed files with 97 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,11 +3,15 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
<% if @has_any_tickets: %>
|
||||
<p><%- @T('You have no tickets to display in this overview.') %></p>
|
||||
<% else: %>
|
||||
<p><%- @T('You have not created a ticket yet.') %></p>
|
||||
<p><%- @T('The way to communicate with us is this thing called "ticket".') %></p>
|
||||
<p><%- @T('Please click the button below to create your first one.') %></p>
|
||||
|
||||
<p><a class="btn btn--primary" href="#customer_ticket_new"><%- @T('Create your first ticket') %></a></p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
|
|
55
spec/system/overview_spec.rb
Normal file
55
spec/system/overview_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue