Improved API, renamed methodes.

This commit is contained in:
Martin Edenhofer 2013-06-04 14:52:56 +02:00
parent b47ad57129
commit 9e20b7d995
9 changed files with 42 additions and 43 deletions

View file

@ -147,7 +147,7 @@ class TicketsController < ApplicationController
return if !ticket_permission( ticket )
# get history of ticket
history = History.history_list( 'Ticket', params[:id], 'Ticket::Article' )
history = History.list( 'Ticket', params[:id], 'Ticket::Article' )
# get related users
users = {}

View file

@ -10,7 +10,7 @@ class History < ApplicationModel
@@cache_object = {}
@@cache_attribute = {}
def self.history_create(data)
def self.add(data)
# lookups
if data[:history_type]
@ -61,13 +61,15 @@ class History < ApplicationModel
end
end
def self.history_destroy( requested_object, requested_object_id )
History.where( :history_object_id => History::Object.where( :name => requested_object ) ).
where( :o_id => requested_object_id ).
destroy_all
def self.remove( requested_object, requested_object_id )
history_object = History::Object.where( :name => requested_object ).first
History.where(
:history_object_id => history_object.id,
:o_id => requested_object_id,
).destroy_all
end
def self.history_list( requested_object, requested_object_id, related_history_object = nil )
def self.list( requested_object, requested_object_id, related_history_object = nil )
if !related_history_object
history_object = self.history_object_lookup( requested_object )
history = History.where( :history_object_id => history_object.id ).
@ -179,7 +181,7 @@ class History < ApplicationModel
if item['history_object'] == 'User'
users[ item['o_id'] ] = User.user_data_full( item['o_id'] )
end
# load users
if !users[ item['created_by_id'] ]
users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] )

View file

@ -19,7 +19,7 @@ class Observer::History < ActiveRecord::Observer
related_o_id = record.ticket_id
related_history_object = 'Ticket'
end
History.history_create(
History.add(
:o_id => record.id,
:history_type => 'created',
:history_object => record.class.name,
@ -143,7 +143,7 @@ class Observer::History < ActiveRecord::Observer
related_o_id = record.ticket_id
related_history_object_id = 'Ticket'
end
History.history_create(
History.add(
:o_id => current.id,
:history_type => 'updated',
:history_object => record.class.name,
@ -169,4 +169,4 @@ class Observer::History < ActiveRecord::Observer
end
h
end
end
end

View file

@ -9,13 +9,12 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer
return true if record.tag_object.name != 'Ticket';
# add ticket history
History.history_create(
History.add(
:o_id => record.o_id,
:history_type => 'added',
:history_object => 'Ticket',
:history_attribute => 'Tag',
:value_from => record.tag_item.name,
:created_by_id => record.created_by_id || UserInfo.current_user_id || 1
)
end
def after_destroy(record)
@ -24,13 +23,12 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer
return true if record.tag_object.name != 'Ticket';
# add ticket history
History.history_create(
History.add(
:o_id => record.o_id,
:history_type => 'removed',
:history_object => 'Ticket',
:history_attribute => 'Tag',
:value_from => record.tag_item.name,
:created_by_id => record.created_by_id || UserInfo.current_user_id || 1
)
end
end
end

View file

@ -55,7 +55,7 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer
end
}
if recipient_list != ''
History.history_create(
History.add(
:o_id => record.id,
:history_type => 'email',
:history_object => 'Ticket::Article',
@ -63,8 +63,7 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer
:related_history_object => 'Ticket',
:value_from => record.subject,
:value_to => recipient_list,
:created_by_id => record.created_by_id,
)
end
end
end
end

View file

@ -24,7 +24,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
ticket = article.ticket
elsif event[:name] == 'Ticket'
ticket = Ticket.lookup( :id => event[:id] )
# next if ticket is already deleted
next if !ticket
@ -235,7 +235,7 @@ From: #{article.from}
# add history record
if recipient_list != ''
History.history_create(
History.add(
:o_id => ticket.id,
:history_type => 'notification',
:history_object => 'Ticket',
@ -299,4 +299,4 @@ From: #{article.from}
# puts @a.inspect
# AuditTrail.new(record, "UPDATED")
end
end
end

View file

@ -695,7 +695,7 @@ class Ticket < ApplicationModel
def destroy_dependencies
# delete history
History.history_destroy( 'Ticket', self.id )
History.remove( 'Ticket', self.id )
# delete articles
self.articles.destroy_all
@ -704,4 +704,4 @@ class Ticket < ApplicationModel
class Number
end
end
end

View file

@ -206,7 +206,7 @@ module Import::OTRS
result = json(response)
self._ticket_result(result)
end
def self._ticket_result(result)
# puts result.inspect
map = {
@ -309,7 +309,7 @@ module Import::OTRS
end
record['Articles'].each { |article|
# get article values
article_new = {
:created_by_id => 1,
@ -342,10 +342,10 @@ module Import::OTRS
rescue
display_name = article_new[:from]
end
# do extra decoding because we needed to use field.value
display_name = Mail::Field.new( 'X-From', display_name ).to_s
roles = Role.lookup( :name => 'Customer' )
user = User.create(
:login => email,
@ -361,7 +361,7 @@ module Import::OTRS
end
article_new[:created_by_id] = user.id
end
if article_new[:ticket_article_sender] == 'customer'
article_new[:ticket_article_sender_id] = Ticket::Article::Sender.lookup( :name => 'Customer' ).id
article_new.delete( :ticket_article_sender )
@ -374,7 +374,7 @@ module Import::OTRS
article_new[:ticket_article_sender_id] = Ticket::Article::Sender.lookup( :name => 'System' ).id
article_new.delete( :ticket_article_sender )
end
if article_new[:ticket_article_type] == 'email-external'
article_new[:ticket_article_type_id] = Ticket::Article::Type.lookup( :name => 'email' ).id
article_new[:internal] = false
@ -410,14 +410,14 @@ module Import::OTRS
article.id = article_new[:id]
article.save
end
}
record['History'].each { |history|
# puts '-------'
# puts history.inspect
if history['HistoryType'] == 'NewTicket'
History.history_create(
History.add(
:id => history['HistoryID'],
:o_id => history['TicketID'],
:history_type => 'created',
@ -444,7 +444,7 @@ module Import::OTRS
end
end
# puts "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}"
History.history_create(
History.add(
:id => history['HistoryID'],
:o_id => history['TicketID'],
:history_type => 'updated',
@ -469,7 +469,7 @@ module Import::OTRS
to = $3
to_id = $4
end
History.history_create(
History.add(
:id => history['HistoryID'],
:o_id => history['TicketID'],
:history_type => 'updated',
@ -494,7 +494,7 @@ module Import::OTRS
to = $3
to_id = $4
end
History.history_create(
History.add(
:id => history['HistoryID'],
:o_id => history['TicketID'],
:history_type => 'updated',
@ -509,7 +509,7 @@ module Import::OTRS
)
end
if history['ArticleID'] && history['ArticleID'] != 0
History.history_create(
History.add(
:id => history['HistoryID'],
:o_id => history['ArticleID'],
:history_type => 'created',
@ -688,7 +688,7 @@ module Import::OTRS
:UserLastname => :lastname,
# :UserTitle =>
:UserLogin => :login,
:UserPw => :password,
:UserPw => :password,
};
result.each { |user|

View file

@ -1,6 +1,6 @@
# encoding: utf-8
require 'test_helper'
class HistoryTest < ActiveSupport::TestCase
test 'ticket' do
tests = [
@ -154,15 +154,15 @@ class HistoryTest < ActiveSupport::TestCase
article.update_attributes( test[:ticket_update][:article] )
end
end
# execute ticket events
# execute ticket events
Observer::Ticket::Notification.transaction
# remember ticket
tickets.push ticket
# get history
history_list = History.history_list( 'Ticket', ticket.id, 'Ticket::Article' )
history_list = History.list( 'Ticket', ticket.id, 'Ticket::Article' )
puts history_list.inspect
test[:history_check].each { |check_item|
# puts '+++++++++++'
@ -207,4 +207,4 @@ class HistoryTest < ActiveSupport::TestCase
assert( !found, "Ticket destroyed")
}
end
end
end