diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index d10ca9ee7..2d1a940fb 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -153,13 +153,42 @@ class TicketsController < ApplicationController users = {} users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id ) users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id ) + + # get only needed data to send to browser + history_list = [] history.each do |item| - users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] ) + users[ item[:created_by_id] ] = User.user_data_full( item[:created_by_id] ) + item_tmp = item.attributes if item['history_object'] == 'Ticket::Article' - item['type'] = 'Article ' + item['type'].to_s + item_temp['type'] = 'Article ' + item['type'].to_s else - item['type'] = 'Ticket ' + item['type'].to_s + item_tmp['type'] = 'Ticket ' + item['type'].to_s end + item_tmp['history_type'] = item.history_type.name + item_tmp['history_object'] = item.history_object.name + if item.history_attribute + item_tmp['history_attribute'] = item.history_attribute.name + end + item_tmp.delete( 'history_attribute_id' ) + item_tmp.delete( 'history_object_id' ) + item_tmp.delete( 'history_type_id' ) + item_tmp.delete( 'o_id' ) + item_tmp.delete( 'updated_at' ) + if item_tmp['id_to'] == nil && item_tmp['id_from'] == nil + item_tmp.delete( 'id_to' ) + item_tmp.delete( 'id_from' ) + end + if item_tmp['value_to'] == nil && item_tmp['value_from'] == nil + item_tmp.delete( 'value_to' ) + item_tmp.delete( 'value_from' ) + end + if item_tmp['related_history_object_id'] == nil + item_tmp.delete( 'related_history_object_id' ) + end + if item_tmp['related_o_id'] == nil + item_tmp.delete( 'related_o_id' ) + end + history_list.push item_tmp end # fetch meta relations @@ -171,7 +200,7 @@ class TicketsController < ApplicationController render :json => { :ticket => ticket, :users => users, - :history => history, + :history => history_list, :history_objects => history_objects, :history_types => history_types, :history_attributes => history_attributes diff --git a/app/models/history.rb b/app/models/history.rb index dbf684789..03f6281c8 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -90,36 +90,7 @@ class History < ApplicationModel order('created_at ASC, id ASC') end - list = [] - history.each { |item| - item_tmp = item.attributes - item_tmp['history_type'] = item.history_type.name - item_tmp['history_object'] = item.history_object.name - if item.history_attribute - item_tmp['history_attribute'] = item.history_attribute.name - end - item_tmp.delete( 'history_attribute_id' ) - item_tmp.delete( 'history_object_id' ) - item_tmp.delete( 'history_type_id' ) - item_tmp.delete( 'o_id' ) - item_tmp.delete( 'updated_at' ) - if item_tmp['id_to'] == nil && item_tmp['id_from'] == nil - item_tmp.delete( 'id_to' ) - item_tmp.delete( 'id_from' ) - end - if item_tmp['value_to'] == nil && item_tmp['value_from'] == nil - item_tmp.delete( 'value_to' ) - item_tmp.delete( 'value_from' ) - end - if item_tmp['related_history_object_id'] == nil - item_tmp.delete( 'related_history_object_id' ) - end - if item_tmp['related_o_id'] == nil - item_tmp.delete( 'related_o_id' ) - end - list.push item_tmp - } - return list + return history end def self.activity_stream( user, limit = 10 ) diff --git a/test/unit/history_test.rb b/test/unit/history_test.rb index 35f2ce47a..e3298afe9 100644 --- a/test/unit/history_test.rb +++ b/test/unit/history_test.rb @@ -163,39 +163,34 @@ class HistoryTest < ActiveSupport::TestCase # get history history_list = History.list( 'Ticket', ticket.id, 'Ticket::Article' ) - puts history_list.inspect - test[:history_check].each { |check_item| -# puts '+++++++++++' -# puts check_item.inspect + test[:history_check].each { |check| match = false - history_list.each { |history_item| + history_list.each { |history| next if match -# puts '--------' -# puts history_item.inspect - next if history_item['history_object'] != check_item[:history_object] - next if history_item['history_type'] != check_item[:history_type] - next if check_item[:history_attribute] != history_item['history_attribute'] + next if history.history_object.name != check[:history_object] + next if history.history_type.name != check[:history_type] + next if check[:history_attribute] && history.history_attribute.name != check[:history_attribute] match = true - if history_item['history_type'] == check_item[:history_type] - assert( true, "History type #{history_item['history_type']} found!") + if history.history_type.name == check[:history_type] + assert( true, "History type #{history.history_type.name} found!") end - if check_item[:history_attribute] - assert_equal( check_item[:history_attribute], history_item['history_attribute'], "check history attribute #{check_item[:history_attribute]}") + if check[:history_attribute] + assert_equal( check[:history_attribute], history.history_attribute.name, "check history attribute #{check[:history_attribute]}") end - if check_item[:value_from] - assert_equal( check_item[:value_from], history_item['value_from'], "check history :value_from #{history_item['value_from']} ok") + if check[:value_from] + assert_equal( check[:value_from], history.value_from, "check history :value_from #{history.value_from} ok") end - if check_item[:value_to] - assert_equal( check_item[:value_to], history_item['value_to'], "check history :value_to #{history_item['value_to']} ok") + if check[:value_to] + assert_equal( check[:value_to], history.value_to, "check history :value_to #{history.value_to} ok") end - if check_item[:id_from] - assert_equal( check_item[:id_from], history_item['id_from'], "check history :id_from #{history_item['id_from']} ok") + if check[:id_from] + assert_equal( check[:id_from], history.id_from, "check history :id_from #{history.id_from} ok") end - if check_item[:id_to] - assert_equal( check_item[:id_to], history_item['id_to'], "check history :id_to #{history_item['id_to']} ok") + if check[:id_to] + assert_equal( check[:id_to], history.id_to, "check history :id_to #{history.id_to} ok") end } - assert( match, "history check not matched! #{check_item.inspect}") + assert( match, "history check not matched! #{check.inspect}") } } @@ -204,7 +199,7 @@ class HistoryTest < ActiveSupport::TestCase ticket_id = ticket.id ticket.destroy found = Ticket.where( :id => ticket_id ).first - assert( !found, "Ticket destroyed") + assert( !found, 'Ticket destroyed') } end end