content_policy_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe KnowledgeBase::Answer::Translation::ContentPolicy do
  4. subject(:policy) { described_class.new(user, record) }
  5. include_context 'basic Knowledge Base'
  6. let(:record) { answer.translation.content }
  7. context 'without user' do
  8. let(:user) { nil }
  9. context 'with a public answer' do
  10. let(:answer) { published_answer }
  11. it { is_expected.to permit_actions :show }
  12. it { is_expected.to forbid_actions :destroy }
  13. end
  14. context 'with a non public answer' do
  15. let(:answer) { internal_answer }
  16. it { is_expected.to forbid_actions :show, :destroy }
  17. end
  18. end
  19. context 'with kb editor' do
  20. let(:user) { create(:admin) }
  21. context 'with an internal answer' do
  22. let(:answer) { internal_answer }
  23. it { is_expected.to permit_actions :show, :destroy }
  24. end
  25. context 'with a draft answer' do
  26. let(:answer) { draft_answer }
  27. it { is_expected.to permit_actions :show, :destroy }
  28. end
  29. end
  30. context 'with kb reader' do
  31. let(:user) { create(:agent) }
  32. context 'with an internal answer' do
  33. let(:answer) { internal_answer }
  34. it { is_expected.to permit_action :show }
  35. it { is_expected.to forbid_action :destroy }
  36. end
  37. context 'with a draft answer' do
  38. let(:answer) { draft_answer }
  39. it { is_expected.to forbid_actions :show, :destroy }
  40. end
  41. end
  42. end