Maintenance: Improved article view for agent customer.
This commit is contained in:
parent
28944de180
commit
cf5a5e3960
4 changed files with 19 additions and 2 deletions
|
@ -55,9 +55,9 @@ class Ticket::ArticlePolicy < ApplicationPolicy
|
||||||
end
|
end
|
||||||
|
|
||||||
def access?(query)
|
def access?(query)
|
||||||
return false if record.internal == true && !user.permissions?('ticket.agent')
|
|
||||||
|
|
||||||
ticket = Ticket.lookup(id: record.ticket_id)
|
ticket = Ticket.lookup(id: record.ticket_id)
|
||||||
|
return false if record.internal == true && !TicketPolicy.new(user, ticket).agent_read_access?
|
||||||
|
|
||||||
Pundit.authorize(user, ticket, query)
|
Pundit.authorize(user, ticket, query)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,6 +41,10 @@ class TicketPolicy < ApplicationPolicy
|
||||||
raise Exceptions::UnprocessableEntity, 'Cannot follow-up on a closed ticket. Please create a new ticket.'
|
raise Exceptions::UnprocessableEntity, 'Cannot follow-up on a closed ticket. Please create a new ticket.'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def agent_read_access?
|
||||||
|
agent_access?('read')
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def access?(access)
|
def access?(access)
|
||||||
|
|
|
@ -8,6 +8,10 @@ FactoryBot.define do
|
||||||
permissions { Permission.where(name: 'ticket.agent') }
|
permissions { Permission.where(name: 'ticket.agent') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :customer do
|
||||||
|
permissions { Permission.where(name: 'ticket.customer') }
|
||||||
|
end
|
||||||
|
|
||||||
trait :admin do
|
trait :admin do
|
||||||
permissions { Permission.where(name: 'admin') }
|
permissions { Permission.where(name: 'admin') }
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,15 @@ describe Ticket::ArticlePolicy do
|
||||||
it { is_expected.to permit_actions(%i[show]) }
|
it { is_expected.to permit_actions(%i[show]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when agent and customer but no agent group access' do
|
||||||
|
let(:user) do
|
||||||
|
customer_role = create(:role, :customer)
|
||||||
|
create(:agent_and_customer, roles: [customer_role])
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.not_to permit_actions(%i[show]) }
|
||||||
|
end
|
||||||
|
|
||||||
context 'when customer' do
|
context 'when customer' do
|
||||||
let(:user) { ticket_customer }
|
let(:user) { ticket_customer }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue