Fixed issue #2273 - Bulk Form javascript error when checking item (fixes #2273)

This commit is contained in:
Billy Zhou 2018-10-12 16:28:37 +08:00
parent 6439203900
commit b1caed65f5
6 changed files with 36 additions and 14 deletions

View file

@ -73,7 +73,7 @@ class Index extends App.ControllerSubContent
user_group_config = false user_group_config = false
groups = [] groups = []
group_ids = App.User.find(@Session.get('id')).all_group_ids() group_ids = App.User.find(@Session.get('id')).allGroupIds()
if group_ids if group_ids
for group_id in group_ids for group_id in group_ids
group = App.Group.find(group_id) group = App.Group.find(group_id)

View file

@ -1222,9 +1222,9 @@ class Table extends App.Controller
ticket_ids = _.map(items, (el) -> $(el).val() ) ticket_ids = _.map(items, (el) -> $(el).val() )
ticket_group_ids = _.map(App.Ticket.findAll(ticket_ids), (ticket) -> ticket.group_id) ticket_group_ids = _.map(App.Ticket.findAll(ticket_ids), (ticket) -> ticket.group_id)
ticket_group_ids = _.uniq(ticket_group_ids) ticket_group_ids = _.uniq(ticket_group_ids)
user_permissions = App.Session.get('group_ids') allowed_group_ids = App.User.find(@Session.get('id')).allGroupIds('change')
group_permissions = ticket_group_ids.map (id) -> user_permissions[id] allowed_group_ids = _.map(allowed_group_ids, (id_string) -> parseInt(id_string, 10) )
_.every(group_permissions, (list) -> 'full' in list || 'change' in list) _.every(ticket_group_ids, (id) -> id in allowed_group_ids)
viewmode: (e) => viewmode: (e) =>
e.preventDefault() e.preventDefault()

View file

@ -249,7 +249,7 @@ class App.Ticket extends App.Model
user_id = App.Session.get('id') user_id = App.Session.get('id')
return true if user_id is @customer_id return true if user_id is @customer_id
return false if !App.User.exists(user_id) return false if !App.User.exists(user_id)
group_ids = App.User.find(user_id).all_group_ids(permission) group_ids = App.User.find(user_id).allGroupIds(permission)
for local_group_id in group_ids for local_group_id in group_ids
if local_group_id.toString() is @group_id.toString() if local_group_id.toString() is @group_id.toString()
return true return true

View file

@ -254,7 +254,19 @@ class App.User extends App.Model
return access if access return access if access
false false
all_group_ids: (permission = 'full') -> ###
Returns a list of all groups for which the user is permitted to perform the given permission key
user = App.User.find(3)
result = user.allGroupIds('change') # access to a given permission key
returns
["1", "2"]
###
allGroupIds: (permission = 'full') ->
group_ids = [] group_ids = []
user_group_ids = App.Session.get('group_ids') user_group_ids = App.Session.get('group_ids')
if user_group_ids if user_group_ids

View file

@ -485,11 +485,12 @@ class AgentTicketOverviewLevel0Test < TestCase
}, },
) )
click( role_edit(
css: 'a[href="#manage"]', data: {
) name: 'Agent',
click( group_permissions: { 2 => ['full'],
css: '.content.active a[href="#manage/groups"]', 3 => ['full'], }
},
) )
user_edit( user_edit(
@ -508,9 +509,7 @@ class AgentTicketOverviewLevel0Test < TestCase
email: 'agent2@example.com', email: 'agent2@example.com',
password: 'test', password: 'test',
role: 'Agent', role: 'Agent',
permissions: { 1 => %w[read create overview], permissions: { 1 => %w[read create overview] }
2 => ['full'],
3 => ['full'], }
}, },
) )

View file

@ -3816,6 +3816,17 @@ wait untill text in selector disabppears
end end
end end
if data.key?(:group_permissions)
data[:group_permissions].each do |key, value|
value.each do |permission|
check(
browser: instance,
css: ".modal input[name=\"group_ids::#{key}\"][value=\"#{permission}\"]",
)
end
end
end
if data.key?(:active) if data.key?(:active)
element = instance.find_elements(css: '.modal select[name="active"]')[0] element = instance.find_elements(css: '.modal select[name="active"]')[0]
dropdown = Selenium::WebDriver::Support::Select.new(element) dropdown = Selenium::WebDriver::Support::Select.new(element)