diff --git a/app/assets/javascripts/app/controllers/_ui_element/permission.coffee b/app/assets/javascripts/app/controllers/_ui_element/permission.coffee index 6c8b87543..96c996467 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/permission.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/permission.coffee @@ -1,6 +1,6 @@ # coffeelint: disable=camel_case_classes class App.UiElement.permission extends App.UiElement.ApplicationUiElement - @render: (attribute, params) -> + @render: (attribute, params = {}) -> permissions = App.Permission.search(sortBy: 'name') diff --git a/app/assets/javascripts/app/controllers/clues.coffee b/app/assets/javascripts/app/controllers/clues.coffee index 5e9e875b7..735a6329d 100644 --- a/app/assets/javascripts/app/controllers/clues.coffee +++ b/app/assets/javascripts/app/controllers/clues.coffee @@ -11,11 +11,11 @@ class Index extends App.Controller App.Ajax.request( id: 'preferences' type: 'PUT' - url: @apiPath + '/users/preferences' + url: "#{@apiPath}/users/preferences" data: JSON.stringify({user:{intro:true}}) processData: true ) @navigate '#' ) -App.Config.set( 'clues', Index, 'Routes' ) +App.Config.set('clues', Index, 'Routes') diff --git a/app/assets/javascripts/app/controllers/dashboard.coffee b/app/assets/javascripts/app/controllers/dashboard.coffee index c87361840..7da78d6ff 100644 --- a/app/assets/javascripts/app/controllers/dashboard.coffee +++ b/app/assets/javascripts/app/controllers/dashboard.coffee @@ -7,7 +7,7 @@ class App.Dashboard extends App.Controller constructor: -> super - if @permissionCheck('ticket.customer') + if !@permissionCheck('ticket.agent') @clueAccess = false return diff --git a/app/assets/javascripts/app/controllers/manage.coffee b/app/assets/javascripts/app/controllers/manage.coffee index 5ab127c7d..23b2cb5fb 100644 --- a/app/assets/javascripts/app/controllers/manage.coffee +++ b/app/assets/javascripts/app/controllers/manage.coffee @@ -10,7 +10,7 @@ App.Config.set('channels/:target/:channel_id', IndexRouter, 'Routes') App.Config.set('system/:target', IndexRouter, 'Routes') App.Config.set('system/:target/:integration', IndexRouter, 'Routes') -App.Config.set('Manage', { prio: 1000, name: 'Manage', target: '#manage', role: ['Admin'] }, 'NavBarAdmin') -App.Config.set('Channels', { prio: 2500, name: 'Channels', target: '#channels', role: ['Admin'] }, 'NavBarAdmin') -App.Config.set('Settings', { prio: 7000, name: 'Settings', target: '#settings', role: ['Admin'] }, 'NavBarAdmin') -App.Config.set('System', { prio: 8000, name: 'System', target: '#system', role: ['Admin'] }, 'NavBarAdmin') +App.Config.set('Manage', { prio: 1000, name: 'Manage', target: '#manage', permission: ['admin.*'] }, 'NavBarAdmin') +App.Config.set('Channels', { prio: 2500, name: 'Channels', target: '#channels', permission: ['admin.*'] }, 'NavBarAdmin') +App.Config.set('Settings', { prio: 7000, name: 'Settings', target: '#settings', permission: ['admin.*'] }, 'NavBarAdmin') +App.Config.set('System', { prio: 8000, name: 'System', target: '#system', permission: ['admin.*'] }, 'NavBarAdmin') diff --git a/app/assets/javascripts/app/controllers/navigation.coffee b/app/assets/javascripts/app/controllers/navigation.coffee index d951aab98..610c93e0b 100644 --- a/app/assets/javascripts/app/controllers/navigation.coffee +++ b/app/assets/javascripts/app/controllers/navigation.coffee @@ -406,7 +406,7 @@ class App.Navigation extends App.ControllerWidgetPermanent recentViewNavbarItemsRebuild: => # remove old views - NavBarRight = @Config.get( 'NavBarRight' ) || {} + NavBarRight = @Config.get('NavBarRight') || {} for key of NavBarRight if NavBarRight[key].parent is '#current_user' part = key.split '::' diff --git a/app/assets/javascripts/app/controllers/role.coffee b/app/assets/javascripts/app/controllers/role.coffee new file mode 100644 index 000000000..1c280f8a8 --- /dev/null +++ b/app/assets/javascripts/app/controllers/role.coffee @@ -0,0 +1,25 @@ +class Index extends App.ControllerContent + requiredPermission: 'admin.role' + constructor: -> + super + + new App.ControllerGenericIndex( + el: @el + id: @id + genericObject: 'Role' + pageData: + title: 'Roles' + home: 'roles' + object: 'Role' + objects: 'Roles' + navupdate: '#roles' + notes: [ + 'Roles are ...' + ] + buttons: [ + { name: 'New Role', 'data-type': 'new', class: 'btn--success' } + ] + container: @el.closest('.content') + ) + +App.Config.set('Role', { prio: 1600, name: 'Roles', parent: '#manage', target: '#manage/roles', controller: Index, permission: ['admin.role'] }, 'NavBarAdmin') diff --git a/app/assets/javascripts/app/models/user.coffee b/app/assets/javascripts/app/models/user.coffee index 30dd4662e..b5237eaa9 100644 --- a/app/assets/javascripts/app/models/user.coffee +++ b/app/assets/javascripts/app/models/user.coffee @@ -172,6 +172,8 @@ class App.User extends App.Model result = user.permission('user_preferences.calendar+ticket.agent') # access must have two permission keys + result = user.permission('admin.*') # access if one sub key access exists + returns true|false @@ -190,9 +192,10 @@ class App.User extends App.Model permissions = {} for role_id in @role_ids role = App.Role.find(role_id) - for permission_id in role.permission_ids - permission = App.Permission.find(permission_id) - permissions[permission.name] = true + if role.active is true + for permission_id in role.permission_ids + permission = App.Permission.find(permission_id) + permissions[permission.name] = true for localKey in keys requiredPermissions = localKey.split('+') @@ -200,12 +203,25 @@ class App.User extends App.Model for requiredPermission in requiredPermissions localAccess = false partString = '' - for part in requiredPermission.split('.') - if partString isnt '' - partString += '.' - partString += part - if permissions[partString] - localAccess = true + parts = requiredPermission.split('.') + + # verify name.* permissions + if parts[parts.length - 1] is '*' + for permission_key, permission_value of permissions + if permission_value is true + length = requiredPermission.length - 1 + if permission_key.substr(0, length) is requiredPermission.substr(0, length) + localAccess = true + + # verify name.explicite permissions + if !localAccess + for part in parts + if partString isnt '' + partString += '.' + partString += part + if permissions[partString] + localAccess = true + if localAccess access = true else diff --git a/app/assets/javascripts/app/views/generic/navbar_level2/navbar.jst.eco b/app/assets/javascripts/app/views/generic/navbar_level2/navbar.jst.eco index 17ab75490..9e23a08c9 100644 --- a/app/assets/javascripts/app/views/generic/navbar_level2/navbar.jst.eco +++ b/app/assets/javascripts/app/views/generic/navbar_level2/navbar.jst.eco @@ -1,12 +1,14 @@ <% if @groups: %> <% for group in @groups: %> -

<%- @T(group.name) %>

- + <% if !_.isEmpty(group.items): %> +

<%- @T(group.name) %>

+ + <% end %> <% end %> <% end %> diff --git a/app/assets/javascripts/app/views/generic/permission.jst.eco b/app/assets/javascripts/app/views/generic/permission.jst.eco index a8ebe892d..4ebbce9b3 100644 --- a/app/assets/javascripts/app/views/generic/permission.jst.eco +++ b/app/assets/javascripts/app/views/generic/permission.jst.eco @@ -2,7 +2,7 @@ <% for permission in @permissions: %> <% if !permission.name.match(/\./): %>