Fixes #1847 - Report profiles - ticket.tags conditions are not working.

This commit is contained in:
Martin Edenhofer 2018-07-04 18:24:51 +02:00
parent 7bdec55960
commit 2b31311bea
8 changed files with 225 additions and 26 deletions

View file

@ -95,7 +95,7 @@ class Table extends App.Controller
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
item = $(e.target).closest('tr').find('.js-name').text() item = $(e.target).closest('tr').find('.js-name').text()
App.GlobalSearchWidget.search(item, 'tag') App.GlobalSearchWidget.search(item, 'tags')
class Edit extends App.ControllerModal class Edit extends App.ControllerModal
buttonClose: true buttonClose: true

View file

@ -115,4 +115,4 @@ class App.WidgetTag extends App.Controller
searchTag: (e) -> searchTag: (e) ->
e.preventDefault() e.preventDefault()
item = $(e.target).text() item = $(e.target).text()
App.GlobalSearchWidget.search(item, 'tag') App.GlobalSearchWidget.search(item, 'tags')

View file

@ -22,7 +22,7 @@ returns
attributes = super attributes = super
return if !attributes return if !attributes
attributes[:tag] = tag_list attributes[:tags] = tag_list
messages = Chat::Message.where(chat_session_id: id) messages = Chat::Message.where(chat_session_id: id)
attributes['messages'] = [] attributes['messages'] = []

View file

@ -23,7 +23,7 @@ returns
# add tags # add tags
tags = tag_list tags = tag_list
if tags.present? if tags.present?
attributes[:tag] = tags attributes[:tags] = tags
end end
# list ignored file extentions # list ignored file extentions

View file

@ -502,6 +502,27 @@ get count of tickets and tickets which match on selector
t[:term] = {} t[:term] = {}
t[:term][key_tmp] = data['value'] t[:term][key_tmp] = data['value']
end end
if data['operator'] == 'is' || data['operator'] == 'contains'
query_must.push t
elsif data['operator'] == 'is not' || data['operator'] == 'contains not'
query_must_not.push t
end
elsif data['operator'] == 'contains all' || data['operator'] == 'contains one' || data['operator'] == 'contains all not' || data['operator'] == 'contains one not'
values = data['value'].split(',').map(&:strip)
t[:query_string] = {}
if data['operator'] == 'contains all'
t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" AND "')}\""
query_must.push t
elsif data['operator'] == 'contains one not'
t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" OR "')}\""
query_must_not.push t
elsif data['operator'] == 'contains one'
t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" OR "')}\""
query_must.push t
elsif data['operator'] == 'contains all not'
t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" AND "')}\""
query_must_not.push t
end
# within last/within next (relative) # within last/within next (relative)
elsif data['operator'] == 'within last (relative)' || data['operator'] == 'within next (relative)' elsif data['operator'] == 'within last (relative)' || data['operator'] == 'within next (relative)'
@ -516,6 +537,7 @@ get count of tickets and tickets which match on selector
else else
t[:range][key_tmp][:lt] = "now+#{data['value']}#{range}" t[:range][key_tmp][:lt] = "now+#{data['value']}#{range}"
end end
query_must.push t
# before/after (relative) # before/after (relative)
elsif data['operator'] == 'before (relative)' || data['operator'] == 'after (relative)' elsif data['operator'] == 'before (relative)' || data['operator'] == 'after (relative)'
@ -530,6 +552,7 @@ get count of tickets and tickets which match on selector
else else
t[:range][key_tmp][:gt] = "now+#{data['value']}#{range}" t[:range][key_tmp][:gt] = "now+#{data['value']}#{range}"
end end
query_must.push t
# before/after (absolute) # before/after (absolute)
elsif data['operator'] == 'before (absolute)' || data['operator'] == 'after (absolute)' elsif data['operator'] == 'before (absolute)' || data['operator'] == 'after (absolute)'
@ -540,22 +563,6 @@ get count of tickets and tickets which match on selector
else else
t[:range][key_tmp][:gt] = (data['value']).to_s t[:range][key_tmp][:gt] = (data['value']).to_s
end end
else
raise "unknown operator '#{data['operator']}' for #{key}"
end
if data['operator'] == 'is'
query_must.push t
elsif data['operator'] == 'is not'
query_must_not.push t
elsif data['operator'] == 'contains'
query_must_not.push t
elsif data['operator'] == 'contains not'
query_must_not.push t
elsif data['operator'] == 'within last (relative)' || data['operator'] == 'within next (relative)'
query_must.push t
elsif data['operator'] == 'before (relative)' || data['operator'] == 'after (relative)'
query_must.push t
elsif data['operator'] == 'before (absolute)' || data['operator'] == 'after (absolute)'
query_must.push t query_must.push t
else else
raise "unknown operator '#{data['operator']}' for #{key}" raise "unknown operator '#{data['operator']}' for #{key}"

View file

@ -405,7 +405,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
# search for tags # search for tags
result = Ticket.search( result = Ticket.search(
current_user: @agent, current_user: @agent,
query: 'tag:someTagA', query: 'tags:someTagA',
limit: 15, limit: 15,
) )
assert(result[0], 'record 1') assert(result[0], 'record 1')
@ -414,7 +414,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
result = Ticket.search( result = Ticket.search(
current_user: @agent, current_user: @agent,
query: 'tag:someTagB', query: 'tags:someTagB',
limit: 15, limit: 15,
) )
assert(result[0], 'record 2') assert(result[0], 'record 2')
@ -437,7 +437,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
# search for tags # search for tags
result = Ticket.search( result = Ticket.search(
current_user: @agent, current_user: @agent,
query: 'tag:someTagA', query: 'tags:someTagA',
limit: 15, limit: 15,
) )
assert(!result[0], 'record 1') assert(!result[0], 'record 1')
@ -445,7 +445,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
result = Ticket.search( result = Ticket.search(
current_user: @agent, current_user: @agent,
query: 'tag:someTagB', query: 'tags:someTagB',
limit: 15, limit: 15,
) )
assert(result[0], 'record 2') assert(result[0], 'record 2')
@ -454,7 +454,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
result = Ticket.search( result = Ticket.search(
current_user: @agent, current_user: @agent,
query: 'tag:someTagC', query: 'tags:someTagC',
limit: 15, limit: 15,
) )
assert(result[0], 'record 1') assert(result[0], 'record 1')

View file

@ -44,6 +44,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ticket1.tag_add('aaa', 1)
@ticket1.tag_add('bbb', 1)
@ticket1.update!( @ticket1.update!(
group: Group.lookup(name: 'Users'), group: Group.lookup(name: 'Users'),
updated_at: '2015-10-28 14:30:00 UTC', updated_at: '2015-10-28 14:30:00 UTC',
@ -75,6 +77,7 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ticket2.tag_add('aaa', 1)
@ticket2.update!( @ticket2.update!(
group_id: group2.id, group_id: group2.id,
updated_at: '2015-10-28 14:30:00 UTC', updated_at: '2015-10-28 14:30:00 UTC',
@ -162,6 +165,7 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ticket5.tag_add('bbb', 1)
@ticket5.update!( @ticket5.update!(
state: Ticket::State.lookup(name: 'open'), state: Ticket::State.lookup(name: 'open'),
updated_at: '2015-10-28 14:30:00 UTC', updated_at: '2015-10-28 14:30:00 UTC',
@ -1161,6 +1165,194 @@ class ReportTest < ActiveSupport::TestCase
assert_equal(@ticket9.id, result[:ticket_ids][0].to_i) assert_equal(@ticket9.id, result[:ticket_ids][0].to_i)
assert_nil(result[:ticket_ids][1]) assert_nil(result[:ticket_ids][1])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'tags' => {
'operator' => 'contains all',
'value' => 'aaa, bbb'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket1.id, result[:ticket_ids][0].to_i)
assert_nil(result[:ticket_ids][1])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'tags' => {
'operator' => 'contains all not',
'value' => 'aaa, bbb'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
assert_nil(result[:ticket_ids][6])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'tags' => {
'operator' => 'contains all',
'value' => 'aaa'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket2.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket1.id, result[:ticket_ids][1].to_i)
assert_nil(result[:ticket_ids][2])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'tags' => {
'operator' => 'contains all not',
'value' => 'aaa'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
assert_nil(result[:ticket_ids][5])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'tags' => {
'operator' => 'contains one not',
'value' => 'aaa'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
assert_nil(result[:ticket_ids][5])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'tags' => {
'operator' => 'contains one not',
'value' => 'aaa, bbb'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
assert_equal(@ticket4.id, result[:ticket_ids][2].to_i)
assert_equal(@ticket3.id, result[:ticket_ids][3].to_i)
assert_nil(result[:ticket_ids][4])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'tags' => {
'operator' => 'contains one',
'value' => 'aaa'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket2.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket1.id, result[:ticket_ids][1].to_i)
assert_nil(result[:ticket_ids][2])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'tags' => {
'operator' => 'contains one',
'value' => 'aaa, bbb'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket5.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket2.id, result[:ticket_ids][1].to_i)
assert_equal(@ticket1.id, result[:ticket_ids][2].to_i)
assert_nil(result[:ticket_ids][3])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'title' => {
'operator' => 'contains',
'value' => 'test'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
assert_equal(@ticket1.id, result[:ticket_ids][6].to_i)
assert_nil(result[:ticket_ids][7])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'title' => {
'operator' => 'contains not',
'value' => 'test'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_nil(result[:ticket_ids][0])
# cleanup # cleanup
Rake::Task['searchindex:drop'].execute Rake::Task['searchindex:drop'].execute
end end

View file

@ -21,7 +21,7 @@ class SearchIndexBackendTest < ActiveSupport::TestCase
(state:new OR state:open) OR priority:3 normal (state:new OR state:open) OR priority:3 normal
(state:new OR state:open) AND customer.lastname:smith (state:new OR state:open) AND customer.lastname:smith
state:(new OR open) AND title:(full text search) # state: new OR open & title: full OR text OR search state:(new OR open) AND title:(full text search) # state: new OR open & title: full OR text OR search
tag: some tag tags: some tag
owner.email: bod@example.com AND state: (new OR open OR pending*) # show all open tickets of a certain agent owner.email: bod@example.com AND state: (new OR open OR pending*) # show all open tickets of a certain agent
state:closed AND _missing_:tag # all closed objects without tags state:closed AND _missing_:tag # all closed objects without tags
article_count: [1 TO 5] # tickets with 1 to 5 articles article_count: [1 TO 5] # tickets with 1 to 5 articles