From 5ec5240debae71331b8d71ece9b51aad19056144 Mon Sep 17 00:00:00 2001 From: rkaldung Date: Fri, 22 Aug 2014 18:49:41 +0200 Subject: [PATCH 01/16] running puma w/ systemd --- script/systemd/zammad.service | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 script/systemd/zammad.service diff --git a/script/systemd/zammad.service b/script/systemd/zammad.service new file mode 100644 index 000000000..a3a7baac1 --- /dev/null +++ b/script/systemd/zammad.service @@ -0,0 +1,12 @@ +[Unit] +Description=Zammad Application + +[Service] +Type=forking +User=zammad +WorkingDirectory=/homer/zammad/zammad +Environment=RAILS_ENV=production +ExecStart=puma -p 3000 -d -e production + +[Install] +WantedBy=multi-user.target From 67cc6fe469da7c8c3d6dd4c0052261df91e33eab Mon Sep 17 00:00:00 2001 From: rkaldung Date: Fri, 22 Aug 2014 19:05:31 +0200 Subject: [PATCH 02/16] fixed typo, added pidfile --- script/systemd/zammad.service | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script/systemd/zammad.service b/script/systemd/zammad.service index a3a7baac1..b928cd2a5 100644 --- a/script/systemd/zammad.service +++ b/script/systemd/zammad.service @@ -4,9 +4,10 @@ Description=Zammad Application [Service] Type=forking User=zammad -WorkingDirectory=/homer/zammad/zammad +WorkingDirectory=/home/zammad/zammad Environment=RAILS_ENV=production -ExecStart=puma -p 3000 -d -e 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 From dbcc5414cf99f54c570d27f066b0bb0066da70b3 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 23 Aug 2014 14:37:01 +0200 Subject: [PATCH 03/16] Improved displayNameLong() - same behaviour like displayName(). --- .../javascripts/app/models/_application_model.js.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/javascripts/app/models/_application_model.js.coffee b/app/assets/javascripts/app/models/_application_model.js.coffee index 99efdf986..a67494ef1 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 '???' @validate: ( data = {} ) -> From 2401d860cd815b65c47699c7ee734d5e0437c3da Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 23 Aug 2014 15:42:25 +0200 Subject: [PATCH 04/16] Added unit tests. --- test/unit/recent_view_test.rb | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/unit/recent_view_test.rb diff --git a/test/unit/recent_view_test.rb b/test/unit/recent_view_test.rb new file mode 100644 index 000000000..2778aaec6 --- /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, user1 ) + sleep 1 + RecentView.log( ticket2, user1 ) + sleep 1 + RecentView.log( ticket1, user1 ) + sleep 1 + RecentView.log( ticket1, user1 ) + + list = RecentView.list( user1 ) + assert( list[0]['o_id'], ticket1.id ) + assert( list[0]['recent_view_object'], 'Ticket' ) + + assert( list[1]['o_id'], ticket1.id ) + assert( list[1]['recent_view_object'], 'Ticket' ) + + assert( list[2]['o_id'], ticket2.id ) + assert( list[2]['recent_view_object'], 'Ticket' ) + + assert( list[3]['o_id'], ticket1.id ) + assert( list[3]['recent_view_object'], 'Ticket' ) + + ticket1.destroy + ticket2.destroy + + #list = RecentView.list( user1 ) + #assert( !list[0], 'check if recent view list is empty' ) + end +end From 3cb4bb72cd25e968efa63a80a50216583c4f4898 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 00:29:04 +0200 Subject: [PATCH 05/16] Moved object lookup to generic model. --- app/models/application_model.rb | 57 +++++++++----- app/models/object_lookup.rb | 38 ++++++++++ app/models/recent_view.rb | 76 +++++-------------- ...date_recent_viewed_create_object_lookup.rb | 22 ++++++ test/unit/object_lookup_test.rb | 34 +++++++++ test/unit/recent_view_test.rb | 14 ++-- 6 files changed, 154 insertions(+), 87 deletions(-) create mode 100644 app/models/object_lookup.rb create mode 100644 db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb create mode 100644 test/unit/object_lookup_test.rb 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..f32f477a4 --- /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 + object_lookup = ObjectLookup.lookup( :id => id ) + return if !object_lookup + @@cache_object[ id ] = object_lookup.name + object_lookup.name + end + + def self.by_name( name ) + + # use cache + return @@cache_object[ name ] if @@cache_object[ name ] + + # lookup + object_lookup = ObjectLookup.lookup( :name => name ) + if object_lookup + @@cache_object[ name ] = object_lookup.id + return object_lookup.id + end + + # create + object_lookup = ObjectLookup.create( + :name => name + ) + @@cache_object[ name ] = object_lookup.id + object_lookup.id + end + +end diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index c3a37ed15..963c441a9 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' - - @@cache_object = {} + belongs_to :object_lookup, :class_name => 'ObjectLookup' def self.log( object, user ) # lookups - recent_view_object = self.object_lookup( object.class.to_s ) + object_lookup_id = ObjectLookup.by_name( object.class.to_s ) # create entry record = { - :o_id => object.id, - :recent_view_object_id => recent_view_object.id, - :created_by_id => user.id, + :o_id => object.id, + :object_lookup_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( :object_lookup_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['object_lookup_id'] ) + data.delete( 'object_lookup_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/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..eeffa6e88 --- /dev/null +++ b/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb @@ -0,0 +1,22 @@ +class UpdateRecentViewedCreateObjectLookup < ActiveRecord::Migration + def up + + create_table :object_lookups do |t| + t.column :name, :string, :limit => 250, :null => false + t.timestamps + end + add_index :object_lookups, [:name], :unique => true + 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 + } + + rename_column :recent_views, :recent_view_object_id, :object_lookup_id + drop_table :recent_view_objects + end + + def down + end +end diff --git a/test/unit/object_lookup_test.rb b/test/unit/object_lookup_test.rb new file mode 100644 index 000000000..312a69561 --- /dev/null +++ b/test/unit/object_lookup_test.rb @@ -0,0 +1,34 @@ +# encoding: utf-8 +require 'test_helper' + +class ObjectLookupTest < ActiveSupport::TestCase + + test 'simple 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 +end diff --git a/test/unit/recent_view_test.rb b/test/unit/recent_view_test.rb index 2778aaec6..bcf5a10a5 100644 --- a/test/unit/recent_view_test.rb +++ b/test/unit/recent_view_test.rb @@ -26,7 +26,7 @@ class RecentViewTest < ActiveSupport::TestCase ) assert( ticket2, "ticket created" ) user1 = User.find(2) - #RecentView.user_log_destroy(user1) + RecentView.user_log_destroy(user1) RecentView.log( ticket1, user1 ) @@ -39,21 +39,21 @@ class RecentViewTest < ActiveSupport::TestCase list = RecentView.list( user1 ) assert( list[0]['o_id'], ticket1.id ) - assert( list[0]['recent_view_object'], 'Ticket' ) + assert( list[0]['object'], 'Ticket' ) assert( list[1]['o_id'], ticket1.id ) - assert( list[1]['recent_view_object'], 'Ticket' ) + assert( list[1]['object'], 'Ticket' ) assert( list[2]['o_id'], ticket2.id ) - assert( list[2]['recent_view_object'], 'Ticket' ) + assert( list[2]['object'], 'Ticket' ) assert( list[3]['o_id'], ticket1.id ) - assert( list[3]['recent_view_object'], 'Ticket' ) + assert( list[3]['object'], 'Ticket' ) ticket1.destroy ticket2.destroy - #list = RecentView.list( user1 ) - #assert( !list[0], 'check if recent view list is empty' ) + list = RecentView.list( user1 ) + assert( !list[0], 'check if recent view list is empty' ) end end From 1a8d503a4ea5dcdf80ccaa696456361000c544c9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 00:34:38 +0200 Subject: [PATCH 06/16] Moved object lookup to generic model. --- .../app/controllers/navigation.js.coffee | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index 62c30caf4..9e9fe250e 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -316,13 +316,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: item.object + ' (' + item.title + ')' + target: item.link divider: divider navheader: navheader } From bafd51e0c835eb86952347127c9b4b748cd40712 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 01:56:45 +0200 Subject: [PATCH 07/16] Moved to support generic objects for recent viewed. --- .../_application_controller.js.coffee | 12 +++++++ .../controllers/organization_zoom.js.coffee | 4 +++ .../app/controllers/ticket_zoom.js.coffee | 8 +++-- .../app/controllers/user_zoom.js.coffee | 3 ++ app/controllers/application_controller.rb | 4 --- app/controllers/recent_viewed_controller.rb | 33 +++++++++++++++++-- app/controllers/tickets_controller.rb | 5 --- app/models/recent_view.rb | 6 ++-- config/routes/recent_viewed.rb | 3 +- test/unit/recent_view_test.rb | 8 ++--- test/unit/session_basic_test.rb | 4 +-- 11 files changed, 65 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 839b34075..215e4c301 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -446,6 +446,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/organization_zoom.js.coffee b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee index 027f370a7..86eb0a0be 100644 --- a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee @@ -34,6 +34,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 2e508a65c..7006e03ef 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -11,7 +11,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 ) @@ -66,7 +65,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) => @@ -101,7 +100,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 a63ba95ff..f807f6739 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -34,6 +34,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/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/recent_view.rb b/app/models/recent_view.rb index 963c441a9..ee7de2c4e 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -3,14 +3,14 @@ class RecentView < ApplicationModel belongs_to :object_lookup, :class_name => 'ObjectLookup' - def self.log( object, user ) + def self.log( object, o_id, user ) # lookups - object_lookup_id = ObjectLookup.by_name( object.class.to_s ) + object_lookup_id = ObjectLookup.by_name( object ) # create entry record = { - :o_id => object.id, + :o_id => o_id, :object_lookup_id => object_lookup_id.to_i, :created_by_id => user.id, } 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/test/unit/recent_view_test.rb b/test/unit/recent_view_test.rb index bcf5a10a5..299ada8db 100644 --- a/test/unit/recent_view_test.rb +++ b/test/unit/recent_view_test.rb @@ -29,13 +29,13 @@ class RecentViewTest < ActiveSupport::TestCase RecentView.user_log_destroy(user1) - RecentView.log( ticket1, user1 ) + RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) sleep 1 - RecentView.log( ticket2, user1 ) + RecentView.log( ticket2.class.to_s, ticket2.id,, user1 ) sleep 1 - RecentView.log( ticket1, user1 ) + RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) sleep 1 - RecentView.log( ticket1, user1 ) + RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) list = RecentView.list( user1 ) assert( list[0]['o_id'], ticket1.id ) diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index 1875c20f7..571fbce32 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 From fe2b7606122c360e66f33f49eb9131a3f8e8b215 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 01:59:46 +0200 Subject: [PATCH 08/16] Moved object lookup to generic model. --- app/models/activity_stream.rb | 46 +++---------------- ...02_update_activity_stream_object_lookup.rb | 16 +++++++ 2 files changed, 23 insertions(+), 39 deletions(-) create mode 100644 db/migrate/20140823000002_update_activity_stream_object_lookup.rb diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index 088c50750..9c13d562f 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -3,10 +3,9 @@ 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' + belongs_to :activity_stream_object, :class_name => 'ObjectLookup' @@cache_type = {} - @@cache_object = {} =begin @@ -30,7 +29,7 @@ add a new activity entry for an object type = self.type_lookup( data[:type] ) end if data[:object] - object = self.object_lookup( data[:object] ) + object_id = ObjectLookup.by_name( data[:object] ) end role_id = nil @@ -47,7 +46,7 @@ add a new activity entry for an object :o_id => data[:o_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 @@ -58,7 +57,7 @@ add a new activity entry for an object record = { :o_id => data[:o_id], :activity_stream_type_id => type.id, - :activity_stream_object_id => object.id, + :activity_stream_object_id => object_id, :role_id => role_id, :group_id => data[:group_id], :created_at => data[:created_at], @@ -77,9 +76,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,7 +111,7 @@ 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['object'] = ObjectLookup.by_id( data['activity_stream_object_id'] ) data['type'] = self.type_lookup_id( data['activity_stream_type_id'] ).name data.delete('activity_stream_object_id') data.delete('activity_stream_type_id') @@ -154,37 +153,6 @@ return all activity entries of an user 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/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..069a8cfce --- /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 + end + + def down + end +end From afa3a34fbf6b6de2c147d669f8d9425a619b73d7 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 02:10:00 +0200 Subject: [PATCH 09/16] Fixed initial setup. --- db/migrate/20120101000001_create_base.rb | 5 +++++ ...0001_update_recent_viewed_create_object_lookup.rb | 12 ++++++++---- ...823000002_update_activity_stream_object_lookup.rb | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/db/migrate/20120101000001_create_base.rb b/db/migrate/20120101000001_create_base.rb index a5411f1c0..2343ec5c2 100644 --- a/db/migrate/20120101000001_create_base.rb +++ b/db/migrate/20120101000001_create_base.rb @@ -144,6 +144,11 @@ 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 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 index eeffa6e88..8d3e043ad 100644 --- a/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb +++ b/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb @@ -1,11 +1,13 @@ class UpdateRecentViewedCreateObjectLookup < ActiveRecord::Migration def up - create_table :object_lookups do |t| - t.column :name, :string, :limit => 250, :null => false - t.timestamps + 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 - add_index :object_lookups, [:name], :unique => true RecentView.all.each {|entry| ro = RecentView::Object.find(entry.recent_view_object_id) lookup_id = ObjectLookup.by_name( ro.name ) @@ -15,6 +17,8 @@ class UpdateRecentViewedCreateObjectLookup < ActiveRecord::Migration rename_column :recent_views, :recent_view_object_id, :object_lookup_id drop_table :recent_view_objects + + Cache.clear end def down diff --git a/db/migrate/20140823000002_update_activity_stream_object_lookup.rb b/db/migrate/20140823000002_update_activity_stream_object_lookup.rb index 069a8cfce..7dae9a53b 100644 --- a/db/migrate/20140823000002_update_activity_stream_object_lookup.rb +++ b/db/migrate/20140823000002_update_activity_stream_object_lookup.rb @@ -7,8 +7,8 @@ class UpdateActivityStreamObjectLookup < ActiveRecord::Migration entry.update_attribute( :activity_stream_object_id, lookup_id ) entry.cache_delete } - drop_table :activity_stream_objects + Cache.clear end def down From 9a3266b3e43b5914a8d69a39dc981f0d6277b727 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 02:16:50 +0200 Subject: [PATCH 10/16] Added backward compatibility. --- app/models/recent_view.rb | 12 ++++++------ ...0001_update_recent_viewed_create_object_lookup.rb | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index ee7de2c4e..f0b4f8d77 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -10,15 +10,15 @@ class RecentView < ApplicationModel # create entry record = { - :o_id => o_id, - :object_lookup_id => object_lookup_id.to_i, - :created_by_id => user.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( :object_lookup_id => ObjectLookup.by_name( requested_object ) ). + RecentView.where( :recent_view_object_id => ObjectLookup.by_name( requested_object ) ). where( :o_id => requested_object_id ). destroy_all end @@ -35,8 +35,8 @@ class RecentView < ApplicationModel list = [] recent_views.each { |item| data = item.attributes - data['object'] = ObjectLookup.by_id( data['object_lookup_id'] ) - data.delete( 'object_lookup_id' ) + data['object'] = ObjectLookup.by_id( data['recent_view_object_id'] ) + data.delete( 'recent_view_object_id' ) list.push data } list diff --git a/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb b/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb index 8d3e043ad..3e40cb87e 100644 --- a/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb +++ b/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb @@ -15,9 +15,7 @@ class UpdateRecentViewedCreateObjectLookup < ActiveRecord::Migration entry.cache_delete } - rename_column :recent_views, :recent_view_object_id, :object_lookup_id drop_table :recent_view_objects - Cache.clear end From 1722bcfa58e57a39880409110470b0e723c96b11 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 02:18:55 +0200 Subject: [PATCH 11/16] Fixed syntax error. --- test/unit/recent_view_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/recent_view_test.rb b/test/unit/recent_view_test.rb index 299ada8db..7235c52e4 100644 --- a/test/unit/recent_view_test.rb +++ b/test/unit/recent_view_test.rb @@ -31,7 +31,7 @@ class RecentViewTest < ActiveSupport::TestCase RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) sleep 1 - RecentView.log( ticket2.class.to_s, ticket2.id,, user1 ) + RecentView.log( ticket2.class.to_s, ticket2.id, user1 ) sleep 1 RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) sleep 1 From 5802f8b86a3c221cf9d07070ef4c4cc3eaf838c3 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 02:21:30 +0200 Subject: [PATCH 12/16] Fixed syntax error. --- test/unit/session_basic_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index 571fbce32..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.class.to_s, ticket.id user ) + RecentView.log( ticket.class.to_s, ticket.id, user ) recent_viewed_client1 = Sessions::Backend::RecentViewed.new(user, false, '123-1') # get as stream From 481209218c9021cfa62e9a2d6f14e2dc4eb49096 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 10:04:20 +0200 Subject: [PATCH 13/16] Moved type lookup to generic model. --- app/models/activity_stream.rb | 43 ++-------- app/models/object_lookup.rb | 24 +++--- app/models/type_lookup.rb | 38 +++++++++ db/migrate/20120101000001_create_base.rb | 9 +- ...date_recent_viewed_create_object_lookup.rb | 2 +- ...date_activity_stream_create_type_lookup.rb | 24 ++++++ test/unit/object_lookup_test.rb | 34 -------- test/unit/object_type_lookup_test.rb | 85 +++++++++++++++++++ 8 files changed, 173 insertions(+), 86 deletions(-) create mode 100644 app/models/type_lookup.rb create mode 100644 db/migrate/20140824000001_update_activity_stream_create_type_lookup.rb delete mode 100644 test/unit/object_lookup_test.rb create mode 100644 test/unit/object_type_lookup_test.rb diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index 9c13d562f..5468724fe 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -2,11 +2,9 @@ class ActivityStream < ApplicationModel 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 => 'ObjectLookup' - @@cache_type = {} - =begin add a new activity entry for an object @@ -26,7 +24,7 @@ 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_id = ObjectLookup.by_name( data[:object] ) @@ -44,7 +42,7 @@ 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, :created_by_id => data[:created_by_id] @@ -56,7 +54,7 @@ add a new activity entry for an object # create history record = { :o_id => data[:o_id], - :activity_stream_type_id => type.id, + :activity_stream_type_id => type_id, :activity_stream_object_id => object_id, :role_id => role_id, :group_id => data[:group_id], @@ -112,7 +110,7 @@ return all activity entries of an user stream.each do |item| data = item.attributes 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_type_id') list.push data @@ -122,37 +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 - class Object < ApplicationModel end diff --git a/app/models/object_lookup.rb b/app/models/object_lookup.rb index f32f477a4..456b6100c 100644 --- a/app/models/object_lookup.rb +++ b/app/models/object_lookup.rb @@ -9,10 +9,10 @@ class ObjectLookup < ApplicationModel return @@cache_object[ id ] if @@cache_object[ id ] # lookup - object_lookup = ObjectLookup.lookup( :id => id ) - return if !object_lookup - @@cache_object[ id ] = object_lookup.name - object_lookup.name + lookup = self.lookup( :id => id ) + return if !lookup + @@cache_object[ id ] = lookup.name + lookup.name end def self.by_name( name ) @@ -21,18 +21,18 @@ class ObjectLookup < ApplicationModel return @@cache_object[ name ] if @@cache_object[ name ] # lookup - object_lookup = ObjectLookup.lookup( :name => name ) - if object_lookup - @@cache_object[ name ] = object_lookup.id - return object_lookup.id + lookup = self.lookup( :name => name ) + if lookup + @@cache_object[ name ] = lookup.id + return lookup.id end # create - object_lookup = ObjectLookup.create( + lookup = self.create( :name => name ) - @@cache_object[ name ] = object_lookup.id - object_lookup.id + @@cache_object[ name ] = lookup.id + lookup.id end -end +end \ No newline at end of file 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/db/migrate/20120101000001_create_base.rb b/db/migrate/20120101000001_create_base.rb index 2343ec5c2..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 @@ -149,6 +149,13 @@ class CreateBase < ActiveRecord::Migration 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 index 3e40cb87e..85a721de8 100644 --- a/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb +++ b/db/migrate/20140823000001_update_recent_viewed_create_object_lookup.rb @@ -21,4 +21,4 @@ class UpdateRecentViewedCreateObjectLookup < ActiveRecord::Migration def down end -end +end \ No newline at end of file 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/test/unit/object_lookup_test.rb b/test/unit/object_lookup_test.rb deleted file mode 100644 index 312a69561..000000000 --- a/test/unit/object_lookup_test.rb +++ /dev/null @@ -1,34 +0,0 @@ -# encoding: utf-8 -require 'test_helper' - -class ObjectLookupTest < ActiveSupport::TestCase - - test 'simple 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 -end diff --git a/test/unit/object_type_lookup_test.rb b/test/unit/object_type_lookup_test.rb new file mode 100644 index 000000000..2f8ddf948 --- /dev/null +++ b/test/unit/object_type_lookup_test.rb @@ -0,0 +1,85 @@ +# 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' ) + +puts "ll #{ObjectLookup.cache_object.inspect}" + end + +end From 61ee9c29066bf6708606c6bda0a260ba97645ae6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 11:52:44 +0200 Subject: [PATCH 14/16] Removed not needed debug message. --- test/unit/object_type_lookup_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/object_type_lookup_test.rb b/test/unit/object_type_lookup_test.rb index 2f8ddf948..c54ae65be 100644 --- a/test/unit/object_type_lookup_test.rb +++ b/test/unit/object_type_lookup_test.rb @@ -79,7 +79,6 @@ class ObjectTypeLookupTest < ActiveSupport::TestCase assert_not_equal( object_lookup_name, type_lookup_name, 'verify lookups' ) -puts "ll #{ObjectLookup.cache_object.inspect}" end end From 4668376ae523f904f612d441638adbd282a3d9bf Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 12:01:24 +0200 Subject: [PATCH 15/16] Added translation for objects in recent viewed. --- app/assets/javascripts/app/controllers/navigation.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index 9e9fe250e..5c27ae17a 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -336,7 +336,7 @@ class App.Navigation extends App.Controller NavBarRight['RecendViewed::' + item.o_id + item.object + '-' + prio ] = { prio: prio parent: '#current_user' - name: item.object + ' (' + item.title + ')' + name: App.i18n.translateInline(item.object) + ' (' + item.title + ')' target: item.link divider: divider navheader: navheader From 665fac5dd73e58ce8820006d2ada9e156b3ac062 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 24 Aug 2014 12:04:32 +0200 Subject: [PATCH 16/16] Added examples now to move attachments from one backend to other. --- app/models/store/file.rb | 2 ++ 1 file changed, 2 insertions(+) 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 }")