diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index df5353287..8bd408bce 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -375,6 +375,18 @@ class App.Controller extends Spine.Controller else fetch(params) + recentView: (object, o_id) => + params = + object: object + o_id: o_id + App.Ajax.request( + id: "recent_view_#{object}_#{o_id}" + type: 'POST' + url: @Config.get('api_path') + '/recent_viewed' + data: JSON.stringify(params) + processData: true + ) + ws_send: (data) -> App.Event.trigger( 'ws:send', JSON.stringify(data) ) diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index 6a898127e..e9c1ded07 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -339,13 +339,28 @@ class App.Navigation extends App.Controller if prio is 8000 divider = true navheader = 'Recent Viewed' - ticket = App.Ticket.find( item.o_id ) + + item.link = '' + item.title = '???' + + # convert backend name space to local name space + item.object = item.object.replace("::", '') + + # lookup real data + if App[item.object] + object = App[item.object].find( item.o_id ) + item.link = object.uiUrl() + item.title = object.displayName() + item.object_name = object.objectDisplayName() + + item.created_by = App.User.find( item.created_by_id ) + prio++ - NavBarRight['RecendViewed::' + ticket.id + '-' + prio ] = { + NavBarRight['RecendViewed::' + item.o_id + item.object + '-' + prio ] = { prio: prio parent: '#current_user' - name: item.recent_view_object + ' (' + ticket.title + ')' - target: ticket.uiUrl() + name: App.i18n.translateInline(item.object) + ' (' + item.title + ')' + target: item.link divider: divider navheader: navheader } diff --git a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee index 02b88bcf4..b06dc9f4f 100644 --- a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee @@ -37,6 +37,10 @@ class App.OrganizationZoom extends App.Controller render: (organization) => + if !@doNotLog + @doNotLog = 1 + @recentView( 'Organization', @organization_id ) + @html App.view('organization_zoom')( organization: organization ) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index e431276bd..d63ebd71a 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -16,7 +16,6 @@ class App.TicketZoom extends App.Controller @ticket_id = params.ticket_id @article_id = params.article_id @signature = undefined - @doNotLog = params['doNotLog'] || 0 @key = 'ticket::' + @ticket_id cache = App.Store.get( @key ) @@ -73,7 +72,7 @@ class App.TicketZoom extends App.Controller @ajax( id: 'ticket_zoom_' + ticket_id type: 'GET' - url: @apiPath + '/ticket_full/' + ticket_id + '?do_not_log=' + @doNotLog + url: @apiPath + '/ticket_full/' + ticket_id processData: true success: (data, status, xhr) => @@ -108,7 +107,10 @@ class App.TicketZoom extends App.Controller # remove task App.TaskManager.remove( @task_key ) ) - @doNotLog = 1 + + if !@doNotLog + @doNotLog = 1 + @recentView( 'Ticket', ticket_id ) load: (data, force) => diff --git a/app/assets/javascripts/app/controllers/user_zoom.js.coffee b/app/assets/javascripts/app/controllers/user_zoom.js.coffee index f5269ad40..2834c5513 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -37,6 +37,9 @@ class App.UserZoom extends App.Controller render: (user) => + if !@doNotLog + @doNotLog = 1 + @recentView( 'User', @user_id ) @html App.view('user_zoom')( user: user diff --git a/app/assets/javascripts/app/models/_application_model.js.coffee b/app/assets/javascripts/app/models/_application_model.js.coffee index b47641675..ba15e918d 100644 --- a/app/assets/javascripts/app/models/_application_model.js.coffee +++ b/app/assets/javascripts/app/models/_application_model.js.coffee @@ -57,6 +57,10 @@ class App.Model extends Spine.Model else if @department name = "#{name} (#{@department})" return name + if @email + return @email + if @title + return @title return '???' icon: (user) -> diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 848319c87..1213a3894 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -223,10 +223,6 @@ class ApplicationController < ActionController::Base return false end - def log_view (object) - RecentView.log( object, current_user ) - end - def config_frontend # config diff --git a/app/controllers/recent_viewed_controller.rb b/app/controllers/recent_viewed_controller.rb index 1f0e67594..9d4cc285a 100644 --- a/app/controllers/recent_viewed_controller.rb +++ b/app/controllers/recent_viewed_controller.rb @@ -14,15 +14,42 @@ Response: } Test: -curl http://localhost/api/v1/recent_viewed.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET +curl http://localhost/api/v1/recent_viewed -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET =end - def recent_viewed + def index recent_viewed = RecentView.list_fulldata( current_user, 10 ) # return result render :json => recent_viewed end -end +=begin + +Resource: +POST /api/v1/recent_viewed + +Payload: +{ + "object": "Ticket", + "o_id": 123, +} + +Response: +{} + +Test: +curl http://localhost/api/v1/recent_viewed -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"object": "Ticket","o_id": 123}' + +=end + + def create + + RecentView.log( params[:object], params[:o_id], current_user ) + + # return result + render :json => { :message => 'ok' } + end + +end \ No newline at end of file diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 05c2e7837..eb5fd344a 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -239,11 +239,6 @@ class TicketsController < ApplicationController ticket = Ticket.find( params[:id] ) return if !ticket_permission( ticket ) - # log object as viewed - if !params[:do_not_log] || params[:do_not_log].to_i == 0 - log_view( ticket ) - end - # get signature signature = {} if ticket.group.signature diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index 088c50750..5468724fe 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -2,11 +2,8 @@ class ActivityStream < ApplicationModel self.table_name = 'activity_streams' - belongs_to :activity_stream_type, :class_name => 'ActivityStream::Type' - belongs_to :activity_stream_object, :class_name => 'ActivityStream::Object' - - @@cache_type = {} - @@cache_object = {} + belongs_to :activity_stream_type, :class_name => 'TypeLookup' + belongs_to :activity_stream_object, :class_name => 'ObjectLookup' =begin @@ -27,10 +24,10 @@ add a new activity entry for an object # lookups if data[:type] - type = self.type_lookup( data[:type] ) + type_id = TypeLookup.by_name( data[:type] ) end if data[:object] - object = self.object_lookup( data[:object] ) + object_id = ObjectLookup.by_name( data[:object] ) end role_id = nil @@ -45,9 +42,9 @@ add a new activity entry for an object # check newest entry - is needed result = ActivityStream.where( :o_id => data[:o_id], - # :activity_stream_type_id => type.id, + # :activity_stream_type_id => type_id, :role_id => role_id, - :activity_stream_object_id => object.id, + :activity_stream_object_id => object_id, :created_by_id => data[:created_by_id] ).order('created_at DESC, id DESC').first @@ -57,8 +54,8 @@ add a new activity entry for an object # create history record = { :o_id => data[:o_id], - :activity_stream_type_id => type.id, - :activity_stream_object_id => object.id, + :activity_stream_type_id => type_id, + :activity_stream_object_id => object_id, :role_id => role_id, :group_id => data[:group_id], :created_at => data[:created_at], @@ -77,9 +74,9 @@ remove whole activity entries of an object =end def self.remove( object_name, o_id ) - object = self.object_lookup( object_name ) + object_id = ObjectLookup.by_name( object_name ) ActivityStream.where( - :activity_stream_object_id => object.id, + :activity_stream_object_id => object_id, :o_id => o_id, ).destroy_all end @@ -112,8 +109,8 @@ return all activity entries of an user list = [] stream.each do |item| data = item.attributes - data['object'] = self.object_lookup_id( data['activity_stream_object_id'] ).name - data['type'] = self.type_lookup_id( data['activity_stream_type_id'] ).name + data['object'] = ObjectLookup.by_id( data['activity_stream_object_id'] ) + data['type'] = TypeLookup.by_id( data['activity_stream_type_id'] ) data.delete('activity_stream_object_id') data.delete('activity_stream_type_id') list.push data @@ -123,68 +120,6 @@ return all activity entries of an user private - def self.type_lookup_id( id ) - - # use cache - return @@cache_type[ id ] if @@cache_type[ id ] - - # lookup - type = ActivityStream::Type.lookup( :id => id ) - @@cache_type[ id ] = type - type - end - - def self.type_lookup( name ) - - # use cache - return @@cache_type[ name ] if @@cache_type[ name ] - - # lookup - type = ActivityStream::Type.lookup( :name => name ) - if type - @@cache_type[ name ] = type - return type - end - - # create - type = ActivityStream::Type.create( - :name => name - ) - @@cache_type[ name ] = type - type - end - - def self.object_lookup_id( id ) - - # use cache - return @@cache_object[ id ] if @@cache_object[ id ] - - # lookup - object = ActivityStream::Object.lookup( :id => id ) - @@cache_object[ id ] = object - object - end - - def self.object_lookup( name ) - - # use cache - return @@cache_object[ name ] if @@cache_object[ name ] - - # lookup - object = ActivityStream::Object.lookup( :name => name ) - if object - @@cache_object[ name ] = object - return object - end - - # create - object = ActivityStream::Object.create( - :name => name - ) - @@cache_object[ name ] = object - object - end - class Object < ApplicationModel end diff --git a/app/models/application_model.rb b/app/models/application_model.rb index aaaf4e568..6fd36e31e 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -31,6 +31,8 @@ class ApplicationModel < ActiveRecord::Base after_update :search_index_update after_destroy :search_index_destroy + after_destroy :recent_view_destroy + # create instance accessor class << self attr_accessor :activity_stream_support_config, :history_support_config, :search_index_support_config @@ -817,6 +819,27 @@ store attachments for this object end end +=begin + +return object and assets + + data = Model.full(123) + data = { + :id => 123, + :assets => assets, + } + +=end + + def self.full(id) + object = self.find(id) + assets = object.assets({}) + { + :id => id, + :assets => assets, + } + end + private def attachments_buffer @@ -848,6 +871,19 @@ store attachments for this object =begin +delete object recent viewed list, will be executed automatically + + model = Model.find(123) + model.recent_view_destroy + +=end + + def recent_view_destroy + RecentView.log_destroy( self.class.to_s, self.id ) + end + +=begin + check string/varchar size and cut them if needed =end @@ -883,25 +919,4 @@ destory object dependencies, will be executed automatically def destroy_dependencies end -=begin - -return object and assets - - data = Model.full(123) - data = { - :id => 123, - :assets => assets, - } - -=end - - def self.full(id) - object = self.find(id) - assets = object.assets({}) - { - :id => id, - :assets => assets, - } - end - end diff --git a/app/models/object_lookup.rb b/app/models/object_lookup.rb new file mode 100644 index 000000000..456b6100c --- /dev/null +++ b/app/models/object_lookup.rb @@ -0,0 +1,38 @@ +# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ + +class ObjectLookup < ApplicationModel + @@cache_object = {} + + def self.by_id( id ) + + # use cache + return @@cache_object[ id ] if @@cache_object[ id ] + + # lookup + lookup = self.lookup( :id => id ) + return if !lookup + @@cache_object[ id ] = lookup.name + lookup.name + end + + def self.by_name( name ) + + # use cache + return @@cache_object[ name ] if @@cache_object[ name ] + + # lookup + lookup = self.lookup( :name => name ) + if lookup + @@cache_object[ name ] = lookup.id + return lookup.id + end + + # create + lookup = self.create( + :name => name + ) + @@cache_object[ name ] = lookup.id + lookup.id + end + +end \ No newline at end of file diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index c3a37ed15..f0b4f8d77 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -1,30 +1,32 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ class RecentView < ApplicationModel - belongs_to :recent_view_object, :class_name => 'RecentView::Object' + belongs_to :object_lookup, :class_name => 'ObjectLookup' - @@cache_object = {} - - def self.log( object, user ) + def self.log( object, o_id, user ) # lookups - recent_view_object = self.object_lookup( object.class.to_s ) + object_lookup_id = ObjectLookup.by_name( object ) # create entry record = { - :o_id => object.id, - :recent_view_object_id => recent_view_object.id, + :o_id => o_id, + :recent_view_object_id => object_lookup_id.to_i, :created_by_id => user.id, } RecentView.create(record) end def self.log_destroy( requested_object, requested_object_id ) - RecentView.where( :recent_view_object_id => RecentView::Object.where( :name => requested_object ) ). + RecentView.where( :recent_view_object_id => ObjectLookup.by_name( requested_object ) ). where( :o_id => requested_object_id ). destroy_all end + def self.user_log_destroy( user ) + RecentView.where( :created_by_id => user.id ).destroy_all + end + def self.list( user, limit = 10 ) recent_views = RecentView.where( :created_by_id => user.id ). order('created_at DESC, id DESC'). @@ -33,8 +35,8 @@ class RecentView < ApplicationModel list = [] recent_views.each { |item| data = item.attributes - data['recent_view_object'] = self.object_lookup_id( data['recent_view_object_id'] ).name - data.delete( 'history_object_id' ) + data['object'] = ObjectLookup.by_id( data['recent_view_object_id'] ) + data.delete( 'recent_view_object_id' ) list.push data } list @@ -48,61 +50,17 @@ class RecentView < ApplicationModel ticket_ids = [] recent_viewed.each {|item| - # load article ids - # if item.recent_view_object == 'Ticket' - ticket = Ticket.find( item['o_id'] ) - ticket_ids.push ticket.id - # end - # if item.recent_view_object 'Ticket::Article' - # tickets.push Ticket::Article.find(item.o_id) - # end - # if item.recent_view_object 'User' - # tickets.push User.find(item.o_id) - # end + # get related objects + require item['object'].to_filename + record = Kernel.const_get( item['object'] ).find( item['o_id'] ) + assets = record.assets(assets) - assets = ticket.assets(assets) } return { :recent_viewed => recent_viewed, - :ticket_ids => ticket_ids, :assets => assets, } end - - private - - def self.object_lookup_id( id ) - - # use cache - return @@cache_object[ id ] if @@cache_object[ id ] - - # lookup - history_object = RecentView::Object.lookup( :id => id ) - @@cache_object[ id ] = history_object - history_object - end - - def self.object_lookup( name ) - - # use cache - return @@cache_object[ name ] if @@cache_object[ name ] - - # lookup - recent_view_object = RecentView::Object.lookup( :name => name ) - if recent_view_object - @@cache_object[ name ] = recent_view_object - return recent_view_object - end - - # create - recent_view_object = RecentView::Object.create( - :name => name - ) - @@cache_object[ name ] = recent_view_object - recent_view_object - end - class Object < ApplicationModel end - -end +end \ No newline at end of file diff --git a/app/models/store/file.rb b/app/models/store/file.rb index ef7313300..978abf108 100644 --- a/app/models/store/file.rb +++ b/app/models/store/file.rb @@ -57,6 +57,8 @@ class Store::File < ApplicationModel end # move file from one to other provider + # e. g. Store::File.move('File', 'DB') + # e. g. Store::File.move('DB', 'File') def self.move(source, target) adapter_source = load_adapter("Store::Provider::#{ source }") adapter_target = load_adapter("Store::Provider::#{ target }") diff --git a/app/models/type_lookup.rb b/app/models/type_lookup.rb new file mode 100644 index 000000000..05f9a6da6 --- /dev/null +++ b/app/models/type_lookup.rb @@ -0,0 +1,38 @@ +# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ + +class TypeLookup < ApplicationModel + @@cache_object = {} + + def self.by_id( id ) + + # use cache + return @@cache_object[ id ] if @@cache_object[ id ] + + # lookup + lookup = self.lookup( :id => id ) + return if !lookup + @@cache_object[ id ] = lookup.name + lookup.name + end + + def self.by_name( name ) + + # use cache + return @@cache_object[ name ] if @@cache_object[ name ] + + # lookup + lookup = self.lookup( :name => name ) + if lookup + @@cache_object[ name ] = lookup.id + return lookup.id + end + + # create + lookup = self.create( + :name => name + ) + @@cache_object[ name ] = lookup.id + lookup.id + end + +end \ No newline at end of file diff --git a/config/routes/recent_viewed.rb b/config/routes/recent_viewed.rb index ed388e9dd..7b584d5a4 100644 --- a/config/routes/recent_viewed.rb +++ b/config/routes/recent_viewed.rb @@ -1,5 +1,6 @@ Zammad::Application.routes.draw do api_path = Rails.configuration.api_path - match api_path + '/recent_viewed', :to => 'recent_viewed#recent_viewed', :via => :get + match api_path + '/recent_viewed', :to => 'recent_viewed#index', :via => :get + match api_path + '/recent_viewed', :to => 'recent_viewed#create', :via => :post end \ No newline at end of file diff --git a/db/migrate/20120101000001_create_base.rb b/db/migrate/20120101000001_create_base.rb index a5411f1c0..003b568ea 100644 --- a/db/migrate/20120101000001_create_base.rb +++ b/db/migrate/20120101000001_create_base.rb @@ -1,6 +1,6 @@ class CreateBase < ActiveRecord::Migration def up - + create_table :sessions do |t| t.string :session_id, :null => false t.text :data @@ -144,6 +144,18 @@ class CreateBase < ActiveRecord::Migration add_index :translations, [:source] add_index :translations, [:locale] + create_table :object_lookups do |t| + t.column :name, :string, :limit => 250, :null => false + t.timestamps + end + add_index :object_lookups, [:name], :unique => true + + create_table :type_lookups do |t| + t.column :name, :string, :limit => 250, :null => false + t.timestamps + end + add_index :type_lookups, [:name], :unique => true + end end diff --git a/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb b/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb new file mode 100644 index 000000000..85a721de8 --- /dev/null +++ b/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb @@ -0,0 +1,24 @@ +class UpdateRecentViewedCreateObjectLookup < ActiveRecord::Migration + def up + + if !ActiveRecord::Base.connection.table_exists? 'object_lookups' + create_table :object_lookups do |t| + t.column :name, :string, :limit => 250, :null => false + t.timestamps + end + add_index :object_lookups, [:name], :unique => true + end + RecentView.all.each {|entry| + ro = RecentView::Object.find(entry.recent_view_object_id) + lookup_id = ObjectLookup.by_name( ro.name ) + entry.update_attribute( :recent_view_object_id, lookup_id ) + entry.cache_delete + } + + drop_table :recent_view_objects + Cache.clear + end + + def down + end +end \ No newline at end of file diff --git a/db/migrate/20140823000002_update_activity_stream_object_lookup.rb b/db/migrate/20140823000002_update_activity_stream_object_lookup.rb new file mode 100644 index 000000000..7dae9a53b --- /dev/null +++ b/db/migrate/20140823000002_update_activity_stream_object_lookup.rb @@ -0,0 +1,16 @@ +class UpdateActivityStreamObjectLookup < ActiveRecord::Migration + def up + + ActivityStream.all.each {|entry| + ao = ActivityStream::Object.find(entry.activity_stream_object_id) + lookup_id = ObjectLookup.by_name( ao.name ) + entry.update_attribute( :activity_stream_object_id, lookup_id ) + entry.cache_delete + } + drop_table :activity_stream_objects + Cache.clear + end + + def down + end +end diff --git a/db/migrate/20140824000001_update_activity_stream_create_type_lookup.rb b/db/migrate/20140824000001_update_activity_stream_create_type_lookup.rb new file mode 100644 index 000000000..415c9c487 --- /dev/null +++ b/db/migrate/20140824000001_update_activity_stream_create_type_lookup.rb @@ -0,0 +1,24 @@ +class UpdateActivityStreamCreateTypeLookup < ActiveRecord::Migration + def up + + if !ActiveRecord::Base.connection.table_exists? 'type_lookups' + create_table :type_lookups do |t| + t.column :name, :string, :limit => 250, :null => false + t.timestamps + end + add_index :type_lookups, [:name], :unique => true + end + ActivityStream.all.each {|entry| + ro = ActivityStream::Type.find(entry.activity_stream_type_id) + lookup_id = TypeLookup.by_name( ro.name ) + entry.update_attribute( :activity_stream_type_id, lookup_id ) + entry.cache_delete + } + + drop_table :activity_stream_types + Cache.clear + end + + def down + end +end diff --git a/script/systemd/zammad.service b/script/systemd/zammad.service new file mode 100644 index 000000000..b928cd2a5 --- /dev/null +++ b/script/systemd/zammad.service @@ -0,0 +1,13 @@ +[Unit] +Description=Zammad Application + +[Service] +Type=forking +User=zammad +WorkingDirectory=/home/zammad/zammad +Environment=RAILS_ENV=production +PIDFile=/var/run/zammad.puma.pid +ExecStart=puma -p 3000 -d -e production --pidfile /var/run/zammad.puma.pid + +[Install] +WantedBy=multi-user.target diff --git a/test/unit/object_type_lookup_test.rb b/test/unit/object_type_lookup_test.rb new file mode 100644 index 000000000..c54ae65be --- /dev/null +++ b/test/unit/object_type_lookup_test.rb @@ -0,0 +1,84 @@ +# encoding: utf-8 +require 'test_helper' + +class ObjectTypeLookupTest < ActiveSupport::TestCase + + test 'object tests' do + + object_lookup_id = ObjectLookup.by_name( 'SomeObject' ) + assert( object_lookup_id, 'first by_name' ) + + object_lookup_name = ObjectLookup.by_id( object_lookup_id ) + assert( object_lookup_name, 'first by_id' ) + assert_equal( object_lookup_name, 'SomeObject' ) + + + object_lookup_id2 = ObjectLookup.by_name( 'Some_Object' ) + assert( object_lookup_id2, 'by_name - Some_Object' ) + + object_lookup_name2 = ObjectLookup.by_id( object_lookup_id2 ) + assert( object_lookup_name2, 'by_id - Some_Object' ) + assert_equal( object_lookup_name2, 'Some_Object' ) + + + object_lookup_id3 = ObjectLookup.by_name( 'SomeObject' ) + assert( object_lookup_id3, 'by_name 2 - SomeObject' ) + + object_lookup_name3 = ObjectLookup.by_id( object_lookup_id3 ) + assert( object_lookup_name3, 'by_id 2 - SomeObject' ) + assert_equal( object_lookup_name3, 'SomeObject' ) + assert_equal( object_lookup_name3, object_lookup_name, 'SomeObject' ) + assert_equal( object_lookup_id3, object_lookup_id, 'SomeObject' ) + + end + + test 'type tests' do + + type_lookup_id = TypeLookup.by_name( 'SomeType' ) + assert( type_lookup_id, 'first by_name' ) + + type_lookup_name = TypeLookup.by_id( type_lookup_id ) + assert( type_lookup_name, 'first by_id' ) + assert_equal( type_lookup_name, 'SomeType' ) + + + type_lookup_id2 = TypeLookup.by_name( 'Some_Type' ) + assert( type_lookup_id2, 'by_name - Some_Type' ) + + type_lookup_name2 = TypeLookup.by_id( type_lookup_id2 ) + assert( type_lookup_name2, 'by_id - Some_Type' ) + assert_equal( type_lookup_name2, 'Some_Type' ) + + + type_lookup_id3 = TypeLookup.by_name( 'SomeType' ) + assert( type_lookup_id3, 'by_name 2 - SomeType' ) + + type_lookup_name3 = TypeLookup.by_id( type_lookup_id3 ) + assert( type_lookup_name3, 'by_id 2 - SomeType' ) + assert_equal( type_lookup_name3, 'SomeType' ) + assert_equal( type_lookup_name3, type_lookup_name, 'SomeType' ) + assert_equal( type_lookup_id3, type_lookup_id, 'SomeType' ) + + end + + test 'type and object tests' do + + object_lookup_id = ObjectLookup.by_name( 'SomeObject' ) + assert( object_lookup_id, 'first by_name' ) + + object_lookup_name = ObjectLookup.by_id( object_lookup_id ) + assert( object_lookup_name, 'first by_id' ) + assert_equal( object_lookup_name, 'SomeObject' ) + + type_lookup_id = TypeLookup.by_name( 'SomeType' ) + assert( type_lookup_id, 'first by_name' ) + + type_lookup_name = TypeLookup.by_id( type_lookup_id ) + assert( type_lookup_name, 'first by_id' ) + assert_equal( type_lookup_name, 'SomeType' ) + + assert_not_equal( object_lookup_name, type_lookup_name, 'verify lookups' ) + + end + +end diff --git a/test/unit/recent_view_test.rb b/test/unit/recent_view_test.rb new file mode 100644 index 000000000..7235c52e4 --- /dev/null +++ b/test/unit/recent_view_test.rb @@ -0,0 +1,59 @@ +# encoding: utf-8 +require 'test_helper' + +class RecentViewTest < ActiveSupport::TestCase + + test 'simple tests' do + + ticket1 = Ticket.create( + :title => 'RecentViewTest 1 some title äöüß', + :group => Group.lookup( :name => 'Users'), + :customer_id => 2, + :state => Ticket::State.lookup( :name => 'new' ), + :priority => Ticket::Priority.lookup( :name => '2 normal' ), + :updated_by_id => 1, + :created_by_id => 1, + ) + assert( ticket1, "ticket created" ) + ticket2 = Ticket.create( + :title => 'RecentViewTest 2 some title äöüß', + :group => Group.lookup( :name => 'Users'), + :customer_id => 2, + :state => Ticket::State.lookup( :name => 'new' ), + :priority => Ticket::Priority.lookup( :name => '2 normal' ), + :updated_by_id => 1, + :created_by_id => 1, + ) + assert( ticket2, "ticket created" ) + user1 = User.find(2) + RecentView.user_log_destroy(user1) + + + RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) + sleep 1 + RecentView.log( ticket2.class.to_s, ticket2.id, user1 ) + sleep 1 + RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) + sleep 1 + RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) + + list = RecentView.list( user1 ) + assert( list[0]['o_id'], ticket1.id ) + assert( list[0]['object'], 'Ticket' ) + + assert( list[1]['o_id'], ticket1.id ) + assert( list[1]['object'], 'Ticket' ) + + assert( list[2]['o_id'], ticket2.id ) + assert( list[2]['object'], 'Ticket' ) + + assert( list[3]['o_id'], ticket1.id ) + assert( list[3]['object'], 'Ticket' ) + + ticket1.destroy + ticket2.destroy + + list = RecentView.list( user1 ) + assert( !list[0], 'check if recent view list is empty' ) + end +end diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index 1875c20f7..442ba03c9 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -261,7 +261,7 @@ class SessionBasicTest < ActiveSupport::TestCase user = User.lookup(:id => 1) ticket = Ticket.all.last - RecentView.log( ticket, user ) + RecentView.log( ticket.class.to_s, ticket.id, user ) recent_viewed_client1 = Sessions::Backend::RecentViewed.new(user, false, '123-1') # get as stream @@ -278,7 +278,7 @@ class SessionBasicTest < ActiveSupport::TestCase result1 = recent_viewed_client1.push assert( !result1, "check recent_viewed - recall 2" ) - RecentView.log( ticket, user ) + RecentView.log( ticket.class.to_s, ticket.id, user ) sleep 20