group_policy_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe GroupPolicy do
  4. subject { described_class.new(user, record) }
  5. let(:record) { create(:group) }
  6. context 'when user is admin' do
  7. let(:user) { create(:admin) }
  8. it { is_expected.to permit_actions(:show) }
  9. end
  10. context 'when user is agent' do
  11. let(:user) { create(:agent) }
  12. context 'when user has access to group' do
  13. before { user.groups << record }
  14. it { is_expected.to permit_actions(:show) }
  15. end
  16. context 'when user does not have access to group' do
  17. it { is_expected.to forbid_actions(:show) }
  18. end
  19. end
  20. context 'when user is customer' do
  21. let(:user) { create(:customer) }
  22. context 'when has ticket in group' do
  23. before { create(:ticket, group: record, customer: user) }
  24. it { is_expected.to permit_actions(:show) }
  25. end
  26. context 'when group is in customer_ticket_create_group_ids' do
  27. before do
  28. Setting.set('customer_ticket_create_group_ids', [record.id])
  29. end
  30. it { is_expected.to permit_actions(:show) }
  31. end
  32. context 'when customer_ticket_create_group_ids is empty and thus all groups are permitted' do
  33. before do
  34. Setting.set('customer_ticket_create_group_ids', [])
  35. end
  36. it { is_expected.to permit_actions(:show) }
  37. end
  38. context 'when group is not in customer_ticket_create_group_ids' do
  39. before do
  40. Setting.set('customer_ticket_create_group_ids', [record.id + 1])
  41. end
  42. context 'when has no ticket in a group' do
  43. it { is_expected.to forbid_actions(:show) }
  44. end
  45. end
  46. end
  47. end