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.stopPropagation()
item = $(e.target).closest('tr').find('.js-name').text()
App.GlobalSearchWidget.search(item, 'tag')
App.GlobalSearchWidget.search(item, 'tags')
class Edit extends App.ControllerModal
buttonClose: true

View file

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

View file

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

View file

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

View file

@ -502,6 +502,27 @@ get count of tickets and tickets which match on selector
t[:term] = {}
t[:term][key_tmp] = data['value']
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)
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
t[:range][key_tmp][:lt] = "now+#{data['value']}#{range}"
end
query_must.push t
# before/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
t[:range][key_tmp][:gt] = "now+#{data['value']}#{range}"
end
query_must.push t
# before/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
t[:range][key_tmp][:gt] = (data['value']).to_s
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
else
raise "unknown operator '#{data['operator']}' for #{key}"

View file

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

View file

@ -44,6 +44,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
@ticket1.tag_add('aaa', 1)
@ticket1.tag_add('bbb', 1)
@ticket1.update!(
group: Group.lookup(name: 'Users'),
updated_at: '2015-10-28 14:30:00 UTC',
@ -75,6 +77,7 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
@ticket2.tag_add('aaa', 1)
@ticket2.update!(
group_id: group2.id,
updated_at: '2015-10-28 14:30:00 UTC',
@ -162,6 +165,7 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
@ticket5.tag_add('bbb', 1)
@ticket5.update!(
state: Ticket::State.lookup(name: 'open'),
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_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
Rake::Task['searchindex:drop'].execute
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) AND customer.lastname:smith
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
state:closed AND _missing_:tag # all closed objects without tags
article_count: [1 TO 5] # tickets with 1 to 5 articles