diff --git a/Gemfile b/Gemfile index 584dd0716..bcdb47fe8 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' ruby '2.2.3' -gem 'rails', '4.2.5.1' +gem 'rails', '4.2.5.2' gem 'rails-observers' gem 'activerecord-session_store' @@ -122,7 +122,7 @@ group :development, :test do end -gem 'puma' +gem 'puma', '< 3.0' # load onw gem's local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local') diff --git a/Gemfile.lock b/Gemfile.lock index 3c86514fc..c5cd62765 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,41 +1,40 @@ GEM remote: https://rubygems.org/ specs: - abstract_type (0.0.7) - actionmailer (4.2.5.1) - actionpack (= 4.2.5.1) - actionview (= 4.2.5.1) - activejob (= 4.2.5.1) + actionmailer (4.2.5.2) + actionpack (= 4.2.5.2) + actionview (= 4.2.5.2) + activejob (= 4.2.5.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.5.1) - actionview (= 4.2.5.1) - activesupport (= 4.2.5.1) + actionpack (4.2.5.2) + actionview (= 4.2.5.2) + activesupport (= 4.2.5.2) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.5.1) - activesupport (= 4.2.5.1) + actionview (4.2.5.2) + activesupport (= 4.2.5.2) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.5.1) - activesupport (= 4.2.5.1) + activejob (4.2.5.2) + activesupport (= 4.2.5.2) globalid (>= 0.3.0) - activemodel (4.2.5.1) - activesupport (= 4.2.5.1) + activemodel (4.2.5.2) + activesupport (= 4.2.5.2) builder (~> 3.1) - activerecord (4.2.5.1) - activemodel (= 4.2.5.1) - activesupport (= 4.2.5.1) + activerecord (4.2.5.2) + activemodel (= 4.2.5.2) + activesupport (= 4.2.5.2) arel (~> 6.0) activerecord-session_store (0.1.2) actionpack (>= 4.0.0, < 5) activerecord (>= 4.0.0, < 5) railties (>= 4.0.0, < 5) - activesupport (4.2.5.1) + activesupport (4.2.5.2) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) @@ -44,23 +43,18 @@ GEM addressable (2.4.0) arel (6.0.3) ast (2.2.0) - autoprefixer-rails (6.3.1) + autoprefixer-rails (6.3.3.1) execjs - json - biz (1.3.3) - abstract_type (~> 0.0.0) + biz (1.3.4) clavius (~> 1.0) - equalizer (~> 0.0.0) - memoizable (~> 0.4.0) tzinfo - browser (1.1.0) + browser (2.0.2) buftok (0.2.0) builder (3.2.2) childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) - clavius (1.0.1) - memoizable (~> 0.4.0) - coderay (1.1.0) + clavius (1.0.2) + coderay (1.1.1) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -72,7 +66,7 @@ GEM coffee-script execjs json - concurrent-ruby (1.0.0) + concurrent-ruby (1.0.1) daemons (1.2.3) delayed_job (4.1.1) activesupport (>= 3.0, < 5.0) @@ -80,9 +74,9 @@ GEM activerecord (>= 3.0, < 5) delayed_job (>= 3.0, < 5) diffy (3.1.0) - dnsruby (1.59.1) + dnsruby (1.59.2) docile (1.1.5) - domain_name (0.5.25) + domain_name (0.5.20160216) unf (>= 0.0.5, < 1.0.0) eco (1.0.0) coffee-script @@ -114,7 +108,7 @@ GEM shellany (~> 0.0) thor (>= 0.18.1) guard-compat (1.2.1) - guard-livereload (2.5.1) + guard-livereload (2.5.2) em-websocket (~> 0.5) guard (~> 2.8) guard-compat (~> 1.0) @@ -134,15 +128,15 @@ GEM icalendar (2.3.0) inflection (1.0.0) json (1.8.3) - jwt (1.5.2) + jwt (1.5.1) koala (2.2.0) addressable faraday multi_json libv8 (3.16.14.13) - listen (3.0.5) + listen (3.0.6) rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) + rb-inotify (>= 0.9.7) loofah (2.0.3) nokogiri (>= 1.5.9) lumberjack (1.0.10) @@ -151,7 +145,7 @@ GEM memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) method_source (0.8.2) - mime-types (2.99) + mime-types (2.99.1) mini_portile2 (2.0.0) minitest (5.8.4) multi_json (1.11.2) @@ -159,27 +153,26 @@ GEM multipart-post (2.0.0) mysql2 (0.3.20) naught (1.1.0) - nenv (0.2.0) - net-ldap (0.13.0) + nenv (0.3.0) + net-ldap (0.14.0) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) notiffany (0.0.8) nenv (~> 0.1) shellany (~> 0.0) - oauth (0.4.7) - oauth2 (1.0.0) + oauth (0.5.1) + oauth2 (1.1.0) faraday (>= 0.8, < 0.10) - jwt (~> 1.0) + jwt (~> 1.0, < 1.5.2) multi_json (~> 1.3) multi_xml (~> 0.5) - rack (~> 1.2) + rack (>= 1.2, < 3) omniauth (1.3.1) hashie (>= 1.2, < 4) rack (>= 1.0, < 3) omniauth-facebook (3.0.0) omniauth-oauth2 (~> 1.2) - omniauth-google-oauth2 (0.3.0) - addressable (~> 2.3) + omniauth-google-oauth2 (0.3.1) jwt (~> 1.0) multi_json (~> 1.3) omniauth (>= 1.1.1) @@ -195,12 +188,12 @@ GEM omniauth-twitter (1.2.1) json (~> 1.3) omniauth-oauth (~> 1.1) - parser (2.3.0.2) + parser (2.3.0.6) ast (~> 2.2) pluginator (1.3.0) power_assert (0.2.7) powerpack (0.1.1) - pre-commit (0.26.0) + pre-commit (0.27.0) pluginator (~> 1.1) pry (0.10.3) coderay (~> 1.1.0) @@ -212,16 +205,16 @@ GEM rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.5.1) - actionmailer (= 4.2.5.1) - actionpack (= 4.2.5.1) - actionview (= 4.2.5.1) - activejob (= 4.2.5.1) - activemodel (= 4.2.5.1) - activerecord (= 4.2.5.1) - activesupport (= 4.2.5.1) + rails (4.2.5.2) + actionmailer (= 4.2.5.2) + actionpack (= 4.2.5.2) + actionview (= 4.2.5.2) + activejob (= 4.2.5.2) + activemodel (= 4.2.5.2) + activerecord (= 4.2.5.2) + activesupport (= 4.2.5.2) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.5.1) + railties (= 4.2.5.2) sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) @@ -233,24 +226,25 @@ GEM loofah (~> 2.0) rails-observers (0.1.2) activemodel (~> 4.0) - railties (4.2.5.1) - actionpack (= 4.2.5.1) - activesupport (= 4.2.5.1) + railties (4.2.5.2) + actionpack (= 4.2.5.2) + activesupport (= 4.2.5.2) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.1.0) rake (10.5.0) rb-fsevent (0.9.7) - rb-inotify (0.9.5) + rb-inotify (0.9.7) ffi (>= 0.5.0) ref (2.0.0) - rubocop (0.36.0) - parser (>= 2.3.0.0, < 3.0) + rubocop (0.37.2) + parser (>= 2.3.0.4, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) + unicode-display_width (~> 0.3) ruby-progressbar (1.7.5) - rubyzip (1.1.7) + rubyzip (1.2.0) sass (3.4.21) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -259,7 +253,7 @@ GEM sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) scrub_rb (1.0.1) - selenium-webdriver (2.50.0) + selenium-webdriver (2.52.0) childprocess (~> 0.5) multi_json (~> 1.0) rubyzip (~> 1.0) @@ -267,7 +261,7 @@ GEM shellany (0.0.1) simple-rss (1.3.1) simple_oauth (0.3.1) - simplecov (0.11.1) + simplecov (0.11.2) docile (~> 1.1.0) json (~> 1.8) simplecov-html (~> 0.10.0) @@ -275,11 +269,11 @@ GEM simplecov-rcov (0.2.3) simplecov (>= 0.4.1) slop (3.6.0) - spring (1.6.2) + spring (1.6.4) sprockets (3.5.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.0.1) + sprockets-rails (3.0.3) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) @@ -310,7 +304,8 @@ GEM json (>= 1.8.0) unf (0.1.4) unf_ext - unf_ext (0.0.7.1) + unf_ext (0.0.7.2) + unicode-display_width (0.3.1) websocket (1.2.2) writeexcel (1.0.5) zendesk_api (1.13.4) @@ -357,9 +352,9 @@ DEPENDENCIES omniauth-linkedin omniauth-twitter pre-commit - puma + puma (< 3.0) rack-livereload - rails (= 4.2.5.1) + rails (= 4.2.5.2) rails-observers rb-fsevent rubocop diff --git a/LICENSE-ICONS-3RD-PARTY.json b/LICENSE-ICONS-3RD-PARTY.json old mode 100755 new mode 100644 diff --git a/app/assets/javascripts/app/controllers/_dashboard/first_steps.coffee b/app/assets/javascripts/app/controllers/_dashboard/first_steps.coffee index 93bb301cf..c71c64bb7 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/first_steps.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/first_steps.coffee @@ -7,7 +7,7 @@ class App.DashboardFirstSteps extends App.Controller constructor: -> super - @interval(@load, 35000) + @interval(@load, 25000) load: => return if @lastData && !@el.is(':visible') diff --git a/app/assets/javascripts/app/controllers/ticket_overview.coffee b/app/assets/javascripts/app/controllers/ticket_overview.coffee index 595059fb8..4dc556a12 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.coffee @@ -23,6 +23,11 @@ class App.TicketOverview extends App.Controller @html elLocal + @bind 'overview:fetch', => + update = => + App.OverviewListCollection.fetch(@view) + @delay(update, 2800, 'overview:fetch') + active: (state) => @activeState = state @@ -197,16 +202,16 @@ class Table extends App.Controller super if @view - @bindId = App.OverviewCollection.bind(@view, @render) + @bindId = App.OverviewListCollection.bind(@view, @render) # rerender view, e. g. on langauge change @bind 'ui:rerender', => return if !@authenticate(true) - @render(App.OverviewCollection.get(@view)) + @render(App.OverviewListCollection.get(@view)) release: => if @bindId - App.OverviewCollection.unbind(@bindId) + App.OverviewListCollection.unbind(@bindId) update: (params) => for key, value of params @@ -219,24 +224,20 @@ class Table extends App.Controller if @view if @bindId - App.OverviewCollection.unbind(@bindId) - @bindId = App.OverviewCollection.bind(@view, @render) + App.OverviewListCollection.unbind(@bindId) + @bindId = App.OverviewListCollection.bind(@view, @render) render: (data) => return if !data # use cache - overview = data.overview - tickets_count = data.tickets_count - ticket_ids = data.ticket_ids - - # use cache if no local change - App.Overview.refresh(overview, { clear: true }) + overview = data.overview + tickets = data.tickets # get ticket list ticket_list_show = [] - for ticket_id in ticket_ids - ticket_list_show.push App.Ticket.fullLocal(ticket_id) + for ticket in tickets + ticket_list_show.push App.Ticket.fullLocal(ticket.id) # if customer and no ticket exists, show the following message only if !ticket_list_show[0] && @isRole('Customer') @@ -622,8 +623,7 @@ class BulkForm extends App.Controller @hide() # fetch overview data again - App.OverviewIndexCollection.fetch() - App.OverviewCollection.fetch(@view) + App.Event.trigger('overview:fetch') ) ) @holder.find('.table-overview').find('[name="bulk"]:checked').prop('checked', false) @@ -761,11 +761,10 @@ class App.OverviewSettings extends App.ControllerModal # fetch overview data again if @reload_needed - App.OverviewIndexCollection.fetch() - App.OverviewCollection.fetch(@overview.link) + App.OverviewListCollection.fetch(@overview.link) else App.OverviewIndexCollection.trigger() - App.OverviewCollection.trigger(@overview.link) + App.OverviewListCollection.trigger(@overview.link) # close modal @close() diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 35600e41b..2c66a6c49 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -350,15 +350,15 @@ class App.TicketZoom extends App.Controller # rerender whole sidebar if customer or organization has changed if @ticketLastAttributes.customer_id isnt @ticket.customer_id || @ticketLastAttributes.organization_id isnt @ticket.organization_id - new App.WidgetAvatar( - el: @$('.ticketZoom-header .js-avatar') - user_id: @ticket.customer_id - size: 50 - ) if elLocal el = elLocal else el = @el + new App.WidgetAvatar( + el: el.find('.ticketZoom-header .js-avatar') + user_id: @ticket.customer_id + size: 50 + ) @sidebar = new App.TicketZoomSidebar( el: el.find('.tabsSidebar') sidebarState: @sidebarState @@ -381,12 +381,12 @@ class App.TicketZoom extends App.Controller ) # scroll to article if given - if @article_id && document.getElementById( 'article-' + @article_id ) - offset = document.getElementById( 'article-' + @article_id ).offsetTop + if @article_id && document.getElementById('article-' + @article_id) + offset = document.getElementById('article-' + @article_id).offsetTop offset = offset - 45 scrollTo = -> - @scrollTo( 0, offset ) - @delay( scrollTo, 100, false ) + @scrollTo(0, offset) + @delay(scrollTo, 100, false) @ticketLastAttributes = @ticket.attributes() @@ -476,8 +476,8 @@ class App.TicketZoom extends App.Controller resetButton = @$('.js-reset') params = {} - params.ticket = @formParam( ticketForm ) - params.article = @formParam( articleForm ) + params.ticket = @formParam(ticketForm) + params.article = @formParam(articleForm) #console.log('markFormDiff', diff, params) # clear all changes @@ -618,25 +618,25 @@ class App.TicketZoom extends App.Controller if @overview_id current_position = 0 overview = App.Overview.find(@overview_id) - list = App.OverviewCollection.get(overview.link) - for ticket_id in list.ticket_ids + list = App.OverviewListCollection.get(overview.link) + for ticket in list.tickets current_position += 1 - if ticket_id is @ticket_id - next = list.ticket_ids[current_position] + if ticket.id is @ticket_id + next = list.tickets[current_position] if next # close task App.TaskManager.remove(@task_key) # open task via task manager to get overview information App.TaskManager.execute( - key: 'Ticket-' + next + key: 'Ticket-' + next.id controller: 'TicketZoom' params: - ticket_id: next + ticket_id: next.id overview_id: @overview_id show: true ) - @navigate "ticket/zoom/#{next}" + @navigate "ticket/zoom/#{next.id}" return # fallback, close task @@ -658,6 +658,8 @@ class App.TicketZoom extends App.Controller # enable form @formEnable(e) + + App.Event.trigger('overview:fetch') ) bookmark: (e) -> @@ -731,6 +733,6 @@ class TicketZoomRouter extends App.ControllerPermanent show: true ) -App.Config.set( 'ticket/zoom/:ticket_id', TicketZoomRouter, 'Routes' ) -App.Config.set( 'ticket/zoom/:ticket_id/nav/:nav', TicketZoomRouter, 'Routes' ) -App.Config.set( 'ticket/zoom/:ticket_id/:article_id', TicketZoomRouter, 'Routes' ) +App.Config.set('ticket/zoom/:ticket_id', TicketZoomRouter, 'Routes') +App.Config.set('ticket/zoom/:ticket_id/nav/:nav', TicketZoomRouter, 'Routes') +App.Config.set('ticket/zoom/:ticket_id/:article_id', TicketZoomRouter, 'Routes') diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/overview_navigator.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/overview_navigator.coffee index 2ccb0685c..39535efed 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/overview_navigator.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/overview_navigator.coffee @@ -12,12 +12,12 @@ class App.TicketZoomOverviewNavigator extends App.Controller @delay(@render, 2600, 'overview-navigator') @overview = App.Overview.find(@overview_id) - @bindId = App.OverviewCollection.bind(@overview.link, lateUpdate, false) + @bindId = App.OverviewListCollection.bind(@overview.link, lateUpdate, false) @render() release: => - App.OverviewCollection.unbind(@bindId) + App.OverviewListCollection.unbind(@bindId) render: => if !@overview_id @@ -25,17 +25,17 @@ class App.TicketZoomOverviewNavigator extends App.Controller return # get overview data - overview = App.OverviewCollection.get(@overview.link) + overview = App.OverviewListCollection.get(@overview.link) return if !overview current_position = 0 found = false - next = false - previous = false - for ticket_id in overview.ticket_ids + item_next = false + item_previous = false + for ticket in overview.tickets current_position += 1 - next = overview.ticket_ids[current_position] - previous = overview.ticket_ids[current_position-2] - if ticket_id is @ticket_id + item_next = overview.tickets[current_position] + item_previous = overview.tickets[current_position-2] + if ticket.id is @ticket_id found = true break @@ -44,10 +44,10 @@ class App.TicketZoomOverviewNavigator extends App.Controller return # get next/previous ticket - if next - next = App.Ticket.find(next) - if previous - previous = App.Ticket.find(previous) + if item_next + next = App.Ticket.find(item_next.id) + if item_previous + previous = App.Ticket.find(item_previous.id) @html App.view('ticket_zoom/overview_navigator')( title: overview.overview.name diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/title.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/title.coffee index a91075af8..d72e8bf69 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/title.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/title.coffee @@ -53,5 +53,7 @@ class App.TicketZoomTitle extends App.Controller # update taskbar with new meta data @metaTaskUpdate() + App.Event.trigger('overview:fetch') + release: => App.Ticket.unsubscribe(@subscribeId) diff --git a/app/assets/javascripts/app/lib/app_post/_collection_base.coffee b/app/assets/javascripts/app/lib/app_post/_collection_base.coffee index 99cb98541..1f7389a1d 100644 --- a/app/assets/javascripts/app/lib/app_post/_collection_base.coffee +++ b/app/assets/javascripts/app/lib/app_post/_collection_base.coffee @@ -44,6 +44,10 @@ class App._CollectionSingletonBase delete @callbacks[counter] fetch: => + if App.WebSocket.support() + App.WebSocket.send(event: @event) + return + return if @fetchActive @fetchActive = true App.Ajax.request( diff --git a/app/assets/javascripts/app/lib/app_post/overview_collection.coffee b/app/assets/javascripts/app/lib/app_post/overview_list_collection.coffee similarity index 71% rename from app/assets/javascripts/app/lib/app_post/overview_collection.coffee rename to app/assets/javascripts/app/lib/app_post/overview_list_collection.coffee index cc21ed7c6..26679bac5 100644 --- a/app/assets/javascripts/app/lib/app_post/overview_collection.coffee +++ b/app/assets/javascripts/app/lib/app_post/overview_list_collection.coffee @@ -1,5 +1,75 @@ -class App.OverviewCollection - _instance = undefined # Must be declared here to force the closure on the class +class _Singleton + constructor: -> + @overview = {} + @callbacks = {} + @fetchActive = {} + @counter = 0 + + App.Event.bind 'ticket_overview_list', (data) => + if !@overview[data.overview.view] + @overview[data.overview.view] = {} + @overview[data.overview.view] = data + @callback(data.overview.view, data) + + get: (view) -> + @overview[view] + + bind: (view, callback, init = true) -> + @counter += 1 + @callbacks[@counter] = + view: view + callback: callback + + # start init call if needed + if init + if @overview[view] is undefined + @fetch(view) + else + @callback(view, @overview[view]) + + @counter + + unbind: (counter) -> + delete @callbacks[counter] + + fetch: (view) => + if App.WebSocket.support() + App.WebSocket.send( + event: 'ticket_overview_list' + view: view + ) + return + + App.OverviewIndexCollection.fetch() + return if @fetchActive[view] + @fetchActive[view] = true + App.Ajax.request( + id: 'ticket_overview_' + view + type: 'GET', + url: App.Config.get('api_path') + '/ticket_overviews', + data: + view: view + processData: true, + success: (data) => + @fetchActive[view] = false + if data.assets + App.Collection.loadAssets(data.assets) + @overview[data.index.overview.view] = data.index + @callback(view, data.index) + error: => + @fetchActive[view] = false + ) + + trigger: (view) => + @callback(view, @get(view)) + + callback: (view, data) => + for counter, meta of @callbacks + if meta.view is view + meta.callback(data) + +class App.OverviewListCollection + _instance = new _Singleton @get: (view) -> if _instance == undefined @@ -25,79 +95,3 @@ class App.OverviewCollection if _instance == undefined _instance ?= new _Singleton _instance.trigger(view) - -# The actual Singleton class -class _Singleton - constructor: -> - @overview = {} - @callbacks = {} - @fetchActive = {} - @counter = 0 - - # websocket updates - App.Event.bind 'ticket_overview_rebuild', (data) => - if !@overview[data.view] - @overview[data.view] = {} - - # proccess assets, delete them later - if data.assets - App.Collection.loadAssets( data.assets ) - delete data.assets - - @overview[data.view] = data - - @callback(data.view, data) - - get: (view) -> - @overview[view] - - bind: (view, callback, init = true) -> - @counter += 1 - @callbacks[@counter] = - view: view - callback: callback - - # start init call if needed - if init - if @overview[view] is undefined - @fetch(view) - else - @callback(view, @overview[view]) - - @counter - - unbind: (counter) -> - delete @callbacks[counter] - - fetch: (view) => - return if @fetchActive[view] - @fetchActive[view] = true - App.Ajax.request( - id: 'ticket_overview_' + view - type: 'GET', - url: App.Config.get('api_path') + '/ticket_overviews', - data: - view: view - processData: true, - success: (data) => - @fetchActive[view] = false - - # proccess assets, delete them later - if data.assets - App.Collection.loadAssets( data.assets ) - delete data.assets - - @overview[data.view] = data - - @callback(view, data) - error: => - @fetchActive[view] = false - ) - - trigger: (view) => - @callback(view, @get(view)) - - callback: (view, data) => - for counter, meta of @callbacks - if meta.view is view - meta.callback(data) diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.coffee index c0a77cf73..5aed8d370 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.coffee @@ -1,38 +1,38 @@ class App.TaskManager _instance = undefined - @init: ( params ) -> - _instance ?= new _taskManagerSingleton( params ) + @init: (params) -> + _instance ?= new _taskManagerSingleton(params) @all: -> _instance.all() - @execute: ( params ) -> - _instance.execute( params ) + @execute: (params) -> + _instance.execute(params) - @get: ( key ) -> - _instance.get( key ) + @get: (key) -> + _instance.get(key) - @update: ( key, params ) -> - _instance.update( key, params ) + @update: (key, params) -> + _instance.update(key, params) @remove: (key, rerender = true) -> _instance.remove(key, rerender) - @notify: ( key ) -> - _instance.notify( key ) + @notify: (key) -> + _instance.notify(key) - @mute: ( key ) -> - _instance.mute( key ) + @mute: (key) -> + _instance.mute(key) - @reorder: ( order ) -> - _instance.reorder( order ) + @reorder: (order) -> + _instance.reorder(order) @reset: -> _instance.reset() - @worker: ( key ) -> - _instance.worker( key ) + @worker: (key) -> + _instance.worker(key) @nextTaskUrl: -> _instance.nextTaskUrl() @@ -181,7 +181,7 @@ class _taskManagerSingleton extends App.Controller if task.key isnt params.key if task.active task.active = false - @taskUpdate( task ) + @taskUpdate(task) else changed = false if !task.active @@ -191,7 +191,7 @@ class _taskManagerSingleton extends App.Controller changed = true task.notify = false if changed - @taskUpdate( task ) + @taskUpdate(task) # start worker for task if not exists @startController(params) @@ -405,12 +405,12 @@ class _taskManagerSingleton extends App.Controller return if @offlineModus for key of @tasksToUpdate continue if !key - task = @get( key ) + task = @get(key) continue if !task if @tasksToUpdate[ task.key ] is 'toUpdate' @tasksToUpdate[ task.key ] = 'inProgress' taskUpdate = new App.Taskbar - taskUpdate.load( task ) + taskUpdate.load(task) if taskUpdate.isOnline() ui = @ taskUpdate.save( @@ -456,11 +456,11 @@ class _taskManagerSingleton extends App.Controller # initial load of permanent tasks authentication = App.Session.get('id') - permanentTask = App.Config.get( 'permanentTask' ) + permanentTask = App.Config.get('permanentTask') task_count = 0 if permanentTask for key, config of permanentTask - if !config.authentication || ( config.authentication && authentication ) + if !config.authentication || (config.authentication && authentication) task_count += 1 do (key, config, task_count) => App.Delay.set( diff --git a/app/assets/javascripts/app/lib/app_post/websocket.coffee b/app/assets/javascripts/app/lib/app_post/websocket.coffee index 6adb7f0f2..8795e66a4 100644 --- a/app/assets/javascripts/app/lib/app_post/websocket.coffee +++ b/app/assets/javascripts/app/lib/app_post/websocket.coffee @@ -30,6 +30,11 @@ class App.WebSocket _instance ?= new _webSocketSingleton _instance.spool() + @support: -> + if _instance == undefined + _instance ?= new _webSocketSingleton + _instance.support() + # The actual Singleton class class _webSocketSingleton extends App.Controller @include App.LogInclude @@ -103,6 +108,9 @@ class _webSocketSingleton extends App.Controller channel: -> @backend + support: -> + @supported + send: (data) => if @backend is 'ajax' @_ajaxSend(data) @@ -180,6 +188,7 @@ class _webSocketSingleton extends App.Controller connect: => if !window.WebSocket + @supported = false @backend = 'ajax' @log 'debug', 'no support of websocket, use ajax long polling' @_ajaxInit() diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index e3cb9ee75..69c471809 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -10,80 +10,42 @@ class TicketOverviewsController < ApplicationController # get navbar overview data if !params[:view] - result = Ticket::Overviews.list( - current_user: current_user, - ) - render json: result - return - end - - # get real overview data - if params[:array] - overview = Ticket::Overviews.list( - view: params[:view], - current_user: current_user, - array: true, - ) - tickets = [] - overview[:tickets].each {|ticket_id| - data = { id: ticket_id } - tickets.push data + index_and_lists = Ticket::Overviews.index(current_user) + indexes = [] + index_and_lists.each { |index| + assets = {} + overview = Overview.lookup(id: index[:overview][:id]) + meta = { + name: overview.name, + prio: overview.prio, + link: overview.link, + count: index[:count], + } + indexes.push meta } - - # return result - render json: { - overview: overview[:overview], - tickets: tickets, - tickets_count: overview[:tickets_count], - } - return - end - overview = Ticket::Overviews.list( - view: params[:view], - current_user: current_user, - array: true, - ) - if !overview - render json: { error: "No such view #{params[:view]}!" }, status: :unprocessable_entity + render json: indexes return end - # get related users + index_and_lists = Ticket::Overviews.index(current_user) + assets = {} - overview[:ticket_ids].each {|ticket_id| - ticket = Ticket.lookup( id: ticket_id ) - assets = ticket.assets(assets) - } + result = {} + index_and_lists.each { |index| + next if index[:overview][:view] != params[:view] - # get groups - group_ids = [] - Group.where( active: true ).each { |group| - group_ids.push group.id - } - agents = {} - User.of_role('Agent').each { |user| - agents[ user.id ] = 1 - } - groups_users = {} - group_ids.each {|group_id| - groups_users[ group_id ] = [] - Group.find(group_id).users.each {|user| - next if !agents[ user.id ] - groups_users[ group_id ].push user.id - assets = user.assets( assets ) + overview = Overview.lookup(id: index[:overview][:id]) + assets = overview.assets(assets) + index[:tickets].each {|ticket_meta| + ticket = Ticket.lookup(id: ticket_meta[:id]) + assets = ticket.assets(assets) } + result = index } - # return result render json: { - view: params[:view], - overview: overview[:overview], - ticket_ids: overview[:ticket_ids], - tickets_count: overview[:tickets_count], - bulk: { - group_id__owner_id: groups_users, - }, assets: assets, + index: result, } end diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 1970c8311..318bc0f4d 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -354,7 +354,7 @@ class TicketsController < ApplicationController def stats if !params[:user_id] && !params[:organization_id] - fail 'Need user_id or organization_id as param' + raise 'Need user_id or organization_id as param' end # permission check diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index 65393eb40..55dd0cd4c 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -34,7 +34,7 @@ add a new activity entry for an object if data[:role] role = Role.lookup(name: data[:role]) if !role - fail "No such Role #{data[:role]}" + raise "No such Role #{data[:role]}" end role_id = role.id end diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 68b038abb..92731b4f2 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -71,7 +71,7 @@ returns def self.param_cleanup(params, newObject = false) if params.nil? - fail "No params for #{self}!" + raise "No params for #{self}!" end # ignore id for new objects @@ -377,7 +377,7 @@ returns return end - fail 'Need name, id, login or email for lookup()' + raise 'Need name, id, login or email for lookup()' end =begin @@ -535,7 +535,7 @@ returns record.save return record else - fail 'Need name, login, email or locale for create_or_update()' + raise 'Need name, login, email or locale for create_or_update()' end end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 28c1609bd..a91fa8bf5 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -268,7 +268,7 @@ returns if location =~ /^http/i result = UserAgent.get(location) if !result.success? - fail result.error + raise result.error end cal_file = result.body else diff --git a/app/models/channel/driver/facebook.rb b/app/models/channel/driver/facebook.rb index 83dd77836..45d66eace 100644 --- a/app/models/channel/driver/facebook.rb +++ b/app/models/channel/driver/facebook.rb @@ -29,7 +29,7 @@ class Channel::Driver::Facebook access_token = page['access_token'] } if !access_token - fail "No access_token found for fb_object_id: #{fb_object_id}" + raise "No access_token found for fb_object_id: #{fb_object_id}" end client = Facebook.new(access_token) client.from_article(article) diff --git a/app/models/channel/driver/twitter.rb b/app/models/channel/driver/twitter.rb index 2c6ce14ad..fe3ceb3d8 100644 --- a/app/models/channel/driver/twitter.rb +++ b/app/models/channel/driver/twitter.rb @@ -184,7 +184,7 @@ returns def stream sync = @channel.options['sync'] - fail 'Need channel.options[\'sync\'] for account, but no params found' if !sync + raise 'Need channel.options[\'sync\'] for account, but no params found' if !sync filter = {} if sync['search'] @@ -315,7 +315,7 @@ returns def check_external_credential(options) if options[:auth] && options[:auth][:external_credential_id] external_credential = ExternalCredential.find_by(id: options[:auth][:external_credential_id]) - fail "No such ExternalCredential.find(#{options[:auth][:external_credential_id]})" if !external_credential + raise "No such ExternalCredential.find(#{options[:auth][:external_credential_id]})" if !external_credential options[:auth][:consumer_key] = external_credential.credentials['consumer_key'] options[:auth][:consumer_secret] = external_credential.credentials['consumer_secret'] end diff --git a/app/models/locale.rb b/app/models/locale.rb index 4d9496c95..7332ea10f 100644 --- a/app/models/locale.rb +++ b/app/models/locale.rb @@ -26,8 +26,8 @@ class Locale < ApplicationModel } ) - fail "Can't load locales from #{url}" if !result - fail "Can't load locales from #{url}: #{result.error}" if !result.success? + raise "Can't load locales from #{url}" if !result + raise "Can't load locales from #{url}: #{result.error}" if !result.success? ActiveRecord::Base.transaction do result.data.each {|locale| diff --git a/app/models/observer/ticket/article/communicate_email/background_job.rb b/app/models/observer/ticket/article/communicate_email/background_job.rb index 049c3eacc..5c9933793 100644 --- a/app/models/observer/ticket/article/communicate_email/background_job.rb +++ b/app/models/observer/ticket/article/communicate_email/background_job.rb @@ -12,9 +12,9 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob # send email if !ticket.group.email_address_id - fail "Can't send email, no email address definde for group id '#{ticket.group.id}'" + raise "Can't send email, no email address definde for group id '#{ticket.group.id}'" elsif !ticket.group.email_address.channel_id - fail "Can't send email, no channel definde for email_address id '#{ticket.group.email_address_id}'" + raise "Can't send email, no channel definde for email_address id '#{ticket.group.email_address_id}'" end channel = ticket.group.email_address.channel diff --git a/app/models/observer/ticket/article/communicate_facebook.rb b/app/models/observer/ticket/article/communicate_facebook.rb index 9c359c793..ea6387284 100644 --- a/app/models/observer/ticket/article/communicate_facebook.rb +++ b/app/models/observer/ticket/article/communicate_facebook.rb @@ -20,15 +20,15 @@ class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer return if type['name'] !~ /\Afacebook/ ticket = Ticket.lookup(id: record.ticket_id) - fail "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences - fail "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id'] + raise "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences + raise "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id'] channel = Channel.lookup(id: ticket.preferences['channel_id']) - fail "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Afacebook/i + raise "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Afacebook/i # check source object id ticket = record.ticket if !ticket.preferences['channel_fb_object_id'] - fail "fb object id is missing in ticket.preferences['channel_fb_object_id'] for Ticket.find(#{ticket.id})" + raise "fb object id is missing in ticket.preferences['channel_fb_object_id'] for Ticket.find(#{ticket.id})" end # fill in_reply_to diff --git a/app/models/observer/ticket/article/communicate_twitter.rb b/app/models/observer/ticket/article/communicate_twitter.rb index 45d63a27e..b878a12b4 100644 --- a/app/models/observer/ticket/article/communicate_twitter.rb +++ b/app/models/observer/ticket/article/communicate_twitter.rb @@ -18,11 +18,11 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer return if type['name'] !~ /\Atwitter/i ticket = Ticket.lookup(id: record.ticket_id) - fail "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences - fail "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id'] + raise "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences + raise "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id'] channel = Channel.lookup(id: ticket.preferences['channel_id']) - fail "No such channel id #{ticket.preferences['channel_id']}" if !channel - fail "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Atwitter/i + raise "No such channel id #{ticket.preferences['channel_id']}" if !channel + raise "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Atwitter/i tweet = channel.deliver( type: type['name'], to: record.to, @@ -54,7 +54,7 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer record.preferences[:twitter_mention_ids] = twitter_mention_ids end else - fail "Unknown tweet type '#{tweet.class}'" + raise "Unknown tweet type '#{tweet.class}'" end record.message_id = tweet.id diff --git a/app/models/observer/ticket/article/fillup_from_email.rb b/app/models/observer/ticket/article/fillup_from_email.rb index beb9f3a05..5a75064c9 100644 --- a/app/models/observer/ticket/article/fillup_from_email.rb +++ b/app/models/observer/ticket/article/fillup_from_email.rb @@ -38,7 +38,7 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer # set sender email_address = ticket.group.email_address if !email_address - fail "No email address found for group '#{ticket.group.name}'" + raise "No email address found for group '#{ticket.group.name}'" end system_sender = "#{email_address.realname} <#{email_address.email}>" if Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName' diff --git a/app/models/observer/ticket/notification.rb b/app/models/observer/ticket/notification.rb index 202cfcd35..5cecc0dd8 100644 --- a/app/models/observer/ticket/notification.rb +++ b/app/models/observer/ticket/notification.rb @@ -105,7 +105,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer end end else - fail "unknown object for notification #{event[:name]}" + raise "unknown object for notification #{event[:name]}" end } list_objects diff --git a/app/models/observer/ticket/notification/background_job.rb b/app/models/observer/ticket/notification/background_job.rb index 2c697b000..7f3cea77d 100644 --- a/app/models/observer/ticket/notification/background_job.rb +++ b/app/models/observer/ticket/notification/background_job.rb @@ -162,7 +162,7 @@ class Observer::Ticket::Notification::BackgroundJob elsif @p[:type] == 'escalation_warning' template = 'ticket_escalation_warning' else - fail "unknown type for notification #{@p[:type]}" + raise "unknown type for notification #{@p[:type]}" end NotificationFactory.notification( diff --git a/app/models/overview.rb b/app/models/overview.rb index c2e04b1f8..579703219 100644 --- a/app/models/overview.rb +++ b/app/models/overview.rb @@ -10,6 +10,8 @@ class Overview < ApplicationModel before_create :fill_link before_update :fill_link + latest_change_support + private # fill link diff --git a/app/models/package.rb b/app/models/package.rb index 5c429c0e7..41c93a13c 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -103,7 +103,7 @@ note: will not take down package migrations, use Package.unlink instead package = entry.sub(%r{^.*/(.+?)\.szpm$}, '\1') end if package == false - fail "Can't link package, '#{package_base_dir}' is no package source directory!" + raise "Can't link package, '#{package_base_dir}' is no package source directory!" end logger.debug package.inspect package @@ -184,7 +184,7 @@ link files + execute migration up if File.file?(entry.to_s) && (File.file?(dest.to_s) && !File.symlink?(dest.to_s)) backup_file = dest.to_s + '.link_backup' if File.exist?(backup_file) - fail "Can't link #{entry} -> #{dest}, destination and .link_backup already exists!" + raise "Can't link #{entry} -> #{dest}, destination and .link_backup already exists!" else logger.info "Create backup file of #{dest} -> #{backup_file}." File.rename(dest.to_s, backup_file) @@ -243,10 +243,10 @@ returns if package_db if !data[:reinstall] if Gem::Version.new(package_db.version) == Gem::Version.new(meta[:version]) - fail "Package '#{meta[:name]}-#{meta[:version]}' already installed!" + raise "Package '#{meta[:name]}-#{meta[:version]}' already installed!" end if Gem::Version.new(package_db.version) > Gem::Version.new(meta[:version]) - fail "Newer version (#{package_db.version}) of package '#{meta[:name]}-#{meta[:version]}' already installed!" + raise "Newer version (#{package_db.version}) of package '#{meta[:name]}-#{meta[:version]}' already installed!" end end @@ -306,7 +306,7 @@ returns def self.reinstall(package_name) package = Package.find_by(name: package_name) if !package - fail "No such package '#{package_name}'" + raise "No such package '#{package_name}'" end file = _get_bin(package.name, package.version) install(string: file, reinstall: true) @@ -367,7 +367,7 @@ returns version: version, ) if !package - fail "No such package '#{name}' version '#{version}'" + raise "No such package '#{name}' version '#{version}'" end list = Store.list( object: 'Package', @@ -376,10 +376,10 @@ returns # find file if !list || !list.first - fail "No such file in storage list #{name} #{version}" + raise "No such file in storage list #{name} #{version}" end if !list.first.content - fail "No such file in storage #{name} #{version}" + raise "No such file in storage #{name} #{version}" end list.first.content end @@ -497,7 +497,7 @@ returns name = $2 end if !version || !name - fail "Invalid package migration '#{migration}'" + raise "Invalid package migration '#{migration}'" end # down diff --git a/app/models/setting.rb b/app/models/setting.rb index 2485f3d52..84d4203b6 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -33,7 +33,7 @@ set config setting def self.set(name, value) setting = Setting.find_by( name: name ) if !setting - fail "Can't find config setting '#{name}'" + raise "Can't find config setting '#{name}'" end setting.state_current = { value: value } setting.save @@ -68,7 +68,7 @@ reset config setting to default def self.reset(name) setting = Setting.find_by( name: name ) if !setting - fail "Can't find config setting '#{name}'" + raise "Can't find config setting '#{name}'" end setting.state_current = setting.state_initial setting.save diff --git a/app/models/store.rb b/app/models/store.rb index 0e82989ef..53418d336 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -142,7 +142,7 @@ returns def content file = Store::File.find_by(id: store_file_id) if !file - fail "No such file #{store_file_id}!" + raise "No such file #{store_file_id}!" end file.content end @@ -150,7 +150,7 @@ returns def provider file = Store::File.find_by(id: store_file_id) if !file - fail "No such file #{store_file_id}!" + raise "No such file #{store_file_id}!" end file.provider end diff --git a/app/models/store/file.rb b/app/models/store/file.rb index 4004f703e..7aca3cf8e 100644 --- a/app/models/store/file.rb +++ b/app/models/store/file.rb @@ -26,7 +26,7 @@ do also verify of written data # load backend based on config adapter_name = Setting.get('storage_provider') || 'DB' if !adapter_name - fail 'Missing storage_provider setting option' + raise 'Missing storage_provider setting option' end adapter = load_adapter("Store::Provider::#{adapter_name}") adapter.add(data, sha) @@ -40,7 +40,7 @@ do also verify of written data read_data = adapter.get(sha) read_sha = Digest::SHA256.hexdigest(read_data) if sha != read_sha - fail "Content not written correctly (provider #{adapter_name})." + raise "Content not written correctly (provider #{adapter_name})." end end end diff --git a/app/models/store/provider/file.rb b/app/models/store/provider/file.rb index 8aab3964f..cc0d936bf 100644 --- a/app/models/store/provider/file.rb +++ b/app/models/store/provider/file.rb @@ -18,7 +18,7 @@ class Store::Provider::File # check sha local_sha = Digest::SHA256.hexdigest(get(sha)) if sha != local_sha - fail "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}" + raise "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}" end true @@ -29,7 +29,7 @@ class Store::Provider::File location = get_location(sha) Rails.logger.debug "read from fs #{location}" if !File.exist?(location) - fail "ERROR: No such file #{location}" + raise "ERROR: No such file #{location}" end data = File.open(location, 'rb') content = data.read @@ -37,7 +37,7 @@ class Store::Provider::File # check sha local_sha = Digest::SHA256.hexdigest(content) if local_sha != sha - fail "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}" + raise "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}" end content end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index a4136218c..804798824 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -367,7 +367,7 @@ get count of tickets and tickets which match on selector =end def self.selectors(selectors, limit = 10, current_user = nil) - fail 'no selectors given' if !selectors + raise 'no selectors given' if !selectors query, bind_params, tables = selector2sql(selectors, current_user) return [] if !query @@ -454,7 +454,7 @@ condition example tables += ', users owners' query += 'tickets.owner_id = owners.id' else - fail "invalid selector #{attribute.inspect}->#{selector.inspect}" + raise "invalid selector #{attribute.inspect}->#{selector.inspect}" end } @@ -462,10 +462,10 @@ condition example selectors.each {|attribute, selector_raw| # validation - fail "Invalid selector #{selector_raw.inspect}" if !selector_raw - fail "Invalid selector #{selector_raw.inspect}" if !selector_raw.respond_to?(:key?) + raise "Invalid selector #{selector_raw.inspect}" if !selector_raw + raise "Invalid selector #{selector_raw.inspect}" if !selector_raw.respond_to?(:key?) selector = selector_raw.stringify_keys - fail "Invalid selector, operator missing #{selector.inspect}" if !selector['operator'] + raise "Invalid selector, operator missing #{selector.inspect}" if !selector['operator'] # validate value / allow empty but only if pre_condition exists if (selector['value'].class == String || selector['value'].class == Array) && (selector['value'].respond_to?(:empty?) && selector['value'].empty?) @@ -492,11 +492,11 @@ condition example query += "#{attribute} IS NOT NULL" end elsif selector['pre_condition'] == 'current_user.id' - fail "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id + raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id query += "#{attribute} IN (?)" bind_params.push current_user_id elsif selector['pre_condition'] == 'current_user.organization_id' - fail "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id + raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id query += "#{attribute} IN (?)" user = User.lookup(id: current_user_id) bind_params.push user.organization_id @@ -563,7 +563,7 @@ condition example elsif selector['range'] == 'year' time = Time.zone.now - selector['value'].to_i.years else - fail "Unknown selector attributes '#{selector.inspect}'" + raise "Unknown selector attributes '#{selector.inspect}'" end bind_params.push time elsif selector['operator'] == 'within next (relative)' @@ -580,7 +580,7 @@ condition example elsif selector['range'] == 'year' time = Time.zone.now + selector['value'].to_i.years else - fail "Unknown selector attributes '#{selector.inspect}'" + raise "Unknown selector attributes '#{selector.inspect}'" end bind_params.push time elsif selector['operator'] == 'before (relative)' @@ -597,7 +597,7 @@ condition example elsif selector['range'] == 'year' time = Time.zone.now - selector['value'].to_i.years else - fail "Unknown selector attributes '#{selector.inspect}'" + raise "Unknown selector attributes '#{selector.inspect}'" end bind_params.push time elsif selector['operator'] == 'after (relative)' @@ -614,11 +614,11 @@ condition example elsif selector['range'] == 'year' time = Time.zone.now + selector['value'].to_i.years else - fail "Unknown selector attributes '#{selector.inspect}'" + raise "Unknown selector attributes '#{selector.inspect}'" end bind_params.push time else - fail "Invalid operator '#{selector['operator']}' for '#{selector['value'].inspect}'" + raise "Invalid operator '#{selector['operator']}' for '#{selector['value'].inspect}'" end } [query, bind_params, tables] diff --git a/app/models/ticket/escalation.rb b/app/models/ticket/escalation.rb index 1d1ee42a1..996d26a69 100644 --- a/app/models/ticket/escalation.rb +++ b/app/models/ticket/escalation.rb @@ -84,7 +84,7 @@ returns } config.hours = hours if !hours || hours.empty? - fail "No congifure hours found in calendar #{calendar.inspect}" + raise "No congifure hours found in calendar #{calendar.inspect}" end # get holidays diff --git a/app/models/ticket/number.rb b/app/models/ticket/number.rb index d5fde9ac6..2936721c7 100644 --- a/app/models/ticket/number.rb +++ b/app/models/ticket/number.rb @@ -23,7 +23,7 @@ returns ticket = Ticket.find_by( number: number ) return number if !ticket } - fail "Can't generate new ticket number!" + raise "Can't generate new ticket number!" end =begin @@ -47,11 +47,11 @@ returns # load backend based on config adapter_name = Setting.get('ticket_number') if !adapter_name - fail 'Missing ticket_number setting option' + raise 'Missing ticket_number setting option' end adapter = load_adapter(adapter_name) if !adapter - fail "Can't load ticket_number adapter '#{adapter_name}'" + raise "Can't load ticket_number adapter '#{adapter_name}'" end adapter end diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index 16a6623f6..aa82c2918 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -3,10 +3,10 @@ module Ticket::Overviews =begin -all overview by user +all overviews by user result = Ticket::Overviews.all( - :current_user => User.find(123), + current_user: User.find(123), ) returns @@ -15,137 +15,105 @@ returns =end - def self.all (data) + def self.all(data) # get customer overviews if data[:current_user].role?('Customer') - role = Role.find_by( name: 'Customer' ) + role = Role.find_by(name: 'Customer') overviews = if data[:current_user].organization_id && data[:current_user].organization.shared - Overview.where( role_id: role.id, active: true ) + Overview.where(role_id: role.id, active: true) else - Overview.where( role_id: role.id, organization_shared: false, active: true ) + Overview.where(role_id: role.id, organization_shared: false, active: true) end return overviews end # get agent overviews - return if !data[:current_user].role?( 'Agent' ) - role = Role.find_by( name: 'Agent' ) - Overview.where( role_id: role.id, active: true ) + return if !data[:current_user].role?('Agent') + role = Role.find_by(name: 'Agent') + Overview.where(role_id: role.id, active: true) end =begin -selected overview by user - - result = Ticket::Overviews.list( - current_user: User.find(123), - view: 'some_view_url', - ) + result = Ticket::Overviews.index(User.find(123)) returns - result = { - tickets: tickets, # [ticket1, ticket2, ticket3] - tickets_count: tickets_count, # count of tickets - overview: overview_selected_raw, # overview attributes + [ + { + overview: { + id: 123, + updated_at: ..., + }, + count: 3, + tickets: [ + { + id: 1, + updated_at: ..., + }, + { + id: 2, + updated_at: ..., + }, + { + id: 3, + updated_at: ..., + } + ], + }, + { + ... } + ] =end - def self.list (data) - - overviews = all(data) - return if !overviews - - # build up attributes hash - overview_selected = nil - overview_selected_raw = nil - - overviews.each { |overview| - - # remember selected view - if data[:view] && data[:view] == overview.link - overview_selected = overview - overview_selected_raw = Marshal.load( Marshal.dump(overview.attributes) ) - end - } - - if data[:view] && !overview_selected - fail "No such view '#{data[:view]}'" - end + def self.index(user) + overviews = Ticket::Overviews.all( + current_user: user, + ) # get only tickets with permissions - access_condition = Ticket.access_condition( data[:current_user] ) + access_condition = Ticket.access_condition(user) - # overview meta for navbar - if !overview_selected + list = [] + overviews.each {|overview| + query_condition, bind_condition = Ticket.selector2sql(overview.condition, user) - # loop each overview - result = [] - overviews.each { |overview| - - query_condition, bind_condition = Ticket.selector2sql(overview.condition, data[:current_user]) - - # get count - count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count() - - # get meta info - all = { - name: overview.name, - prio: overview.prio, - link: overview.link, - } - - # push to result data - result.push all.merge( { count: count } ) - } - return result - end - - # get result list - if data[:array] - order_by = overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s - if overview_selected.group_by && !overview_selected.group_by.empty? - order_by = overview_selected.group_by + '_id, ' + order_by + order_by = "#{overview.order[:by]} #{overview.order[:direction]}" + if overview.group_by && !overview.group_by.empty? + order_by = "#{overview.group_by}_id, #{order_by}" end - query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user]) + ticket_result = Ticket.select('id, updated_at') + .where(access_condition) + .where(query_condition, *bind_condition) + .order(order_by) + .limit(500) - tickets = Ticket.select('id') - .where( access_condition ) - .where( query_condition, *bind_condition ) - .order( order_by ) - .limit( 500 ) - - ticket_ids = [] - tickets.each { |ticket| - ticket_ids.push ticket.id + tickets = [] + ticket_result.each { |ticket| + ticket_item = { + id: ticket.id, + updated_at: ticket.updated_at, + } + tickets.push ticket_item + } + count = Ticket.where(access_condition).where(query_condition, *bind_condition).count() + item = { + overview: { + id: overview.id, + view: overview.link, + updated_at: overview.updated_at, + }, + tickets: tickets, + count: count, } - tickets_count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count() - - return { - ticket_ids: ticket_ids, - tickets_count: tickets_count, - overview: overview_selected_raw, - } - end - - # get tickets for overview - data[:start_page] ||= 1 - query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user]) - tickets = Ticket.where( access_condition ) - .where( query_condition, *bind_condition ) - .order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ) - - tickets_count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count() - - { - tickets: tickets, - tickets_count: tickets_count, - overview: overview_selected_raw, + list.push item } + list end end diff --git a/app/models/ticket/state.rb b/app/models/ticket/state.rb index 5ebe899ea..4abf0d45e 100644 --- a/app/models/ticket/state.rb +++ b/app/models/ticket/state.rb @@ -43,7 +43,7 @@ returns: state_type_id: Ticket::StateType.where( name: %w(closed) ) ) end - fail "Unknown category '#{category}'" + raise "Unknown category '#{category}'" end =begin diff --git a/app/models/translation.rb b/app/models/translation.rb index 629891564..aca7a7399 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -44,7 +44,7 @@ dedicated: read_timeout: 16, } ) - fail "Can't load translations from #{url}: #{result.error}" if !result.success? + raise "Can't load translations from #{url}: #{result.error}" if !result.success? translations = Translation.where(locale: locale).all ActiveRecord::Base.transaction do @@ -120,7 +120,7 @@ push translations to online read_timeout: 16, } ) - fail "Can't push translations to #{url}: #{result.error}" if !result.success? + raise "Can't push translations to #{url}: #{result.error}" if !result.success? # set new translator_key if given if result.data['translator_key'] diff --git a/app/models/user_device.rb b/app/models/user_device.rb index 2db2d5def..b75be0c1d 100644 --- a/app/models/user_device.rb +++ b/app/models/user_device.rb @@ -21,6 +21,11 @@ store device for user def self.add(user_agent, ip, user_id, fingerprint, type) + # since gem browser 2 is not handling nil for user_agent, set it to '' + if user_agent.nil? + user_agent = '' + end + # get location info location_details = Service::GeoIp.location(ip) location = 'unknown' @@ -49,7 +54,7 @@ store device for user end # get browser details - browser = Browser.new(ua: user_agent, accept_language: 'en-us') + browser = Browser.new(user_agent, accept_language: 'en-us') browser = { plattform: browser.platform.to_s.camelize, name: browser.name, @@ -58,6 +63,9 @@ store device for user } # generate device name + if browser[:name] == 'Generic Browser' + browser[:name] = user_agent + end name = '' if browser[:plattform] && browser[:plattform] != 'Other' name = browser[:plattform] diff --git a/lib/application_lib.rb b/lib/application_lib.rb index 8eb8f5fce..53ab30f2b 100644 --- a/lib/application_lib.rb +++ b/lib/application_lib.rb @@ -54,7 +54,7 @@ returns adapter = adapter.constantize if !adapter - fail "Can't load adapter '#{adapter_name}'" + raise "Can't load adapter '#{adapter_name}'" end adapter diff --git a/lib/auto_wizard.rb b/lib/auto_wizard.rb index 7e3adf04f..f69c521f0 100644 --- a/lib/auto_wizard.rb +++ b/lib/auto_wizard.rb @@ -32,7 +32,7 @@ returns def self.data auto_wizard_file_location = file_location - fail "So such file #{auto_wizard_file_location}" if !File.file?(auto_wizard_file_location) + raise "So such file #{auto_wizard_file_location}" if !File.file?(auto_wizard_file_location) JSON.parse( File.read(auto_wizard_file_location) ) end diff --git a/lib/external_credential/facebook.rb b/lib/external_credential/facebook.rb index 689007320..926eb6eb0 100644 --- a/lib/external_credential/facebook.rb +++ b/lib/external_credential/facebook.rb @@ -23,6 +23,7 @@ class ExternalCredential::Facebook state = rand(999_999_999_999).to_s { request_token: state, + #authorize_url: oauth.url_for_oauth_code(permissions: 'publish_pages, manage_pages, user_posts', state: state), authorize_url: oauth.url_for_oauth_code(permissions: 'publish_pages, manage_pages', state: state), } end @@ -30,7 +31,7 @@ class ExternalCredential::Facebook def self.link_account(_request_token, params) # fail if request_token.params[:oauth_token] != params[:state] external_credential = ExternalCredential.find_by(name: 'facebook') - fail 'No such account' if !external_credential + raise 'No such account' if !external_credential oauth = Koala::Facebook::OAuth.new( external_credential.credentials['application_id'], external_credential.credentials['application_secret'], diff --git a/lib/external_credential/twitter.rb b/lib/external_credential/twitter.rb index 77831a94f..d2659413b 100644 --- a/lib/external_credential/twitter.rb +++ b/lib/external_credential/twitter.rb @@ -27,7 +27,7 @@ class ExternalCredential::Twitter end def self.link_account(request_token, params) - fail if request_token.params[:oauth_token] != params[:oauth_token] + raise if request_token.params[:oauth_token] != params[:oauth_token] external_credential = ExternalCredential.find_by(name: 'twitter') access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier]) client = Twitter::REST::Client.new( diff --git a/lib/facebook.rb b/lib/facebook.rb index cb49a52d5..5df6bf5fc 100644 --- a/lib/facebook.rb +++ b/lib/facebook.rb @@ -309,7 +309,7 @@ result Rails.logger.debug 'Create feed comment from article...' post = @client.put_comment(article[:in_reply_to], article[:body]) else - fail "Can't handle unknown facebook article type '#{article[:type]}'." + raise "Can't handle unknown facebook article type '#{article[:type]}'." end Rails.logger.debug post.inspect @client.get_object(post['id']) diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index 230c49345..b0e60417f 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -23,14 +23,14 @@ module Import::OTRS def self.request_json(data, data_only = false) response = post(data) if !response - fail "Can't connect to Zammad Migrator" + raise "Can't connect to Zammad Migrator" end if !response.success? - fail "Can't connect to Zammad Migrator" + raise "Can't connect to Zammad Migrator" end result = json(response) if !result - fail 'Invalid response' + raise 'Invalid response' end if data_only result['Result'] @@ -303,12 +303,12 @@ module Import::OTRS # check if system is in import mode if !Setting.get('import_mode') - fail 'System is not in import mode!' + raise 'System is not in import mode!' end result = request_json({}) if !result['Success'] - fail 'API key not valid!' + raise 'API key not valid!' end # set settings @@ -495,7 +495,7 @@ module Import::OTRS # check if system is in import mode if !Setting.get('import_mode') - fail 'System is not in import mode!' + raise 'System is not in import mode!' end # create states diff --git a/lib/import/zendesk.rb b/lib/import/zendesk.rb index a2e4a46d7..a86261e77 100644 --- a/lib/import/zendesk.rb +++ b/lib/import/zendesk.rb @@ -12,7 +12,7 @@ module Import::Zendesk # check if system is in import mode if !Setting.get('import_mode') - fail 'System is not in import mode!' + raise 'System is not in import mode!' end initialize_client diff --git a/lib/models.rb b/lib/models.rb index 4b7fb4541..357a6d495 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -215,7 +215,7 @@ returns if force total = references_total(object_name, object_id_to_merge) if total > 1000 - fail "Can't merge object because object has more then 1000 (#{total}) references, please contact your system administrator." + raise "Can't merge object because object has more then 1000 (#{total}) references, please contact your system administrator." end end diff --git a/lib/notification_factory.rb b/lib/notification_factory.rb index 1b6376c57..25b0be97e 100644 --- a/lib/notification_factory.rb +++ b/lib/notification_factory.rb @@ -314,17 +314,18 @@ returns template_body = '' locale = data[:locale] || 'en' template = data[:template] - location = "app/views/mailer/#{template}/#{locale}.html.erb" + root = Rails.root + location = "#{root}/app/views/mailer/#{template}/#{locale}.html.erb" # as fallback, use 2 char locale if !File.exist?(location) locale = locale[0, 2] - location = "app/views/mailer/#{template}/#{locale}.html.erb" + location = "#{root}/app/views/mailer/#{template}/#{locale}.html.erb" end # as fallback, use en if !File.exist?(location) - location = "app/views/mailer/#{template}/en.html.erb" + location = "#{root}/app/views/mailer/#{template}/en.html.erb" end File.open(location, 'r:UTF-8').each do |line| @@ -340,7 +341,7 @@ returns if !data[:raw] application_template = nil - File.open('app/views/mailer/application.html.erb', 'r:UTF-8') do |file| + File.open("#{root}/app/views/mailer/application.html.erb", 'r:UTF-8') do |file| application_template = file.read end data[:objects][:message] = message_body diff --git a/lib/report/base.rb b/lib/report/base.rb index 249102146..21283bee0 100644 --- a/lib/report/base.rb +++ b/lib/report/base.rb @@ -98,9 +98,9 @@ class Report::Base ).count end - fail "UNKOWN params (#{params.inspect})!" + raise "UNKOWN params (#{params.inspect})!" end - fail "UNKOWN :type (#{params[:type]})!" + raise "UNKOWN :type (#{params[:type]})!" end # :object @@ -219,7 +219,7 @@ class Report::Base ticket_ids: ticket_ids, } end - fail "UNKOWN :type (#{data[:type]})!" + raise "UNKOWN :type (#{data[:type]})!" end # :type diff --git a/lib/report/ticket_generic_time.rb b/lib/report/ticket_generic_time.rb index b913a19de..b557a3a53 100644 --- a/lib/report/ticket_generic_time.rb +++ b/lib/report/ticket_generic_time.rb @@ -56,16 +56,16 @@ returns (1..stop_interval).each {|_counter| match = false if !result_es - fail "Invalid es result #{result_es.inspect}" + raise "Invalid es result #{result_es.inspect}" end if !result_es['aggregations'] - fail "Invalid es result, no aggregations #{result_es.inspect}" + raise "Invalid es result, no aggregations #{result_es.inspect}" end if !result_es['aggregations']['time_buckets'] - fail "Invalid es result, no time_buckets #{result_es.inspect}" + raise "Invalid es result, no time_buckets #{result_es.inspect}" end if !result_es['aggregations']['time_buckets']['buckets'] - fail "Invalid es result, no buckets #{result_es.inspect}" + raise "Invalid es result, no buckets #{result_es.inspect}" end result_es['aggregations']['time_buckets']['buckets'].each {|item| if params[:interval] == 'minute' diff --git a/lib/report/ticket_moved.rb b/lib/report/ticket_moved.rb index 61265e5b2..b9302231e 100644 --- a/lib/report/ticket_moved.rb +++ b/lib/report/ticket_moved.rb @@ -160,6 +160,6 @@ returns } end end - fail "Unknown selector params '#{selector.inspect}'" + raise "Unknown selector params '#{selector.inspect}'" end end diff --git a/lib/rss.rb b/lib/rss.rb index d83ce8f2d..34de4bb7f 100644 --- a/lib/rss.rb +++ b/lib/rss.rb @@ -9,7 +9,7 @@ module Rss Rails.logger.info "fetch rss... #{url}" response = UserAgent.request(url) if !response.success? - fail "Can't fetch '#{url}', http code: #{response.code}" + raise "Can't fetch '#{url}', http code: #{response.code}" end rss = SimpleRSS.parse response.body items = [] diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 6b417d55a..3b9e8ebab 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -59,7 +59,7 @@ create/update/delete index ) Rails.logger.info "# #{response.code}" return true if response.success? - fail response.inspect + raise response.inspect end =begin @@ -91,7 +91,7 @@ add new object to search index ) Rails.logger.info "# #{response.code}" return true if response.success? - fail response.inspect + raise response.inspect end =begin @@ -270,7 +270,7 @@ get count of tickets and tickets which match on selector =end def self.selectors(index = nil, selectors = nil, limit = 10, current_user = nil, aggs_interval = nil) - fail 'no selectors given' if !selectors + raise 'no selectors given' if !selectors url = build_url() return if !url @@ -303,7 +303,7 @@ get count of tickets and tickets which match on selector Rails.logger.info "# #{response.code}" if !response.success? - fail "ERROR: #{response.inspect}" + raise "ERROR: #{response.inspect}" end Rails.logger.debug response.data.to_json @@ -345,7 +345,7 @@ get count of tickets and tickets which match on selector elsif data['operator'] == 'contains not' query_must_not.push t else - fail "unknown operator '#{data['operator']}'" + raise "unknown operator '#{data['operator']}'" end } end diff --git a/lib/service/geo_calendar/zammad.rb b/lib/service/geo_calendar/zammad.rb index 22252a51e..7b01d2422 100644 --- a/lib/service/geo_calendar/zammad.rb +++ b/lib/service/geo_calendar/zammad.rb @@ -30,7 +30,7 @@ class Service::GeoCalendar::Zammad }, ) if !response.success? && response.code.to_s !~ /^40.$/ - fail "ERROR: #{response.code}/#{response.body}" + raise "ERROR: #{response.code}/#{response.body}" end data = response.data diff --git a/lib/service/geo_ip/zammad.rb b/lib/service/geo_ip/zammad.rb index 7e8014845..7820a50f3 100644 --- a/lib/service/geo_ip/zammad.rb +++ b/lib/service/geo_ip/zammad.rb @@ -26,7 +26,7 @@ class Service::GeoIp::Zammad }, ) if !response.success? && response.code.to_s !~ /^40.$/ - fail "ERROR: #{response.code}/#{response.body}" + raise "ERROR: #{response.code}/#{response.body}" end data = response.data diff --git a/lib/sessions/backend/activity_stream.rb b/lib/sessions/backend/activity_stream.rb index d3ee37ec4..10f6874bc 100644 --- a/lib/sessions/backend/activity_stream.rb +++ b/lib/sessions/backend/activity_stream.rb @@ -1,17 +1,18 @@ class Sessions::Backend::ActivityStream - def initialize( user, client = nil, client_id = nil, ttl = 30 ) - @user = user - @client = client - @client_id = client_id - @ttl = ttl - @last_change = nil + def initialize(user, asset_lookup, client = nil, client_id = nil, ttl = 25) + @user = user + @client = client + @client_id = client_id + @ttl = ttl + @asset_lookup = asset_lookup + @last_change = nil end def load # get whole collection - activity_stream = @user.activity_stream( 25 ) + activity_stream = @user.activity_stream(25) if activity_stream && !activity_stream.first return end @@ -25,7 +26,7 @@ class Sessions::Backend::ActivityStream @last_change = activity_stream.first['created_at'] end - @user.activity_stream( 25, true ) + @user.activity_stream(25, true) end def client_key @@ -35,11 +36,11 @@ class Sessions::Backend::ActivityStream def push # check timeout - timeout = Sessions::CacheIn.get( client_key ) + timeout = Sessions::CacheIn.get(client_key) return if timeout # set new timeout - Sessions::CacheIn.set( client_key, true, { expires_in: @ttl.seconds } ) + Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds }) data = load diff --git a/lib/sessions/backend/base.rb b/lib/sessions/backend/base.rb new file mode 100644 index 000000000..0c693c220 --- /dev/null +++ b/lib/sessions/backend/base.rb @@ -0,0 +1,23 @@ +class Sessions::Backend::Base + def initialize(user, asset_lookup, client, client_id, ttl = 30) + @user = user + @client = client + @client_id = client_id + @ttl = ttl + @asset_lookup = asset_lookup + @last_change = nil + end + + def asset_needed?(record) + class_name = record.class.to_s + if !@asset_lookup || !@asset_lookup[class_name] || !@asset_lookup[class_name][record.id] || @asset_lookup[class_name][record.id] < record.updated_at + if !@asset_lookup[class_name] + @asset_lookup[class_name] = {} + end + @asset_lookup[class_name][record.id] = record.updated_at + return true + end + false + end + +end diff --git a/lib/sessions/backend/collections.rb b/lib/sessions/backend/collections.rb index 3dcff68e2..25668b8b9 100644 --- a/lib/sessions/backend/collections.rb +++ b/lib/sessions/backend/collections.rb @@ -1,11 +1,12 @@ -class Sessions::Backend::Collections +class Sessions::Backend::Collections < Sessions::Backend::Base - def initialize( user, client, client_id, ttl = 10 ) - @user = user - @client = client - @client_id = client_id - @ttl = ttl - @backends = backend + def initialize(user, asset_lookup, client, client_id, ttl = 10) + @user = user + @client = client + @client_id = client_id + @ttl = ttl + @asset_lookup = asset_lookup + @backends = backend end def push @@ -28,14 +29,14 @@ class Sessions::Backend::Collections # load collections to deliver from external files dir = File.expand_path('../../../../', __FILE__) - files = Dir.glob( "#{dir}/lib/sessions/backend/collections/*.rb" ) + files = Dir.glob("#{dir}/lib/sessions/backend/collections/*.rb") files.each { |file| file.gsub!("#{dir}/lib/", '') file.gsub!(/\.rb$/, '') next if file.classify == 'Sessions::Backend::Collections::Base' #puts "LOAD #{file.classify}---" #next if file == '' - backend = file.classify.constantize.new(@user, @client, @client_id, @ttl) + backend = file.classify.constantize.new(@user, @asset_lookup, @client, @client_id, @ttl) if backend backends.push backend end diff --git a/lib/sessions/backend/collections/base.rb b/lib/sessions/backend/collections/base.rb index f4f3b59f2..24010785a 100644 --- a/lib/sessions/backend/collections/base.rb +++ b/lib/sessions/backend/collections/base.rb @@ -1,12 +1,13 @@ -class Sessions::Backend::Collections::Base +class Sessions::Backend::Collections::Base < Sessions::Backend::Base class << self; attr_accessor :model, :roles, :not_roles end - def initialize( user, client, client_id, ttl ) - @user = user - @client = client - @client_id = client_id - @ttl = ttl - @last_change = nil + def initialize(user, asset_lookup, client, client_id, ttl) + @user = user + @client = client + @client_id = client_id + @ttl = ttl + @asset_lookup = asset_lookup + @last_change = nil end def load @@ -42,11 +43,11 @@ class Sessions::Backend::Collections::Base end # check timeout - timeout = Sessions::CacheIn.get( client_key ) + timeout = Sessions::CacheIn.get(client_key) return if timeout # set new timeout - Sessions::CacheIn.set( client_key, true, { expires_in: @ttl.seconds } ) + Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds }) # check if update has been done last_change = self.class.model.constantize.latest_change @@ -67,6 +68,7 @@ class Sessions::Backend::Collections::Base # collect assets assets = {} items.each {|item| + next if !asset_needed?(item) assets = item.assets(assets) } if !@client diff --git a/lib/sessions/backend/collections/organization.rb b/lib/sessions/backend/collections/organization.rb index b799e0b4c..916a7585b 100644 --- a/lib/sessions/backend/collections/organization.rb +++ b/lib/sessions/backend/collections/organization.rb @@ -8,7 +8,7 @@ class Sessions::Backend::Collections::Organization < Sessions::Backend::Collecti if !@user.role?('Customer') all = Organization.all elsif @user.organization_id - all = Organization.where( id: @user.organization_id ) + all = Organization.where(id: @user.organization_id) end all diff --git a/lib/sessions/backend/rss.rb b/lib/sessions/backend/rss.rb index d43485c49..388ae733d 100644 --- a/lib/sessions/backend/rss.rb +++ b/lib/sessions/backend/rss.rb @@ -1,13 +1,6 @@ require 'rss' -class Sessions::Backend::Rss - - def initialize( user, client, client_id, ttl = 30 ) - @user = user - @client = client - @ttl = ttl - @client_id = client_id - end +class Sessions::Backend::Rss < Sessions::Backend::Base def collection_key "rss::load::#{self.class}::#{@user.id}" @@ -16,14 +9,14 @@ class Sessions::Backend::Rss def load # check timeout - cache = Sessions::CacheIn.get( collection_key ) + cache = Sessions::CacheIn.get(collection_key) return cache if cache url = 'http://www.heise.de/newsticker/heise-atom.xml' - rss_items = Rss.fetch( url, 8 ) + rss_items = Rss.fetch(url, 8) # set new timeout - Sessions::CacheIn.set( collection_key, rss_items, { expires_in: 1.hour } ) + Sessions::CacheIn.set(collection_key, rss_items, { expires_in: 1.hour }) rss_items end @@ -35,11 +28,11 @@ class Sessions::Backend::Rss def push # check timeout - timeout = Sessions::CacheIn.get( client_key ) + timeout = Sessions::CacheIn.get(client_key) return if timeout # set new timeout - Sessions::CacheIn.set( client_key, true, { expires_in: @ttl.seconds } ) + Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds }) data = load diff --git a/lib/sessions/backend/ticket_create.rb b/lib/sessions/backend/ticket_create.rb index 1c130eeb5..b4b098e3e 100644 --- a/lib/sessions/backend/ticket_create.rb +++ b/lib/sessions/backend/ticket_create.rb @@ -1,11 +1,4 @@ -class Sessions::Backend::TicketCreate - def initialize( user, client = nil, client_id = nil, ttl = 30 ) - @user = user - @client = client - @client_id = client_id - @ttl = ttl - @last_change = nil - end +class Sessions::Backend::TicketCreate < Sessions::Backend::Base def load @@ -33,11 +26,11 @@ class Sessions::Backend::TicketCreate def push # check timeout - timeout = Sessions::CacheIn.get( client_key ) + timeout = Sessions::CacheIn.get(client_key) return if timeout # set new timeout - Sessions::CacheIn.set( client_key, true, { expires_in: @ttl.seconds } ) + Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds }) data = load diff --git a/lib/sessions/backend/ticket_overview_index.rb b/lib/sessions/backend/ticket_overview_index.rb deleted file mode 100644 index d3da40ab5..000000000 --- a/lib/sessions/backend/ticket_overview_index.rb +++ /dev/null @@ -1,66 +0,0 @@ -class Sessions::Backend::TicketOverviewIndex - def initialize( user, client = nil, client_id = nil, ttl = 5 ) - @user = user - @client = client - @client_id = client_id - @ttl = ttl - @last_change = nil - @last_ticket_change = nil - end - - def load - - # get whole collection - overview = Ticket::Overviews.list( - current_user: @user, - ) - - # no data exists - return if !overview - - # no change exists - return if @last_change == overview - - # remember last state - @last_change = overview - - overview - end - - def client_key - "as::load::#{self.class}::#{@user.id}::#{@client_id}" - end - - def push - - # check check interval - return if Sessions::CacheIn.get( client_key ) - - # reset check interval - Sessions::CacheIn.set( client_key, true, { expires_in: @ttl.seconds } ) - - # check if min one ticket has changed - last_ticket_change = Ticket.latest_change - return if last_ticket_change == @last_ticket_change - @last_ticket_change = last_ticket_change - - # load current data - data = load - - return if !data - - if !@client - return { - event: 'ticket_overview_index', - data: data, - } - end - - @client.log "push overview_index for user #{@user.id}" - @client.send( - event: 'ticket_overview_index', - data: data, - ) - end - -end diff --git a/lib/sessions/backend/ticket_overview_list.rb b/lib/sessions/backend/ticket_overview_list.rb index 7b14aede7..fc47b9ccd 100644 --- a/lib/sessions/backend/ticket_overview_list.rb +++ b/lib/sessions/backend/ticket_overview_list.rb @@ -1,127 +1,129 @@ -class Sessions::Backend::TicketOverviewList - def initialize( user, client = nil, client_id = nil, ttl = 6 ) - @user = user - @client = client - @client_id = client_id - @ttl = ttl - @last_change = nil - @last_ticket_change = nil +class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base + + def self.reset(user_id) + key = "TicketOverviewPull::#{user_id}" + Cache.write(key, { needed: true }) + end + + def initialize(user, asset_lookup, client = nil, client_id = nil, ttl = 8) + @user = user + @client = client + @client_id = client_id + @ttl = ttl + @asset_lookup = asset_lookup + @last_change = nil + @last_overview = {} + @last_overview_change = nil + @last_ticket_change = nil end def load # get whole collection - overviews = Ticket::Overviews.all( - current_user: @user, - ) - return if !overviews - result = [] - overviews.each { |overview| - overview_data = Ticket::Overviews.list( - view: overview.link, - current_user: @user, - array: true, - ) - data = { list: overview_data, index: overview } - result.push data - } + index_and_lists = Ticket::Overviews.index(@user) # no data exists - return if !result || result.empty? + return if !index_and_lists || index_and_lists.empty? # no change exists - return if @last_change == result + return if @last_change == index_and_lists # remember last state - @last_change = result + @last_change = index_and_lists - result + index_and_lists end def client_key "as::load::#{self.class}::#{@user.id}::#{@client_id}" end + def work_needed? + key = "TicketOverviewPull::#{@user.id}" + if Cache.get(key) + Cache.delete(key) + return true + end + return false if Sessions::CacheIn.get(client_key) + true + end + def push - # check interval - return if Sessions::CacheIn.get( client_key ) + return if !work_needed? # reset check interval - Sessions::CacheIn.set( client_key, true, { expires_in: @ttl.seconds } ) + Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds }) - # check if min one ticket has changed + # check if min one ticket or overview has changed + last_overview_change = Overview.latest_change last_ticket_change = Ticket.latest_change - return if last_ticket_change == @last_ticket_change + return if last_ticket_change == @last_ticket_change && last_overview_change == @last_overview_change + @last_overview_change = last_overview_change @last_ticket_change = last_ticket_change # load current data - items = load - return if !items + index_and_lists = load + return if !index_and_lists + + # push overview index + indexes = [] + index_and_lists.each { |index| + assets = {} + overview = Overview.lookup(id: index[:overview][:id]) + meta = { + name: overview.name, + prio: overview.prio, + link: overview.link, + count: index[:count], + } + indexes.push meta + } + if @client + @client.log "push overview_index for user #{@user.id}" + @client.send( + event: 'ticket_overview_index', + data: indexes, + ) + end # push overviews results = [] - items.each { |item| + index_and_lists.each { |index| - overview_data = item[:list] + # do not deliver unchanged lists + next if @last_overview[index[:overview][:id]] == index + @last_overview[index[:overview][:id]] = index assets = {} - overview_data[:ticket_ids].each {|ticket_id| - ticket = Ticket.find( ticket_id ) + overview = Overview.lookup(id: index[:overview][:id]) + if asset_needed?(overview) + assets = overview.assets(assets) + end + index[:tickets].each {|ticket_meta| + ticket = Ticket.lookup(id: ticket_meta[:id]) + next if !asset_needed?(ticket) assets = ticket.assets(assets) } - # get groups - group_ids = [] - Group.where(active: true).each { |group| - group_ids.push group.id - } - agents = {} - User.of_role('Agent').each { |user| - agents[ user.id ] = 1 - } - users = {} - groups_users = {} - groups_users[''] = [] - group_ids.each {|group_id| - groups_users[ group_id ] = [] - Group.find(group_id).users.each {|user| - next if !agents[ user.id ] - groups_users[ group_id ].push user.id - if !users[user.id] - users[user.id] = User.find(user.id) - assets = users[user.id].assets(assets) - end - } - } - if !@client result = { - event: 'navupdate_ticket_overview', - data: item[:index], + event: 'ticket_overview_list', + data: index, } results.push result else - @client.log "push overview_list for user #{@user.id}" + @client.log "push overview_list #{overview.link} for user #{@user.id}" # send update to browser @client.send( + event: 'loadAssets', data: assets, - event: 'loadAssets' ) @client.send( - data: { - view: item[:index].link.to_s, - overview: overview_data[:overview], - ticket_ids: overview_data[:ticket_ids], - tickets_count: overview_data[:tickets_count], - bulk: { - group_id__owner_id: groups_users, - owner_id: [], - }, - }, - event: 'ticket_overview_rebuild', + event: 'ticket_overview_list', + data: index, ) end } diff --git a/lib/sessions/cache_in.rb b/lib/sessions/cache_in.rb index a70ba428f..82080aff9 100644 --- a/lib/sessions/cache_in.rb +++ b/lib/sessions/cache_in.rb @@ -7,12 +7,12 @@ module Sessions::CacheIn @@expires_in_ttl = {} # rubocop:enable Style/ClassVars - def self.delete( key ) - @@data.delete( key ) - @@data_time.delete( key ) + def self.delete(key) + @@data.delete(key) + @@data_time.delete(key) end - def self.set( key, value, params = {} ) + def self.set(key, value, params = {}) if params[:expires_in] @@expires_in[key] = Time.zone.now + params[:expires_in] @@expires_in_ttl[key] = params[:expires_in] @@ -21,7 +21,7 @@ module Sessions::CacheIn @@data_time[ key ] = Time.zone.now end - def self.expired( key, params = {} ) + def self.expired(key, params = {}) # expire if value never was set return true if !@@data.include? key @@ -47,8 +47,8 @@ module Sessions::CacheIn false end - def self.get( key, params = {} ) - return if expired( key, params ) + def self.get(key, params = {}) + return if expired( key, params) @@data[ key ] end end diff --git a/lib/sessions/client.rb b/lib/sessions/client.rb index f5270f109..067b6bd6d 100644 --- a/lib/sessions/client.rb +++ b/lib/sessions/client.rb @@ -1,6 +1,6 @@ class Sessions::Client - def initialize( client_id ) + def initialize(client_id) @client_id = client_id log '---client start ws connection---' fetch @@ -10,7 +10,6 @@ class Sessions::Client def fetch backends = [ - 'Sessions::Backend::TicketOverviewIndex', 'Sessions::Backend::TicketOverviewList', 'Sessions::Backend::Collections', 'Sessions::Backend::Rss', @@ -18,22 +17,24 @@ class Sessions::Client 'Sessions::Backend::TicketCreate', ] + asset_lookup = {} backend_pool = [] user_id_last_run = nil loop_count = 0 loop do # get connection user - session_data = Sessions.get( @client_id ) + session_data = Sessions.get(@client_id) return if !session_data return if !session_data[:user] return if !session_data[:user]['id'] - user = User.lookup( id: session_data[:user]['id'] ) + user = User.lookup(id: session_data[:user]['id']) return if !user # init new backends if user_id_last_run != user.id user_id_last_run = user.id + asset_lookup = {} # release old objects backend_pool.collect! { @@ -43,7 +44,7 @@ class Sessions::Client # create new pool backend_pool = [] backends.each {|backend| - item = backend.constantize.new(user, self, @client_id) + item = backend.constantize.new(user, asset_lookup, self, @client_id) backend_pool.push item } end @@ -66,11 +67,11 @@ class Sessions::Client end # send update to browser - def send( data ) - Sessions.send( @client_id, data ) + def send(data) + Sessions.send(@client_id, data) end - def log( msg ) + def log(msg) Rails.logger.debug "client(#{@client_id}) #{msg}" end end diff --git a/lib/sessions/event/base.rb b/lib/sessions/event/base.rb index 0d4a66d94..dd98274b8 100644 --- a/lib/sessions/event/base.rb +++ b/lib/sessions/event/base.rb @@ -25,6 +25,30 @@ class Sessions::Event::Base end end + def valid_session? + if !@session + error = { + event: 'error', + data: { + state: 'no_session', + }, + } + Sessions.send(@client_id, error) + return + end + if !@session['id'] + error = { + event: 'error', + data: { + state: 'no_session_user_id', + }, + } + Sessions.send(@client_id, error) + return + end + true + end + def log(level, data, client_id = nil) if !@options[:v] return if level == 'debug' diff --git a/lib/sessions/event/ticket_overview_index.rb b/lib/sessions/event/ticket_overview_index.rb new file mode 100644 index 000000000..2c8dd191f --- /dev/null +++ b/lib/sessions/event/ticket_overview_index.rb @@ -0,0 +1,8 @@ +class Sessions::Event::TicketOverviewIndex < Sessions::Event::Base + + def run + return if !valid_session? + Sessions::Backend::TicketOverviewList.reset(@session['id']) + end + +end diff --git a/lib/sessions/event/ticket_overview_list.rb b/lib/sessions/event/ticket_overview_list.rb new file mode 100644 index 000000000..b2f945fb0 --- /dev/null +++ b/lib/sessions/event/ticket_overview_list.rb @@ -0,0 +1,8 @@ +class Sessions::Event::TicketOverviewList < Sessions::Event::Base + + def run + return if !valid_session? + Sessions::Backend::TicketOverviewList.reset(@session['id']) + end + +end diff --git a/lib/static_assets.rb b/lib/static_assets.rb index 722b27de1..a4d7939a3 100644 --- a/lib/static_assets.rb +++ b/lib/static_assets.rb @@ -20,7 +20,7 @@ returns data[:content] = Base64.decode64($2) return data end - fail "Unable to parse data url: #{data_url.substr(0, 100)}" + raise "Unable to parse data url: #{data_url.substr(0, 100)}" end =begin @@ -67,7 +67,7 @@ returns if list && list[0] return Store.find( list[0] ) end - fail 'No such raw logo!' + raise 'No such raw logo!' end =begin diff --git a/lib/tasks/test_browser.rake b/lib/tasks/test_browser.rake index 533960e4a..2bc8d1a87 100644 --- a/lib/tasks/test_browser.rake +++ b/lib/tasks/test_browser.rake @@ -11,7 +11,7 @@ namespace :test do end Dir.glob('test/browser/*_test.rb').sort.each { |r| sh "#{args.opts} ruby -Itest #{r}" do |ok, res| - fail 'Failed test. ' + res.inspect if !ok + raise 'Failed test. ' + res.inspect if !ok end } puts 'All browser tests, elapsed: ' + (Time.zone.now - start).to_s + ' seconds' diff --git a/lib/tweet_base.rb b/lib/tweet_base.rb index cb6db1e81..b606fee4e 100644 --- a/lib/tweet_base.rb +++ b/lib/tweet_base.rb @@ -18,7 +18,7 @@ class TweetBase Rails.logger.debug tweet.user.inspect return tweet.user else - fail "Unknown tweet type '#{tweet.class}'" + raise "Unknown tweet type '#{tweet.class}'" end end @@ -100,6 +100,7 @@ class TweetBase end def to_ticket(tweet, user, group_id, channel) + UserInfo.current_user_id = user.id Rails.logger.debug 'Create ticket from tweet...' Rails.logger.debug tweet.inspect @@ -119,8 +120,6 @@ class TweetBase return ticket if ticket end - UserInfo.current_user_id = user.id - # prepare title title = tweet.text if title.length > 80 @@ -177,7 +176,7 @@ class TweetBase end in_reply_to = tweet.in_reply_to_status_id else - fail "Unknown tweet type '#{tweet.class}'" + raise "Unknown tweet type '#{tweet.class}'" end UserInfo.current_user_id = user.id @@ -233,7 +232,7 @@ class TweetBase end to_article(tweet, user, ticket) else - fail "Unknown tweet type '#{tweet.class}'" + raise "Unknown tweet type '#{tweet.class}'" end # execute ticket events @@ -269,7 +268,7 @@ class TweetBase } ) else - fail "Can't handle unknown twitter article type '#{article[:type]}'." + raise "Can't handle unknown twitter article type '#{article[:type]}'." end Rails.logger.debug tweet.inspect diff --git a/lib/user_agent.rb b/lib/user_agent.rb index 0cb9be737..edf7ba483 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -322,7 +322,7 @@ returns code: response.code, ) when Net::HTTPRedirection - fail 'Too many redirections for the original URL, halting.' if count <= 0 + raise 'Too many redirections for the original URL, halting.' if count <= 0 url = response['location'] return get(url, params, options, count - 1) when Net::HTTPOK @@ -351,7 +351,7 @@ returns ) end - fail "Unable to process http call '#{response.inspect}'" + raise "Unable to process http call '#{response.inspect}'" end def self.ftp(uri, options) diff --git a/public/assets/form/form.css b/public/assets/form/form.css index 042d040d7..daa01d175 100644 --- a/public/assets/form/form.css +++ b/public/assets/form/form.css @@ -33,6 +33,7 @@ width: 100%; height: 100%; text-align: center; + z-index: 999; } .modal:before { diff --git a/script/build/test_shutdown.sh b/script/build/test_shutdown.sh index ed4c900a7..deb07be6c 100755 --- a/script/build/test_shutdown.sh +++ b/script/build/test_shutdown.sh @@ -6,7 +6,7 @@ EXIT=$4 || 0 script/scheduler.rb stop script/websocket-server.rb stop -kill $(cat tmp/pids/puma.pid) +kill $(cat tmp/pids/server.pid) rake db:drop diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh index 75dd186a8..e28097008 100755 --- a/script/build/test_slice_tests.sh +++ b/script/build/test_slice_tests.sh @@ -9,6 +9,7 @@ if [ "$LEVEL" == '1' ]; then rm test/browser/agent_organization_profile_test.rb rm test/browser/agent_ticket_*.rb rm test/browser/chat_test.rb + rm test/browser/first_steps_test.rb rm test/browser/keyboard_shortcuts_test.rb rm test/browser/prefereces_test.rb rm test/browser/setting_test.rb @@ -25,6 +26,7 @@ elif [ "$LEVEL" == '2' ]; then rm test/browser/auth_test.rb rm test/browser/chat_test.rb rm test/browser/customer_ticket_create_test.rb + rm test/browser/first_steps_test.rb rm test/browser/form_test.rb rm test/browser/keyboard_shortcuts_test.rb rm test/browser/maintenance_*.rb diff --git a/script/build/test_startup.sh b/script/build/test_startup.sh index 7f905dd74..825c9c207 100755 --- a/script/build/test_startup.sh +++ b/script/build/test_startup.sh @@ -10,6 +10,12 @@ rails r "Setting.set('websocket_port', '$WS_PORT')" rails r "Setting.set('fqdn', '$IP:$BROWSER_PORT')" rails r "Setting.set('chat_agent_idle_timeout', '45')" -pumactl start --pidfile tmp/pids/puma.pid -d -p $APP_PORT -e $RAILS_ENV +echo "env used for script/build/test_startup.sh $1 $2 $3" +echo "export RAILS_ENV=$RAILS_ENV" +echo "export IP=$IP" +echo "export BROWSER_PORT=$BROWSER_PORT" + +#rails s puma -d --pid tmp/pids/server.pid --bind 0.0.0.0 --port $APP_PORT +pumactl start --pidfile tmp/pids/server.pid -d -p $APP_PORT -e $RAILS_ENV script/websocket-server.rb start -d -p $WS_PORT script/scheduler.rb start diff --git a/test/browser/first_steps_test.rb b/test/browser/first_steps_test.rb new file mode 100644 index 000000000..415e8d0ac --- /dev/null +++ b/test/browser/first_steps_test.rb @@ -0,0 +1,141 @@ +# encoding: utf-8 +require 'browser_test_helper' + +class FirstStepsTest < TestCase + + def test_basic + agent = "bob.smith_#{rand(99_999_999)}" + customer = "customer.smith_#{rand(99_999_999)}" + + @browser = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + click( + css: '.active.content .tab[data-area="first-steps-widgets"]', + ) + watch_for( + css: '.active.content', + value: 'Configuration', + ) + + # invite agent + click( + css: '.active.content .js-inviteAgent', + ) + sleep 4 + set( + css: '.modal [name="firstname"]', + value: 'Bob', + ) + set( + css: '.modal [name="lastname"]', + value: 'Smith', + ) + set( + css: '.modal [name="email"]', + value: "#{agent}@example.com", + ) + check( + css: '.modal [name="group_ids"]', + ) + click( + css: '.modal button.btn.btn--primary', + fast: true, + ) + watch_for( + css: 'body div.modal', + value: 'Sending', + ) + watch_for_disappear( + css: 'body div.modal', + value: 'Sending', + ) + + # invite customer + click( + css: '.active.content .js-inviteCustomer', + ) + sleep 4 + set( + css: '.modal [name="firstname"]', + value: 'Client', + ) + set( + css: '.modal [name="lastname"]', + value: 'Smith', + ) + set( + css: '.modal [name="email"]', + value: "#{customer}@example.com", + ) + set( + css: '.modal [data-name="note"]', + value: 'some note', + ) + click( + css: '.modal button.btn.btn--primary', + fast: true, + ) + watch_for( + css: 'body div.modal', + value: 'Sending', + ) + watch_for_disappear( + css: 'body div.modal', + value: 'Sending', + ) + + # test ticket + click( + css: '.active.content .js-testTicket', + fast: true, + ) + watch_for( + css: 'body div.modal', + value: 'A Test Ticket has been created', + ) + click( + css: '.modal .modal-body', + fast: true, + ) + watch_for_disappear( + css: 'body div.modal', + value: 'Test Ticket', + ) + execute( + js: '$(".active.content .sidebar").show()', + ) + watch_for( + css: '.active.content .js-activityContent', + value: 'Nicole Braun created Article for Test Ticket!', + timeout: 35, + ) + + # check update + click( + css: '.active.content a[href="#channels/form"]', + ) + sleep 2 + switch( + css: '#content .js-formSetting', + type: 'on', + ) + sleep 2 + click( + css: '#navigation a[href="#dashboard"]', + ) + hit = false + (1..38).each { + next if !@browser.find_elements(css: '.active.content a[href="#channels/form"].todo.is-done')[0] + hit = true + break + } + assert(hit) + + end + +end diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index b4053376c..d5570c204 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -153,7 +153,7 @@ class TestCase < Test::Unit::TestCase login = instance.find_elements(css: '.user-menu .user a')[0].attribute('title') if login != params[:username] screenshot(browser: instance, comment: 'auto wizard login failed') - fail 'auto wizard login failed' + raise 'auto wizard login failed' end assert(true, 'auto wizard login ok') @@ -165,7 +165,7 @@ class TestCase < Test::Unit::TestCase return end screenshot(browser: instance, comment: 'login_failed') - fail 'No login box found' + raise 'No login box found' end screenshot(browser: instance, comment: 'login') @@ -186,7 +186,7 @@ class TestCase < Test::Unit::TestCase login = instance.find_elements(css: '.user-menu .user a')[0].attribute('title') if login != params[:username] screenshot(browser: instance, comment: 'login_failed') - fail 'login failed' + raise 'login failed' end clues_close( @@ -226,7 +226,7 @@ class TestCase < Test::Unit::TestCase return } screenshot(browser: instance, comment: 'logout_failed') - fail 'no login box found, seems logout was not successfully!' + raise 'no login box found, seems logout was not successfully!' end =begin @@ -247,7 +247,7 @@ class TestCase < Test::Unit::TestCase clues = instance.find_elements(css: '.js-modal--clue .js-close')[0] if !params[:optional] && !clues screenshot(browser: instance, comment: 'no_clues') - fail 'Unable to closes clues, no clues found!' + raise 'Unable to closes clues, no clues found!' end return if !clues instance.execute_script("$('.js-modal--clue .js-close').click()") @@ -296,7 +296,7 @@ class TestCase < Test::Unit::TestCase current_url = instance.current_url if current_url !~ /#{Regexp.quote(params[:url])}/ screenshot(browser: instance, comment: 'location_check_failed') - fail "url #{current_url} is not matching #{params[:url]}" + raise "url #{current_url} is not matching #{params[:url]}" end assert(true, "url #{current_url} is matching #{params[:url]}") end @@ -412,7 +412,7 @@ class TestCase < Test::Unit::TestCase if params[:js] return instance.execute_script(params[:js]) end - fail "Invalid execute params #{params.inspect}" + raise "Invalid execute params #{params.inspect}" end =begin @@ -431,7 +431,7 @@ class TestCase < Test::Unit::TestCase instance = params[:browser] || @browser if !instance.find_elements(css: params[:css])[0] screenshot(browser: instance, comment: 'exists_failed') - fail "#{params[:css]} dosn't exist, but should" + raise "#{params[:css]} dosn't exist, but should" end true end @@ -452,7 +452,7 @@ class TestCase < Test::Unit::TestCase instance = params[:browser] || @browser if instance.find_elements(css: params[:css])[0] screenshot(browser: instance, comment: 'exists_not_failed') - fail "#{params[:css]} exists but should not" + raise "#{params[:css]} exists but should not" end true end @@ -637,7 +637,7 @@ class TestCase < Test::Unit::TestCase if params[:slow] sleep 2 else - sleep 0.6 + sleep 0.3 end end @@ -673,10 +673,10 @@ class TestCase < Test::Unit::TestCase end if params[:should_not_match] if success - fail "should not match '#{params[:value]}' in select list, but is matching" + raise "should not match '#{params[:value]}' in select list, but is matching" end elsif !success - fail "not matching '#{params[:value]}' in select list" + raise "not matching '#{params[:value]}' in select list" end return true @@ -719,10 +719,10 @@ class TestCase < Test::Unit::TestCase if match if params[:should_not_match] - fail "matching '#{params[:value]}' in content '#{text}' but should not!" + raise "matching '#{params[:value]}' in content '#{text}' but should not!" end elsif !params[:should_not_match] - fail "not matching '#{params[:value]}' in content '#{text}' but should!" + raise "not matching '#{params[:value]}' in content '#{text}' but should!" end sleep 0.8 match @@ -769,7 +769,7 @@ class TestCase < Test::Unit::TestCase instance.find_elements(css: ".content.active .js-secondaryActionLabel[data-type=#{params[:type]}]")[0].click return end - fail "Unknown params for task_type: #{params.inspect}" + raise "Unknown params for task_type: #{params.inspect}" end =begin @@ -809,23 +809,23 @@ class TestCase < Test::Unit::TestCase if params.key?(:value ) && cookie[:value].to_s =~ /#{params[:value]}/i assert(true, "matching value '#{params[:value]}' in cookie '#{cookie}'") else - fail "not matching value '#{params[:value]}' in cookie '#{cookie}'" + raise "not matching value '#{params[:value]}' in cookie '#{cookie}'" end if params.key?(:expires) && cookie[:expires].to_s =~ /#{params[:expires]}/i assert(true, "matching expires '#{params[:expires].inspect}' in cookie '#{cookie}'") else - fail "not matching expires '#{params[:expires]}' in cookie '#{cookie}'" + raise "not matching expires '#{params[:expires]}' in cookie '#{cookie}'" end return if !params[:should_not_exist] - fail "cookie with name '#{params[:name]}' should not exist, but exists '#{cookies}'" + raise "cookie with name '#{params[:name]}' should not exist, but exists '#{cookies}'" } if params[:should_not_exist] assert(true, "cookie with name '#{params[:name]}' is not existing") return end - fail "not matching name '#{params[:name]}' in cookie '#{cookies}'" + raise "not matching name '#{params[:name]}' in cookie '#{cookies}'" end =begin @@ -847,7 +847,7 @@ class TestCase < Test::Unit::TestCase if title =~ /#{params[:value]}/i assert(true, "matching '#{params[:value]}' in title '#{title}'") else - fail "not matching '#{params[:value]}' in title '#{title}'" + raise "not matching '#{params[:value]}' in title '#{title}'" end end @@ -880,7 +880,7 @@ class TestCase < Test::Unit::TestCase if title =~ /#{data[:title]}/i assert(true, "matching '#{data[:title]}' in title '#{title}'") else - fail "not matching '#{data[:title]}' in title '#{title}'" + raise "not matching '#{data[:title]}' in title '#{title}'" end end puts "tv #{params.inspect}" @@ -899,16 +899,16 @@ class TestCase < Test::Unit::TestCase if is_modified assert(true, "task '#{data[:title]}' is modifed") elsif !exists - fail "task '#{data[:title]}' not exists, should not modified" + raise "task '#{data[:title]}' not exists, should not modified" else - fail "task '#{data[:title]}' is not modifed" + raise "task '#{data[:title]}' is not modifed" end elsif !is_modified assert(true, "task '#{data[:title]}' is modifed") elsif !exists - fail "task '#{data[:title]}' not exists, should be not modified" + raise "task '#{data[:title]}' not exists, should be not modified" else - fail "task '#{data[:title]}' is modifed, but should not" + raise "task '#{data[:title]}' is modifed, but should not" end end rescue => e @@ -943,7 +943,7 @@ class TestCase < Test::Unit::TestCase element = instance.find_elements(partial_link_text: data[:title])[0] if !element screenshot(browser: instance, comment: 'open_task_failed') - fail "no task with title '#{data[:title]}' found" + raise "no task with title '#{data[:title]}' found" end element.click true @@ -971,7 +971,7 @@ class TestCase < Test::Unit::TestCase element = instance.find_elements(partial_link_text: data[:title])[0] if !element screenshot(browser: instance, comment: 'close_task_failed') - fail "no task with title '#{data[:title]}' found" + raise "no task with title '#{data[:title]}' found" end instance.mouse.move_to(element) @@ -1058,7 +1058,7 @@ class TestCase < Test::Unit::TestCase sleep 0.5 } screenshot(browser: instance, comment: 'watch_for_failed') - fail "'#{params[:value]}' found in '#{text}'" + raise "'#{params[:value]}' found in '#{text}'" end =begin @@ -1116,7 +1116,7 @@ wait untill text in selector disabppears sleep 1 } screenshot(browser: instance, comment: 'disappear_failed') - fail "#{params[:css]}) still exsists" + raise "#{params[:css]}) still exsists" end =begin @@ -1171,7 +1171,7 @@ wait untill text in selector disabppears instance = params[:browser] || @browser (1..100).each do - sleep 1 + sleep 0.2 begin if instance.find_elements(css: '.navigation .tasks .task:first-child')[0] instance.mouse.move_to(instance.find_elements(css: '.navigation .tasks .task:first-child')[0]) @@ -1193,7 +1193,6 @@ wait untill text in selector disabppears # try again end end - sleep 1 assert(true, 'all tasks closed') end @@ -1310,7 +1309,7 @@ wait untill text in selector disabppears sleep 1 } screenshot(browser: instance, comment: 'overview_create_failed') - fail 'overview creation failed' + raise 'overview creation failed' end =begin @@ -1348,7 +1347,7 @@ wait untill text in selector disabppears element = instance.find_elements(css: '.active .newTicket')[0] if !element screenshot(browser: instance, comment: 'ticket_create_failed') - fail 'no ticket create screen found!' + raise 'no ticket create screen found!' end sleep 1 @@ -1448,7 +1447,7 @@ wait untill text in selector disabppears sleep 1 } screenshot(browser: instance, comment: 'ticket_create_failed') - fail "ticket creation failed, can't get zoom url (current url is '#{instance.current_url}')" + raise "ticket creation failed, can't get zoom url (current url is '#{instance.current_url}')" end =begin @@ -1604,7 +1603,7 @@ wait untill text in selector disabppears if !found screenshot(browser: instance, comment: 'ticket_update_discard_message_failed') - fail 'no discard message found' + raise 'no discard message found' end end @@ -1633,7 +1632,7 @@ wait untill text in selector disabppears sleep 1 } screenshot(browser: instance, comment: 'ticket_update_failed') - fail 'unable to update ticket' + raise 'unable to update ticket' end =begin @@ -1662,7 +1661,7 @@ wait untill text in selector disabppears if title =~ /#{data[:title]}/i assert(true, "matching '#{data[:title]}' in title '#{title}'") else - fail "not matching '#{data[:title]}' in title '#{title}'" + raise "not matching '#{data[:title]}' in title '#{title}'" end end @@ -1671,7 +1670,7 @@ wait untill text in selector disabppears if body =~ /#{data[:body]}/i assert(true, "matching '#{data[:body]}' in body '#{body}'") else - fail "not matching '#{data[:body]}' in body '#{body}'" + raise "not matching '#{data[:body]}' in body '#{body}'" end end true @@ -1710,7 +1709,7 @@ wait untill text in selector disabppears number = instance.find_elements(css: '.active .ticketZoom-header .ticket-number')[0].text if number !~ /#{params[:number]}/ screenshot(browser: instance, comment: 'ticket_open_by_overview_failed') - fail "unable to search/find ticket #{params[:number]}!" + raise "unable to search/find ticket #{params[:number]}!" end sleep 1 assert(true, "ticket #{params[:number]} found") @@ -1744,7 +1743,7 @@ wait untill text in selector disabppears sleep 0.5 text = instance.find_elements(css: '#global-search')[0].attribute('value') if !text - fail '#global-search is not empty!' + raise '#global-search is not empty!' end # search by number again @@ -1760,7 +1759,7 @@ wait untill text in selector disabppears number = instance.find_elements(css: '.active .ticketZoom-header .ticket-number')[0].text if number !~ /#{params[:number]}/ screenshot(browser: instance, comment: 'ticket_open_by_search_failed') - fail "unable to search/find ticket #{params[:number]}!" + raise "unable to search/find ticket #{params[:number]}!" end sleep 1 true @@ -1794,7 +1793,7 @@ wait untill text in selector disabppears title = instance.find_elements(css: '.active .ticketZoom-header .ticket-title-update')[0].text if title !~ /#{params[:title]}/ screenshot(browser: instance, comment: 'ticket_open_by_title_failed') - fail "unable to search/find ticket #{params[:title]}!" + raise "unable to search/find ticket #{params[:title]}!" end sleep 1 true @@ -1872,7 +1871,7 @@ wait untill text in selector disabppears sleep 0.5 text = instance.find_elements(css: '#global-search')[0].attribute('value') if !text - fail '#global-search is not empty!' + raise '#global-search is not empty!' end element = instance.find_elements(css: '#global-search')[0] element.click @@ -1884,7 +1883,7 @@ wait untill text in selector disabppears name = instance.find_elements(css: '.active h1')[0].text if name !~ /#{params[:value]}/ screenshot(browser: instance, comment: 'organization_open_by_search_failed') - fail "unable to search/find org #{params[:value]}!" + raise "unable to search/find org #{params[:value]}!" end assert(true, "org #{params[:value]} found") sleep 2 @@ -1916,7 +1915,7 @@ wait untill text in selector disabppears name = instance.find_elements(css: '.active h1')[0].text if name !~ /#{params[:value]}/ screenshot(browser: instance, comment: 'user_open_by_search_failed') - fail "unable to search/find user #{params[:value]}!" + raise "unable to search/find user #{params[:value]}!" end assert(true, "user #{params[:term]} found") sleep 2 @@ -2025,7 +2024,7 @@ wait untill text in selector disabppears sleep 1 } screenshot(browser: instance, comment: 'sla_create_failed') - fail 'sla creation failed' + raise 'sla creation failed' end =begin @@ -2074,7 +2073,7 @@ wait untill text in selector disabppears sleep 1 } screenshot(browser: instance, comment: 'text_module_create_failed') - fail 'text module creation failed' + raise 'text module creation failed' end =begin @@ -2121,7 +2120,7 @@ wait untill text in selector disabppears sleep 1 } screenshot(browser: instance, comment: 'signature_create_failed') - fail 'signature creation failed' + raise 'signature creation failed' end =begin @@ -2195,7 +2194,7 @@ wait untill text in selector disabppears return true } screenshot(browser: instance, comment: 'group_create_failed') - fail 'group creation failed' + raise 'group creation failed' end def quote(string) diff --git a/test/integration/elasticsearch_test.rb b/test/integration/elasticsearch_test.rb index 5878bbcd2..7a034636b 100644 --- a/test/integration/elasticsearch_test.rb +++ b/test/integration/elasticsearch_test.rb @@ -5,11 +5,11 @@ class ElasticsearchTest < ActiveSupport::TestCase # set config if !ENV['ES_URL'] - fail "ERROR: Need ES_URL - hint ES_URL='http://172.0.0.1:9200'" + raise "ERROR: Need ES_URL - hint ES_URL='http://172.0.0.1:9200'" end Setting.set('es_url', ENV['ES_URL']) if !ENV['ES_INDEX'] && !ENV['ES_INDEX_RAND'] - fail "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'" + raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'" end if ENV['ES_INDEX_RAND'] ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}" diff --git a/test/integration/email_helper_test.rb b/test/integration/email_helper_test.rb index 0ef8ad585..1b0da03d3 100644 --- a/test/integration/email_helper_test.rb +++ b/test/integration/email_helper_test.rb @@ -249,7 +249,7 @@ class EmailHelperTest < ActiveSupport::TestCase # realtest - test I if !ENV['EMAILHELPER_MAILBOX_1'] - fail "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@znuny.com:somepass'" + raise "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@znuny.com:somepass'" end mailbox_user = ENV['EMAILHELPER_MAILBOX_1'].split(':')[0] mailbox_password = ENV['EMAILHELPER_MAILBOX_1'].split(':')[1] @@ -401,7 +401,7 @@ class EmailHelperTest < ActiveSupport::TestCase # realtest - test I if !ENV['EMAILHELPER_MAILBOX_1'] - fail "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@znuny.com:somepass'" + raise "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@znuny.com:somepass'" end mailbox_user = ENV['EMAILHELPER_MAILBOX_1'].split(':')[0] mailbox_password = ENV['EMAILHELPER_MAILBOX_1'].split(':')[1] @@ -433,7 +433,7 @@ class EmailHelperTest < ActiveSupport::TestCase # realtest - test I, with imap if !ENV['EMAILHELPER_MAILBOX_1'] - fail "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@znuny.com:somepass'" + raise "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@znuny.com:somepass'" end mailbox_user = ENV['EMAILHELPER_MAILBOX_1'].split(':')[0] mailbox_password = ENV['EMAILHELPER_MAILBOX_1'].split(':')[1] @@ -448,7 +448,7 @@ class EmailHelperTest < ActiveSupport::TestCase # realtest - test II, gmail with only pop3 if !ENV['EMAILHELPER_MAILBOX_2'] - fail "Need EMAILHELPER_MAILBOX_2 as ENV variable like export EMAILHELPER_MAILBOX_2='hansb36621@gmail.com:somepass'" + raise "Need EMAILHELPER_MAILBOX_2 as ENV variable like export EMAILHELPER_MAILBOX_2='hansb36621@gmail.com:somepass'" end mailbox_user = ENV['EMAILHELPER_MAILBOX_2'].split(':')[0] mailbox_password = ENV['EMAILHELPER_MAILBOX_2'].split(':')[1] @@ -467,7 +467,7 @@ class EmailHelperTest < ActiveSupport::TestCase # realtest - test I, with imap if !ENV['EMAILHELPER_MAILBOX_1'] - fail "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@znuny.com:somepass'" + raise "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@znuny.com:somepass'" end mailbox_user = ENV['EMAILHELPER_MAILBOX_1'].split(':')[0] mailbox_password = ENV['EMAILHELPER_MAILBOX_1'].split(':')[1] @@ -499,7 +499,7 @@ class EmailHelperTest < ActiveSupport::TestCase # realtest - test II, gmail with pop3 if !ENV['EMAILHELPER_MAILBOX_2'] - fail "Need EMAILHELPER_MAILBOX_2 as ENV variable like export EMAILHELPER_MAILBOX_2='hansb36621@gmail.com:somepass'" + raise "Need EMAILHELPER_MAILBOX_2 as ENV variable like export EMAILHELPER_MAILBOX_2='hansb36621@gmail.com:somepass'" end mailbox_user = ENV['EMAILHELPER_MAILBOX_2'].split(':')[0] mailbox_password = ENV['EMAILHELPER_MAILBOX_2'].split(':')[1] diff --git a/test/integration/facebook_browser_test.rb b/test/integration/facebook_browser_test.rb index 3774b7867..b4a311a05 100644 --- a/test/integration/facebook_browser_test.rb +++ b/test/integration/facebook_browser_test.rb @@ -6,28 +6,28 @@ class FacebookBrowserTest < TestCase # app config if !ENV['FACEBOOK_BT_APP_ID'] - fail "ERROR: Need FACEBOOK_BT_APP_ID - hint FACEBOOK_BT_APP_ID='1234'" + raise "ERROR: Need FACEBOOK_BT_APP_ID - hint FACEBOOK_BT_APP_ID='1234'" end app_id = ENV['FACEBOOK_BT_APP_ID'] if !ENV['FACEBOOK_BT_APP_SECRET'] - fail "ERROR: Need FACEBOOK_BT_APP_SECRET - hint FACEBOOK_BT_APP_SECRET='1234'" + raise "ERROR: Need FACEBOOK_BT_APP_SECRET - hint FACEBOOK_BT_APP_SECRET='1234'" end app_secret = ENV['FACEBOOK_BT_APP_SECRET'] if !ENV['FACEBOOK_BT_USER_LOGIN'] - fail "ERROR: Need FACEBOOK_BT_USER_LOGIN - hint FACEBOOK_BT_USER_LOGIN='1234'" + raise "ERROR: Need FACEBOOK_BT_USER_LOGIN - hint FACEBOOK_BT_USER_LOGIN='1234'" end user_login = ENV['FACEBOOK_BT_USER_LOGIN'] if !ENV['FACEBOOK_BT_USER_PW'] - fail "ERROR: Need FACEBOOK_BT_USER_PW - hint FACEBOOK_BT_USER_PW='1234'" + raise "ERROR: Need FACEBOOK_BT_USER_PW - hint FACEBOOK_BT_USER_PW='1234'" end user_pw = ENV['FACEBOOK_BT_USER_PW'] if !ENV['FACEBOOK_BT_PAGE_ID'] - fail "ERROR: Need FACEBOOK_BT_PAGE_ID - hint FACEBOOK_BT_PAGE_ID='1234'" + raise "ERROR: Need FACEBOOK_BT_PAGE_ID - hint FACEBOOK_BT_PAGE_ID='1234'" end page_id = ENV['FACEBOOK_BT_PAGE_ID'] if !ENV['FACEBOOK_BT_CUSTOMER'] - fail "ERROR: Need FACEBOOK_BT_CUSTOMER - hint FACEBOOK_BT_CUSTOMER='name:1234:access_token'" + raise "ERROR: Need FACEBOOK_BT_CUSTOMER - hint FACEBOOK_BT_CUSTOMER='name:1234:access_token'" end customer_name = ENV['FACEBOOK_BT_CUSTOMER'].split(':')[0] customer_id = ENV['FACEBOOK_BT_CUSTOMER'].split(':')[1] diff --git a/test/integration/facebook_test.rb b/test/integration/facebook_test.rb index 1bff8d42c..ba61aa570 100644 --- a/test/integration/facebook_test.rb +++ b/test/integration/facebook_test.rb @@ -16,21 +16,21 @@ class FacebookTest < ActiveSupport::TestCase # account config if !ENV['FACEBOOK_USER'] - fail "ERROR: Need FACEBOOK_USER - hint FACEBOOK_USER='name:1234:access_token'" + raise "ERROR: Need FACEBOOK_USER - hint FACEBOOK_USER='name:1234:access_token'" end user_name = ENV['FACEBOOK_USER'].split(':')[0] user_id = ENV['FACEBOOK_USER'].split(':')[1] user_access_token = ENV['FACEBOOK_USER'].split(':')[2] if !ENV['FACEBOOK_PAGE'] - fail "ERROR: Need FACEBOOK_PAGE - hint FACEBOOK_PAGE='name:1234:access_token'" + raise "ERROR: Need FACEBOOK_PAGE - hint FACEBOOK_PAGE='name:1234:access_token'" end page_name = ENV['FACEBOOK_PAGE'].split(':')[0] page_id = ENV['FACEBOOK_PAGE'].split(':')[1] page_access_token = ENV['FACEBOOK_PAGE'].split(':')[2] if !ENV['FACEBOOK_CUSTOMER'] - fail "ERROR: Need FACEBOOK_CUSTOMER - hint FACEBOOK_CUSTOMER='name:1234:access_token'" + raise "ERROR: Need FACEBOOK_CUSTOMER - hint FACEBOOK_CUSTOMER='name:1234:access_token'" end customer_name = ENV['FACEBOOK_CUSTOMER'].split(':')[0] customer_id = ENV['FACEBOOK_CUSTOMER'].split(':')[1] diff --git a/test/integration/otrs_import_browser_test.rb b/test/integration/otrs_import_browser_test.rb index 4f59578aa..57e52d4f0 100644 --- a/test/integration/otrs_import_browser_test.rb +++ b/test/integration/otrs_import_browser_test.rb @@ -5,10 +5,10 @@ class OtrsImportBrowserTest < TestCase def test_import if !ENV['IMPORT_BT_OTRS_ENDPOINT'] - fail "ERROR: Need IMPORT_BT_OTRS_ENDPOINT - hint IMPORT_BT_OTRS_ENDPOINT='http://vz305.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator'" + raise "ERROR: Need IMPORT_BT_OTRS_ENDPOINT - hint IMPORT_BT_OTRS_ENDPOINT='http://vz305.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator'" end if !ENV['IMPORT_BT_OTRS_ENDPOINT_KEY'] - fail "ERROR: Need IMPORT_BT_OTRS_ENDPOINT_KEY - hint IMPORT_BT_OTRS_ENDPOINT_KEY='01234567899876543210'" + raise "ERROR: Need IMPORT_BT_OTRS_ENDPOINT_KEY - hint IMPORT_BT_OTRS_ENDPOINT_KEY='01234567899876543210'" end @browser = browser_instance diff --git a/test/integration/otrs_import_test.rb b/test/integration/otrs_import_test.rb index ace09a5b8..fe0eb33c3 100644 --- a/test/integration/otrs_import_test.rb +++ b/test/integration/otrs_import_test.rb @@ -4,10 +4,10 @@ require 'integration_test_helper' class OtrsImportTest < ActiveSupport::TestCase if !ENV['IMPORT_OTRS_ENDPOINT'] - fail "ERROR: Need IMPORT_OTRS_ENDPOINT - hint IMPORT_OTRS_ENDPOINT='http://vz305.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator'" + raise "ERROR: Need IMPORT_OTRS_ENDPOINT - hint IMPORT_OTRS_ENDPOINT='http://vz305.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator'" end if !ENV['IMPORT_OTRS_ENDPOINT_KEY'] - fail "ERROR: Need IMPORT_OTRS_ENDPOINT_KEY - hint IMPORT_OTRS_ENDPOINT_KEY='01234567899876543210'" + raise "ERROR: Need IMPORT_OTRS_ENDPOINT_KEY - hint IMPORT_OTRS_ENDPOINT_KEY='01234567899876543210'" end Setting.set('import_otrs_endpoint', ENV['IMPORT_OTRS_ENDPOINT']) diff --git a/test/integration/report_test.rb b/test/integration/report_test.rb index 960cd748d..1a9c7b3dd 100644 --- a/test/integration/report_test.rb +++ b/test/integration/report_test.rb @@ -5,11 +5,11 @@ class ReportTest < ActiveSupport::TestCase # set config if !ENV['ES_URL'] - fail "ERROR: Need ES_URL - hint ES_URL='http://172.0.0.1:9200'" + raise "ERROR: Need ES_URL - hint ES_URL='http://172.0.0.1:9200'" end Setting.set('es_url', ENV['ES_URL']) if !ENV['ES_INDEX'] && !ENV['ES_INDEX_RAND'] - fail "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'" + raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'" end if ENV['ES_INDEX_RAND'] ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}" diff --git a/test/integration/twitter_browser_test.rb b/test/integration/twitter_browser_test.rb index 94624d942..7cfed4ecd 100644 --- a/test/integration/twitter_browser_test.rb +++ b/test/integration/twitter_browser_test.rb @@ -6,31 +6,31 @@ class TwitterBrowserTest < TestCase # app config if !ENV['TWITTER_BT_CONSUMER_KEY'] - fail "ERROR: Need TWITTER_BT_CONSUMER_KEY - hint TWITTER_BT_CONSUMER_KEY='1234'" + raise "ERROR: Need TWITTER_BT_CONSUMER_KEY - hint TWITTER_BT_CONSUMER_KEY='1234'" end consumer_key = ENV['TWITTER_BT_CONSUMER_KEY'] if !ENV['TWITTER_BT_CONSUMER_SECRET'] - fail "ERROR: Need TWITTER_BT_CONSUMER_SECRET - hint TWITTER_BT_CONSUMER_SECRET='1234'" + raise "ERROR: Need TWITTER_BT_CONSUMER_SECRET - hint TWITTER_BT_CONSUMER_SECRET='1234'" end consumer_secret = ENV['TWITTER_BT_CONSUMER_SECRET'] if !ENV['TWITTER_BT_USER_LOGIN'] - fail "ERROR: Need TWITTER_BT_USER_LOGIN - hint TWITTER_BT_USER_LOGIN='1234'" + raise "ERROR: Need TWITTER_BT_USER_LOGIN - hint TWITTER_BT_USER_LOGIN='1234'" end twitter_user_login = ENV['TWITTER_BT_USER_LOGIN'] if !ENV['TWITTER_BT_USER_PW'] - fail "ERROR: Need TWITTER_BT_USER_PW - hint TWITTER_BT_USER_PW='1234'" + raise "ERROR: Need TWITTER_BT_USER_PW - hint TWITTER_BT_USER_PW='1234'" end twitter_user_pw = ENV['TWITTER_BT_USER_PW'] if !ENV['TWITTER_BT_CUSTOMER_TOKEN'] - fail "ERROR: Need TWITTER_BT_CUSTOMER_TOKEN - hint TWITTER_BT_CUSTOMER_TOKEN='1234'" + raise "ERROR: Need TWITTER_BT_CUSTOMER_TOKEN - hint TWITTER_BT_CUSTOMER_TOKEN='1234'" end twitter_customer_token = ENV['TWITTER_BT_CUSTOMER_TOKEN'] if !ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET'] - fail "ERROR: Need TWITTER_BT_CUSTOMER_TOKEN_SECRET - hint TWITTER_BT_CUSTOMER_TOKEN_SECRET='1234'" + raise "ERROR: Need TWITTER_BT_CUSTOMER_TOKEN_SECRET - hint TWITTER_BT_CUSTOMER_TOKEN_SECRET='1234'" end twitter_customer_token_secret = ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET'] diff --git a/test/integration/twitter_test.rb b/test/integration/twitter_test.rb index 9f4965fd6..9be9eca28 100644 --- a/test/integration/twitter_test.rb +++ b/test/integration/twitter_test.rb @@ -17,23 +17,23 @@ class TwitterTest < ActiveSupport::TestCase # app config if !ENV['TWITTER_CONSUMER_KEY'] - fail "ERROR: Need TWITTER_CONSUMER_KEY - hint TWITTER_CONSUMER_KEY='1234'" + raise "ERROR: Need TWITTER_CONSUMER_KEY - hint TWITTER_CONSUMER_KEY='1234'" end if !ENV['TWITTER_CONSUMER_SECRET'] - fail "ERROR: Need TWITTER_CONSUMER_SECRET - hint TWITTER_CONSUMER_SECRET='1234'" + raise "ERROR: Need TWITTER_CONSUMER_SECRET - hint TWITTER_CONSUMER_SECRET='1234'" end consumer_key = ENV['TWITTER_CONSUMER_KEY'] consumer_secret = ENV['TWITTER_CONSUMER_SECRET'] # armin_theo (is system and is following marion_bauer) if !ENV['TWITTER_SYSTEM_LOGIN'] - fail "ERROR: Need TWITTER_SYSTEM_LOGIN - hint TWITTER_SYSTEM_LOGIN='@system'" + raise "ERROR: Need TWITTER_SYSTEM_LOGIN - hint TWITTER_SYSTEM_LOGIN='@system'" end if !ENV['TWITTER_SYSTEM_TOKEN'] - fail "ERROR: Need TWITTER_SYSTEM_TOKEN - hint TWITTER_SYSTEM_TOKEN='1234'" + raise "ERROR: Need TWITTER_SYSTEM_TOKEN - hint TWITTER_SYSTEM_TOKEN='1234'" end if !ENV['TWITTER_SYSTEM_TOKEN_SECRET'] - fail "ERROR: Need TWITTER_SYSTEM_TOKEN_SECRET - hint TWITTER_SYSTEM_TOKEN_SECRET='1234'" + raise "ERROR: Need TWITTER_SYSTEM_TOKEN_SECRET - hint TWITTER_SYSTEM_TOKEN_SECRET='1234'" end system_login = ENV['TWITTER_SYSTEM_LOGIN'] system_login_without_at = system_login[1, system_login.length] @@ -42,13 +42,13 @@ class TwitterTest < ActiveSupport::TestCase # me_bauer (is customer and is following armin_theo) if !ENV['TWITTER_CUSTOMER_LOGIN'] - fail "ERROR: Need CUSTOMER_LOGIN - hint TWITTER_CUSTOMER_LOGIN='@customer'" + raise "ERROR: Need CUSTOMER_LOGIN - hint TWITTER_CUSTOMER_LOGIN='@customer'" end if !ENV['TWITTER_CUSTOMER_TOKEN'] - fail "ERROR: Need CUSTOMER_TOKEN - hint TWITTER_CUSTOMER_TOKEN='1234'" + raise "ERROR: Need CUSTOMER_TOKEN - hint TWITTER_CUSTOMER_TOKEN='1234'" end if !ENV['TWITTER_CUSTOMER_TOKEN_SECRET'] - fail "ERROR: Need CUSTOMER_TOKEN_SECRET - hint TWITTER_CUSTOMER_TOKEN_SECRET='1234'" + raise "ERROR: Need CUSTOMER_TOKEN_SECRET - hint TWITTER_CUSTOMER_TOKEN_SECRET='1234'" end customer_login = ENV['TWITTER_CUSTOMER_LOGIN'] customer_token = ENV['TWITTER_CUSTOMER_TOKEN'] diff --git a/test/integration/zendesk_import_browser_test.rb b/test/integration/zendesk_import_browser_test.rb index b40b378c7..d2765a07b 100644 --- a/test/integration/zendesk_import_browser_test.rb +++ b/test/integration/zendesk_import_browser_test.rb @@ -5,13 +5,13 @@ class ZendeskImportBrowserTest < TestCase def test_import if !ENV['IMPORT_BT_ZENDESK_ENDPOINT'] - fail "ERROR: Need IMPORT_BT_ZENDESK_ENDPOINT - hint IMPORT_BT_ZENDESK_ENDPOINT='https://example.zendesk.com/' (including trailing slash!)" + raise "ERROR: Need IMPORT_BT_ZENDESK_ENDPOINT - hint IMPORT_BT_ZENDESK_ENDPOINT='https://example.zendesk.com/' (including trailing slash!)" end if !ENV['IMPORT_BT_ZENDESK_ENDPOINT_USERNAME'] - fail "ERROR: Need IMPORT_BT_ZENDESK_ENDPOINT_USERNAME - hint IMPORT_BT_ZENDESK_ENDPOINT_USERNAME='your@email.com'" + raise "ERROR: Need IMPORT_BT_ZENDESK_ENDPOINT_USERNAME - hint IMPORT_BT_ZENDESK_ENDPOINT_USERNAME='your@email.com'" end if !ENV['IMPORT_BT_ZENDESK_ENDPOINT_KEY'] - fail "ERROR: Need IMPORT_BT_ZENDESK_ENDPOINT_KEY - hint IMPORT_BT_ZENDESK_ENDPOINT_KEY='XYZ3133723421111'" + raise "ERROR: Need IMPORT_BT_ZENDESK_ENDPOINT_KEY - hint IMPORT_BT_ZENDESK_ENDPOINT_KEY='XYZ3133723421111'" end @browser = browser_instance diff --git a/test/integration/zendesk_import_test.rb b/test/integration/zendesk_import_test.rb index 52a302cef..a68fa24c5 100644 --- a/test/integration/zendesk_import_test.rb +++ b/test/integration/zendesk_import_test.rb @@ -4,13 +4,13 @@ require 'integration_test_helper' class ZendeskImportTest < ActiveSupport::TestCase if !ENV['IMPORT_ZENDESK_ENDPOINT'] - fail "ERROR: Need IMPORT_ZENDESK_ENDPOINT - hint IMPORT_ZENDESK_ENDPOINT='https://example.zendesk.com/api/v2'" + raise "ERROR: Need IMPORT_ZENDESK_ENDPOINT - hint IMPORT_ZENDESK_ENDPOINT='https://example.zendesk.com/api/v2'" end if !ENV['IMPORT_ZENDESK_ENDPOINT_KEY'] - fail "ERROR: Need IMPORT_ZENDESK_ENDPOINT_KEY - hint IMPORT_ZENDESK_ENDPOINT_KEY='01234567899876543210'" + raise "ERROR: Need IMPORT_ZENDESK_ENDPOINT_KEY - hint IMPORT_ZENDESK_ENDPOINT_KEY='01234567899876543210'" end if !ENV['IMPORT_ZENDESK_ENDPOINT_USERNAME'] - fail "ERROR: Need IMPORT_ZENDESK_ENDPOINT_USERNAME - hint IMPORT_ZENDESK_ENDPOINT_USERNAME='bob.ross@happylittletrees.com'" + raise "ERROR: Need IMPORT_ZENDESK_ENDPOINT_USERNAME - hint IMPORT_ZENDESK_ENDPOINT_USERNAME='bob.ross@happylittletrees.com'" end Setting.set('import_zendesk_endpoint', ENV['IMPORT_ZENDESK_ENDPOINT']) diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index 327f72a1d..98f3b6e7e 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -3,52 +3,52 @@ require 'test_helper' class SessionBasicTest < ActiveSupport::TestCase test 'a cache' do - Sessions::CacheIn.set( 'last_run_test', true, { expires_in: 2.seconds } ) - result = Sessions::CacheIn.get( 'last_run_test' ) - assert_equal( true, result, 'check 1' ) + Sessions::CacheIn.set('last_run_test', true, { expires_in: 2.seconds }) + result = Sessions::CacheIn.get('last_run_test') + assert_equal(true, result, 'check 1') # should not be expired - result = Sessions::CacheIn.expired( 'last_run_test' ) - assert_equal( false, result, 'check 1 - expired' ) + result = Sessions::CacheIn.expired('last_run_test') + assert_equal(false, result, 'check 1 - expired') # should be expired sleep 3 - result = Sessions::CacheIn.expired( 'last_run_test' ) - assert_equal( true, result, 'check 1 - expired' ) + result = Sessions::CacheIn.expired('last_run_test') + assert_equal(true, result, 'check 1 - expired') # renew expire - result = Sessions::CacheIn.get( 'last_run_test', re_expire: true ) - assert_equal( true, result, 'check 1 - re_expire' ) + result = Sessions::CacheIn.get('last_run_test', re_expire: true) + assert_equal(true, result, 'check 1 - re_expire') # should not be expired - result = Sessions::CacheIn.expired( 'last_run_test' ) - assert_equal( false, result, 'check 1 - expired' ) + result = Sessions::CacheIn.expired('last_run_test') + assert_equal(false, result, 'check 1 - expired') # ignore expired sleep 3 - result = Sessions::CacheIn.get( 'last_run_test', ignore_expire: true ) - assert_equal( true, result, 'check 1 - ignore_expire' ) + result = Sessions::CacheIn.get('last_run_test', ignore_expire: true) + assert_equal(true, result, 'check 1 - ignore_expire') # should be expired - result = Sessions::CacheIn.expired( 'last_run_test' ) - assert_equal( true, result, 'check 2' ) + result = Sessions::CacheIn.expired('last_run_test') + assert_equal(true, result, 'check 2') - result = Sessions::CacheIn.get( 'last_run_test' ) - assert_equal( nil, result, 'check 2' ) + result = Sessions::CacheIn.get('last_run_test') + assert_equal(nil, result, 'check 2') # check delete cache - Sessions::CacheIn.set( 'last_run_delete', true, { expires_in: 5.seconds } ) - result = Sessions::CacheIn.get( 'last_run_delete' ) - assert_equal( true, result, 'check 1' ) - Sessions::CacheIn.delete( 'last_run_delete' ) - result = Sessions::CacheIn.get( 'last_run_delete' ) - assert_equal( nil, nil, 'check delete' ) + Sessions::CacheIn.set('last_run_delete', true, { expires_in: 5.seconds }) + result = Sessions::CacheIn.get('last_run_delete') + assert_equal(true, result, 'check 1') + Sessions::CacheIn.delete('last_run_delete') + result = Sessions::CacheIn.get('last_run_delete') + assert_equal(nil, nil, 'check delete') end test 'c session create / update' do # create users - roles = Role.where( name: [ 'Agent'] ) + roles = Role.where(name: ['Agent']) groups = Group.all UserInfo.current_user_id = 1 @@ -67,34 +67,34 @@ class SessionBasicTest < ActiveSupport::TestCase # create sessions client_id1 = '123456789' - Sessions.create( client_id1, {}, { type: 'websocket' } ) + Sessions.create(client_id1, {}, { type: 'websocket' }) # check if session exists - assert( Sessions.session_exists?(client_id1), 'check if session exists' ) + assert(Sessions.session_exists?(client_id1), 'check if session exists') # check session data data = Sessions.get(client_id1) - assert( data[:meta], 'check if meta exists' ) - assert( data[:user], 'check if user exists' ) - assert_equal( data[:user]['id'], nil, 'check if user id is correct' ) + assert(data[:meta], 'check if meta exists') + assert(data[:user], 'check if user exists') + assert_equal(data[:user]['id'], nil, 'check if user id is correct') # recreate session - Sessions.create( client_id1, agent1.attributes, { type: 'websocket' } ) + Sessions.create(client_id1, agent1.attributes, { type: 'websocket' }) # check if session exists - assert( Sessions.session_exists?(client_id1), 'check if session exists' ) + assert(Sessions.session_exists?(client_id1), 'check if session exists') # check session data data = Sessions.get(client_id1) - assert( data[:meta], 'check if meta exists' ) - assert( data[:user], 'check if user exists' ) - assert_equal( data[:user]['id'], agent1.id, 'check if user id is correct' ) + assert(data[:meta], 'check if meta exists') + assert(data[:user], 'check if user exists') + assert_equal(data[:user]['id'], agent1.id, 'check if user id is correct') # destroy session Sessions.destory(client_id1) # check if session exists - assert( !Sessions.session_exists?(client_id1), 'check if session exists' ) + assert(!Sessions.session_exists?(client_id1), 'check if session exists') end @@ -103,23 +103,23 @@ class SessionBasicTest < ActiveSupport::TestCase UserInfo.current_user_id = 2 user = User.lookup(id: 1) - collection_client1 = Sessions::Backend::Collections::Group.new(user, false, '123-1', 3) - collection_client2 = Sessions::Backend::Collections::Group.new(user, false, '234-2', 3) + collection_client1 = Sessions::Backend::Collections::Group.new(user, {}, false, '123-1', 3) + collection_client2 = Sessions::Backend::Collections::Group.new(user, {}, false, '234-2', 3) # get whole collections result1 = collection_client1.push - assert( !result1.empty?, 'check collections' ) + assert(!result1.empty?, 'check collections') sleep 0.6 result2 = collection_client2.push - assert( !result2.empty?, 'check collections' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2.empty?, 'check collections') + assert_equal(result1, result2, 'check collections') # next check should be empty result1 = collection_client1.push - assert( !result1, 'check collections - recall' ) + assert(!result1, 'check collections - recall') sleep 1 result2 = collection_client2.push - assert( !result2, 'check collections - recall' ) + assert(!result2, 'check collections - recall') # change collection group = Group.first @@ -128,36 +128,36 @@ class SessionBasicTest < ActiveSupport::TestCase # get whole collections result1 = collection_client1.push - assert( !result1.empty?, 'check collections - after touch' ) + assert(!result1.empty?, 'check collections - after touch') result2 = collection_client2.push - assert( !result2.empty?, 'check collections - after touch' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2.empty?, 'check collections - after touch') + assert_equal(result1, result2, 'check collections') # check again after touch result1 = collection_client1.push - assert( !result1, 'check collections - after touch - recall' ) + assert(!result1, 'check collections - after touch - recall') result2 = collection_client2.push - assert( !result2, 'check collections - after touch - recall' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2, 'check collections - after touch - recall') + assert_equal(result1, result2, 'check collections') # change collection - group = Group.create( name: 'SomeGroup::' + rand(999_999).to_s, active: true ) + group = Group.create(name: 'SomeGroup::' + rand(999_999).to_s, active: true) sleep 4 # get whole collections result1 = collection_client1.push - assert( !result1.empty?, 'check collections - after create' ) + assert(!result1.empty?, 'check collections - after create') result2 = collection_client2.push - assert( !result2.empty?, 'check collections - after create' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2.empty?, 'check collections - after create') + assert_equal(result1, result2, 'check collections') # check again after create sleep 4 result1 = collection_client1.push - assert( !result1, 'check collections - after create - recall' ) + assert(!result1, 'check collections - after create - recall') result2 = collection_client2.push - assert( !result2, 'check collections - after create - recall' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2, 'check collections - after create - recall') + assert_equal(result1, result2, 'check collections') # change collection group.destroy @@ -165,22 +165,22 @@ class SessionBasicTest < ActiveSupport::TestCase # get whole collections result1 = collection_client1.push - assert( !result1.empty?, 'check collections - after destroy' ) + assert(!result1.empty?, 'check collections - after destroy') result2 = collection_client2.push - assert( !result2.empty?, 'check collections - after destroy' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2.empty?, 'check collections - after destroy') + assert_equal(result1, result2, 'check collections') # check again after destroy sleep 4 result1 = collection_client1.push - assert( !result1, 'check collections - after destroy - recall' ) + assert(!result1, 'check collections - after destroy - recall') result2 = collection_client2.push - assert( !result2, 'check collections - after destroy - recall' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2, 'check collections - after destroy - recall') + assert_equal(result1, result2, 'check collections') end user = User.lookup(id: 1) - roles = Role.where( name: %w(Agent Admin) ) + roles = Role.where(name: %w(Agent Admin)) user.roles = roles user.save @@ -190,41 +190,41 @@ class SessionBasicTest < ActiveSupport::TestCase user = User.lookup(id: 1) org = Organization.create( name: 'SomeOrg1::' + rand(999_999).to_s, active: true ) - collection_client1 = Sessions::Backend::Collections::Organization.new(user, false, '123-1', 3) - collection_client2 = Sessions::Backend::Collections::Organization.new(user, false, '234-2', 3) + collection_client1 = Sessions::Backend::Collections::Organization.new(user, {}, false, '123-1', 3) + collection_client2 = Sessions::Backend::Collections::Organization.new(user, {}, false, '234-2', 3) # get whole collections - should be nil, no org exists! result1 = collection_client1.push - assert( !result1.empty?, 'check collections' ) + assert(!result1.empty?, 'check collections') result2 = collection_client2.push - assert( !result2.empty?, 'check collections' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2.empty?, 'check collections') + assert_equal(result1, result2, 'check collections') # next check - should still be nil, no org exists! result1 = collection_client1.push - assert( !result1, 'check collections - recall' ) + assert(!result1, 'check collections - recall') sleep 0.6 result2 = collection_client2.push - assert( !result2, 'check collections - recall' ) + assert(!result2, 'check collections - recall') # change collection - org = Organization.create( name: 'SomeOrg2::' + rand(999_999).to_s, active: true ) + org = Organization.create(name: 'SomeOrg2::' + rand(999_999).to_s, active: true) sleep 4 # get whole collections result1 = collection_client1.push - assert( !result1.empty?, 'check collections - after create' ) + assert(!result1.empty?, 'check collections - after create') result2 = collection_client2.push - assert( !result2.empty?, 'check collections - after create' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result2.empty?, 'check collections - after create') + assert_equal(result1, result2, 'check collections') sleep 4 # next check should be empty result1 = collection_client1.push - assert( !result1, 'check collections - after create recall' ) + assert(!result1, 'check collections - after create recall') result2 = collection_client2.push - assert( !result2, 'check collections - after create recall' ) + assert(!result2, 'check collections - after create recall') organization = Organization.first organization.touch @@ -232,32 +232,32 @@ class SessionBasicTest < ActiveSupport::TestCase # get whole collections result1 = collection_client1.push - assert( !result1.empty?, 'check collections - after touch' ) + assert(!result1.empty?, 'check collections - after touch') result2 = collection_client2.push - assert( !result1.empty?, 'check collections - after touch' ) - assert_equal( result1, result2, 'check collections' ) + assert(!result1.empty?, 'check collections - after touch') + assert_equal(result1, result2, 'check collections') end test 'c rss' do user = User.lookup(id: 1) - collection_client1 = Sessions::Backend::Rss.new(user, false, '123-1') + collection_client1 = Sessions::Backend::Rss.new(user, {}, false, '123-1') # get whole collections result1 = collection_client1.push #puts "RSS1: #{result1.inspect}" - assert( !result1.empty?, 'check rss' ) + assert(!result1.empty?, 'check rss') sleep 1 # next check should be empty result1 = collection_client1.push #puts "R1: #{result1.inspect}" - assert( !result1, 'check rss - recall' ) + assert(!result1, 'check rss - recall') end test 'c activity stream' do # create users - roles = Role.where( name: %w(Agent Admin) ) + roles = Role.where(name: %w(Agent Admin)) groups = Group.all UserInfo.current_user_id = 2 @@ -272,61 +272,61 @@ class SessionBasicTest < ActiveSupport::TestCase groups: groups, ) agent1.roles = roles - assert( agent1.save, 'create/update agent1' ) + assert(agent1.save, 'create/update agent1') - as_client1 = Sessions::Backend::ActivityStream.new(agent1, false, '123-1', 3) + as_client1 = Sessions::Backend::ActivityStream.new(agent1, {}, false, '123-1', 3) # get as stream result1 = as_client1.push - assert( result1, 'check as agent1' ) + assert(result1, 'check as agent1') sleep 1 # next check should be empty result1 = as_client1.push - assert( !result1, 'check as agent1 - recall' ) + assert(!result1, 'check as agent1 - recall') # next check should be empty sleep 4 result1 = as_client1.push - assert( !result1, 'check as agent1 - recall 2' ) + assert(!result1, 'check as agent1 - recall 2') - agent1.update_attribute( :email, 'activity-stream-agent11@example.com' ) - ticket = Ticket.create(title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 ) + agent1.update_attribute(:email, 'activity-stream-agent11@example.com') + ticket = Ticket.create(title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1) sleep 4 # get as stream result1 = as_client1.push - assert( result1, 'check as agent1 - recall 3' ) + assert( result1, 'check as agent1 - recall 3') end test 'c ticket_create' do UserInfo.current_user_id = 2 user = User.lookup(id: 1) - ticket_create_client1 = Sessions::Backend::TicketCreate.new(user, false, '123-1', 3) + ticket_create_client1 = Sessions::Backend::TicketCreate.new(user, {}, false, '123-1', 3) # get as stream result1 = ticket_create_client1.push - assert( result1, 'check ticket_create' ) + assert(result1, 'check ticket_create') sleep 0.6 # next check should be empty result1 = ticket_create_client1.push - assert( !result1, 'check ticket_create - recall' ) + assert(!result1, 'check ticket_create - recall') # next check should be empty sleep 0.6 result1 = ticket_create_client1.push - assert( !result1, 'check ticket_create - recall 2' ) + assert(!result1, 'check ticket_create - recall 2') - Group.create( name: 'SomeTicketCreateGroup::' + rand(999_999).to_s, active: true ) + Group.create(name: 'SomeTicketCreateGroup::' + rand(999_999).to_s, active: true) sleep 4 # get as stream result1 = ticket_create_client1.push - assert( result1, 'check ticket_create - recall 3' ) + assert(result1, 'check ticket_create - recall 3') end end diff --git a/test/unit/session_basic_ticket_test.rb b/test/unit/session_basic_ticket_test.rb index 29867dc6b..eeea8232a 100644 --- a/test/unit/session_basic_ticket_test.rb +++ b/test/unit/session_basic_ticket_test.rb @@ -3,11 +3,12 @@ require 'test_helper' class SessionBasicTicketTest < ActiveSupport::TestCase - test 'b ticket_overview_index' do + test 'b ticket_overview_List' do UserInfo.current_user_id = 1 + Ticket.destroy_all # create users - roles = Role.where( name: [ 'Agent' ] ) + roles = Role.where(name: ['Agent']) groups = Group.all agent1 = User.create_or_update( @@ -22,81 +23,54 @@ class SessionBasicTicketTest < ActiveSupport::TestCase ) agent1.roles = roles - assert( agent1.save, 'create/update agent1' ) + assert(agent1.save, 'create/update agent1') - Ticket.create( title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 ) + Ticket.create(title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1) - user = User.lookup( id: agent1.id ) - client1 = Sessions::Backend::TicketOverviewIndex.new(user, false, '123-1', 5) + user = User.lookup(id: agent1.id) + client1 = Sessions::Backend::TicketOverviewList.new(user, {}, false, '123-1', 5) - # get as stream result1 = client1.push - assert( result1, 'check ticket_overview_index' ) + assert(result1, 'check ticket_overview_List') # next check should be empty / no changes result1 = client1.push - assert( !result1, 'check ticket_overview_index - recall' ) + assert(!result1, 'check ticket_overview_index - recall') # next check should be empty / no changes sleep 6 result1 = client1.push - assert( !result1, 'check ticket_overview_index - recall 2' ) + assert(!result1, 'check ticket_overview_index - recall 2') # create ticket - ticket = Ticket.create( title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 ) + ticket = Ticket.create(title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1) sleep 6 - # get as stream result1 = client1.push - assert( result1, 'check ticket_overview_index - recall 3' ) - end + assert(result1, 'check ticket_overview_index - recall 3') + sleep 6 - test 'b ticket_overview_list' do - UserInfo.current_user_id = 1 - - # create users - roles = Role.where( name: [ 'Agent' ] ) - groups = Group.all - - agent1 = User.create_or_update( - login: 'session-basic-ticket-agent-1', - firstname: 'Session', - lastname: 'session basic ' + rand(99_999).to_s, - email: 'session-basic-ticket-agent-1@example.com', - password: 'agentpw', - active: true, - roles: roles, - groups: groups, + # chnage overview + overviews = Ticket::Overviews.all( + current_user: user, ) + overviews.first.touch - agent1.roles = roles - assert( agent1.save, 'create/update agent1' ) - - Ticket.create( title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 ) - - user = User.lookup( id: agent1.id ) - - client1 = Sessions::Backend::TicketOverviewList.new(user, false, '123-1', 5) - - # get as stream result1 = client1.push - assert( result1, 'check ticket_overview_list' ) + assert(result1, 'check ticket_overview_index - recall 4') - # next check should be empty / no changes result1 = client1.push - assert( !result1, 'check ticket_overview_list - recall' ) + assert(!result1, 'check ticket_overview_index - recall 5') - # next check should be empty / no changes - sleep 6 + Sessions::Backend::TicketOverviewList.reset(user.id) result1 = client1.push - assert( !result1, 'check ticket_overview_list - recall 2' ) + assert(!result1, 'check ticket_overview_index - recall 6') - # create ticket - ticket = Ticket.create( title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 ) - sleep 6 - - # get as stream + ticket = Ticket.create(title: '12323 - 2', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1) + Sessions::Backend::TicketOverviewList.reset(user.id) result1 = client1.push - assert( result1, 'check ticket_overview_list - recall 3' ) + assert(result1, 'check ticket_overview_index - recall 7') + end + end diff --git a/test/unit/session_collections_test.rb b/test/unit/session_collections_test.rb index 420638784..4f0e07c4a 100644 --- a/test/unit/session_collections_test.rb +++ b/test/unit/session_collections_test.rb @@ -8,7 +8,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase UserInfo.current_user_id = 1 # create users - roles = Role.where( name: %w(Agent Admin) ) + roles = Role.where(name: %w(Agent Admin)) groups = Group.all agent1 = User.create_or_update( @@ -24,7 +24,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase agent1.roles = roles agent1.save - roles = Role.where( name: [ 'Agent' ] ) + roles = Role.where(name: ['Agent']) groups = Group.all agent2 = User.create_or_update( @@ -40,7 +40,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase agent2.roles = roles agent2.save - roles = Role.where( name: [ 'Customer'] ) + roles = Role.where(name: ['Customer']) customer1 = User.create_or_update( login: 'session-collections-customer-1', firstname: 'Session', @@ -54,41 +54,41 @@ class SessionCollectionsTest < ActiveSupport::TestCase customer1.roles = roles customer1.save - collection_client1 = Sessions::Backend::Collections.new(agent1, nil, 'aaa-1', 3) - collection_client2 = Sessions::Backend::Collections.new(agent2, nil, 'bbb-2', 3) - collection_client3 = Sessions::Backend::Collections.new(customer1, nil, 'ccc-2', 3) + collection_client1 = Sessions::Backend::Collections.new(agent1, {}, nil, 'aaa-1', 3) + collection_client2 = Sessions::Backend::Collections.new(agent2, {}, nil, 'bbb-2', 3) + collection_client3 = Sessions::Backend::Collections.new(customer1, {}, nil, 'ccc-2', 3) # get whole collections result1 = collection_client1.push - assert( result1, 'check collections' ) - assert( check_if_collection_exists(result1, :Group), 'check collections - after init' ) - assert( check_if_collection_exists(result1, :Role), 'check collections - after init' ) - assert( check_if_collection_exists(result1, :Signature), 'check collections - after init' ) - assert( check_if_collection_exists(result1, :EmailAddress), 'check collections - after init' ) + assert(result1, 'check collections') + assert(check_if_collection_exists(result1, :Group), 'check collections - after init') + assert(check_if_collection_exists(result1, :Role), 'check collections - after init') + assert(check_if_collection_exists(result1, :Signature), 'check collections - after init') + assert(check_if_collection_exists(result1, :EmailAddress), 'check collections - after init') sleep 1 result2 = collection_client2.push - assert( result2, 'check collections' ) - assert( check_if_collection_exists(result2, :Group), 'check collections - after init' ) - assert( check_if_collection_exists(result2, :Role), 'check collections - after init' ) - assert( check_if_collection_exists(result2, :Signature), 'check collections - after init' ) - assert( check_if_collection_exists(result2, :EmailAddress), 'check collections - after init' ) - assert_equal( result1, result2, 'check collections' ) + assert(result2, 'check collections') + assert(check_if_collection_exists(result2, :Group), 'check collections - after init') + assert(check_if_collection_exists(result2, :Role), 'check collections - after init') + assert(check_if_collection_exists(result2, :Signature), 'check collections - after init') + assert(check_if_collection_exists(result2, :EmailAddress), 'check collections - after init') + assert_equal(result1, result2, 'check collections') result3 = collection_client3.push - assert( result3, 'check collections' ) - assert( check_if_collection_exists(result3, :Group), 'check collections - after init' ) - assert( check_if_collection_exists(result3, :Role), 'check collections - after init' ) - assert( !check_if_collection_exists(result3, :Signature), 'check collections - after init' ) - assert( !check_if_collection_exists(result3, :EmailAddress), 'check collections - after init' ) + assert(result3, 'check collections') + assert(check_if_collection_exists(result3, :Group), 'check collections - after init') + assert(check_if_collection_exists(result3, :Role), 'check collections - after init') + assert(!check_if_collection_exists(result3, :Signature), 'check collections - after init') + assert(!check_if_collection_exists(result3, :EmailAddress), 'check collections - after init') # next check should be empty result1 = collection_client1.push - assert( result1.empty?, 'check collections - recall' ) + assert(result1.empty?, 'check collections - recall') sleep 0.4 result2 = collection_client2.push - assert( result2.empty?, 'check collections - recall' ) + assert(result2.empty?, 'check collections - recall') result3 = collection_client3.push - assert( result3.empty?, 'check collections - recall' ) + assert(result3.empty?, 'check collections - recall') # change collection group = Group.first @@ -97,42 +97,42 @@ class SessionCollectionsTest < ActiveSupport::TestCase # get whole collections result1 = collection_client1.push - assert( result1, 'check collections - after touch' ) - assert( check_if_collection_exists(result1, :Group), 'check collections - after touch' ) + assert(result1, 'check collections - after touch') + assert(check_if_collection_exists(result1, :Group), 'check collections - after touch') sleep 0.1 result2 = collection_client2.push - assert( result2, 'check collections - after touch' ) - assert( check_if_collection_exists(result2, :Group), 'check collections - after touch' ) + assert(result2, 'check collections - after touch') + assert(check_if_collection_exists(result2, :Group), 'check collections - after touch') result3 = collection_client3.push - assert( result3, 'check collections - after touch' ) - assert( check_if_collection_exists(result3, :Group), 'check collections - after touch' ) + assert(result3, 'check collections - after touch') + assert(check_if_collection_exists(result3, :Group), 'check collections - after touch') # change collection - org = Organization.create( name: 'SomeOrg::' + rand(999_999).to_s, active: true, member_ids: [customer1.id] ) + org = Organization.create(name: 'SomeOrg::' + rand(999_999).to_s, active: true, member_ids: [customer1.id]) sleep 4 # get whole collections result1 = collection_client1.push - assert( result1, 'check collections - after create' ) - assert( check_if_collection_exists(result1, :Organization, { id: org.id, member_ids: [customer1.id] } ), 'check collections - after create with attributes' ) + assert(result1, 'check collections - after create') + assert(check_if_collection_exists(result1, :Organization, { id: org.id, member_ids: [customer1.id] }), 'check collections - after create with attributes') sleep 0.3 result2 = collection_client2.push - assert( result2, 'check collections - after create' ) - assert( check_if_collection_exists(result2, :Organization), 'check collections - after create' ) + assert(result2, 'check collections - after create') + assert(check_if_collection_exists(result2, :Organization), 'check collections - after create') # user has no organization, so collection should be empty result3 = collection_client3.push - assert( result3, 'check collections - after create' ) - assert( !check_if_collection_exists(result3, :Organization), 'check collections - after create' ) + assert(result3, 'check collections - after create') + assert(!check_if_collection_exists(result3, :Organization), 'check collections - after create') # next check should be empty sleep 1 result1 = collection_client1.push - assert( result1.empty?, 'check collections - recall' ) + assert(result1.empty?, 'check collections - recall') result2 = collection_client2.push - assert( result2.empty?, 'check collections - recall' ) + assert(result2.empty?, 'check collections - recall') result3 = collection_client3.push - assert( result3.empty?, 'check collections - recall' ) + assert(result3.empty?, 'check collections - recall') end def check_if_collection_exists(results, collection, attributes = nil) diff --git a/test/unit/session_enhanced_test.rb b/test/unit/session_enhanced_test.rb index c31561e59..1690cb310 100644 --- a/test/unit/session_enhanced_test.rb +++ b/test/unit/session_enhanced_test.rb @@ -5,7 +5,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase test 'a check clients and send messages' do # create users - roles = Role.where( name: [ 'Agent'] ) + roles = Role.where(name: ['Agent']) groups = Group.all UserInfo.current_user_id = 1 @@ -53,21 +53,21 @@ class SessionEnhancedTest < ActiveSupport::TestCase Sessions.destory(client_id1) Sessions.destory(client_id2) Sessions.destory(client_id3) - Sessions.create( client_id1, agent1.attributes, { type: 'websocket' } ) - Sessions.create( client_id2, agent2.attributes, { type: 'ajax' } ) - Sessions.create( client_id3, agent3.attributes, { type: 'ajax' } ) + Sessions.create(client_id1, agent1.attributes, { type: 'websocket' }) + Sessions.create(client_id2, agent2.attributes, { type: 'ajax' }) + Sessions.create(client_id3, agent3.attributes, { type: 'ajax' }) # check if session exists - assert( Sessions.session_exists?(client_id1), 'check if session exists' ) - assert( Sessions.session_exists?(client_id2), 'check if session exists' ) - assert( Sessions.session_exists?(client_id3), 'check if session exists' ) + assert(Sessions.session_exists?(client_id1), 'check if session exists') + assert(Sessions.session_exists?(client_id2), 'check if session exists') + assert(Sessions.session_exists?(client_id3), 'check if session exists') # check if session still exists after idle cleanup sleep 1 Sessions.destory_idle_sessions(5) - assert( Sessions.session_exists?(client_id1), 'check if session exists after 1 sec' ) - assert( Sessions.session_exists?(client_id2), 'check if session exists after 1 sec' ) - assert( Sessions.session_exists?(client_id3), 'check if session exists after 1 sec' ) + assert(Sessions.session_exists?(client_id1), 'check if session exists after 1 sec') + assert(Sessions.session_exists?(client_id2), 'check if session exists after 1 sec') + assert(Sessions.session_exists?(client_id3), 'check if session exists after 1 sec') # check if session still exists after idle cleanup with touched sessions sleep 6 @@ -75,71 +75,71 @@ class SessionEnhancedTest < ActiveSupport::TestCase Sessions.touch(client_id2) Sessions.touch(client_id3) Sessions.destory_idle_sessions(5) - assert( Sessions.session_exists?(client_id1), 'check if session exists after touch' ) - assert( Sessions.session_exists?(client_id2), 'check if session exists after touch' ) - assert( Sessions.session_exists?(client_id3), 'check if session exists after touch' ) + assert(Sessions.session_exists?(client_id1), 'check if session exists after touch') + assert(Sessions.session_exists?(client_id2), 'check if session exists after touch') + assert(Sessions.session_exists?(client_id3), 'check if session exists after touch') # check session data data = Sessions.get(client_id1) - assert( data[:meta], 'check if meta exists' ) - assert( data[:user], 'check if user exists' ) - assert_equal( data[:user]['id'], agent1.id, 'check if user id is correct' ) + assert(data[:meta], 'check if meta exists') + assert(data[:user], 'check if user exists') + assert_equal(data[:user]['id'], agent1.id, 'check if user id is correct') data = Sessions.get(client_id2) - assert( data[:meta], 'check if meta exists' ) - assert( data[:user], 'check if user exists' ) - assert_equal( data[:user]['id'], agent2.id, 'check if user id is correct' ) + assert(data[:meta], 'check if meta exists') + assert(data[:user], 'check if user exists') + assert_equal(data[:user]['id'], agent2.id, 'check if user id is correct') data = Sessions.get(client_id3) - assert( data[:meta], 'check if meta exists' ) - assert( data[:user], 'check if user exists' ) - assert_equal( data[:user]['id'], agent3.id, 'check if user id is correct' ) + assert(data[:meta], 'check if meta exists') + assert(data[:user], 'check if user exists') + assert_equal(data[:user]['id'], agent3.id, 'check if user id is correct') # send data to one client - Sessions.send( client_id1, { msg: 'äöüß123' } ) - Sessions.send( client_id1, { msg: 'äöüß1234' } ) + Sessions.send(client_id1, { msg: 'äöüß123' }) + Sessions.send(client_id1, { msg: 'äöüß1234' }) messages = Sessions.queue(client_id1) - assert_equal( 3, messages.count, 'messages count') - assert_equal( 'ws:login', messages[0]['event'], 'messages 1') - assert_equal( true, messages[0]['data']['success'], 'messages 1') - assert_equal( 'äöüß123', messages[1]['msg'], 'messages 2') - assert_equal( 'äöüß1234', messages[2]['msg'], 'messages 3') + assert_equal(3, messages.count, 'messages count') + assert_equal('ws:login', messages[0]['event'], 'messages 1') + assert_equal(true, messages[0]['data']['success'], 'messages 1') + assert_equal('äöüß123', messages[1]['msg'], 'messages 2') + assert_equal('äöüß1234', messages[2]['msg'], 'messages 3') messages = Sessions.queue(client_id2) - assert_equal( messages.count, 1, 'messages count') - assert_equal( 'ws:login', messages[0]['event'], 'messages 1') - assert_equal( true, messages[0]['data']['success'], 'messages 1') + assert_equal(messages.count, 1, 'messages count') + assert_equal('ws:login', messages[0]['event'], 'messages 1') + assert_equal(true, messages[0]['data']['success'], 'messages 1') messages = Sessions.queue(client_id3) - assert_equal( messages.count, 1, 'messages count') - assert_equal( 'ws:login', messages[0]['event'], 'messages 1') - assert_equal( true, messages[0]['data']['success'], 'messages 1') + assert_equal(messages.count, 1, 'messages count') + assert_equal('ws:login', messages[0]['event'], 'messages 1') + assert_equal(true, messages[0]['data']['success'], 'messages 1') # broadcast to all clients - Sessions.broadcast( { msg: 'ooo123123123123123123' } ) + Sessions.broadcast({ msg: 'ooo123123123123123123' }) messages = Sessions.queue(client_id1) - assert_equal( messages.count, 1, 'messages count') - assert_equal( 'ooo123123123123123123', messages[0]['msg'], 'messages broadcast 1') + assert_equal(messages.count, 1, 'messages count') + assert_equal('ooo123123123123123123', messages[0]['msg'], 'messages broadcast 1') messages = Sessions.queue(client_id2) - assert_equal( messages.count, 1, 'messages count') - assert_equal( 'ooo123123123123123123', messages[0]['msg'], 'messages broadcast 1') + assert_equal(messages.count, 1, 'messages count') + assert_equal('ooo123123123123123123', messages[0]['msg'], 'messages broadcast 1') messages = Sessions.queue(client_id3) - assert_equal( messages.count, 1, 'messages count') - assert_equal( 'ooo123123123123123123', messages[0]['msg'], 'messages broadcast 1') + assert_equal(messages.count, 1, 'messages count') + assert_equal('ooo123123123123123123', messages[0]['msg'], 'messages broadcast 1') # send dedicated message to user - Sessions.send_to( agent1.id, { msg: 'ooo1231231231231231234' } ) + Sessions.send_to(agent1.id, { msg: 'ooo1231231231231231234' }) messages = Sessions.queue(client_id1) - assert_equal( messages.count, 1, 'messages count') - assert_equal( 'ooo1231231231231231234', messages[0]['msg'], 'messages send 1') + assert_equal(messages.count, 1, 'messages count') + assert_equal('ooo1231231231231231234', messages[0]['msg'], 'messages send 1') messages = Sessions.queue(client_id2) - assert_equal( messages.count, 0, 'messages count') + assert_equal(messages.count, 0, 'messages count') messages = Sessions.queue(client_id3) - assert_equal( messages.count, 0, 'messages count') + assert_equal(messages.count, 0, 'messages count') # start jobs jobs = Thread.new { @@ -149,25 +149,25 @@ class SessionEnhancedTest < ActiveSupport::TestCase #jobs.join # check client threads - assert( Sessions.thread_client_exists?(client_id1), 'check if client is running' ) - assert( Sessions.thread_client_exists?(client_id2), 'check if client is running' ) - assert( Sessions.thread_client_exists?(client_id3), 'check if client is running' ) + assert(Sessions.thread_client_exists?(client_id1), 'check if client is running') + assert(Sessions.thread_client_exists?(client_id2), 'check if client is running') + assert(Sessions.thread_client_exists?(client_id3), 'check if client is running') # check if session still exists after idle cleanup sleep 8 client_ids = Sessions.destory_idle_sessions(5) # check client sessions - assert( !Sessions.session_exists?(client_id1), 'check if session is removed' ) - assert( !Sessions.session_exists?(client_id2), 'check if session is removed' ) - assert( !Sessions.session_exists?(client_id3), 'check if session is removed' ) + assert(!Sessions.session_exists?(client_id1), 'check if session is removed') + assert(!Sessions.session_exists?(client_id2), 'check if session is removed') + assert(!Sessions.session_exists?(client_id3), 'check if session is removed') sleep 10 # check client threads - assert( !Sessions.thread_client_exists?(client_id1), 'check if client is running' ) - assert( !Sessions.thread_client_exists?(client_id2), 'check if client is running' ) - assert( !Sessions.thread_client_exists?(client_id3), 'check if client is running' ) + assert(!Sessions.thread_client_exists?(client_id1), 'check if client is running') + assert(!Sessions.thread_client_exists?(client_id2), 'check if client is running') + assert(!Sessions.thread_client_exists?(client_id3), 'check if client is running') # exit jobs jobs.exit @@ -176,7 +176,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase test 'b check client and backends' do # create users - roles = Role.where( name: [ 'Agent'] ) + roles = Role.where(name: ['Agent']) groups = Group.all UserInfo.current_user_id = 1 @@ -204,7 +204,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase ) agent2.roles = roles agent2.save - org = Organization.create( name: 'SomeOrg::' + rand(999_999).to_s, active: true ) + org = Organization.create(name: 'SomeOrg::' + rand(999_999).to_s, active: true) # create sessions client_id1_0 = '1234-1' @@ -219,16 +219,16 @@ class SessionEnhancedTest < ActiveSupport::TestCase Sessions.jobs } sleep 5 - Sessions.create( client_id1_0, agent1.attributes, { type: 'websocket' } ) + Sessions.create(client_id1_0, agent1.attributes, { type: 'websocket' }) sleep 6.5 - Sessions.create( client_id1_1, agent1.attributes, { type: 'websocket' } ) + Sessions.create(client_id1_1, agent1.attributes, { type: 'websocket' }) sleep 3.2 - Sessions.create( client_id2, agent2.attributes, { type: 'ajax' } ) + Sessions.create(client_id2, agent2.attributes, { type: 'ajax' }) # check if session exists - assert( Sessions.session_exists?(client_id1_0), 'check if session exists' ) - assert( Sessions.session_exists?(client_id1_1), 'check if session exists' ) - assert( Sessions.session_exists?(client_id2), 'check if session exists' ) + assert(Sessions.session_exists?(client_id1_0), 'check if session exists') + assert(Sessions.session_exists?(client_id1_1), 'check if session exists') + assert(Sessions.session_exists?(client_id2), 'check if session exists') sleep 11 # check collections @@ -282,9 +282,9 @@ class SessionEnhancedTest < ActiveSupport::TestCase client_ids = Sessions.destory_idle_sessions(5) # check client sessions - assert( !Sessions.session_exists?(client_id1_0), 'check if session is removed' ) - assert( !Sessions.session_exists?(client_id1_1), 'check if session is removed' ) - assert( !Sessions.session_exists?(client_id2), 'check if session is removed' ) + assert(!Sessions.session_exists?(client_id1_0), 'check if session is removed') + assert(!Sessions.session_exists?(client_id1_1), 'check if session is removed') + assert(!Sessions.session_exists?(client_id2), 'check if session is removed') end diff --git a/test/unit/user_device_test.rb b/test/unit/user_device_test.rb index 33975e783..d9fa244ab 100644 --- a/test/unit/user_device_test.rb +++ b/test/unit/user_device_test.rb @@ -21,7 +21,7 @@ class UserDeviceTest < ActiveSupport::TestCase ) end - test 'session test' do + test 'aaa - session test' do # signin with fingerprint A from country A via session -> new device #1 user_device1 = UserDevice.add( @@ -84,7 +84,7 @@ class UserDeviceTest < ActiveSupport::TestCase end - test 'session test - user agent (unknown)' do + test 'bbb - session test - user agent (unknown)' do # known user agent user_device1 = UserDevice.add( @@ -118,8 +118,8 @@ class UserDeviceTest < ActiveSupport::TestCase 'session', ) assert_equal('Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H143 Safari/600.1.4', user_device3.user_agent) - assert_equal('iPhone', user_device3.browser) - assert_equal('iPhone', user_device3.name) + assert_equal('Safari', user_device3.browser) + assert_equal('Ios, Safari', user_device3.name) user_device4 = UserDevice.add( 'Mac+OS+X/10.10.5 (14F27) CalendarAgent/316.1', @@ -130,11 +130,11 @@ class UserDeviceTest < ActiveSupport::TestCase ) assert_equal('Mac+OS+X/10.10.5 (14F27) CalendarAgent/316.1', user_device4.user_agent) assert_equal('Mac+OS+X/10.10.5 (14F27) CalendarAgent/316.1', user_device4.browser) - assert_equal('Mac+OS+X/10.10.5 (14F27) CalendarAgent/316.1', user_device4.name) + assert_equal('Mac, Mac+OS+X/10.10.5 (14F27) CalendarAgent/316.1', user_device4.name) end - test 'api test' do + test 'ccc - api test' do # signin with ua from country A via basic auth -> new device #1 user_device1 = UserDevice.add(