Fixed issue #1864 - Bulk-Action: Not possible to change owner (fixes #1864)

This commit is contained in:
Billy Zhou 2018-08-06 21:02:16 +08:00
parent 4ec3f1324d
commit 9c600bbfe5
3 changed files with 170 additions and 0 deletions

View file

@ -1089,6 +1089,7 @@ class Table extends App.Controller
if @$('table').find('input[name="bulk"]:checked').length == 0 if @$('table').find('input[name="bulk"]:checked').length == 0
@bulkForm.hide() @bulkForm.hide()
else else
@bulkForm.render()
@bulkForm.show() @bulkForm.show()
if @lastChecked && e.shiftKey if @lastChecked && e.shiftKey
@ -1266,6 +1267,10 @@ class BulkForm extends App.Controller
handlers = @Config.get('TicketZoomFormHandler') handlers = @Config.get('TicketZoomFormHandler')
for attribute in @configure_attributes_ticket
continue if attribute.name != 'owner_id'
attribute.alt_options = @userOptionsForSelection()
new App.ControllerForm( new App.ControllerForm(
el: @$('#form-ticket-bulk') el: @$('#form-ticket-bulk')
model: model:
@ -1302,6 +1307,31 @@ class BulkForm extends App.Controller
noFieldset: true noFieldset: true
) )
userOptionsForSelection: =>
items = $('.content.active .table-overview .table').find('[name="bulk"]:checked')
# we want to display all users for which we can assign the tickets directly
# for this we need to get the groups of all selected tickets
# after we got those we need to check which users are available in all groups
# users that are not in all groups can't get the tickets assigned
ticket_ids = _.map(items, (el) -> $(el).val() )
ticket_group_ids = _.map(App.Ticket.findAll(ticket_ids), (ticket) -> ticket.group_id)
users = @usersInGroups(ticket_group_ids)
users.map( (user) -> {value: user.id, name: user.displayName()} )
usersInGroups: (group_ids) ->
ids_by_group = _.chain(@formMeta?.dependencies?.group_id)
.pick(group_ids)
.values()
.map( (e) -> e.owner_id)
.value()
# Underscore's intersection doesn't work when chained
ids_in_all_groups = _.intersection(ids_by_group...)
users = App.User.findAll(ids_in_all_groups)
_.sortBy(users, (user) -> user.firstname)
articleTypeFilter: (items) -> articleTypeFilter: (items) ->
for item in items for item in items
if item.name is 'note' if item.name is 'note'

View file

@ -0,0 +1,26 @@
class OwnerFormHandlerDependencies
# central method, is getting called on every ticket form change
@run: (params, attribute, attributes, classname, form, ui) ->
return if 'group_id' not of params || 'owner_id' not of params
owner_attribute = _.find(attributes, (o) -> o.name == 'owner_id')
return if !owner_attribute
return if 'alt_options' not of owner_attribute
if !params.group_id
# if no group is chosen, then we use the alt_options to populate the owner_id field
owner_attribute.options = owner_attribute.alt_options
delete owner_attribute['relation']
else
# if a group is chosen, then populate owner_id using attribute.relation
owner_attribute.relation = 'User'
delete owner_attribute['options']
# replace new option list
owner_attribute.default = params[owner_attribute.name]
owner_attribute.newValue = params[owner_attribute.name]
newElement = ui.formGenItem(owner_attribute, classname, form)
form.find('select[name="owner_id"]').closest('.form-group').replaceWith(newElement)
App.Config.set('150-ticketFormChanges', OwnerFormHandlerDependencies, 'TicketZoomFormHandler')

View file

@ -365,4 +365,118 @@ class AgentTicketOverviewLevel0Test < TestCase
# cleanup # cleanup
tasks_close_all() tasks_close_all()
end end
# verify correct behaviour for issue #1864 - Bulk-Action: Not possible to change owner
def test_bulk_owner_change
@browser = browser_instance
login(
username: 'master@example.com',
password: 'test',
url: browser_url,
)
tasks_close_all()
# test bulk action
# create new ticket
ticket1 = ticket_create(
data: {
customer: 'nico',
group: 'Users',
title: 'overview owner change test #1',
body: 'overview owner change #1',
}
)
ticket2 = ticket_create(
data: {
customer: 'nico',
group: 'Users',
title: 'overview owner change #2',
body: 'overview owner change #2',
}
)
# open Overview menu tab
click(
css: '.js-menu .js-overviewsMenuItem',
)
# enable full overviews
execute(
js: '$(".content.active .sidebar").css("display", "block")',
)
# click Unassigned & Open tab
click(
css: '.content.active [href="#ticket/view/all_unassigned"]',
)
watch_for(
css: '.content.active',
value: 'overview owner change #2',
timeout: 8,
)
# remember current overview count
overview_counter_before = overview_counter()
# select both via bulk action
click(
css: '.content.active table tr td input[value="' + ticket1[:id] + '"] + .icon-checkbox.icon-unchecked',
fast: true,
)
# scroll to reply - needed for chrome
scroll_to(
position: 'top',
css: '.content.active table tr td input[value="' + ticket2[:id] + '"] + .icon-checkbox.icon-unchecked',
)
click(
css: '.content.active table tr td input[value="' + ticket2[:id] + '"] + .icon-checkbox.icon-unchecked',
fast: true,
)
exists(
css: '.content.active table tr td input[value="' + ticket1[:id] + '"][type="checkbox"]:checked',
)
exists(
css: '.content.active table tr td input[value="' + ticket2[:id] + '"][type="checkbox"]:checked',
)
select(
css: '.content.active .bulkAction [name="owner_id"]',
value: 'Test Master Agent',
)
select(
css: '.content.active .bulkAction [name="state_id"]',
value: 'closed',
)
click(
css: '.content.active .bulkAction .js-confirm',
)
click(
css: '.content.active .bulkAction .js-submit',
)
watch_for_disappear(
css: '.content.active table tr td input[value="' + ticket2[:id] + '"]',
timeout: 12,
)
exists_not(
css: '.content.active table tr td input[value="' + ticket1[:id] + '"]',
)
exists_not(
css: '.content.active table tr td input[value="' + ticket2[:id] + '"]',
)
# get new overview count
overview_counter_new = overview_counter()
assert_equal(overview_counter_before['#ticket/view/all_unassigned'] - 2, overview_counter_new['#ticket/view/all_unassigned'])
# cleanup
tasks_close_all()
end
end end