Fixes #3437 - Agent role permissions are ignored when there is only a single group.
This commit is contained in:
parent
3cf7b79edc
commit
191385714b
5 changed files with 7 additions and 70 deletions
|
@ -46,11 +46,6 @@ class App.UiElement.user_permission
|
||||||
if group_id.toString() is group.id.toString()
|
if group_id.toString() is group.id.toString()
|
||||||
groupsSelected[group.id] = true
|
groupsSelected[group.id] = true
|
||||||
|
|
||||||
# if only one group is selectable, hide all groups
|
|
||||||
hideGroups = false
|
|
||||||
if groups.length <= 1
|
|
||||||
hideGroups = true
|
|
||||||
|
|
||||||
# get roles with group plugin
|
# get roles with group plugin
|
||||||
rolesWithGroupPlugin = {}
|
rolesWithGroupPlugin = {}
|
||||||
for role in rolesRaw
|
for role in rolesRaw
|
||||||
|
@ -76,7 +71,6 @@ class App.UiElement.user_permission
|
||||||
groups: groups
|
groups: groups
|
||||||
params: params
|
params: params
|
||||||
groupsSelected: groupsSelected
|
groupsSelected: groupsSelected
|
||||||
hideGroups: hideGroups
|
|
||||||
groupAccesses: App.Group.accesses()
|
groupAccesses: App.Group.accesses()
|
||||||
) )
|
) )
|
||||||
|
|
||||||
|
@ -95,12 +89,12 @@ class App.UiElement.user_permission
|
||||||
|
|
||||||
# if customer, remove admin and agent
|
# if customer, remove admin and agent
|
||||||
item.find('[name=role_ids]').bind('change', (e) =>
|
item.find('[name=role_ids]').bind('change', (e) =>
|
||||||
@checkUncheck($(e.currentTarget), rolesWithGroupPlugin, item, hideGroups)
|
@checkUncheck($(e.currentTarget), rolesWithGroupPlugin, item)
|
||||||
)
|
)
|
||||||
item.find('[name=role_ids]').trigger('change')
|
item.find('[name=role_ids]').trigger('change')
|
||||||
item
|
item
|
||||||
|
|
||||||
@checkUncheck: (element, rolesWithGroupPlugin, item, hideGroups) ->
|
@checkUncheck: (element, rolesWithGroupPlugin, item) ->
|
||||||
checked = element.prop('checked')
|
checked = element.prop('checked')
|
||||||
role_id = element.prop('value')
|
role_id = element.prop('value')
|
||||||
return if !role_id
|
return if !role_id
|
||||||
|
@ -122,33 +116,5 @@ class App.UiElement.user_permission
|
||||||
item.localElement.prop('checked', false)
|
item.localElement.prop('checked', false)
|
||||||
triggers.push item.localElement
|
triggers.push item.localElement
|
||||||
|
|
||||||
# if role with groups plugin is deselected, hide group selection
|
|
||||||
if !checked
|
|
||||||
selectedRoleIds = []
|
|
||||||
item.find('input[name=role_ids]:checked').each( ->
|
|
||||||
selectedRoleIds.push($(@).val())
|
|
||||||
)
|
|
||||||
|
|
||||||
show = false
|
|
||||||
for role_id, group of rolesWithGroupPlugin
|
|
||||||
if _.contains(selectedRoleIds, role_id.toString())
|
|
||||||
show = true
|
|
||||||
break
|
|
||||||
if !show
|
|
||||||
item.find('.js-groupList').addClass('hidden')
|
|
||||||
|
|
||||||
# select groups if only one is available
|
|
||||||
if hideGroups
|
|
||||||
item.find('.js-groupList .js-groupListItem[value=full]').prop('checked', false)
|
|
||||||
return
|
|
||||||
|
|
||||||
# if role with groups plugin is selected, show group selection
|
|
||||||
if rolesWithGroupPlugin[role_id] is 'group'
|
|
||||||
item.find('.js-groupList:not(.js-groupListHide)').removeClass('hidden')
|
|
||||||
|
|
||||||
# select groups if only one is available
|
|
||||||
if hideGroups
|
|
||||||
item.find('.js-groupList .js-groupListItem[value=full]').prop('checked', true)
|
|
||||||
|
|
||||||
for trigger in triggers
|
for trigger in triggers
|
||||||
trigger.trigger('change')
|
trigger.trigger('change')
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<span class="help-text"><%- @T.apply(@, [permission.note].concat(permission.preferences.translations)) %></span>
|
<span class="help-text"><%- @T.apply(@, [permission.note].concat(permission.preferences.translations)) %></span>
|
||||||
</label>
|
</label>
|
||||||
<% if _.contains(permission.preferences.plugin, 'groups'): %>
|
<% if _.contains(permission.preferences.plugin, 'groups'): %>
|
||||||
<div style="padding-left: 18px; padding-top: 10px;" class="js-groupList <% if @hideGroups: %>js-groupListHide hidden<% end %>">
|
<div style="padding-left: 18px; padding-top: 10px;" class="js-groupList">
|
||||||
<table class="settings-list">
|
<table class="settings-list">
|
||||||
<thead>
|
<thead>
|
||||||
<th><%- @T('Group') %>
|
<th><%- @T('Group') %>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<div style="padding-left: 18px; padding-top: 10px; width: 95%;" class="js-groupList <% if @hideGroups: %>js-groupListHide hidden<% end %>">
|
<div style="padding-left: 18px; padding-top: 10px; width: 95%;" class="js-groupList">
|
||||||
<hr>
|
<hr>
|
||||||
<table class="settings-list" style="width: 100%;">
|
<table class="settings-list" style="width: 100%;">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
|
@ -149,6 +149,7 @@ class AaaGettingStartedTest < TestCase
|
||||||
# click(
|
# click(
|
||||||
# css: '.js-agent input[name="group_ids"][value="1"]',
|
# css: '.js-agent input[name="group_ids"][value="1"]',
|
||||||
# )
|
# )
|
||||||
|
check(css: '.js-agent .js-groupListItem[value=full]')
|
||||||
click(
|
click(
|
||||||
css: '.js-agent .btn--success',
|
css: '.js-agent .btn--success',
|
||||||
)
|
)
|
||||||
|
|
|
@ -58,13 +58,7 @@ class AgentTicketActionLevel0Test < TestCase
|
||||||
css: '.modal [name="email"]',
|
css: '.modal [name="email"]',
|
||||||
value: "#{agent}@example.com",
|
value: "#{agent}@example.com",
|
||||||
)
|
)
|
||||||
exists(
|
check(css: '.modal .js-groupListItem[value=full]')
|
||||||
displayed: false,
|
|
||||||
css: '.modal .js-groupList',
|
|
||||||
)
|
|
||||||
exists(
|
|
||||||
css: '.modal .js-groupListItem[value=full]:checked',
|
|
||||||
)
|
|
||||||
click(
|
click(
|
||||||
css: '.modal button.btn.btn--primary',
|
css: '.modal button.btn.btn--primary',
|
||||||
fast: true,
|
fast: true,
|
||||||
|
@ -99,31 +93,7 @@ class AgentTicketActionLevel0Test < TestCase
|
||||||
value: "#{agent}2@example.com",
|
value: "#{agent}2@example.com",
|
||||||
)
|
)
|
||||||
|
|
||||||
# disable agent role
|
check(css: '.modal .js-groupListItem[value=full]')
|
||||||
uncheck(
|
|
||||||
css: '.modal [name="role_ids"][value=2]',
|
|
||||||
)
|
|
||||||
|
|
||||||
exists(
|
|
||||||
displayed: false,
|
|
||||||
css: '.modal .js-groupList',
|
|
||||||
)
|
|
||||||
exists_not(
|
|
||||||
css: '.modal .js-groupListItem[value=full]:checked',
|
|
||||||
)
|
|
||||||
|
|
||||||
# enable agent role
|
|
||||||
check(
|
|
||||||
css: '.modal [name="role_ids"][value=2]',
|
|
||||||
)
|
|
||||||
|
|
||||||
exists(
|
|
||||||
displayed: false,
|
|
||||||
css: '.modal .js-groupList',
|
|
||||||
)
|
|
||||||
exists(
|
|
||||||
css: '.modal .js-groupListItem[value=full]:checked',
|
|
||||||
)
|
|
||||||
|
|
||||||
click(
|
click(
|
||||||
css: '.modal button.btn.btn--primary',
|
css: '.modal button.btn.btn--primary',
|
||||||
|
|
Loading…
Reference in a new issue