From 3ea96e6f84bdca21d8b3555ad7c408976df0992e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 18 Aug 2016 07:24:58 +0200 Subject: [PATCH] Added permission config support for permanent tasks. --- app/assets/javascripts/app/controllers/chat.coffee | 2 +- app/assets/javascripts/app/controllers/cti.coffee | 2 +- app/assets/javascripts/app/controllers/dashboard.coffee | 4 +++- app/assets/javascripts/app/controllers/layout_ref.coffee | 4 ++-- .../javascripts/app/controllers/ticket_overview.coffee | 2 +- .../javascripts/app/lib/app_post/task_manager.coffee | 7 +++++-- app/assets/javascripts/app/models/user.coffee | 3 +++ 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index ec8efae01..b1ca174cb 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -770,5 +770,5 @@ class Setting extends App.ControllerModal ) App.Config.set('customer_chat', CustomerChatRouter, 'Routes') -App.Config.set('CustomerChat', { controller: 'CustomerChat', authentication: true }, 'permanentTask') +App.Config.set('CustomerChat', { controller: 'CustomerChat', permission: ['chat.agent'] }, 'permanentTask') App.Config.set('CustomerChat', { prio: 1200, parent: '', name: 'Customer Chat', target: '#customer_chat', key: 'CustomerChat', shown: false, permission: ['chat.agent'], class: 'chat' }, 'NavBar') diff --git a/app/assets/javascripts/app/controllers/cti.coffee b/app/assets/javascripts/app/controllers/cti.coffee index cfea89af1..9b5d4da8f 100644 --- a/app/assets/javascripts/app/controllers/cti.coffee +++ b/app/assets/javascripts/app/controllers/cti.coffee @@ -205,5 +205,5 @@ class CTIRouter extends App.ControllerPermanent ) App.Config.set('cti', CTIRouter, 'Routes') -App.Config.set('CTI', { controller: 'CTI', authentication: true }, 'permanentTask') +App.Config.set('CTI', { controller: 'CTI', permission: ['cti.agent'] }, 'permanentTask') App.Config.set('CTI', { prio: 1300, parent: '', name: 'Phone', target: '#cti', key: 'CTI', shown: false, permission: ['cti.agent'], class: 'phone' }, 'NavBar') diff --git a/app/assets/javascripts/app/controllers/dashboard.coffee b/app/assets/javascripts/app/controllers/dashboard.coffee index 67e97464d..c87361840 100644 --- a/app/assets/javascripts/app/controllers/dashboard.coffee +++ b/app/assets/javascripts/app/controllers/dashboard.coffee @@ -93,6 +93,8 @@ class App.Dashboard extends App.Controller @$(".tab-content.#{target}").removeClass('hidden') class DashboardRouter extends App.ControllerPermanent + requiredPermission: ['*'] + constructor: (params) -> super @@ -108,5 +110,5 @@ class DashboardRouter extends App.ControllerPermanent ) App.Config.set('dashboard', DashboardRouter, 'Routes') +App.Config.set('Dashboard', { controller: 'Dashboard', permission: ['*'] }, 'permanentTask') App.Config.set('Dashboard', { prio: 100, parent: '', name: 'Dashboard', target: '#dashboard', key: 'Dashboard', permission: ['ticket.agent'], class: 'dashboard' }, 'NavBar') -App.Config.set('Dashboard', { controller: 'Dashboard', authentication: true }, 'permanentTask') diff --git a/app/assets/javascripts/app/controllers/layout_ref.coffee b/app/assets/javascripts/app/controllers/layout_ref.coffee index ba262572d..576122660 100644 --- a/app/assets/javascripts/app/controllers/layout_ref.coffee +++ b/app/assets/javascripts/app/controllers/layout_ref.coffee @@ -1908,8 +1908,8 @@ class CustomerChatRef extends App.Controller # ) App.Config.set( 'layout_ref/customer_chat', CustomerChatRef, 'Routes' ) -# App.Config.set( 'CustomerChatRef', { controller: 'CustomerChatRef', authentication: true }, 'permanentTask' ) -# App.Config.set( 'CustomerChatRef', { prio: 1200, parent: '', name: 'Customer Chat', target: '#layout_ref/customer_chat', key: 'CustomerChatRef', role: ['Agent'], class: 'chat' }, 'NavBar' ) +# App.Config.set( 'CustomerChatRef', { controller: 'CustomerChatRef', permission: ['chat.agent'] }, 'permanentTask' ) +# App.Config.set( 'CustomerChatRef', { prio: 1200, parent: '', name: 'Customer Chat', target: '#layout_ref/customer_chat', key: 'CustomerChatRef', permission: ['chat.agent'], class: 'chat' }, 'NavBar' ) class ChatWindowRef extends Spine.Controller @extend Spine.Events diff --git a/app/assets/javascripts/app/controllers/ticket_overview.coffee b/app/assets/javascripts/app/controllers/ticket_overview.coffee index a86a1f9d7..62a13af8b 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.coffee @@ -787,5 +787,5 @@ class TicketOverviewRouter extends App.ControllerPermanent App.Config.set('ticket/view', TicketOverviewRouter, 'Routes') App.Config.set('ticket/view/:view', TicketOverviewRouter, 'Routes') -App.Config.set('TicketOverview', { controller: 'TicketOverview', authentication: true }, 'permanentTask') +App.Config.set('TicketOverview', { controller: 'TicketOverview', permission: ['ticket.agent', 'ticket.customer'] }, 'permanentTask') App.Config.set('TicketOverview', { prio: 1000, parent: '', name: 'Overviews', target: '#ticket/view', key: 'TicketOverview', permission: ['ticket.agent', 'ticket.customer'], class: 'overviews' }, 'NavBar') 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 a0295ce69..c2d646aae 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.coffee @@ -533,12 +533,15 @@ class _taskManagerSingleton extends App.Controller App.Event.trigger 'taskbar:init' # initial load of permanent tasks - authentication = App.Session.get('id') + user_id = App.Session.get('id') + user = undefined + if user_id + user = App.User.find(user_id) permanentTask = App.Config.get('permanentTask') taskCount = 0 if permanentTask for key, config of permanentTask - if !config.authentication || (config.authentication && authentication) + if !config.permission || (user && user.permission(config.permission)) taskCount += 1 do (key, config, taskCount) => App.Delay.set( diff --git a/app/assets/javascripts/app/models/user.coffee b/app/assets/javascripts/app/models/user.coffee index dbea75fa5..30dd4662e 100644 --- a/app/assets/javascripts/app/models/user.coffee +++ b/app/assets/javascripts/app/models/user.coffee @@ -183,6 +183,9 @@ class App.User extends App.Model if !_.isArray(key) keys = [key] + # if any permission exists + return true if _.contains(keys, '*') + # get all permissions of user permissions = {} for role_id in @role_ids