Fixes #3234 - Renaming a Group should trigger reindexing.

This commit is contained in:
Rolf Schmidt 2021-01-27 13:55:22 +01:00 committed by Thorsten Eckel
parent d0b5cbfe4b
commit 0eac6f0fd9
5 changed files with 75 additions and 3 deletions

View file

@ -63,14 +63,23 @@ returns
=end
def search_index_update_associations_full
return if self.class.to_s != 'Organization'
update_class = {
'Organization' => :organization_id,
'Group' => :group_id,
'Ticket::State' => :state_id,
'Ticket::Priority' => :priority_id,
}
update_column = update_class[self.class.to_s]
return if update_column.blank?
# reindex all organization tickets for the given organization id
# reindex all object related tickets for the given object id
# we can not use the delta function for this because of the excluded
# ticket article attachments. see explain in delta function
Ticket.select('id').where(organization_id: id).order(id: :desc).limit(10_000).pluck(:id).each do |ticket_id|
Ticket.select('id').where(update_column => id).order(id: :desc).limit(10_000).pluck(:id).each do |ticket_id|
SearchIndexJob.perform_later('Ticket', ticket_id)
end
true
end
=begin

View file

@ -9,6 +9,7 @@ class Group < ApplicationModel
include HasObjectManagerAttributesValidation
include HasCollectionUpdate
include HasTicketCreateScreenImpact
include HasSearchIndexBackend
belongs_to :email_address, optional: true
belongs_to :signature, optional: true

View file

@ -2,6 +2,7 @@
class Ticket::Priority < ApplicationModel
include CanBeImported
include HasCollectionUpdate
include HasSearchIndexBackend
self.table_name = 'ticket_priorities'
validates :name, presence: true

View file

@ -3,6 +3,7 @@ class Ticket::State < ApplicationModel
include CanBeImported
include ChecksLatestChangeObserved
include HasCollectionUpdate
include HasSearchIndexBackend
belongs_to :state_type, class_name: 'Ticket::StateType', inverse_of: :states, optional: true
belongs_to :next_state, class_name: 'Ticket::State', optional: true

View file

@ -426,6 +426,66 @@ RSpec.describe 'Search', type: :request, searchindex: true do
expect(json_response['assets']['Ticket'][ticket_nested.id.to_s]).to be_truthy
end
it 'does find the ticket by group name even if the group name changes' do
authenticated_as(agent)
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && group.name:ultrasupport" }, as: :json
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['assets']['Ticket']).to be_falsey
expect(group).not_to eq('ultrasupport')
group.update(name: 'ultrasupport')
Scheduler.worker(true)
SearchIndexBackend.refresh
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && group.name:ultrasupport" }, as: :json
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
end
it 'does find the ticket by state name even if the state name changes' do
authenticated_as(agent)
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && state.name:ultrastate" }, as: :json
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['assets']['Ticket']).to be_falsey
expect(ticket1.state.name).not_to eq('ultrastate')
ticket1.state.update(name: 'ultrastate')
Scheduler.worker(true)
SearchIndexBackend.refresh
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && state.name:ultrastate" }, as: :json
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
end
it 'does find the ticket by priority name even if the priority name changes' do
authenticated_as(agent)
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && priority.name:ultrapriority" }, as: :json
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['assets']['Ticket']).to be_falsey
expect(ticket1.priority.name).not_to eq('ultrapriority')
ticket1.priority.update(name: 'ultrapriority')
Scheduler.worker(true)
SearchIndexBackend.refresh
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && priority.name:ultrapriority" }, as: :json
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response).to be_truthy
expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
end
it 'does find the ticket by attachment even after ticket reindex' do
params = {
query: 'text66',