2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2021-03-01 08:18:40 +00:00
|
|
|
|
|
|
|
# If a user is assigned to another organization, also assign their latest tickets to it.
|
|
|
|
module User::UpdatesTicketOrganization
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
after_create :user_update_ticket_organization
|
|
|
|
after_update :user_update_ticket_organization
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user_update_ticket_organization
|
|
|
|
|
|
|
|
# check if organization has changed
|
|
|
|
return true if !saved_change_to_attribute?('organization_id')
|
|
|
|
|
|
|
|
# update last 100 tickets of user
|
|
|
|
tickets = Ticket.where(customer_id: id).limit(100)
|
|
|
|
tickets.each do |ticket|
|
|
|
|
if ticket.organization_id != organization_id
|
|
|
|
ticket.organization_id = organization_id
|
|
|
|
ticket.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|