Fixed issue #1769 - Ticket shown multiple times in overview.

This commit is contained in:
Rolf Schmidt 2018-02-09 16:46:55 +01:00
parent 351b0dec66
commit 4bd9dcf518
5 changed files with 111 additions and 13 deletions

View file

@ -424,14 +424,14 @@ get count of tickets and tickets which match on selector
ActiveRecord::Base.transaction(requires_new: true) do ActiveRecord::Base.transaction(requires_new: true) do
begin begin
if !current_user if !current_user
ticket_count = Ticket.where(query, *bind_params).joins(tables).count ticket_count = Ticket.distinct.where(query, *bind_params).joins(tables).count
tickets = Ticket.where(query, *bind_params).joins(tables).limit(limit) tickets = Ticket.distinct.where(query, *bind_params).joins(tables).limit(limit)
return [ticket_count, tickets] return [ticket_count, tickets]
end end
access_condition = Ticket.access_condition(current_user, access) access_condition = Ticket.access_condition(current_user, access)
ticket_count = Ticket.where(access_condition).where(query, *bind_params).joins(tables).count ticket_count = Ticket.distinct.where(access_condition).where(query, *bind_params).joins(tables).count
tickets = Ticket.where(access_condition).where(query, *bind_params).joins(tables).limit(limit) tickets = Ticket.distinct.where(access_condition).where(query, *bind_params).joins(tables).limit(limit)
return [ticket_count, tickets] return [ticket_count, tickets]
rescue ActiveRecord::StatementInvalid => e rescue ActiveRecord::StatementInvalid => e

View file

@ -113,23 +113,21 @@ returns
end end
end end
ticket_result = Ticket.select('id, updated_at') ticket_result = Ticket.distinct
.where(access_condition) .where(access_condition)
.where(query_condition, *bind_condition) .where(query_condition, *bind_condition)
.joins(tables) .joins(tables)
.order(order_by) .order(order_by)
.limit(1000) .limit(1000)
.pluck(:id, :updated_at)
tickets = [] tickets = ticket_result.map do |ticket|
ticket_result.each do |ticket| {
ticket_item = { id: ticket[:id],
id: ticket[0], updated_at: ticket[:updated_at],
updated_at: ticket[1],
} }
tickets.push ticket_item
end end
count = Ticket.where(access_condition).where(query_condition, *bind_condition).joins(tables).count()
count = Ticket.distinct.where(access_condition).where(query_condition, *bind_condition).joins(tables).count()
item = { item = {
overview: { overview: {
name: overview.name, name: overview.name,

View file

@ -0,0 +1,34 @@
FactoryBot.define do
factory :overview do
name 'My Factory Tickets'
link 'my_factory_tickets'
prio 1100
role_ids { [ Role.find_by(name: 'Customer').id, Role.find_by(name: 'Agent').id, Role.find_by(name: 'Admin').id ] }
out_of_office true
condition do
{
'ticket.state_id' => {
operator: 'is',
value: [ Ticket::State.lookup(name: 'new').id, Ticket::State.lookup(name: 'open').id ],
},
}
end
order do
{
by: 'created_at',
direction: 'DESC',
}
end
view do
{
d: %w[title customer state created_at],
s: %w[number title state created_at],
m: %w[number title state created_at],
view_mode_default: 's',
}
end
updated_by_id 1
created_by_id 1
end
end

View file

@ -0,0 +1,37 @@
require 'rails_helper'
RSpec.describe Ticket::Overviews do
describe '#index' do
# https://github.com/zammad/zammad/issues/1769
it 'does not return multiple results for a single ticket' do
user = create(:user)
source_ticket = create(:ticket, customer: user, created_by_id: user.id)
source_ticket2 = create(:ticket, customer: user, created_by_id: user.id)
# create some articles
create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf1@blubselector.de', created_by_id: user.id)
create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf2@blubselector.de', created_by_id: user.id)
create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf3@blubselector.de', created_by_id: user.id)
create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf3@blubselector.de', created_by_id: user.id)
create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf4@blubselector.de', created_by_id: user.id)
create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf5@blubselector.de', created_by_id: user.id)
condition = {
'article.from' => {
operator: 'contains',
value: 'blubselector.de',
},
}
overview = create(:overview, condition: condition)
result = Ticket::Overviews.index(user)
result = result.select { |x| x[:overview][:name] == 'My Factory Tickets' }
expect(result.count).to be == 1
expect(result[0][:count]).to be == 2
expect(result[0][:tickets].count).to be == 2
end
end
end

View file

@ -203,6 +203,35 @@ RSpec.describe Ticket do
end end
describe '#selectors' do
# https://github.com/zammad/zammad/issues/1769
it 'does not return multiple results for a single ticket' do
source_ticket = create(:ticket)
source_ticket2 = create(:ticket)
# create some articles
create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf1@blubselector.de')
create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf2@blubselector.de')
create(:ticket_article, ticket_id: source_ticket.id, from: 'asdf3@blubselector.de')
create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf4@blubselector.de')
create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf5@blubselector.de')
create(:ticket_article, ticket_id: source_ticket2.id, from: 'asdf6@blubselector.de')
condition = {
'article.from' => {
operator: 'contains',
value: 'blubselector.de',
},
}
ticket_count, tickets = Ticket.selectors(condition, 100, nil, 'full')
expect(ticket_count).to be == 2
expect(tickets.count).to be == 2
end
end
context 'callbacks' do context 'callbacks' do
describe '#reset_pending_time' do describe '#reset_pending_time' do