Fixed permission check with ticket.agent lookup.
This commit is contained in:
parent
a0e0dfcc3a
commit
93345553ad
2 changed files with 47 additions and 1 deletions
|
@ -303,7 +303,7 @@ module HasGroups
|
||||||
instances = joins(group_through.name)
|
instances = joins(group_through.name)
|
||||||
.where( group_through.table_name => { group_id: group_id, access: access }, active: true )
|
.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')
|
permissions = Permission.with_parents('ticket.agent')
|
||||||
instances = instances
|
instances = instances
|
||||||
.joins(roles: :permissions)
|
.joins(roles: :permissions)
|
||||||
|
|
|
@ -866,4 +866,50 @@ class UserTest < ActiveSupport::TestCase
|
||||||
assert_equal(1, admin_count_inital)
|
assert_equal(1, admin_count_inital)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue