2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2015-04-27 23:19:26 +00:00
|
|
|
module Ticket::Overviews
|
2013-08-17 20:04:57 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
all overviews by user
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2013-08-19 10:21:31 +00:00
|
|
|
result = Ticket::Overviews.all(
|
2016-03-03 01:51:24 +00:00
|
|
|
current_user: User.find(123),
|
2013-08-17 20:04:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = [overview1, overview2]
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
def self.all(data)
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# get customer overviews
|
2015-05-08 08:15:45 +00:00
|
|
|
if data[:current_user].role?('Customer')
|
2016-08-31 07:10:25 +00:00
|
|
|
role_id = Role.lookup(name: 'Customer').id
|
2016-01-15 17:22:57 +00:00
|
|
|
overviews = if data[:current_user].organization_id && data[:current_user].organization.shared
|
2016-08-31 07:10:25 +00:00
|
|
|
Overview.where(role_id: role_id, active: true).order(:prio)
|
2016-01-15 17:22:57 +00:00
|
|
|
else
|
2016-08-31 07:10:25 +00:00
|
|
|
Overview.where(role_id: role_id, organization_shared: false, active: true).order(:prio)
|
2016-01-15 17:22:57 +00:00
|
|
|
end
|
2016-03-14 15:05:52 +00:00
|
|
|
overviews_list = []
|
2016-06-30 20:04:48 +00:00
|
|
|
overviews.each { |overview|
|
2016-03-14 15:05:52 +00:00
|
|
|
user_ids = overview.user_ids
|
|
|
|
next if !user_ids.empty? && !user_ids.include?(data[:current_user].id)
|
|
|
|
overviews_list.push overview
|
|
|
|
}
|
|
|
|
return overviews_list
|
2015-04-27 21:27:51 +00:00
|
|
|
end
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# get agent overviews
|
2016-03-03 01:51:24 +00:00
|
|
|
return if !data[:current_user].role?('Agent')
|
2016-08-31 07:10:25 +00:00
|
|
|
role_id = Role.lookup(name: 'Agent').id
|
|
|
|
overviews = Overview.where(role_id: role_id, active: true).order(:prio)
|
2016-03-14 15:05:52 +00:00
|
|
|
overviews_list = []
|
2016-06-30 20:04:48 +00:00
|
|
|
overviews.each { |overview|
|
2016-03-14 15:05:52 +00:00
|
|
|
user_ids = overview.user_ids
|
|
|
|
next if !user_ids.empty? && !user_ids.include?(data[:current_user].id)
|
|
|
|
overviews_list.push overview
|
|
|
|
}
|
|
|
|
overviews_list
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
|
|
|
|
2013-08-17 20:04:57 +00:00
|
|
|
=begin
|
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
result = Ticket::Overviews.index(User.find(123))
|
2013-08-17 20:04:57 +00:00
|
|
|
|
|
|
|
returns
|
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
overview: {
|
|
|
|
id: 123,
|
|
|
|
updated_at: ...,
|
|
|
|
},
|
|
|
|
count: 3,
|
|
|
|
tickets: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
updated_at: ...,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
updated_at: ...,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
updated_at: ...,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...
|
2013-08-17 20:04:57 +00:00
|
|
|
}
|
2016-03-03 01:51:24 +00:00
|
|
|
]
|
2013-08-17 20:04:57 +00:00
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
def self.index(user)
|
|
|
|
overviews = Ticket::Overviews.all(
|
|
|
|
current_user: user,
|
|
|
|
)
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# get only tickets with permissions
|
2016-03-03 01:51:24 +00:00
|
|
|
access_condition = Ticket.access_condition(user)
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
list = []
|
2016-06-30 20:04:48 +00:00
|
|
|
overviews.each { |overview|
|
2016-03-03 01:51:24 +00:00
|
|
|
query_condition, bind_condition = Ticket.selector2sql(overview.condition, user)
|
2015-09-17 18:39:51 +00:00
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
order_by = "#{overview.order[:by]} #{overview.order[:direction]}"
|
|
|
|
if overview.group_by && !overview.group_by.empty?
|
|
|
|
order_by = "#{overview.group_by}_id, #{order_by}"
|
2013-08-17 20:04:57 +00:00
|
|
|
end
|
2015-09-17 18:39:51 +00:00
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
ticket_result = Ticket.select('id, updated_at')
|
|
|
|
.where(access_condition)
|
|
|
|
.where(query_condition, *bind_condition)
|
|
|
|
.order(order_by)
|
|
|
|
.limit(500)
|
2016-08-31 07:10:25 +00:00
|
|
|
.pluck(:id, :updated_at)
|
2016-03-03 01:51:24 +00:00
|
|
|
|
|
|
|
tickets = []
|
|
|
|
ticket_result.each { |ticket|
|
|
|
|
ticket_item = {
|
2016-08-31 07:10:25 +00:00
|
|
|
id: ticket[0],
|
|
|
|
updated_at: ticket[1],
|
2016-03-03 01:51:24 +00:00
|
|
|
}
|
|
|
|
tickets.push ticket_item
|
2015-04-27 23:19:26 +00:00
|
|
|
}
|
2016-03-03 01:51:24 +00:00
|
|
|
count = Ticket.where(access_condition).where(query_condition, *bind_condition).count()
|
|
|
|
item = {
|
|
|
|
overview: {
|
|
|
|
id: overview.id,
|
|
|
|
view: overview.link,
|
|
|
|
updated_at: overview.updated_at,
|
|
|
|
},
|
|
|
|
tickets: tickets,
|
|
|
|
count: count,
|
2013-08-17 20:04:57 +00:00
|
|
|
}
|
2015-04-27 23:19:26 +00:00
|
|
|
|
2016-03-03 01:51:24 +00:00
|
|
|
list.push item
|
2015-04-27 23:19:26 +00:00
|
|
|
}
|
2016-03-03 01:51:24 +00:00
|
|
|
list
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2014-02-03 19:23:00 +00:00
|
|
|
end
|