From 7bf4f3e91cc1a17f0357f5e83f7a799bbf61cefb Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 1 Mar 2015 19:30:14 +0100 Subject: [PATCH] Improved permanent task handling (check if controller need authentication first). --- .../app/controllers/dashboard.js.coffee | 11 ++--- .../app/controllers/ticket_overview.js.coffee | 13 +++--- .../app/lib/app_post/task_manager.js.coffee | 45 ++++++++++--------- .../agent_ticket_overview_level0_test.rb | 6 +-- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/app/assets/javascripts/app/controllers/dashboard.js.coffee b/app/assets/javascripts/app/controllers/dashboard.js.coffee index 8ab077c65..6a69bb761 100644 --- a/app/assets/javascripts/app/controllers/dashboard.js.coffee +++ b/app/assets/javascripts/app/controllers/dashboard.js.coffee @@ -1,11 +1,7 @@ class App.Dashboard extends App.Controller - constructor: -> super - # check authentication - return if !@authenticate() - if @isRole('Customer') @navigate '#' return @@ -158,6 +154,9 @@ class DashboardRouter extends App.ControllerPermanent constructor: (params) -> super + # check authentication + return if !@authenticate() + App.TaskManager.execute( key: 'Dashboard' controller: 'Dashboard' @@ -166,8 +165,6 @@ class DashboardRouter extends App.ControllerPermanent persistent: true ) - App.Config.set( 'dashboard', DashboardRouter, 'Routes' ) App.Config.set( 'Dashboard', { prio: 100, parent: '', name: 'Dashboard', target: '#dashboard', role: ['Agent'], class: 'dashboard' }, 'NavBar' ) - -App.Config.set( 'Dashboard', 'Dashboard', 'permanentTask' ) +App.Config.set( 'Dashboard', { controller: 'Dashboard', authentication: true }, 'permanentTask' ) diff --git a/app/assets/javascripts/app/controllers/ticket_overview.js.coffee b/app/assets/javascripts/app/controllers/ticket_overview.js.coffee index e045fe4f6..810ebb939 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.js.coffee @@ -2,9 +2,6 @@ class App.TicketOverview extends App.Controller constructor: -> super - # check authentication - return if !@authenticate() - @render() render: -> @@ -515,7 +512,7 @@ class App.OverviewSettings extends App.ControllerModal constructor: -> super @overview = App.Overview.find(@overview_id) - console.log('overview_id', @overview_id) + @configure_attributes_article = [] if @view_mode is 'd' @configure_attributes_article.push({ @@ -795,6 +792,9 @@ class TicketOverviewRouter extends App.ControllerPermanent constructor: (params) -> super + # check authentication + return if !@authenticate() + # cleanup params clean_params = view: params.view @@ -809,8 +809,5 @@ class TicketOverviewRouter extends App.ControllerPermanent App.Config.set( 'ticket/view', TicketOverviewRouter, 'Routes' ) App.Config.set( 'ticket/view/:view', TicketOverviewRouter, 'Routes' ) -#App.Config.set( 'ticket/view/:view/:position/:direction', Router, 'Routes' ) - -App.Config.set( 'TicketOverview', 'TicketOverview', 'permanentTask' ) - +App.Config.set( 'TicketOverview', { controller: 'TicketOverview', authentication: true }, 'permanentTask' ) App.Config.set( 'TicketOverview', { prio: 1000, parent: '', name: 'Overviews', target: '#ticket/view', role: ['Agent', 'Customer'], class: 'overviews' }, 'NavBar' ) diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee index df2e057ef..088af5e25 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee @@ -80,6 +80,7 @@ class _taskManagerSingleton extends Spine.Module App.Event.bind( 'auth:login' => + @reset() @tasksInitial() 'task' ) @@ -202,7 +203,7 @@ class _taskManagerSingleton extends Spine.Module startController: (params) => - @log 'debug', 'controller start try...', params + #console.log 'debug', 'controller start try...', params # create clean params params_app = _.clone(params.params) @@ -444,31 +445,33 @@ class _taskManagerSingleton extends Spine.Module App.Event.trigger 'taskbar:init' # initial load of permanent tasks - task_count = 0 - permanentTask = App.Config.get( 'permanentTask' ) + authentication = App.Session.get('id') + permanentTask = App.Config.get( 'permanentTask' ) + task_count = 0 if permanentTask - for key, callback of permanentTask - task_count += 1 - do (task) => - App.Delay.set( - => - @execute( - key: key - controller: callback - params: {} - show: false - persistent: true - init: true - ) - task_count * 50 - undefined - 'task' - ) + for key, config of permanentTask + if !config.authentication || ( config.authentication && authentication ) + task_count += 1 + do (key, config, task_count) => + App.Delay.set( + => + @execute( + key: key + controller: config.controller + params: {} + show: false + persistent: true + init: true + ) + task_count * 350 + undefined + 'task' + ) # initial load of taskbar collection for task in @allTasks task_count += 1 - do (task) => + do (task, task_count) => App.Delay.set( => @execute( diff --git a/test/browser/agent_ticket_overview_level0_test.rb b/test/browser/agent_ticket_overview_level0_test.rb index 6829f4003..f8f54f486 100644 --- a/test/browser/agent_ticket_overview_level0_test.rb +++ b/test/browser/agent_ticket_overview_level0_test.rb @@ -30,10 +30,10 @@ class AgentTicketOverviewLevel0Test < TestCase :body => 'overview count test #3', } ) - + sleep 6 # till overview is updated click( :css => '#navigation li.overviews a' ) click( :css => '.content.active .sidebar a[href="#ticket/view/all_unassigned"]' ) - sleep 10 + sleep 2 # till overview is rendered # select both via bulk action click( @@ -62,7 +62,7 @@ class AgentTicketOverviewLevel0Test < TestCase click( :css => '.active .bulkAction .js-submit', ) - sleep 6 + sleep 8 exists_not( :css => '.active table tr td input[value="' + ticket1[:id] + '"]',