Fixed permission check with ticket.agent lookup.

This commit is contained in:
Martin Edenhofer 2017-10-20 10:58:02 +02:00
parent a0e0dfcc3a
commit 93345553ad
2 changed files with 47 additions and 1 deletions

View file

@ -303,7 +303,7 @@ module HasGroups
instances = joins(group_through.name)
.where( group_through.table_name => { group_id: group_id, access: access }, active: true )
if respond_to?(:permissions?)
if method_defined?(:permissions?)
permissions = Permission.with_parents('ticket.agent')
instances = instances
.joins(roles: :permissions)

View file

@ -866,4 +866,50 @@ class UserTest < ActiveSupport::TestCase
assert_equal(1, admin_count_inital)
end
test 'only valid agent in group permission check' do
name = rand(999_999_999)
group = Group.create!(
name: "ValidAgentGroupPermission-#{name}",
active: true,
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Agent')
agent1 = User.create_or_update(
login: "agent-default-vaild_agent_group_permission-1#{name}@example.com",
firstname: 'vaild_agent_group_permission-1',
lastname: "Agent#{name}",
email: "agent-default-vaild_agent_group_permission-1#{name}@example.com",
password: 'agentpw',
active: true,
roles: roles,
groups: [group],
updated_by_id: 1,
created_by_id: 1,
)
agent2 = User.create_or_update(
login: "agent-default-vaild_agent_group_permission-2#{name}@example.com",
firstname: 'vaild_agent_group_permission-2',
lastname: "Agent#{name}",
email: "agent-default-vaild_agent_group_permission-2#{name}@example.com",
password: 'agentpw',
active: true,
roles: roles,
groups: [group],
updated_by_id: 1,
created_by_id: 1,
)
assert_equal(2, User.group_access(group.id, 'full').count)
agent2.active = false
agent2.save!
assert_equal(1, User.group_access(group.id, 'full').count)
agent2.active = true
agent2.save!
assert_equal(2, User.group_access(group.id, 'full').count)
roles = Role.where(name: 'Customer')
agent2.roles = roles
agent2.save!
assert_equal(1, User.group_access(group.id, 'full').count)
end
end