Merge branch 'develop' into interface

This commit is contained in:
Martin Edenhofer 2014-08-24 12:07:18 +02:00
commit 4e5fb8373f
24 changed files with 457 additions and 180 deletions

View file

@ -375,6 +375,18 @@ class App.Controller extends Spine.Controller
else else
fetch(params) 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) -> ws_send: (data) ->
App.Event.trigger( 'ws:send', JSON.stringify(data) ) App.Event.trigger( 'ws:send', JSON.stringify(data) )

View file

@ -339,13 +339,28 @@ class App.Navigation extends App.Controller
if prio is 8000 if prio is 8000
divider = true divider = true
navheader = 'Recent Viewed' 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++ prio++
NavBarRight['RecendViewed::' + ticket.id + '-' + prio ] = { NavBarRight['RecendViewed::' + item.o_id + item.object + '-' + prio ] = {
prio: prio prio: prio
parent: '#current_user' parent: '#current_user'
name: item.recent_view_object + ' (' + ticket.title + ')' name: App.i18n.translateInline(item.object) + ' (' + item.title + ')'
target: ticket.uiUrl() target: item.link
divider: divider divider: divider
navheader: navheader navheader: navheader
} }

View file

@ -37,6 +37,10 @@ class App.OrganizationZoom extends App.Controller
render: (organization) => render: (organization) =>
if !@doNotLog
@doNotLog = 1
@recentView( 'Organization', @organization_id )
@html App.view('organization_zoom')( @html App.view('organization_zoom')(
organization: organization organization: organization
) )

View file

@ -16,7 +16,6 @@ class App.TicketZoom extends App.Controller
@ticket_id = params.ticket_id @ticket_id = params.ticket_id
@article_id = params.article_id @article_id = params.article_id
@signature = undefined @signature = undefined
@doNotLog = params['doNotLog'] || 0
@key = 'ticket::' + @ticket_id @key = 'ticket::' + @ticket_id
cache = App.Store.get( @key ) cache = App.Store.get( @key )
@ -73,7 +72,7 @@ class App.TicketZoom extends App.Controller
@ajax( @ajax(
id: 'ticket_zoom_' + ticket_id id: 'ticket_zoom_' + ticket_id
type: 'GET' type: 'GET'
url: @apiPath + '/ticket_full/' + ticket_id + '?do_not_log=' + @doNotLog url: @apiPath + '/ticket_full/' + ticket_id
processData: true processData: true
success: (data, status, xhr) => success: (data, status, xhr) =>
@ -108,7 +107,10 @@ class App.TicketZoom extends App.Controller
# remove task # remove task
App.TaskManager.remove( @task_key ) App.TaskManager.remove( @task_key )
) )
@doNotLog = 1
if !@doNotLog
@doNotLog = 1
@recentView( 'Ticket', ticket_id )
load: (data, force) => load: (data, force) =>

View file

@ -37,6 +37,9 @@ class App.UserZoom extends App.Controller
render: (user) => render: (user) =>
if !@doNotLog
@doNotLog = 1
@recentView( 'User', @user_id )
@html App.view('user_zoom')( @html App.view('user_zoom')(
user: user user: user

View file

@ -57,6 +57,10 @@ class App.Model extends Spine.Model
else if @department else if @department
name = "#{name} (#{@department})" name = "#{name} (#{@department})"
return name return name
if @email
return @email
if @title
return @title
return '???' return '???'
icon: (user) -> icon: (user) ->

View file

@ -223,10 +223,6 @@ class ApplicationController < ActionController::Base
return false return false
end end
def log_view (object)
RecentView.log( object, current_user )
end
def config_frontend def config_frontend
# config # config

View file

@ -14,15 +14,42 @@ Response:
} }
Test: 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 =end
def recent_viewed def index
recent_viewed = RecentView.list_fulldata( current_user, 10 ) recent_viewed = RecentView.list_fulldata( current_user, 10 )
# return result # return result
render :json => recent_viewed render :json => recent_viewed
end 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

View file

@ -239,11 +239,6 @@ class TicketsController < ApplicationController
ticket = Ticket.find( params[:id] ) ticket = Ticket.find( params[:id] )
return if !ticket_permission( ticket ) 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 # get signature
signature = {} signature = {}
if ticket.group.signature if ticket.group.signature

View file

@ -2,11 +2,8 @@
class ActivityStream < ApplicationModel class ActivityStream < ApplicationModel
self.table_name = 'activity_streams' self.table_name = 'activity_streams'
belongs_to :activity_stream_type, :class_name => 'ActivityStream::Type' belongs_to :activity_stream_type, :class_name => 'TypeLookup'
belongs_to :activity_stream_object, :class_name => 'ActivityStream::Object' belongs_to :activity_stream_object, :class_name => 'ObjectLookup'
@@cache_type = {}
@@cache_object = {}
=begin =begin
@ -27,10 +24,10 @@ add a new activity entry for an object
# lookups # lookups
if data[:type] if data[:type]
type = self.type_lookup( data[:type] ) type_id = TypeLookup.by_name( data[:type] )
end end
if data[:object] if data[:object]
object = self.object_lookup( data[:object] ) object_id = ObjectLookup.by_name( data[:object] )
end end
role_id = nil role_id = nil
@ -45,9 +42,9 @@ add a new activity entry for an object
# check newest entry - is needed # check newest entry - is needed
result = ActivityStream.where( result = ActivityStream.where(
:o_id => data[:o_id], :o_id => data[:o_id],
# :activity_stream_type_id => type.id, # :activity_stream_type_id => type_id,
:role_id => role_id, :role_id => role_id,
:activity_stream_object_id => object.id, :activity_stream_object_id => object_id,
:created_by_id => data[:created_by_id] :created_by_id => data[:created_by_id]
).order('created_at DESC, id DESC').first ).order('created_at DESC, id DESC').first
@ -57,8 +54,8 @@ add a new activity entry for an object
# create history # create history
record = { record = {
:o_id => data[:o_id], :o_id => data[:o_id],
:activity_stream_type_id => type.id, :activity_stream_type_id => type_id,
:activity_stream_object_id => object.id, :activity_stream_object_id => object_id,
:role_id => role_id, :role_id => role_id,
:group_id => data[:group_id], :group_id => data[:group_id],
:created_at => data[:created_at], :created_at => data[:created_at],
@ -77,9 +74,9 @@ remove whole activity entries of an object
=end =end
def self.remove( object_name, o_id ) def self.remove( object_name, o_id )
object = self.object_lookup( object_name ) object_id = ObjectLookup.by_name( object_name )
ActivityStream.where( ActivityStream.where(
:activity_stream_object_id => object.id, :activity_stream_object_id => object_id,
:o_id => o_id, :o_id => o_id,
).destroy_all ).destroy_all
end end
@ -112,8 +109,8 @@ return all activity entries of an user
list = [] list = []
stream.each do |item| stream.each do |item|
data = item.attributes data = item.attributes
data['object'] = self.object_lookup_id( data['activity_stream_object_id'] ).name data['object'] = ObjectLookup.by_id( data['activity_stream_object_id'] )
data['type'] = self.type_lookup_id( data['activity_stream_type_id'] ).name data['type'] = TypeLookup.by_id( data['activity_stream_type_id'] )
data.delete('activity_stream_object_id') data.delete('activity_stream_object_id')
data.delete('activity_stream_type_id') data.delete('activity_stream_type_id')
list.push data list.push data
@ -123,68 +120,6 @@ return all activity entries of an user
private 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 class Object < ApplicationModel
end end

View file

@ -31,6 +31,8 @@ class ApplicationModel < ActiveRecord::Base
after_update :search_index_update after_update :search_index_update
after_destroy :search_index_destroy after_destroy :search_index_destroy
after_destroy :recent_view_destroy
# create instance accessor # create instance accessor
class << self class << self
attr_accessor :activity_stream_support_config, :history_support_config, :search_index_support_config attr_accessor :activity_stream_support_config, :history_support_config, :search_index_support_config
@ -817,6 +819,27 @@ store attachments for this object
end end
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 private
def attachments_buffer def attachments_buffer
@ -848,6 +871,19 @@ store attachments for this object
=begin =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 check string/varchar size and cut them if needed
=end =end
@ -883,25 +919,4 @@ destory object dependencies, will be executed automatically
def destroy_dependencies def destroy_dependencies
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
end end

View file

@ -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

View file

@ -1,30 +1,32 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class RecentView < ApplicationModel 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, o_id, user )
def self.log( object, user )
# lookups # lookups
recent_view_object = self.object_lookup( object.class.to_s ) object_lookup_id = ObjectLookup.by_name( object )
# create entry # create entry
record = { record = {
:o_id => object.id, :o_id => o_id,
:recent_view_object_id => recent_view_object.id, :recent_view_object_id => object_lookup_id.to_i,
:created_by_id => user.id, :created_by_id => user.id,
} }
RecentView.create(record) RecentView.create(record)
end end
def self.log_destroy( requested_object, requested_object_id ) 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 ). where( :o_id => requested_object_id ).
destroy_all destroy_all
end end
def self.user_log_destroy( user )
RecentView.where( :created_by_id => user.id ).destroy_all
end
def self.list( user, limit = 10 ) def self.list( user, limit = 10 )
recent_views = RecentView.where( :created_by_id => user.id ). recent_views = RecentView.where( :created_by_id => user.id ).
order('created_at DESC, id DESC'). order('created_at DESC, id DESC').
@ -33,8 +35,8 @@ class RecentView < ApplicationModel
list = [] list = []
recent_views.each { |item| recent_views.each { |item|
data = item.attributes data = item.attributes
data['recent_view_object'] = self.object_lookup_id( data['recent_view_object_id'] ).name data['object'] = ObjectLookup.by_id( data['recent_view_object_id'] )
data.delete( 'history_object_id' ) data.delete( 'recent_view_object_id' )
list.push data list.push data
} }
list list
@ -48,61 +50,17 @@ class RecentView < ApplicationModel
ticket_ids = [] ticket_ids = []
recent_viewed.each {|item| recent_viewed.each {|item|
# load article ids # get related objects
# if item.recent_view_object == 'Ticket' require item['object'].to_filename
ticket = Ticket.find( item['o_id'] ) record = Kernel.const_get( item['object'] ).find( item['o_id'] )
ticket_ids.push ticket.id assets = record.assets(assets)
# 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
assets = ticket.assets(assets)
} }
return { return {
:recent_viewed => recent_viewed, :recent_viewed => recent_viewed,
:ticket_ids => ticket_ids,
:assets => assets, :assets => assets,
} }
end 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 class Object < ApplicationModel
end end
end
end

View file

@ -57,6 +57,8 @@ class Store::File < ApplicationModel
end end
# move file from one to other provider # 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) def self.move(source, target)
adapter_source = load_adapter("Store::Provider::#{ source }") adapter_source = load_adapter("Store::Provider::#{ source }")
adapter_target = load_adapter("Store::Provider::#{ target }") adapter_target = load_adapter("Store::Provider::#{ target }")

38
app/models/type_lookup.rb Normal file
View file

@ -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

View file

@ -1,5 +1,6 @@
Zammad::Application.routes.draw do Zammad::Application.routes.draw do
api_path = Rails.configuration.api_path 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 end

View file

@ -1,6 +1,6 @@
class CreateBase < ActiveRecord::Migration class CreateBase < ActiveRecord::Migration
def up def up
create_table :sessions do |t| create_table :sessions do |t|
t.string :session_id, :null => false t.string :session_id, :null => false
t.text :data t.text :data
@ -144,6 +144,18 @@ class CreateBase < ActiveRecord::Migration
add_index :translations, [:source] add_index :translations, [:source]
add_index :translations, [:locale] 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
end end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -261,7 +261,7 @@ class SessionBasicTest < ActiveSupport::TestCase
user = User.lookup(:id => 1) user = User.lookup(:id => 1)
ticket = Ticket.all.last 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') recent_viewed_client1 = Sessions::Backend::RecentViewed.new(user, false, '123-1')
# get as stream # get as stream
@ -278,7 +278,7 @@ class SessionBasicTest < ActiveSupport::TestCase
result1 = recent_viewed_client1.push result1 = recent_viewed_client1.push
assert( !result1, "check recent_viewed - recall 2" ) assert( !result1, "check recent_viewed - recall 2" )
RecentView.log( ticket, user ) RecentView.log( ticket.class.to_s, ticket.id, user )
sleep 20 sleep 20