Fixes #3437 - Agent role permissions are ignored when there is only a single group.

This commit is contained in:
Rolf Schmidt 2021-10-20 13:02:52 +02:00
parent 3cf7b79edc
commit 191385714b
5 changed files with 7 additions and 70 deletions

View file

@ -46,11 +46,6 @@ class App.UiElement.user_permission
if group_id.toString() is group.id.toString()
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
rolesWithGroupPlugin = {}
for role in rolesRaw
@ -76,7 +71,6 @@ class App.UiElement.user_permission
groups: groups
params: params
groupsSelected: groupsSelected
hideGroups: hideGroups
groupAccesses: App.Group.accesses()
) )
@ -95,12 +89,12 @@ class App.UiElement.user_permission
# if customer, remove admin and agent
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
@checkUncheck: (element, rolesWithGroupPlugin, item, hideGroups) ->
@checkUncheck: (element, rolesWithGroupPlugin, item) ->
checked = element.prop('checked')
role_id = element.prop('value')
return if !role_id
@ -122,33 +116,5 @@ class App.UiElement.user_permission
item.localElement.prop('checked', false)
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
trigger.trigger('change')

View file

@ -18,7 +18,7 @@
<span class="help-text"><%- @T.apply(@, [permission.note].concat(permission.preferences.translations)) %></span>
</label>
<% 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">
<thead>
<th><%- @T('Group') %>

View file

@ -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>
<table class="settings-list" style="width: 100%;">
<thead>

View file

@ -149,6 +149,7 @@ class AaaGettingStartedTest < TestCase
# click(
# css: '.js-agent input[name="group_ids"][value="1"]',
# )
check(css: '.js-agent .js-groupListItem[value=full]')
click(
css: '.js-agent .btn--success',
)

View file

@ -58,13 +58,7 @@ class AgentTicketActionLevel0Test < TestCase
css: '.modal [name="email"]',
value: "#{agent}@example.com",
)
exists(
displayed: false,
css: '.modal .js-groupList',
)
exists(
css: '.modal .js-groupListItem[value=full]:checked',
)
check(css: '.modal .js-groupListItem[value=full]')
click(
css: '.modal button.btn.btn--primary',
fast: true,
@ -99,31 +93,7 @@ class AgentTicketActionLevel0Test < TestCase
value: "#{agent}2@example.com",
)
# disable agent role
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',
)
check(css: '.modal .js-groupListItem[value=full]')
click(
css: '.modal button.btn.btn--primary',