Skip to content

Commit

Permalink
Maintenance: Improved article view for agent customer.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfschmidt authored and thorsteneckel committed Nov 6, 2020
1 parent d9de9ca commit bf573b4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/policies/ticket/article_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def deletable_timeframe
end

def access?(query)
return false if record.internal == true && !user.permissions?('ticket.agent')

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)
end
end
4 changes: 4 additions & 0 deletions app/policies/ticket_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def follow_up?
raise Exceptions::UnprocessableEntity, 'Cannot follow-up on a closed ticket. Please create a new ticket.'
end

def agent_read_access?
agent_access?('read')
end

private

def access?(access)
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
permissions { Permission.where(name: 'ticket.agent') }
end

trait :customer do
permissions { Permission.where(name: 'ticket.customer') }
end

trait :admin do
permissions { Permission.where(name: 'admin') }
end
Expand Down
9 changes: 9 additions & 0 deletions spec/policies/ticket/article_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
it { is_expected.to permit_actions(%i[show]) }
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
let(:user) { ticket_customer }

Expand Down

0 comments on commit bf573b4

Please sign in to comment.